Created
October 28, 2025 17:50
-
-
Save chrismatthieu/eb7e0b15bc2564895a88453590109930 to your computer and use it in GitHub Desktop.
python twist
This file contains hidden or 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
| import rclpy | |
| from rclpy.node import Node | |
| from geometry_msgs.msg import Twist | |
| class TwistSubscriber(Node): | |
| def __init__(self): | |
| super().__init__('twist_subscriber') | |
| self.subscription = self.create_subscription( | |
| Twist, | |
| 'cmd_vel', | |
| self.listener_callback, | |
| 10) | |
| self.subscription # prevent unused variable warning | |
| def listener_callback(self, msg): | |
| self.get_logger().info(f"Received Twist: linear.x={msg.linear.x}, angular.z={msg.angular.z}") | |
| def main(args=None): | |
| rclpy.init(args=args) | |
| twist_subscriber = TwistSubscriber() | |
| rclpy.spin(twist_subscriber) | |
| twist_subscriber.destroy_node() | |
| rclpy.shutdown() | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment