|
@@ -29,6 +29,7 @@ import termios
|
|
from decorator_time import decorator_time
|
|
from decorator_time import decorator_time
|
|
import check
|
|
import check
|
|
from redis_publisher import Publisher
|
|
from redis_publisher import Publisher
|
|
|
|
+from scipy.interpolate import CubicSpline
|
|
|
|
|
|
pi = np.pi
|
|
pi = np.pi
|
|
|
|
|
|
@@ -94,6 +95,34 @@ class MoveIt_Control:
|
|
#rospy.lohome_poseinfo("Current Pose: {}".format(pose))
|
|
#rospy.lohome_poseinfo("Current Pose: {}".format(pose))
|
|
return pose
|
|
return pose
|
|
|
|
|
|
|
|
+ #TODO 使用三次样条插值平滑轨迹
|
|
|
|
+ def smooth_trajectory(self, trajectory, num_points=0):
|
|
|
|
+
|
|
|
|
+ # print(f"原始轨迹点数: {len(trajectory.joint_trajectory.points)}")
|
|
|
|
+ num_points = len(trajectory.joint_trajectory.points) + 50
|
|
|
|
+ # 创建平滑后的轨迹
|
|
|
|
+ smoothed_trajectory = []
|
|
|
|
+ for i in range(len(trajectory.joint_trajectory.joint_names)):
|
|
|
|
+ joint_trajectory = [point.positions[i] for point in trajectory.joint_trajectory.points]
|
|
|
|
+ cs = CubicSpline(range(len(joint_trajectory)), joint_trajectory) #创建三次样条插值器
|
|
|
|
+ smooth_joint_trajectory = cs(np.linspace(0, len(joint_trajectory) - 1, num_points)) #生成平滑后的轨迹
|
|
|
|
+ smoothed_trajectory.append(smooth_joint_trajectory)
|
|
|
|
+
|
|
|
|
+ # 创建平滑后的轨迹点
|
|
|
|
+ smoothed_trajectory_points = []
|
|
|
|
+ for j in range(num_points):
|
|
|
|
+ point = trajectory.joint_trajectory.points[0]
|
|
|
|
+ smoothed_point = JointTrajectoryPoint()
|
|
|
|
+ smoothed_point.positions = [smoothed_trajectory[i][j] for i in range(len(smoothed_trajectory))]
|
|
|
|
+ smoothed_point.time_from_start = rospy.Duration(j * 0.05) # 控制每个点之间的时间间隔
|
|
|
|
+ smoothed_trajectory_points.append(smoothed_point)
|
|
|
|
+
|
|
|
|
+ # 将平滑后的轨迹生成新的 JointTrajectory
|
|
|
|
+ trajectory.joint_trajectory.points = smoothed_trajectory_points
|
|
|
|
+ # print(f"平滑后的轨迹点数: {len(trajectory.joint_trajectory.points)}")
|
|
|
|
+
|
|
|
|
+ return trajectory
|
|
|
|
+
|
|
#TODO move_p 路径约束
|
|
#TODO move_p 路径约束
|
|
def create_path_constraints2(self, start_point, end_point, r):
|
|
def create_path_constraints2(self, start_point, end_point, r):
|
|
#计算起点指向终点的向量
|
|
#计算起点指向终点的向量
|
|
@@ -174,7 +203,13 @@ class MoveIt_Control:
|
|
trajj_with_type = mark_the_traj(trajj,"during-p", welding_sequence)
|
|
trajj_with_type = mark_the_traj(trajj,"during-p", welding_sequence)
|
|
trajectory_with_type.append(trajj_with_type)
|
|
trajectory_with_type.append(trajj_with_type)
|
|
points.append(point)
|
|
points.append(point)
|
|
- trajectory.append(trajj)
|
|
|
|
|
|
+ trajectory.append(trajj)
|
|
|
|
+ #平滑轨迹
|
|
|
|
+ # smooth_traj = self.smooth_trajectory(trajj)
|
|
|
|
+ # trajj_with_type = mark_the_traj(smooth_traj,"during-p", welding_sequence)
|
|
|
|
+ # trajectory_with_type.append(trajj_with_type)
|
|
|
|
+ # points.append(point)
|
|
|
|
+ # trajectory.append(smooth_traj)
|
|
break
|
|
break
|
|
else:
|
|
else:
|
|
rospy.loginfo("check failed! 移动轨迹无效")
|
|
rospy.loginfo("check failed! 移动轨迹无效")
|
|
@@ -305,6 +340,14 @@ class MoveIt_Control:
|
|
points.append(point)
|
|
points.append(point)
|
|
trajectory.append(trajj)
|
|
trajectory.append(trajj)
|
|
trajectory_with_type.append(trajj_with_type)
|
|
trajectory_with_type.append(trajj_with_type)
|
|
|
|
+ #平滑轨迹
|
|
|
|
+ # smoothed_plan = self.smooth_trajectory(trajj)
|
|
|
|
+ # trajj_with_type = mark_the_traj(smoothed_plan, "during-l", welding_sequence)
|
|
|
|
+ # trajj_with_type.points[-len(smoothed_plan.joint_trajectory.points)].type = "start"
|
|
|
|
+ # trajj_with_type.points[-1].type = "end"
|
|
|
|
+ # points.append(point)
|
|
|
|
+ # trajectory.append(smoothed_plan)
|
|
|
|
+ # trajectory_with_type.append(trajj_with_type)
|
|
else:
|
|
else:
|
|
rospy.loginfo("本次焊缝规划失败")
|
|
rospy.loginfo("本次焊缝规划失败")
|
|
points.pop() #将本条焊缝的起点从规划中删除
|
|
points.pop() #将本条焊缝的起点从规划中删除
|