forked from autowarefoundation/autoware_universe
-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathrely_trajectory.py
executable file
·50 lines (37 loc) · 1.19 KB
/
rely_trajectory.py
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
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python3
import threading
from autoware_auto_planning_msgs.msg import Trajectory
import rclpy
from rclpy.node import Node
class RelayTrajectoryNode(Node):
def __init__(self):
super().__init__("relay_trajectory")
self.subscription = self.create_subscription(
Trajectory, "/tmp/planning/scenario_planning/trajectory", self.listener_callback, 10
)
self.publisher = self.create_publisher(
Trajectory, "/planning/scenario_planning/trajectory", 10
)
self.running = True
def listener_callback(self, msg):
if self.running:
self.publisher.publish(msg)
def main(args=None):
rclpy.init(args=args)
node = RelayTrajectoryNode()
def input_thread():
nonlocal node
while True:
user_input = input("Enter 'y' to stop publishing: ")
if user_input.lower() == "y":
node.running = False
print("Publishing stopped.")
break
thread = threading.Thread(target=input_thread)
thread.start()
rclpy.spin(node)
thread.join()
node.destroy_node()
rclpy.shutdown()
if __name__ == "__main__":
main()