123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- import rospy, sys
- import numpy as np
- from tf.transformations import euler_from_quaternion,quaternion_from_euler,quaternion_from_euler, quaternion_multiply
- def check_joint_positions(joint_trajectory):
- is_limited = False
- Limit_margin = True
-
- for i in range(len(joint_trajectory.joint_trajectory.points) - 1):
- if not is_limited:
- joint_positions1 = joint_trajectory.joint_trajectory.points[i].positions
- joint_positions2 = joint_trajectory.joint_trajectory.points[i + 1].positions
- for j in range(len(joint_positions1)):
- position_diff = abs(joint_positions1[j] - joint_positions2[j])
-
- if position_diff > 6:
- rospy.loginfo("发生大角度翻转: point{}-joint{}:{}".format(i,j+1,joint_positions1))
-
-
- joint_limt =[[],[],[],[-1.6,1.6],[],[-3.838,3.838]]
-
-
- Limit_point = joint_positions1[j]
-
-
- distance_to_Limit_point = abs(joint_trajectory.joint_trajectory.points[0].positions[j]- Limit_point)
- Joint_range = abs(joint_limt[j][0] - joint_limt[j][1])
- margin = distance_to_Limit_point / Joint_range
- if margin > 0.3:
- Limit_margin = True
- else:
- Limit_margin = False
- rospy.loginfo("margin = {}".format(margin))
- is_limited = True
- break
-
- if position_diff > 3:
- rospy.loginfo("point{}-joint{}:{}".format(i,j+1,joint_positions1))
-
- Limit_margin = True
- is_limited = True
- break
- if is_limited:
- break
- if not is_limited:
- rospy.loginfo("Check OK! 轨迹有效")
- return is_limited,Limit_margin
- def angle_adjustment(pose,axis,angle):
- if len(pose) == 6:
- q_initial = quaternion_from_euler(pose[3], pose[4], pose[5])
- else:
- q_initial = (pose[3], pose[4], pose[5],pose[6])
- if axis == 'z':
- q_rotation = quaternion_from_euler(0, 0, angle)
- if axis == 'y':
- q_rotation = quaternion_from_euler(0, angle, 0)
- if axis == 'x':
- q_rotation = quaternion_from_euler(angle, 0, 0)
- q_new = quaternion_multiply(q_initial, q_rotation)
- pose[3:] = q_new
- return pose
-
-
-
-
-
-
-
-
-
-
-
-
-
|