mirror of
https://github.com/bjoernellens1/rmp220_teleop.git
synced 2024-11-25 17:20:54 +00:00
switched to different style: ditching timer
This commit is contained in:
parent
6361e36d44
commit
88c22fc719
@ -9,7 +9,6 @@ class TeleopTwistJoy(Node):
|
|||||||
super().__init__('teleop_twist_joy')
|
super().__init__('teleop_twist_joy')
|
||||||
self.cmd_vel_pub = self.create_publisher(Twist, '/diffbot_base_controller/cmd_vel_unstamped', 10)
|
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.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.twist = Twist()
|
||||||
self.vFactor = 1 # if compensation is needed. Not needed anymore for bot_mini
|
self.vFactor = 1 # if compensation is needed. Not needed anymore for bot_mini
|
||||||
self.limit = 1 * self.vFactor
|
self.limit = 1 * self.vFactor
|
||||||
@ -27,8 +26,9 @@ class TeleopTwistJoy(Node):
|
|||||||
self.twist.linear.x = self.limit * joy_msg.axes[1]
|
self.twist.linear.x = self.limit * joy_msg.axes[1]
|
||||||
self.twist.angular.z = self.limit * joy_msg.axes[0] * 1 * 3.141592
|
self.twist.angular.z = self.limit * joy_msg.axes[0] * 1 * 3.141592
|
||||||
|
|
||||||
def timer_callback(self):
|
# Publish the twist message only when joystick keys are pressed
|
||||||
self.cmd_vel_pub.publish(self.twist)
|
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):
|
def main(args=None):
|
||||||
@ -39,7 +39,6 @@ def main(args=None):
|
|||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
teleop_twist_joy.destroy_node()
|
teleop_twist_joy.destroy_node()
|
||||||
rclpy.shutdown()
|
rclpy.shutdown()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
Loading…
Reference in New Issue
Block a user