From 58bc706c8193cd6f302702ef1e16c4409ef93980 Mon Sep 17 00:00:00 2001 From: TiaSinghania Date: Fri, 10 Jan 2025 13:15:17 -0800 Subject: [PATCH 1/9] minor sim fixes --- rb_ws/src/buggy/buggy/simulator/engine.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rb_ws/src/buggy/buggy/simulator/engine.py b/rb_ws/src/buggy/buggy/simulator/engine.py index b3cb774..6c7e7ad 100644 --- a/rb_ws/src/buggy/buggy/simulator/engine.py +++ b/rb_ws/src/buggy/buggy/simulator/engine.py @@ -10,7 +10,7 @@ import numpy as np import utm sys.path.append("/rb_ws/src/buggy/buggy") -from rb_ws.src.buggy.buggy.util.constants import Constants +from util.constants import Constants class Simulator(Node): @@ -130,7 +130,7 @@ def publish(self): with self.lock: p.position.x = self.e_utm p.position.y = self.n_utm - p.position.z = self.heading + p.position.z = float(self.heading) velocity = self.velocity self.plot_publisher.publish(p) From ad11394ea9f0fe2c528c543a8574c7dc40e46295 Mon Sep 17 00:00:00 2001 From: TiaSinghania Date: Fri, 10 Jan 2025 14:04:22 -0800 Subject: [PATCH 2/9] added env vars (in yaml not in env.dev) --- .env.dev | 3 +++ docker-dev.yml | 4 ++++ rb_ws/src/buggy/buggy/controller/controller_node.py | 6 +----- rb_ws/src/buggy/buggy/controller/controller_superclass.py | 2 -- rb_ws/src/buggy/buggy/controller/stanley_controller.py | 2 -- rb_ws/src/buggy/buggy/simulator/engine.py | 4 +--- 6 files changed, 9 insertions(+), 12 deletions(-) diff --git a/.env.dev b/.env.dev index baed5be..8f6619e 100755 --- a/.env.dev +++ b/.env.dev @@ -3,3 +3,6 @@ WEBCAM_PORT=/dev/null RLSENSE_PORT=/dev/null TEENSY_PORT=/dev/null FEATHER_PORT=/dev/null +ROOT_DIR="/rb_ws/src/buggy" +SCRIPTS_DIR="$ROOT_DIR/buggy" + diff --git a/docker-dev.yml b/docker-dev.yml index 65470a1..c2000e5 100755 --- a/docker-dev.yml +++ b/docker-dev.yml @@ -12,8 +12,12 @@ services: - "${FEATHER_PORT:-/dev/null}:/dev/ttyACM1" stdin_open: true # docker run -i tty: true # docker run -t + env_file: .env.dev environment: - DISPLAY=host.docker.internal:0 + - ROOT_DIR=${ROOT_DIR:-/rb_ws/src/buggy} + - SCRIPTS_DIR=${SCRIPTS_DIR:-/rb_ws/src/buggy/buggy} + - PYTHONPATH=${SCRIPTS_DIR:-/rb_ws/src/buggy/buggy} hostname: main ports: - "0.0.0.0:8765:8765" # foxglove bridge diff --git a/rb_ws/src/buggy/buggy/controller/controller_node.py b/rb_ws/src/buggy/buggy/controller/controller_node.py index 9d13593..df1b418 100644 --- a/rb_ws/src/buggy/buggy/controller/controller_node.py +++ b/rb_ws/src/buggy/buggy/controller/controller_node.py @@ -1,15 +1,11 @@ import threading -import sys - import numpy as np - import rclpy from rclpy.node import Node from std_msgs.msg import Float32, Float64, Bool from nav_msgs.msg import Odometry -sys.path.append("/rb_ws/src/buggy/buggy") from util.trajectory import Trajectory from controller.stanley_controller import StanleyController @@ -21,7 +17,7 @@ def __init__(self): Creates a ROS node with a publisher that periodically sends a message indicating whether the node is still alive. - + """ super().__init__('controller') self.get_logger().info('INITIALIZED.') diff --git a/rb_ws/src/buggy/buggy/controller/controller_superclass.py b/rb_ws/src/buggy/buggy/controller/controller_superclass.py index f960de7..905d606 100644 --- a/rb_ws/src/buggy/buggy/controller/controller_superclass.py +++ b/rb_ws/src/buggy/buggy/controller/controller_superclass.py @@ -1,10 +1,8 @@ from abc import ABC, abstractmethod -import sys from nav_msgs.msg import Odometry -sys.path.append("/rb_ws/src/buggy/buggy") from util.trajectory import Trajectory class Controller(ABC): diff --git a/rb_ws/src/buggy/buggy/controller/stanley_controller.py b/rb_ws/src/buggy/buggy/controller/stanley_controller.py index 3407653..b5f69ca 100644 --- a/rb_ws/src/buggy/buggy/controller/stanley_controller.py +++ b/rb_ws/src/buggy/buggy/controller/stanley_controller.py @@ -1,11 +1,9 @@ -import sys import numpy as np from sensor_msgs.msg import NavSatFix from geometry_msgs.msg import Pose as ROSPose from nav_msgs.msg import Odometry -sys.path.append("/rb_ws/src/buggy/buggy") from util.trajectory import Trajectory from controller.controller_superclass import Controller from util.pose import Pose diff --git a/rb_ws/src/buggy/buggy/simulator/engine.py b/rb_ws/src/buggy/buggy/simulator/engine.py index 6c7e7ad..b6047f1 100644 --- a/rb_ws/src/buggy/buggy/simulator/engine.py +++ b/rb_ws/src/buggy/buggy/simulator/engine.py @@ -1,6 +1,6 @@ #! /usr/bin/env python3 import threading -import sys + import rclpy from rclpy.node import Node from geometry_msgs.msg import Pose, Twist, PoseWithCovariance, TwistWithCovariance @@ -9,7 +9,6 @@ from nav_msgs.msg import Odometry import numpy as np import utm -sys.path.append("/rb_ws/src/buggy/buggy") from util.constants import Constants class Simulator(Node): @@ -19,7 +18,6 @@ def __init__(self): super().__init__('sim_single') self.get_logger().info('INITIALIZED.') - self.starting_poses = { "Hill1_NAND": (Constants.UTM_EAST_ZERO + 0, Constants.UTM_NORTH_ZERO + 0, -110), "Hill1_SC": (Constants.UTM_EAST_ZERO + 20, Constants.UTM_NORTH_ZERO + 30, -110), From 6f292bd922e1a8bf6e1dfecd7e3e2ba3e76b2a05 Mon Sep 17 00:00:00 2001 From: TiaSinghania Date: Fri, 10 Jan 2025 14:05:13 -0800 Subject: [PATCH 3/9] futureproofing --- .env.dev | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.env.dev b/.env.dev index 8f6619e..c3681e7 100755 --- a/.env.dev +++ b/.env.dev @@ -1,3 +1,5 @@ +# NOTE: this file is not being used in docker compose correctly +# SET ALL ENVIRONMENT VARIABLES IN THE YAML GPS_PORT=/dev/null WEBCAM_PORT=/dev/null RLSENSE_PORT=/dev/null From 1d860d89f6e6d7f5253102a6c6ef57741c630b51 Mon Sep 17 00:00:00 2001 From: TiaSinghania Date: Fri, 10 Jan 2025 21:32:11 -0800 Subject: [PATCH 4/9] added bash script to set env vars outside of docker --- setup.bash | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 setup.bash diff --git a/setup.bash b/setup.bash new file mode 100644 index 0000000..5cf7476 --- /dev/null +++ b/setup.bash @@ -0,0 +1,4 @@ +#!/bin/bash + +export ROOT_DIR="/rb_ws" +export SCRIPTS_DIR="$ROOT_DIR/src/buggy/buggy" \ No newline at end of file From a3806318383e3c45b7a763331dcdc1dd4bacef65 Mon Sep 17 00:00:00 2001 From: Mehul Goel Date: Fri, 10 Jan 2025 22:25:14 -0800 Subject: [PATCH 5/9] removed dependence on python path --- rb_ws/src/buggy/scripts/controller/controller_node.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/rb_ws/src/buggy/scripts/controller/controller_node.py b/rb_ws/src/buggy/scripts/controller/controller_node.py index beefa05..316df8a 100755 --- a/rb_ws/src/buggy/scripts/controller/controller_node.py +++ b/rb_ws/src/buggy/scripts/controller/controller_node.py @@ -2,7 +2,6 @@ import threading import numpy as np -import sys import rclpy from rclpy.node import Node @@ -10,8 +9,6 @@ from nav_msgs.msg import Odometry from buggy.msg import TrajectoryMsg - -sys.path.append("/rb_ws/src/buggy/scripts") from util.trajectory import Trajectory from controller.stanley_controller import StanleyController From 600cf45ea74e26e969b3f18611c4dd623ef4aca6 Mon Sep 17 00:00:00 2001 From: Mehul Goel Date: Fri, 10 Jan 2025 23:10:42 -0800 Subject: [PATCH 6/9] added env_var support --- rb_ws/src/buggy/scripts/controller/controller_node.py | 3 ++- rb_ws/src/buggy/scripts/path_planner/path_planner.py | 7 +++---- rb_ws/src/buggy/scripts/simulator/engine.py | 1 + 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/rb_ws/src/buggy/scripts/controller/controller_node.py b/rb_ws/src/buggy/scripts/controller/controller_node.py index 316df8a..e52fb4b 100755 --- a/rb_ws/src/buggy/scripts/controller/controller_node.py +++ b/rb_ws/src/buggy/scripts/controller/controller_node.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 +import os import threading import numpy as np import rclpy @@ -32,7 +33,7 @@ def __init__(self): self.declare_parameter("traj_name", "buggycourse_safe.json") traj_name = self.get_parameter("traj_name").value - self.cur_traj = Trajectory(json_filepath="/rb_ws/src/buggy/paths/" + traj_name) #TODO: Fixed filepath, not good + self.cur_traj = Trajectory(json_filepath=os.environ["TRAJPATH"] + traj_name) #TODO: Fixed filepath, not good start_index = self.cur_traj.get_index_from_distance(start_dist) diff --git a/rb_ws/src/buggy/scripts/path_planner/path_planner.py b/rb_ws/src/buggy/scripts/path_planner/path_planner.py index a42e6a1..b43d40a 100755 --- a/rb_ws/src/buggy/scripts/path_planner/path_planner.py +++ b/rb_ws/src/buggy/scripts/path_planner/path_planner.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 -import sys +import os from threading import Lock import numpy as np @@ -12,7 +12,6 @@ from geometry_msgs.msg import Pose from buggy.msg import TrajectoryMsg -sys.path.append("/rb_ws/src/buggy/scripts") from util.trajectory import Trajectory class PathPlanner(Node): @@ -53,7 +52,7 @@ def __init__(self) -> None: #Parameters self.declare_parameter("traj_name", "buggycourse_safe.json") traj_name = self.get_parameter("traj_name").value - self.nominal_traj = Trajectory(json_filepath="/rb_ws/src/buggy/paths/" + traj_name) #TODO: Fixed filepath, not good + self.nominal_traj = Trajectory(json_filepath=os.environ["TRAJPATH"] + traj_name) #TODO: Fixed filepath, not good self.declare_parameter("curb_name", "") curb_name = self.get_parameter("curb_name").value @@ -61,7 +60,7 @@ def __init__(self) -> None: if curb_name is None: self.left_curb = None else: - self.left_curb = Trajectory(json_filepath="/rb_ws/src/buggy/paths/" + curb_name) #TODO: Fixed filepath, not good + self.left_curb = Trajectory(json_filepath=os.environ["TRAJPATH"] + curb_name) #TODO: Fixed filepath, not good #Publishers self.other_buggy_xtrack_publisher = self.create_publisher(Float64, "debug/other_buggy_xtrack", 10) diff --git a/rb_ws/src/buggy/scripts/simulator/engine.py b/rb_ws/src/buggy/scripts/simulator/engine.py index 25694e7..0b802ef 100755 --- a/rb_ws/src/buggy/scripts/simulator/engine.py +++ b/rb_ws/src/buggy/scripts/simulator/engine.py @@ -1,6 +1,7 @@ #! /usr/bin/env python3 import threading import rclpy +import time from rclpy.node import Node from geometry_msgs.msg import Pose, Twist, PoseWithCovariance, TwistWithCovariance from std_msgs.msg import Float64 From 0495c9421793b52429e2b29db33e6e20a639f36c Mon Sep 17 00:00:00 2001 From: Mehul Goel Date: Fri, 10 Jan 2025 23:10:55 -0800 Subject: [PATCH 7/9] added env var for docker environment, waiting for SC and NAND --- .env.dev | 2 -- Dockerfile | 3 ++- docker-dev.yml | 3 --- rb_ws/environments/docker_env.bash | 4 ++++ 4 files changed, 6 insertions(+), 6 deletions(-) create mode 100755 rb_ws/environments/docker_env.bash diff --git a/.env.dev b/.env.dev index c3681e7..54a8182 100755 --- a/.env.dev +++ b/.env.dev @@ -5,6 +5,4 @@ WEBCAM_PORT=/dev/null RLSENSE_PORT=/dev/null TEENSY_PORT=/dev/null FEATHER_PORT=/dev/null -ROOT_DIR="/rb_ws/src/buggy" -SCRIPTS_DIR="$ROOT_DIR/buggy" diff --git a/Dockerfile b/Dockerfile index 4ffeb8d..9b0305e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,7 +24,8 @@ RUN echo 'source "/opt/ros/humble/setup.bash" --' >> ~/.bashrc && \ echo 'cd rb_ws' >> ~/.bashrc && \ echo 'colcon build --symlink-install' >> ~/.bashrc && \ echo 'source install/local_setup.bash' >> ~/.bashrc && \ - echo 'chmod -R +x src/buggy/scripts/' >> ~/.bashrc + echo 'chmod -R +x src/buggy/scripts/' >> ~/.bashrc && \ + echo 'source environments/docker_env.bash' >> ~/.bashrc # add mouse to tmux RUN echo 'set -g mouse on' >> ~/.tmux.conf diff --git a/docker-dev.yml b/docker-dev.yml index c2000e5..6dd0db3 100755 --- a/docker-dev.yml +++ b/docker-dev.yml @@ -15,9 +15,6 @@ services: env_file: .env.dev environment: - DISPLAY=host.docker.internal:0 - - ROOT_DIR=${ROOT_DIR:-/rb_ws/src/buggy} - - SCRIPTS_DIR=${SCRIPTS_DIR:-/rb_ws/src/buggy/buggy} - - PYTHONPATH=${SCRIPTS_DIR:-/rb_ws/src/buggy/buggy} hostname: main ports: - "0.0.0.0:8765:8765" # foxglove bridge diff --git a/rb_ws/environments/docker_env.bash b/rb_ws/environments/docker_env.bash new file mode 100755 index 0000000..f580c4d --- /dev/null +++ b/rb_ws/environments/docker_env.bash @@ -0,0 +1,4 @@ +#!/bin/sh +export RBROOT=/rb_ws +export PYTHONPATH=$PYTHONPATH:$RBROOT/src/buggy/scripts +export TRAJPATH=$RBROOT/src/buggy/paths/ \ No newline at end of file From 8c3404449ee72d7817d02d67c7992e8bdca3693c Mon Sep 17 00:00:00 2001 From: Mehul Goel Date: Fri, 10 Jan 2025 23:14:36 -0800 Subject: [PATCH 8/9] pylint --- rb_ws/src/buggy/scripts/simulator/engine.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rb_ws/src/buggy/scripts/simulator/engine.py b/rb_ws/src/buggy/scripts/simulator/engine.py index 0b802ef..6c89591 100755 --- a/rb_ws/src/buggy/scripts/simulator/engine.py +++ b/rb_ws/src/buggy/scripts/simulator/engine.py @@ -1,7 +1,7 @@ #! /usr/bin/env python3 import threading -import rclpy import time +import rclpy from rclpy.node import Node from geometry_msgs.msg import Pose, Twist, PoseWithCovariance, TwistWithCovariance from std_msgs.msg import Float64 From 211d64893b9615b29866f80efe82fd25db4f47cc Mon Sep 17 00:00:00 2001 From: Mehul Goel Date: Mon, 13 Jan 2025 20:24:19 -0500 Subject: [PATCH 9/9] fixed according to saransh --- rb_ws/src/buggy/scripts/controller/controller_node.py | 2 +- rb_ws/src/buggy/scripts/path_planner/path_planner.py | 4 ++-- setup.bash | 4 ---- 3 files changed, 3 insertions(+), 7 deletions(-) delete mode 100644 setup.bash diff --git a/rb_ws/src/buggy/scripts/controller/controller_node.py b/rb_ws/src/buggy/scripts/controller/controller_node.py index e52fb4b..438cd6f 100755 --- a/rb_ws/src/buggy/scripts/controller/controller_node.py +++ b/rb_ws/src/buggy/scripts/controller/controller_node.py @@ -33,7 +33,7 @@ def __init__(self): self.declare_parameter("traj_name", "buggycourse_safe.json") traj_name = self.get_parameter("traj_name").value - self.cur_traj = Trajectory(json_filepath=os.environ["TRAJPATH"] + traj_name) #TODO: Fixed filepath, not good + self.cur_traj = Trajectory(json_filepath=os.environ["TRAJPATH"] + traj_name) start_index = self.cur_traj.get_index_from_distance(start_dist) diff --git a/rb_ws/src/buggy/scripts/path_planner/path_planner.py b/rb_ws/src/buggy/scripts/path_planner/path_planner.py index b43d40a..2f27706 100755 --- a/rb_ws/src/buggy/scripts/path_planner/path_planner.py +++ b/rb_ws/src/buggy/scripts/path_planner/path_planner.py @@ -52,7 +52,7 @@ def __init__(self) -> None: #Parameters self.declare_parameter("traj_name", "buggycourse_safe.json") traj_name = self.get_parameter("traj_name").value - self.nominal_traj = Trajectory(json_filepath=os.environ["TRAJPATH"] + traj_name) #TODO: Fixed filepath, not good + self.nominal_traj = Trajectory(json_filepath=os.environ["TRAJPATH"] + traj_name) self.declare_parameter("curb_name", "") curb_name = self.get_parameter("curb_name").value @@ -60,7 +60,7 @@ def __init__(self) -> None: if curb_name is None: self.left_curb = None else: - self.left_curb = Trajectory(json_filepath=os.environ["TRAJPATH"] + curb_name) #TODO: Fixed filepath, not good + self.left_curb = Trajectory(json_filepath=os.environ["TRAJPATH"] + curb_name) #Publishers self.other_buggy_xtrack_publisher = self.create_publisher(Float64, "debug/other_buggy_xtrack", 10) diff --git a/setup.bash b/setup.bash deleted file mode 100644 index 5cf7476..0000000 --- a/setup.bash +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -export ROOT_DIR="/rb_ws" -export SCRIPTS_DIR="$ROOT_DIR/src/buggy/buggy" \ No newline at end of file