import rospy
import arm
import actionlib
+import numpy as np
from sensor_msgs.msg import JointState
from control_msgs.msg import FollowJointTrajectoryAction, FollowJointTrajectoryActionResult, FollowJointTrajectoryActionFeedback, FollowJointTrajectoryResult
from actionlib_msgs.msg import GoalStatus
+from time import sleep
from math import *
lJointNames = ["base_to_link1", "link_1_2_joint", "link_2_3_joint", "gripper_joint_1", "gripper_joint_2", "left_gripper_joint", "right_gripper_joint"]
rospy.init_node('arm')
self.speed = 220
+ self.lAngles = [0] * 6
arm.switch(0)
arm.switch(2)
arm.set_hall_mode(3, 0)
joint_state = JointState()
joint_state.header.stamp = rospy.Time.now()
joint_state.name = lJointNames
- joint_state.position = [-arm.get_angle(0), arm.get_angle(1), -arm.get_angle(2), -arm.get_angle(3), arm.get_angle(4), 0.175-arm.get_angle(5)/2, 0.175-arm.get_angle(5)/2]
+ self.lAngles = [-arm.get_angle(0), arm.get_angle(1), -arm.get_angle(2), -arm.get_angle(3), arm.get_angle(4), arm.get_angle(5)]
+ joint_state.position = self.lAngles[:-1] + [0.175-self.lAngles[-1]/2, 0.175-self.lAngles[-1]/2]
self.pub_joint_states.publish(joint_state)
def execute_joint_trajectory(self, goal):
for point in goal.trajectory.points:
print goal.trajectory.joint_names
print point.positions
- arm.to_angle(0, self.speed, -point.positions[goal.trajectory.joint_names.index(lJointNames[0])])
- arm.to_angle(1, self.speed, point.positions[goal.trajectory.joint_names.index(lJointNames[1])])
- arm.to_angle(2, self.speed, -point.positions[goal.trajectory.joint_names.index(lJointNames[2])])
- arm.to_angle(3, self.speed, -point.positions[goal.trajectory.joint_names.index(lJointNames[3])])
- arm.to_angle(4, self.speed, point.positions[goal.trajectory.joint_names.index(lJointNames[4])])
+ lGoalPosOrdered = [
+ point.positions[goal.trajectory.joint_names.index(lJointNames[0])],
+ point.positions[goal.trajectory.joint_names.index(lJointNames[1])],
+ point.positions[goal.trajectory.joint_names.index(lJointNames[2])],
+ point.positions[goal.trajectory.joint_names.index(lJointNames[3])],
+ point.positions[goal.trajectory.joint_names.index(lJointNames[4])],
+ ]
+ arm.to_angle(0, self.speed, -lGoalPosOrdered[0])
+ arm.to_angle(1, self.speed, lGoalPosOrdered[1])
+ arm.to_angle(2, self.speed, -lGoalPosOrdered[2])
+ arm.to_angle(3, self.speed, -lGoalPosOrdered[3])
+ arm.to_angle(4, self.speed, lGoalPosOrdered[4])
+
+ error = 0
+ while True:
+ error = np.array(lGoalPosOrdered) - np.array(self.lAngles[:-1])
+ if np.linalg.norm(error) < 0.01:
+ break
+
+ if self._as.is_preempt_requested():
+ self._as.set_preempted()
+ break
+ sleep(0.001)
+
self._feedback.status = GoalStatus.SUCCEEDED
- self._feedback.feedback.joint_names = goal.trajectory.joint_names
- self._feedback.feedback.desired = point
+ self._feedback.feedback.joint_names = lJointNames[:-1]
+ self._feedback.feedback.desired.positions = lGoalPosOrdered
+ self._feedback.feedback.actual.positions = self.lAngles[:-1]
+ self._feedback.feedback.error.positions = error
self._as.publish_feedback(self._feedback.feedback)
self._result.status = FollowJointTrajectoryResult.SUCCESSFUL
self._as.set_succeeded(self._result.result)
<parent link="base_link"/>
<child link="link1"/>
<axis xyz="0 0 1"/>
- <limit effort="1000.0" lower="0.0" upper="5.672320068981571" velocity="1.0"/>
+ <limit effort="1000.0" lower="-5.672320068981571" upper="0.0" velocity="1.0"/>
</joint>
<joint name="link_1_2_joint" type="continuous">
<child link="link3"/>
<axis xyz="0 0 1"/>
<origin xyz="0.240 0.0 0.0" rpy="0 0 0"/>
- <limit effort="1000.0" lower="0.0" upper="3.141592653589793" velocity="1.0"/>
+ <limit effort="1000.0" lower="-3.141592653589793" upper="0.0" velocity="1.0"/>
</joint>
<joint name="gripper_joint_1" type="continuous">
<child link="gripper_pole1"/>
<axis xyz="1 0 0"/>
<origin xyz="0 0.135 0.0" rpy="1.57075 0 1.57075"/>
- <limit effort="1000.0" lower="-0.6981317007977319" upper="7.679448708775051" velocity="1.0"/>
+ <limit effort="1000.0" lower="-7.679448708775051" upper="0.6981317007977319" velocity="1.0"/>
</joint>
<joint name="gripper_joint_2" type="continuous">