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
11 from datetime
import datetime, timedelta
14 if __name__ ==
"__main__":
15 rospy.init_node(
"fake_path_and_destinations")
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)
24 loop_rate = rospy.Rate(publish_rate)
26 path_msg = PredictedLocations()
27 destinations_msg = PredictedLocations()
31 while not rospy.is_shutdown():
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)]
37 path_msg = PredictedLocations()
38 nowDt = datetime.now(pytz.utc)
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())
53 path_msg.data.append(predicted_location)
55 x = x + random.random()
56 y = y + random.random()
57 past_seconds = past_seconds + time_deltas[i]
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]])
66 path_pub.publish(path_msg)
67 destinations_pub.publish(destinations_msg)