fake_path_and_destinations.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 
4 import rospy
5 from std_msgs.msg import String
6 from geometry_msgs.msg import Quaternion
7 from amr_interop_msgs.msg import PredictedLocation
8 from amr_interop_msgs.msg import PredictedLocations
9 import random
10 import uuid
11 from datetime import datetime, timedelta
12 import pytz
13 
14 if __name__ == "__main__":
15  rospy.init_node("fake_path_and_destinations")
16 
17  path_pub = rospy.Publisher("path", PredictedLocations, queue_size=1)
18  destinations_pub = rospy.Publisher("destinations", PredictedLocations, queue_size=1)
19  path_lower = rospy.get_param("~path_lower", 0)
20  path_upper = rospy.get_param("~path_lower", 10)
21  max_seconds = rospy.get_param("~max_minites", 15*60)
22  publish_rate = rospy.get_param("~publish_rate", 1)
23 
24  loop_rate = rospy.Rate(publish_rate)
25 
26  path_msg = PredictedLocations()
27  destinations_msg = PredictedLocations()
28 
29  x = 0
30  y = 0
31  while not rospy.is_shutdown():
32  # make path
33  path_count = random.randint(path_lower, path_upper)
34  time_deltas = [random.randint(1, max_seconds/path_count) for i in range(path_count)]
35 
36  # path_msg.data.clear()
37  path_msg = PredictedLocations()
38  nowDt = datetime.now(pytz.utc)
39  past_seconds = 0
40  for i in range(path_count):
41  predicted_location = PredictedLocation()
42  predicted_location.timestamp = (nowDt+timedelta(seconds=(time_deltas[i]+past_seconds))).strftime("%Y-%m-%dT%H:%M:%S%z")
43  predicted_location.x = x
44  predicted_location.y = y
45  predicted_location.z = float("nan")
46  predicted_location.angle = Quaternion()
47  predicted_location.angle.x = random.random()
48  predicted_location.angle.y = random.random()
49  predicted_location.angle.z = random.random()
50  predicted_location.angle.w = random.random()
51  predicted_location.planar_datum_uuid = str(uuid.uuid4())
52 
53  path_msg.data.append(predicted_location)
54 
55  x = x + random.random()
56  y = y + random.random()
57  past_seconds = past_seconds + time_deltas[i]
58 
59  # choice dest
60  destinations_count = random.randint(0, path_count)
61  destinations_indexes = random.sample(range(path_count), destinations_count)
62  destinations_msg = PredictedLocations()
63  for i in range(destinations_count):
64  destinations_msg.data.append(path_msg.data[destinations_indexes[i]])
65 
66  path_pub.publish(path_msg)
67  destinations_pub.publish(destinations_msg)
68  loop_rate.sleep()


amr_interop_bridge
Author(s):
autogenerated on Tue Mar 1 2022 23:45:33