5 from gazebo_msgs.msg
import ModelState, ModelStates
6 from std_msgs.msg
import Duration
9 from collections
import namedtuple
11 Point = namedtuple(
"Point", [
"x",
"y"])
15 minutes = int(duration.to_sec() / 60)
16 seconds = int(duration.to_sec()) % 60
17 fraction = duration.to_sec() - floor(duration.to_sec())
18 return str(minutes) +
":" + str(seconds).ljust(2,
'0') + \
19 "." + str(int(fraction * 100)).ljust(2,
'0')
28 return abs(self.center.x - point.x) < self.extents.x \
29 and abs(self.center.y - point.y) < self.extents.y
40 "/lap_time", Duration, queue_size=1)
46 rospy.loginfo(
"Lap started (" + self.
name +
")")
47 self.
start = rospy.Time.now()
57 time = rospy.Time.now()
58 duration = time - self.
start 59 self.history.append(duration)
61 rospy.loginfo(
"Lap " + str(len(self.
history)) +
" (" + self.
name +
"): " +
64 average = rospy.Duration(sum([item.to_sec()
for item
in self.
history]) / len(self.
history))
65 rospy.loginfo(
"Lap " + str(len(self.
history)) +
" (" + self.
name +
"): " +
68 self.lap_time_publisher.publish(duration)
71 world_name = rospy.get_param(
'world_name')
72 if world_name
not in [
73 'racetrack_decorated',
74 'racetrack_decorated_2',
75 'racetrack_decorated_2_big']:
76 rospy.logfatal(
'Racetrack not supported by lap_timer.')
85 if world_name ==
'racetrack_decorated_2_big':
92 area.center =
Point(area.center.x * 2.5, area.center.y * 2.5)
93 area.extents =
Point(area.extents.x * 2.5, area.extents.y * 2.5)
95 forward_track =
Timer(
"forward", (
115 if len(message.pose) < 2:
118 position =
Point(message.pose[1].position.x, message.pose[1].position.y)
119 forward_track.update(position)
120 reverse_track.update(position)
123 rospy.init_node(
'lap_timer', anonymous=
True)
124 rospy.Subscriber(
"/gazebo/model_states", ModelStates, model_state_callback)