Skip to content
Snippets Groups Projects
Commit 4df21100 authored by uquzq's avatar uquzq
Browse files

Create a publisher for the pose of the end effector

parent 43ed19ed
Branches
No related tags found
No related merge requests found
...@@ -22,6 +22,8 @@ class Forward_Kinematics_Node_1Dof(Node): ...@@ -22,6 +22,8 @@ class Forward_Kinematics_Node_1Dof(Node):
self.point_publisher_ = self.create_publisher(Marker, 'visualization_marker', 10) self.point_publisher_ = self.create_publisher(Marker, 'visualization_marker', 10)
# create a publisher for the plotjuggler angles # create a publisher for the plotjuggler angles
self.angle_publisher_ = self.create_publisher(Float64, '/angles_1dof/plotjuggler', 10) self.angle_publisher_ = self.create_publisher(Float64, '/angles_1dof/plotjuggler', 10)
# create a publisher for the pose
self.pose_publisher_ = self.create_publisher(PoseStamped, '/end_effector_pose', 10)
#RViz #RViz
self.path = Path() self.path = Path()
self.path.header.frame_id = "map" self.path.header.frame_id = "map"
...@@ -35,14 +37,14 @@ class Forward_Kinematics_Node_1Dof(Node): ...@@ -35,14 +37,14 @@ class Forward_Kinematics_Node_1Dof(Node):
def transformation(self): def transformation(self):
# Define the desired rotation here # Define the desired rotation here
theta = - pi / 2 theta = pi / 2
# Split theta # Split theta
theta_fraction = self.phi * theta theta_fraction = self.phi * theta
self.publish_angle(theta_fraction) self.publish_angle(theta_fraction)
# Define the vector # Define the vector
start_vector = np.array([-1.0, 0.0, 0.0, 1.0]) start_vector = np.array([1.0, 0.0, 0.0, 1.0])
# Define the matrix # Define the matrix
intermediate_rotation = np.array([ intermediate_rotation = np.array([
...@@ -54,7 +56,9 @@ class Forward_Kinematics_Node_1Dof(Node): ...@@ -54,7 +56,9 @@ class Forward_Kinematics_Node_1Dof(Node):
# Calculate the intermediate vectors # Calculate the intermediate vectors
intermediate_vector = np.matmul(intermediate_rotation, start_vector) intermediate_vector = np.matmul(intermediate_rotation, start_vector)
self.publish_pose(intermediate_vector)
self.construct_path(intermediate_vector) self.construct_path(intermediate_vector)
def construct_path(self, vector): def construct_path(self, vector):
...@@ -104,6 +108,21 @@ class Forward_Kinematics_Node_1Dof(Node): ...@@ -104,6 +108,21 @@ class Forward_Kinematics_Node_1Dof(Node):
angle_msg.data = angle * 180 / pi angle_msg.data = angle * 180 / pi
self.angle_publisher_.publish(angle_msg) self.angle_publisher_.publish(angle_msg)
def publish_pose(self, vector):
pose_msg = PoseStamped()
pose_msg.header.frame_id = "map"
pose_msg.header.stamp = self.get_clock().now().to_msg()
pose_msg.pose.position.x = vector[0]
pose_msg.pose.position.y = vector[1]
pose_msg.pose.position.z = vector[2]
pose_msg.pose.orientation.x = 0.0
pose_msg.pose.orientation.y = 0.0
pose_msg.pose.orientation.z = 0.0
pose_msg.pose.orientation.w = 1.0
self.pose_publisher_.publish(pose_msg)
def main(args = None): def main(args = None):
rclpy.init(args = args) rclpy.init(args = args)
node = Forward_Kinematics_Node_1Dof() node = Forward_Kinematics_Node_1Dof()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment