From 88c22fc719d8d39607bee824c1828cf94c272fa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ellensohn?= Date: Tue, 25 Jul 2023 13:00:05 +0200 Subject: [PATCH] switched to different style: ditching timer --- rmp220_teleop/rmp220_teleop.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/rmp220_teleop/rmp220_teleop.py b/rmp220_teleop/rmp220_teleop.py index 07f9cb6..67461cd 100644 --- a/rmp220_teleop/rmp220_teleop.py +++ b/rmp220_teleop/rmp220_teleop.py @@ -9,7 +9,6 @@ class TeleopTwistJoy(Node): super().__init__('teleop_twist_joy') self.cmd_vel_pub = self.create_publisher(Twist, '/diffbot_base_controller/cmd_vel_unstamped', 10) self.joy_sub = self.create_subscription(Joy, 'joy', self.joy_callback, 10) - self.timer = self.create_timer(0.01, self.timer_callback) # 100 Hz self.twist = Twist() self.vFactor = 1 # if compensation is needed. Not needed anymore for bot_mini self.limit = 1 * self.vFactor @@ -27,8 +26,9 @@ class TeleopTwistJoy(Node): self.twist.linear.x = self.limit * joy_msg.axes[1] self.twist.angular.z = self.limit * joy_msg.axes[0] * 1 * 3.141592 - def timer_callback(self): - self.cmd_vel_pub.publish(self.twist) + # Publish the twist message only when joystick keys are pressed + if joy_msg.buttons[4] or joy_msg.buttons[5] or joy_msg.axes[1] != 0.0 or joy_msg.axes[0] != 0.0: + self.cmd_vel_pub.publish(self.twist) def main(args=None): @@ -39,7 +39,6 @@ def main(args=None): except KeyboardInterrupt: teleop_twist_joy.destroy_node() rclpy.shutdown() - if __name__ == '__main__': main()