5 from control_msgs.msg
import FollowJointTrajectoryActionFeedback, FollowJointTrajectoryActionResult, \
6 FollowJointTrajectoryAction, FollowJointTrajectoryGoal
7 from trajectory_msgs.msg
import JointTrajectory, JointTrajectoryPoint
8 import moveit_commander
13 def jog(vx, vy, vz, ang_x, ang_y, ang_z, action_client):
14 desired_twist = np.array([vx, vy, vz, ang_x, ang_y, ang_z])
16 startingPoint = JointTrajectoryPoint()
17 startingPoint.positions = arm_group.get_current_joint_values()
18 startingPoint.time_from_start.secs = 0
20 trajectory = JointTrajectory()
21 trajectory.points = [startingPoint]
26 dt_point2point = Time_total_sec/N_points
29 for i
in range(1, N_points):
30 point = JointTrajectoryPoint()
32 jacobian = arm_group.get_jacobian_matrix(trajectory.points[i-1].positions)
33 pseudoInverseJacobian = np.linalg.pinv(jacobian)
34 jointVelocities = pseudoInverseJacobian.dot(desired_twist)
36 point.positions = (trajectory.points[i-1].positions + (jointVelocities*dt_point2point)).tolist()
38 time_from_start = time_from_start + dt_point2point
39 point.time_from_start = rospy.Duration.from_sec(time_from_start)
40 trajectory.points.append(point)
42 trajectory.joint_names = [
'joint1',
'joint2',
'joint3',
'joint4',
'joint5',
'joint6',
'joint7']
43 goal = FollowJointTrajectoryGoal()
44 goal.trajectory = trajectory
46 action_client.send_goal(goal)
48 action_client.wait_for_result()
52 desired_twist = np.array([0, 0, 0, 0, 0, 0])
54 startingPoint = JointTrajectoryPoint()
55 startingPoint.positions = arm_group.get_current_joint_values()
56 startingPoint.time_from_start.secs = 0
57 q_i_desired = startingPoint.positions[q_index-1] + q_i_change
59 trajectory = JointTrajectory()
60 trajectory.points = [startingPoint]
65 dt_point2point = Time_total_sec/N_points
68 for i
in range(1, N_points):
69 point = JointTrajectoryPoint()
71 jacobian = arm_group.get_jacobian_matrix(trajectory.points[i-1].positions)
72 pseudoInverseJacobian = np.linalg.pinv(jacobian)
73 nullSpaceProjector = \
74 np.identity(7) - pseudoInverseJacobian.dot(jacobian)
75 q_i_current = trajectory.points[i-1].positions[q_index-1]
76 gradient_q = np.zeros(7)
77 gradient_q[q_index-1] = q_i_current-q_i_desired
78 eta = alpha_scale*gradient_q
80 pseudoInverseJacobian.dot(desired_twist) \
81 + nullSpaceProjector.dot(eta)
84 (trajectory.points[i-1].positions \
85 + (jointVelocities*dt_point2point)).tolist()
86 time_from_start = time_from_start + dt_point2point
87 point.time_from_start = rospy.Duration.from_sec(time_from_start)
88 trajectory.points.append(point)
90 trajectory.joint_names = [
'joint1',
'joint2',
'joint3',
'joint4',
'joint5',
'joint6',
'joint7']
91 goal = FollowJointTrajectoryGoal()
92 goal.trajectory = trajectory
94 action_client.send_goal(goal)
96 action_client.wait_for_result()
99 if __name__ ==
'__main__':
101 parser = argparse.ArgumentParser(description=
'Redundancy Resolution')
102 parser.add_argument(
'-q',
'--q_angle_change', default=-90.0,
103 metavar=
'[degrees]', type=float,help=
'desired joint angle change in degrees')
104 parser.add_argument(
'-i',
'--index', default=1,
105 metavar=
'[ith joint]', type=int,
106 help=
'which joint to set the desired angle (starting from 1st)')
107 parser.add_argument(
'-a',
'--alpha', default=-0.5,
108 metavar=
'[value]', type=float,help=
'stepsize scaling parameter alpha')
109 args = parser.parse_args()
110 q_angle_change_rad = args.q_angle_change/180.0*np.pi
112 alpha = -abs(args.alpha)
114 moveit_commander.roscpp_initialize(
'')
115 rospy.init_node(
'robot_jogging')
117 client = actionlib.SimpleActionClient(
'/xarm/xarm7_traj_controller/follow_joint_trajectory',
118 FollowJointTrajectoryAction)
119 client.wait_for_server()
121 arm_group_name =
"xarm7" 122 robot = moveit_commander.RobotCommander(
"robot_description")
123 scene = moveit_commander.PlanningSceneInterface(ns=rospy.get_namespace())
124 arm_group = moveit_commander.MoveGroupCommander(arm_group_name, ns=rospy.get_namespace())
125 display_trajectory_publisher = rospy.Publisher(rospy.get_namespace() +
'move_group/display_planned_path',
126 moveit_msgs.msg.DisplayTrajectory,
def jog(vx, vy, vz, ang_x, ang_y, ang_z, action_client)
def redundancy_resolution(q_i_change, q_index, alpha_scale, action_client)