-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsample_node.py
More file actions
executable file
·40 lines (32 loc) · 1.09 KB
/
sample_node.py
File metadata and controls
executable file
·40 lines (32 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env python3
from geometry_msgs.msg import Twist
import rclpy
from rclpy.executors import ExternalShutdownException
from rclpy.node import Node
from turtlesim.msg import Pose as TurtlePose
class TestListener(Node):
def __init__(self):
super().__init__("warp_listener")
self.turtle_pose_sub = self.create_subscription(
TurtlePose, "/turtle1/pose", self.gt_callback, 10
)
self.velocity_publisher = self.create_publisher(Twist, "/turtle1/cmd_vel", 10)
self.gt_pose = None
self.twist = Twist()
def gt_callback(self, msg):
vel_msg = Twist()
vel_msg.linear.x = 1.0
self.velocity_publisher.publish(vel_msg)
self.gt_pose = msg
if self.gt_pose.x > 8:
self.get_logger().info("Turtle nearing right edge. Initiate shutdown.")
self.executor.shutdown()
def main():
try:
rclpy.init()
listener = TestListener()
rclpy.spin(listener)
except (KeyboardInterrupt, ExternalShutdownException):
rclpy.try_shutdown()
if __name__ == "__main__":
main()