Loading the lesson...
In the print dialog, choose "Save as PDF" as the destination.
Lab 04
Building a custom velocity-control node
Keypress
ROS node
Twist message
/cmd_vel
Robot moves in Gazebo
ROS nodes workwarehouse_simulationw : +0.1 m/s forward x : -0.1 m/s (backward)
a : +0.2 rad/s left turn d : -0.2 rad/s right turn
s : Stop SPACE : Emergency stop
q : Quit1.0 m/s, max angular 2.0 rad/sclass TeleopKeyNode(Node):
def __init__(self):
super().__init__('teleop_key')
self.publisher = self.create_publisher(Twist, '/cmd_vel', 10)
self.linear_velocity = 0.0
self.angular_velocity = 0.0
self.linear_step = 0.1
self.angular_step = 0.2
self.max_linear = 1.0
self.max_angular = 2.0__init__.Enter neededfinallydef get_key(self):
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(fd)
ch = sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
return chtermios settings are saved before tty.setraw and restored no matter what happens.def update_velocity(self, linear_change, angular_change):
self.linear_velocity += linear_change
self.angular_velocity += angular_change
self.linear_velocity = max(-self.max_linear,
min(self.max_linear, self.linear_velocity))
self.angular_velocity = max(-self.max_angular,
min(self.max_angular, self.angular_velocity))def publish_velocity(self):
msg = Twist()
msg.linear.x = self.linear_velocity
msg.angular.z = self.angular_velocity
self.publisher.publish(msg)linear.x (forward and back) and angular.z (yaw): no y/z motion or roll/pitchs or SPACE zero out both velocities immediatelyfinally block always stops the robot before the node exitselif key == 's' or key == ' ':
self.linear_velocity = 0.0
self.angular_velocity = 0.0
self.publish_velocity()SPACE and s share the same stop handler.setup.pychmod +x warehouse_simulation/teleop_key.pyentry_points={
'console_scripts': [
'teleop_key = warehouse_simulation.teleop_key:main',
],
},colcon build --packages-select warehouse_simulation
source install/setup.bashros2 launch warehouse_simulation warehouse_simulation.launch.py
ros2 run warehouse_simulation teleop_keyw three times to accelerate forwarda twice to turn lefts to stopx twice to reversed three times to turn rightSPACE for an emergency stopq to quitros2 topic echo /cmd_vel
ros2 node list
ros2 node info /teleop_key
ros2 run rqt_graph rqt_graph/teleop_key
/cmd_vel
/parameter_bridge
Gazebo
ros2 run teleop_twist_keyboard teleop_twist_keyboard (i/j/k/l layout)joy_node plus teleop_twist_joyTwist message to /cmd_vel to robot motionlinear.x and angular.z on a Twist messageEnterros2 topic echo, ros2 node info, and rqt_graph before trusting behavior/cmd_vel is the most common cause of a robot behaving oddlyMahmoud Abas|Lab 04: Keyboard Teleop Control for Warehouse Robot