9 from tf.transformations
import euler_from_quaternion
10 from track_geometry
import PATH
12 from collections
import namedtuple
13 Point = namedtuple(
"Point", [
"x",
"y"])
17 def __init__(self, segment, x, y, point, track):
26 track.forward[segment, 1], track.forward[segment, 0])
29 return "{0:.2f} m ({1:.0f}%), segment {2:d}, to center: {3:.2f} m, track: {4:.0f}°".format(
34 self.
angle * 180 / math.pi
43 euler = euler_from_quaternion(quaternion)
44 return (euler[0] + self.
angle) % (2 * math.pi) - math.pi
53 self.
size = points.shape[0] - 1
54 relative = points[1:, :] - points[:-1, :]
64 ''' Returns a TrackPosition object based on a position in world space. ''' 65 local = np.array([point.x, point.y]) - self.
points 66 x = local[:, 0] * self.
right[:, 0] + local[:, 1] * self.
right[:, 1]
67 y = local[:, 0] * self.
forward[:, 0] + local[:, 1] * self.
forward[:, 1]
70 segment = np.argmin(distances)
71 return TrackPosition(segment, x[segment], y[segment], point, self)
74 ''' Returns a TrackPosition object based on the on-track distance from the start 75 line and the distance to the center of the track. ''' 81 segment_distance + self.
right[segment, 0] * distance_to_center
83 segment_distance + self.
right[segment, 1] * distance_to_center
85 segment_distance,
Point(x, y), self)
88 world_name = rospy.get_param(
"world_name")
90 if world_name
not in [
91 "racetrack_decorated",
92 "racetrack_decorated_2",
93 "racetrack_decorated_2_big"]:
94 print "ERROR: Racetrack not supported by track.py" 97 if world_name ==
"racetrack_decorated_2_big":