3 import riptide_controllers.msg
5 from trajectory_msgs.msg
import MultiDOFJointTrajectory, MultiDOFJointTrajectoryPoint
6 from geometry_msgs.msg
import Transform, Quaternion, Vector3, PoseStamped
7 from moveit_msgs.msg
import ExecuteTrajectoryActionGoal
8 from nav_msgs.msg
import Path, Odometry
10 from tf.transformations
import quaternion_multiply, quaternion_inverse, quaternion_from_euler
16 return np.array([msg.x, msg.y, msg.z, msg.w])
17 return np.array([msg.x, msg.y, msg.z])
21 Rotates world-frame vector to body-frame
23 Rotates vector to body frame
26 orientation (np.array): The current orientation of the robot as a quaternion
27 vector (np.array): The 3D vector to rotate
30 np.array: 3 dimensional rotated vector
34 vector = np.append(vector, 0)
35 orientation_inv = quaternion_inverse(orientation)
36 new_vector = quaternion_multiply(orientation, quaternion_multiply(vector, orientation_inv))
44 self.
trajectory_pub = rospy.Publisher(
"execute_trajectory/goal/", ExecuteTrajectoryActionGoal, queue_size=1)
45 self.
position_pub = rospy.Publisher(
"position", Vector3, queue_size=1)
47 self.
path_pub = rospy.Publisher(
"script_ohio_path", Path, queue_size=1)
51 self.
_result = riptide_controllers.msg.CalibrateBuoyancyResult()
53 PATH =
"~/Downloads/script_ohio.csv"
59 with open(os.path.expanduser(PATH),
"r")
as csvfile:
60 spamreader = csv.reader(csvfile, delimiter=
',', quotechar=
'|')
61 for row
in spamreader:
62 self.
points.append(list(map(int, map(float, row))))
65 self.
points *= np.array([1, -1])
73 body_frame_position = self.
scale * np.array([0, input_point[0] - self.
middle_x, input_point[1] - self.
middle_y])
74 world_frame_position =
body_2_world(orientation, body_frame_position) + position
76 return world_frame_position
93 odom_msg = rospy.wait_for_message(
"odometry/filtered", Odometry)
95 orientation =
msg_2_numpy(odom_msg.pose.pose.orientation)
99 self.
position_pub.publish(Vector3(*world_frame_position))
103 trajectory = MultiDOFJointTrajectory()
105 path.header.frame_id =
"world"
106 path.header.stamp = rospy.get_rostime()
109 for i
in range(self.
points.shape[0]):
112 point = MultiDOFJointTrajectoryPoint()
113 point.transforms.append(Transform(Vector3(*world_frame_position), Quaternion(*orientation)))
114 point.time_from_start = rospy.Duration(i * dt)
115 trajectory.points.append(point)
117 path_point = PoseStamped()
118 path_point.pose.position = Vector3(*world_frame_position)
119 path_point.header.stamp = rospy.get_rostime() + rospy.Duration(i * dt)
120 path_point.header.frame_id =
"world"
121 path.poses.append(path_point)
123 trajectory_action = ExecuteTrajectoryActionGoal()
124 trajectory_action.goal.trajectory.multi_dof_joint_trajectory = trajectory
133 world_frame_end_position = self.
input_2_world(np.array(self.
i_dot), position, orientation)
134 self.
position_pub.publish(Vector3(*world_frame_end_position))
138 bowed_orientation = quaternion_multiply(orientation, quaternion_from_euler(0, 0.4, 0))
148 if __name__ ==
'__main__':
149 rospy.init_node(
'script_ohio')