-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Modified Twist imports to work with Jazzy. Also added Joy Teleop #1134
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
base: jazzy
Are you sure you want to change the base?
Changes from 1 commit
579e06e
3950a8e
d3253e0
afca8af
5c25d36
33f0dd8
f1d02f4
c5522a5
2de8205
d93f505
107b6c7
501a3fc
94f40f6
2d39e36
de213b8
23a4906
bfce208
5b9d8a1
02441cf
e1b0ec6
769be3e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| from launch import LaunchDescription | ||
| from launch_ros.actions import Node | ||
| from launch.actions import IncludeLaunchDescription | ||
| from launch.launch_description_sources import PythonLaunchDescriptionSource | ||
| from launch.substitutions import PathJoinSubstitution | ||
| from launch_ros.substitutions import FindPackageShare | ||
|
|
||
|
|
||
| def generate_launch_description(): | ||
|
|
||
| # Include the robot bringup launch file | ||
| robot_bringup = IncludeLaunchDescription( | ||
| PythonLaunchDescriptionSource([ | ||
| PathJoinSubstitution([ | ||
| FindPackageShare('turtlebot3_bringup'), | ||
| 'launch', | ||
| 'robot.launch.py' | ||
| ]) | ||
| ]) | ||
| ) | ||
|
|
||
| # Joy node to read joystick | ||
| joy_node = Node( | ||
| package='joy', | ||
| executable='joy_node', | ||
| name='joy_node' | ||
| ) | ||
|
|
||
| # Teleop node to convert joy to cmd_vel | ||
| teleop_node = Node( | ||
| package='teleop_twist_joy', | ||
| executable='teleop_node', | ||
| name='teleop_twist_joy_node', | ||
| parameters=[{ | ||
| 'axis_linear.x': 1, | ||
| 'axis_angular.yaw': 3, | ||
| 'publish_stamped_twist': True, | ||
| 'scale_linear.x': 0.5, | ||
| 'scale_angular.yaw': 0.5, | ||
| }] | ||
| ) | ||
|
|
||
| return LaunchDescription([ | ||
| robot_bringup, | ||
| joy_node, | ||
| teleop_node | ||
| ]) |
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -21,7 +21,7 @@ | |||||||||||
| import time | ||||||||||||
|
|
||||||||||||
| from geometry_msgs.msg import Point | ||||||||||||
| from geometry_msgs.msg import Twist | ||||||||||||
| from geometry_msgs.msg import Twist, TwistStamped | ||||||||||||
| from nav_msgs.msg import Odometry | ||||||||||||
| import rclpy | ||||||||||||
| from rclpy.action import ActionServer | ||||||||||||
|
|
@@ -50,7 +50,7 @@ def __init__(self): | |||||||||||
| goal_callback=self.goal_callback) | ||||||||||||
|
|
||||||||||||
| self.goal_msg = Patrol.Goal() | ||||||||||||
| self.twist = Twist() | ||||||||||||
| self.twist = TwistStamped() | ||||||||||||
| self.odom = Odometry() | ||||||||||||
| self.position = Point() | ||||||||||||
| self.rotation = 0.0 | ||||||||||||
|
|
@@ -60,15 +60,15 @@ def __init__(self): | |||||||||||
|
|
||||||||||||
| qos = QoSProfile(depth=10) | ||||||||||||
|
|
||||||||||||
| self.cmd_vel_pub = self.create_publisher(Twist, 'cmd_vel', qos) | ||||||||||||
| self.cmd_vel_pub = self.create_publisher(TwistStamped, 'cmd_vel', qos) | ||||||||||||
|
|
||||||||||||
| self.odom_sub = self.create_subscription( | ||||||||||||
| Odometry, 'odom', self.odom_callback, qos | ||||||||||||
| ) | ||||||||||||
|
|
||||||||||||
| def init_twist(self): | ||||||||||||
| self.twist.linear.x = 0.0 | ||||||||||||
| self.twist.angular.z = 0.0 | ||||||||||||
| self.twist.twist.linear.x = 0.0 | ||||||||||||
| self.twist.twist.angular.z = 0.0 | ||||||||||||
| self.cmd_vel_pub.publish(self.twist) | ||||||||||||
|
|
||||||||||||
| def odom_callback(self, msg): | ||||||||||||
|
|
@@ -82,11 +82,11 @@ def get_yaw(self): | |||||||||||
|
|
||||||||||||
| def go_front(self, position, length): | ||||||||||||
| while True: | ||||||||||||
| position += self.twist.linear.x | ||||||||||||
| position += self.twist.twist.linear.x | ||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There appears to be a logic error here. You are incrementing A more robust implementation would use odometry to track the actual distance traveled instead of relying on
Suggested change
|
||||||||||||
| if position >= length: | ||||||||||||
| break | ||||||||||||
| self.twist.linear.x = self.linear_x | ||||||||||||
| self.twist.angular.z = 0.0 | ||||||||||||
| self.twist.twist.linear.x = self.linear_x | ||||||||||||
| self.twist.twist.angular.z = 0.0 | ||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Suggested change
|
||||||||||||
| self.cmd_vel_pub.publish(self.twist) | ||||||||||||
|
|
||||||||||||
| time.sleep(1) | ||||||||||||
|
|
@@ -110,8 +110,8 @@ def turn(self, target_angle): | |||||||||||
| if yaw_diff < 0.01: | ||||||||||||
| break | ||||||||||||
|
|
||||||||||||
| self.twist.linear.x = 0.0 | ||||||||||||
| self.twist.angular.z = self.angular_z | ||||||||||||
| self.twist.twist.linear.x = 0.0 | ||||||||||||
| self.twist.twist.angular.z = self.angular_z | ||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As in other parts of the file, the timestamp in the
Suggested change
|
||||||||||||
| self.cmd_vel_pub.publish(self.twist) | ||||||||||||
|
|
||||||||||||
| self.init_twist() | ||||||||||||
|
|
||||||||||||
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.
When using
TwistStampedmessages, it's crucial to populate theheaderfield, especially the timestamp, before publishing. This allows other nodes to know when the command was issued. You should update the timestamp every time you are about to publish the message.Additionally, it would be good practice to set the
frame_idin the__init__method, for example:self.twist.header.frame_id = 'base_link'.