forked from CMU-Robotics-Club/RoboBuggy2
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Velocity port done #20
Open
JoyceZhu2486
wants to merge
16
commits into
main
Choose a base branch
from
velocity-port
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
fc57679
move files from simulation-velocity-port
JoyceZhu2486 441020c
move files from simulation-velocity-port
JoyceZhu2486 911509d
copy paste files from simulation-velocity-port
JoyceZhu2486 9701efe
fix file reading
JoyceZhu2486 73dbccb
Merge branch 'velocity-port' of https://github.com/CMU-Robotics-Club/…
JoyceZhu2486 2b6ab24
fix merge error
JoyceZhu2486 8923009
fix merge error
JoyceZhu2486 d32f012
fix velocity publisher and wrong topic name for subscriber error
JoyceZhu2486 765f2b9
fix unused import
JoyceZhu2486 3060cce
add environment variable for the file path of checkpoints
JoyceZhu2486 08b2e29
add environment variable for the file path of checkpoints
JoyceZhu2486 283f95b
fix minor error in xml
JoyceZhu2486 cbcd1df
Merge branch 'main' into velocity-port
mehulgoel873 edb7b9f
add yaml file and change launch file for launch parameters
JoyceZhu2486 70fe750
Merge branch 'velocity-port' of https://github.com/CMU-Robotics-Club/…
JoyceZhu2486 0c898d6
add a txt file for explaining each checkpoints.json file because we c…
JoyceZhu2486 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
#!/bin/sh | ||
export RBROOT=/rb_ws | ||
export PYTHONPATH=$PYTHONPATH:$RBROOT/src/buggy/scripts | ||
export TRAJPATH=$RBROOT/src/buggy/paths/ | ||
export TRAJPATH=$RBROOT/src/buggy/paths/ | ||
export VELPATH=$RBROOT/src/buggy/scripts/simulator/velocity_checkpoints/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/**: # Global Params | ||
ros__parameters: | ||
traj_name: "buggycourse_safe.json" | ||
checkpoints_name : "buggycourse_safe_checkpoints_1.json" | ||
|
||
|
||
SC: | ||
SC_sim_single: | ||
ros__parameters: | ||
velocity: 12 | ||
pose: "Hill1_SC" | ||
|
||
SC: | ||
SC_controller: | ||
ros__parameters: | ||
dist: 0.0 | ||
# traj_name: "buggycourse_safe.json" | ||
controller: "stanley" | ||
|
||
SC: | ||
SC_path_planner: | ||
ros__parameters: | ||
traj_name: "buggycourse_safe.json" | ||
curb_name: "buggycourse_curb.json" | ||
|
||
SC: | ||
SC_velocity_updater: | ||
ros__parameters: | ||
init_vel: 12 | ||
checkpoints_name : "buggycourse_safe_checkpoints_1.json" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,18 @@ | ||
<launch> | ||
|
||
<arg name="config_file" default="src/buggy/config/sim_single_sc.yaml"/> | ||
|
||
<node pkg="foxglove_bridge" exec="foxglove_bridge" name="foxglove" namespace="SC"/> | ||
|
||
<node pkg="buggy" exec="engine.py" name="SC_sim_single" namespace="SC"> | ||
<param from="$(var config_file)"/> | ||
<node pkg="buggy" exec="hello_world" name="hello_world" namespace="SC" /> | ||
<node pkg="buggy" exec="sim_single" name="SC_sim_single" namespace="SC"> | ||
<param name="velocity" value="12"/> | ||
<param name="pose" value="Hill1_SC"/> | ||
</node> | ||
<node pkg="buggy" exec="buggy_state_converter.py" name="SC_state_converter" namespace="SC"/> | ||
<node pkg="buggy" exec="controller_node.py" name="SC_controller" namespace="SC"> | ||
<param from="$(var config_file)"/> | ||
<node pkg="buggy" exec="sim_single" name="NAND_sim_single" namespace="NAND"> | ||
<param name="velocity" value="12"/> | ||
<param name="pose" value="Hill1_NAND"/> | ||
</node> | ||
|
||
<!-- <node name="foxglove" pkg="foxglove_bridge" type="foxglove_bridge" /> | ||
<node name="hello_world" pkg="buggy" type="hello_world" /> --> | ||
|
||
<node pkg="buggy" exec="watchdog_node.py" name="SC_watchdog" namespace="SC"/> | ||
</launch> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<launch> | ||
|
||
<arg name="config_file" default="src/buggy/config/sim_single_velocity.yaml"/> | ||
|
||
<node pkg="foxglove_bridge" exec="foxglove_bridge" name="foxglove" output = "screen" namespace="SC"/> | ||
|
||
<node pkg="buggy" exec="buggy_state_converter.py" name="SC_state_converter" output = "screen" namespace="SC"/> | ||
<node pkg="buggy" exec="controller_node.py" name="SC_controller" output = "screen" namespace="SC"> | ||
<param from="$(var config_file)"/> | ||
</node> | ||
<node pkg="buggy" exec="engine.py" name="SC_sim_single" output = "screen" namespace="SC"> | ||
<param from="$(var config_file)"/> | ||
</node> | ||
<node pkg="buggy" exec="path_planner.py" name="SC_path_planner" namespace="SC" output = "screen"> | ||
<param from="$(var config_file)"/> | ||
</node> | ||
<node pkg="buggy" exec="velocity_updater.py" name="SC_velocity_updater" namespace="SC"> | ||
<param from="$(var config_file)"/> | ||
</node> | ||
|
||
</launch> |
17 changes: 17 additions & 0 deletions
17
rb_ws/src/buggy/scripts/simulator/velocity_checkpoints/buggycourse_safe_checkpoints_1.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"checkpoints": | ||
[ | ||
{ | ||
"x-pos": 589700, | ||
"y-pos": 4477159, | ||
"radius": 20, | ||
"velocity": 12.345 | ||
}, | ||
{ | ||
"x-pos": 589685, | ||
"y-pos": 4477153, | ||
"radius": 20, | ||
"velocity": 17.234 | ||
} | ||
] | ||
} |
5 changes: 5 additions & 0 deletions
5
rb_ws/src/buggy/scripts/simulator/velocity_checkpoints/checkpoints_explained.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Each checkpoints file have a corresponding traj file. Each traj file may have multiple checkpoints file. | ||
Each checkpoints file also needs explaination and comments on the source of data. That is what this file does.\ | ||
|
||
Checkpoints File | Corresponding Traj File | Data Source and/or comments | ||
buggycourse_safe_checkpoints_1.json | buggycourse_safe.json | Nonsense data for testing only with on decrease and than increase in velocity |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
#! /usr/bin/env python3 | ||
import os | ||
import math | ||
import threading | ||
import json | ||
import rclpy | ||
from rclpy.node import Node | ||
from geometry_msgs.msg import Pose | ||
from geometry_msgs.msg import Point | ||
from std_msgs.msg import Float64 | ||
|
||
class VelocityUpdater(Node): | ||
RATE = 100 | ||
|
||
def __init__(self): | ||
super().__init__('velocity_updater') | ||
self.get_logger().info('INITIALIZED.') | ||
|
||
# Bubbles for updating acceleration based on position | ||
# represented as {x-pos, y-pos, radius, velocity} | ||
# imported from a json file corresponding to the path | ||
self.declare_parameter("checkpoints_name", "buggycourse_safe_checkpoints_1.json") | ||
checkpoints_name = self.get_parameter("checkpoints_name").value | ||
checkpoints_path = os.environ["VELPATH"] + checkpoints_name | ||
with open(checkpoints_path, 'r') as checkpoints_file: | ||
self.CHECKPOINTS = (json.load(checkpoints_file))["checkpoints"] | ||
|
||
# Declare parameters with default values | ||
self.declare_parameter('init_vel', 12) | ||
self.declare_parameter('buggy_name', 'SC') | ||
mehulgoel873 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# Get the parameter values | ||
self.init_vel = self.get_parameter("init_vel").value | ||
self.buggy_name = self.get_parameter("buggy_name").value | ||
|
||
# initialize variables | ||
self.buggy_vel = self.init_vel | ||
self.debug_dist = 0 | ||
|
||
self.position = Point() | ||
self.lock = threading.Lock() | ||
|
||
# subscribe sim_2d/utm for position values | ||
self.pose_subscriber = self.create_subscription( | ||
Pose, | ||
"sim_2d/utm", | ||
self.update_position, | ||
1 | ||
) | ||
|
||
# publish velocity to "sim/velocity" | ||
self.velocity_publisher = self.create_publisher(Float64, "sim/velocity", 1) | ||
|
||
# ROS2 timer for stepping | ||
self.timer = self.create_timer(1.0 / self.RATE, self.step) | ||
|
||
def update_position(self, new_pose: Pose): | ||
'''Callback function to update internal position variable when new | ||
buggy position is published | ||
|
||
Args: | ||
new_pose (Pose): Pose object from topic | ||
''' | ||
with self.lock: | ||
self.position = new_pose.position | ||
|
||
def check_velocity(self): | ||
'''Check if the position of the buggy is in any of the checkpoints set | ||
in self.CHECKPOINTS, and update velocity of buggy accordingly | ||
''' | ||
for checkpoint in self.CHECKPOINTS: | ||
x = checkpoint["x-pos"] | ||
y = checkpoint["y-pos"] | ||
r = checkpoint["radius"] | ||
v = checkpoint["velocity"] | ||
dist = math.sqrt((x-self.position.x)**2 + (y-self.position.y)**2) | ||
self.debug_dist = dist | ||
if dist < r: | ||
self.buggy_vel = v | ||
break | ||
|
||
def step(self): | ||
'''Update velocity of buggy for one timestep | ||
and publish it so that the simulator engine can subscribe and use it''' | ||
|
||
# update velocity | ||
self.check_velocity() | ||
|
||
# publish velocity | ||
float_64_velocity = Float64() | ||
float_64_velocity.data = float(self.buggy_vel) | ||
self.velocity_publisher.publish(float_64_velocity) | ||
|
||
|
||
def main(args=None): | ||
rclpy.init(args=args) | ||
vel_updater = VelocityUpdater() | ||
rclpy.spin(vel_updater) | ||
rclpy.shutdown() | ||
|
||
if __name__ == "__main__": | ||
main() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to label these points, at least in the JSON for visual reference?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a txt file to record the corresponding traj file, data source and comments for each checkpoints.json file