17 from uuv_control_msgs.msg
import TrajectoryPoint
as TrajectoryPointMsg
18 import geometry_msgs.msg
as geometry_msgs
23 """Trajectory point data structure. 27 * `t` (*type:* `float`, *value:* `0`): Timestamp 28 * `pos` (*type:* list of `float` or `numpy.array`, *default:* `[0, 0, 0]`): 29 3D position vector in meters 30 * `quat` (*type:* list of `float` or `numpy.array`, *default:* `[0, 0, 0, 1]`): 31 Quaternion in the form of `(x, y, z, w)`. 32 * `lin_vel` (*type:* list of `float` or `numpy.array`, *default:* `[0, 0, 0]`): 33 3D linear velocity vector in m/s 34 * `ang_vel` (*type:* list of `float` or `numpy.array`, *default:* `[0, 0, 0]`): 35 3D angular velocity vector as rad/s 36 * `lin_acc` (*type:* list of `float` or `numpy.array`, *default:* `[0, 0, 0]`): 37 3D linear acceleration vector as m/s$^2$ 38 * `ang_acc` (*type:* list of `float` or `numpy.array`, *default:* `[0, 0, 0]`): 39 3D angular acceleration vector as rad/s$^2$ 41 def __init__(self, t=0.0, pos=[0, 0, 0], quat=[0, 0, 0, 1],
42 lin_vel=[0, 0, 0], ang_vel=[0, 0, 0], lin_acc=[0, 0, 0],
46 self.
_vel = np.hstack((lin_vel, ang_vel))
47 self.
_acc = np.hstack((lin_acc, ang_acc))
51 msg =
'Time [s] = {}\n'.format(self.
_t)
52 msg +=
'Position [m] = ({}, {}, {})\n'.format(self.
_pos[0], self.
_pos[1], self.
_pos[2])
53 eu = [a * 180 / np.pi
for a
in self.
rot]
54 msg +=
'Rotation [degrees] = ({}, {}, {})\n'.format(eu[0], eu[1], eu[2])
55 msg +=
'Lin. velocity [m/s] = ({}, {}, {})\n'.format(self.
_vel[0], self.
_vel[1], self.
_vel[2])
56 msg +=
'Ang. velocity [m/s] = ({}, {}, {})\n'.format(self.
_vel[3], self.
_vel[4], self.
_vel[5])
60 return self.
_t == pnt._t
and np.array_equal(self.
_pos, pnt._pos)
and \
61 np.array_equal(self.
_rot, pnt._rot)
and \
62 np.array_equal(self.
_vel, pnt._vel)
and \
63 np.array_equal(self.
_acc, pnt._acc)
67 """`numpy.array`: Position vector""" 72 """`numpy.array`: Quaternion vector as `(x, y, z, w)`""" 77 """`numpy.array`: Linear velocity vector""" 82 """`numpy.array`: Angular velocity vector""" 87 """`numpy.array`: Linear acceleration vector""" 92 """`numpy.array`: Angular acceleartion vector""" 97 """`float`: X coordinate of position vector""" 106 """`float`: Y coordinate of position vector""" 115 """`float`: Z coordinate of position vector""" 124 """`float`: Time stamp""" 133 """`numpy.array`: Position vector""" 138 self.
_pos = np.array(new_pos)
142 """`numpy.array`: `roll`, `pitch` and `yaw` angles""" 143 rpy = euler_from_quaternion(self.
_rot)
144 return np.array([rpy[0], rpy[1], rpy[2]])
148 self.
_rot = quaternion_from_euler(*new_rot)
152 """`numpy.array`: Rotation matrix""" 153 return quaternion_matrix(self.
_rot)[0:3, 0:3]
157 """`numpy.array`: Quaternion vector as `(x, y, z, w)`""" 166 """`numpy.array`: Linear velocity vector""" 171 self.
_vel = np.array(new_vel)
175 """`numpy.array`: Linear acceleration vector""" 180 self.
_acc = np.array(new_acc)
183 """Convert current data to a trajectory point message. 187 Trajectory point message as `uuv_control_msgs/TrajectoryPoint` 189 p_msg = TrajectoryPointMsg()
191 p_msg.header.stamp = rospy.Time(self.
t)
192 p_msg.pose.position = geometry_msgs.Vector3(*self.
p)
193 p_msg.pose.orientation = geometry_msgs.Quaternion(*self.
q)
194 p_msg.velocity.linear = geometry_msgs.Vector3(*self.
v)
195 p_msg.velocity.angular = geometry_msgs.Vector3(*self.
w)
196 p_msg.acceleration.linear = geometry_msgs.Vector3(*self.
a)
197 p_msg.acceleration.angular = geometry_msgs.Vector3(*self.
alpha)
201 """Parse a trajectory point message of type `uuv_control_msgs/TrajectoryPoint` 202 into the `uuv_trajectory_generator/TrajectoryPoint`. 206 * `msg` (*type:* `uuv_control_msgs/TrajectoryPoint`): Input trajectory message 208 t = msg.header.stamp.to_sec()
209 p = msg.pose.position
210 q = msg.pose.orientation
211 v = msg.velocity.linear
212 w = msg.velocity.angular
213 a = msg.acceleration.linear
214 al = msg.acceleration.angular
217 self.
_pos = np.array([p.x, p.y, p.z])
218 self.
_rot = np.array([q.x, q.y, q.z, q.w])
219 self.
_vel = np.array([v.x, v.y, v.z, w.x, w.y, w.z])
220 self.
_acc = np.array([a.x, a.y, a.z, al.x, al.y, al.z])
224 """Initialize the trajectory point attributes from a `dict`. 228 * `data` (*type:* `dict`): Trajectory point as a `dict` 230 self.
_t = data[
'time']
231 self.
_pos = np.array(data[
'pos'])
232 if self._rot.size == 3:
233 self.
_rot = quaternion_from_euler(data[
'rot'])
235 self.
_rot = np.array(data[
'rot'])
236 self.
_vel = np.array(data[
'vel'])
237 self.
_acc = np.array(data[
'acc'])
240 """Convert trajectory point to `dict`. 244 Trajectory points data as a `dict` 246 data = dict(time=self.
_t,
def __init__(self, t=0.0, pos=[0, quat=[0, lin_vel=[0, ang_vel=[0, lin_acc=[0, ang_acc=[0)
def from_message(self, msg)
def from_dict(self, data)