|
@@ -22,7 +22,7 @@ import tf
|
|
|
from tf.transformations import euler_from_quaternion,quaternion_from_euler,quaternion_from_euler, quaternion_multiply
|
|
|
import math
|
|
|
import traceback
|
|
|
-from lstrobot_planning.msg import JointTrajectoryPoint_ex,JointTrajectory_ex
|
|
|
+from lst_robot_r.msg import JointTrajectoryPoint_ex,JointTrajectory_ex
|
|
|
import json
|
|
|
import termios
|
|
|
from decorator_time import decorator_time
|
|
@@ -63,18 +63,19 @@ class MoveIt_Control:
|
|
|
#self.move_j()
|
|
|
self.go_home()
|
|
|
self.home_pose=self.get_now_pose()
|
|
|
+ #self.go_ready()
|
|
|
|
|
|
-
|
|
|
+ #TODO plan_cartesian_path
|
|
|
def plan_cartesian_path_LLL(self,point_s,point_e,waypoints,trajectory,trajectory_with_type,a=1,v=1):
|
|
|
fraction = 0.0 # 路径规划覆盖率
|
|
|
maxtries = 50 # 最大尝试规划次数
|
|
|
attempts = 0 # 已经尝试规划次数
|
|
|
|
|
|
#起点位置设置为规划组最后一个点
|
|
|
- pose = self.arm.get_current_pose(self.end_effector_link).pose
|
|
|
- wpose = deepcopy(pose)
|
|
|
+ start_pose = self.arm.get_current_pose(self.end_effector_link).pose
|
|
|
+ wpose = deepcopy(start_pose)
|
|
|
waypoint=[]
|
|
|
- print(waypoint)
|
|
|
+ #print(waypoint)
|
|
|
if waypoints:
|
|
|
wpose.position.x=waypoints[-1].position.x
|
|
|
wpose.position.y=waypoints[-1].position.y
|
|
@@ -84,16 +85,6 @@ class MoveIt_Control:
|
|
|
wpose.orientation.z=waypoints[-1].orientation.z
|
|
|
wpose.orientation.w=waypoints[-1].orientation.w
|
|
|
waypoint.append(deepcopy(wpose))
|
|
|
- # else:
|
|
|
- # wpose.position.x=self.home_pose[0]
|
|
|
- # wpose.position.y=self.home_pose[1]
|
|
|
- # wpose.position.z=self.home_pose[2]
|
|
|
- # wpose.orientation.x=self.home_pose[3]
|
|
|
- # wpose.orientation.y=self.home_pose[4]
|
|
|
- # wpose.orientation.z=self.home_pose[5]
|
|
|
- # wpose.orientation.w=self.home_pose[6]
|
|
|
- # waypoint.append(deepcopy(wpose))
|
|
|
- #waypoints.append(deepcopy(wpose))
|
|
|
|
|
|
#wpose = deepcopy(pose)
|
|
|
wpose.position.x=point_s[0]
|
|
@@ -129,11 +120,14 @@ class MoveIt_Control:
|
|
|
rospy.loginfo("Path computed successfully.")
|
|
|
#traj = plan
|
|
|
trajj = plan #取出规划的信息
|
|
|
+ retimed_planed=self.retime_plan(trajj)
|
|
|
trajj_with_type = mark_the_traj(trajj,"during-l",welding_sequence)
|
|
|
trajj_with_type.points[-len(trajj.joint_trajectory.points)].type = "start"
|
|
|
trajj_with_type.points[-1].type = "end"
|
|
|
trajectory.append(trajj)
|
|
|
- moveit_server.arm.execute(trajj)
|
|
|
+ rospy.loginfo("开始执行")
|
|
|
+ moveit_server.arm.execute(retimed_planed)
|
|
|
+ rospy.loginfo("执行结束")
|
|
|
trajectory_with_type.append(trajj_with_type)
|
|
|
else:
|
|
|
rospy.loginfo(
|
|
@@ -147,7 +141,18 @@ class MoveIt_Control:
|
|
|
#self.hf_num=self.hf_num+1#焊缝计数
|
|
|
return waypoints,trajectory,trajectory_with_type
|
|
|
|
|
|
+ def retime_plan(self,traj):
|
|
|
+ current_state = self.arm.get_current_state()
|
|
|
+
|
|
|
+ retimed_traj = self.arm.retime_trajectory(
|
|
|
+ current_state,
|
|
|
+ traj,
|
|
|
+ velocity_scaling_factor=0.5,
|
|
|
+ acceleration_scaling_factor=1)
|
|
|
+
|
|
|
+ return retimed_traj
|
|
|
|
|
|
+
|
|
|
def get_now_pose(self):
|
|
|
# 获取机械臂当前位姿
|
|
|
current_pose = self.arm.get_current_pose(self.end_effector_link).pose
|
|
@@ -272,8 +277,6 @@ class MoveIt_Control:
|
|
|
return points,trajectory,trajectory_with_type,er
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
#TODO go_home
|
|
|
@decorator_time
|
|
|
def go_home(self,a=1,v=1):
|
|
@@ -285,9 +288,20 @@ class MoveIt_Control:
|
|
|
self.arm.go()
|
|
|
rospy.loginfo("go_home end")
|
|
|
# rospy.sleep(1)
|
|
|
+
|
|
|
+ def go_ready(self,a=1,v=1):
|
|
|
+ rospy.loginfo("go_ready start")
|
|
|
+ self.arm.set_max_acceleration_scaling_factor(a)
|
|
|
+ self.arm.set_max_velocity_scaling_factor(v)
|
|
|
+ self.arm.set_named_target('ready')
|
|
|
+ rospy.loginfo("get_ready end")
|
|
|
+ self.arm.go()
|
|
|
+ rospy.loginfo("go_ready end")
|
|
|
|
|
|
#TODO go_home_justplan
|
|
|
+ @decorator_time
|
|
|
def go_home_justplan(self,trajectory,trajectory_with_type,a=1,v=1):
|
|
|
+ rospy.loginfo("go_home start")
|
|
|
self.arm.set_max_acceleration_scaling_factor(a)
|
|
|
self.arm.set_max_velocity_scaling_factor(v)
|
|
|
state = self.arm.get_current_state()
|
|
@@ -296,6 +310,8 @@ class MoveIt_Control:
|
|
|
self.arm.set_named_target('home')
|
|
|
traj = self.arm.plan()
|
|
|
trajj = traj[1]
|
|
|
+ moveit_server.arm.execute(trajj)
|
|
|
+ rospy.loginfo("go_home end")
|
|
|
traj_with_type = mark_the_traj(trajj,"go-home",welding_sequence)
|
|
|
trajectory.append(trajj)
|
|
|
trajectory_with_type.append(traj_with_type)
|
|
@@ -321,13 +337,14 @@ class MoveIt_Control:
|
|
|
|
|
|
rospy.loginfo("第%d条焊缝规划完毕",i+1)
|
|
|
rospy.loginfo("*******************")
|
|
|
- # if gohome:
|
|
|
- # #trajectory,trajectory_with_type= self.move_p_flexible(trajectory,trajectory_with_type)
|
|
|
- # trajectory,trajectory_with_type = self.go_home_justplan(trajectory,trajectory_with_type)
|
|
|
+ rospy.loginfo("All of The trajectory Plan successfully")
|
|
|
+ rospy.loginfo("*******************")
|
|
|
+ if gohome:
|
|
|
+ #trajectory,trajectory_with_type= self.move_p_flexible(trajectory,trajectory_with_type)
|
|
|
+ trajectory,trajectory_with_type = self.go_home_justplan(trajectory,trajectory_with_type)
|
|
|
|
|
|
traj_merge= merge_trajectories(trajectory)
|
|
|
trajectory_with_type_merge= merge_trajectories_with_type(trajectory_with_type)
|
|
|
- rospy.loginfo("All of The trajectory Plan successfully")
|
|
|
return trajectory,traj_merge,trajectory_with_type_merge
|
|
|
|
|
|
###########################################################class end#############################################################
|
|
@@ -365,7 +382,6 @@ def mark_the_traj(traj,TYPE,SEQUENCE):
|
|
|
]
|
|
|
return traj_with_type
|
|
|
|
|
|
-
|
|
|
def merge_trajectories(trajectories):
|
|
|
if not trajectories:
|
|
|
return None
|
|
@@ -482,12 +498,9 @@ def get_user_input():
|
|
|
#rospy.loginfo(f"用户输入的速度缩放因子为{vv}")
|
|
|
return vv
|
|
|
except Exception as e:
|
|
|
- rospy.logerr(f"发生错误:{e}")
|
|
|
+ rospy.logerr(f"发生错误:{e}")
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
if __name__ =="__main__":
|
|
|
# from redis_publisher import Publisher
|
|
|
# publisher = Publisher()
|
|
@@ -502,11 +515,10 @@ if __name__ =="__main__":
|
|
|
# rospy.loginfo(f"用户输入的速度缩放因子为{speed_v}")
|
|
|
|
|
|
trajectory,trajectory_merge,trajectory_with_type_merge = moveit_server.path_planning(folder_path)
|
|
|
- #ROS2_msgs(trajectory_with_type_merge,moveit_server)
|
|
|
- #write_ee(trajectory_with_type_merge, moveit_server)
|
|
|
-
|
|
|
|
|
|
- # moveit_server.go_home()
|
|
|
- # moveit_server.arm.execute(trajectory_merge)
|
|
|
+ #moveit_server.go_ready()
|
|
|
+ rospy.loginfo("开始执行合并后轨迹")
|
|
|
+ moveit_server.arm.execute(trajectory_merge)
|
|
|
+ rospy.loginfo("合并后轨迹执行完毕")
|
|
|
|
|
|
rospy.set_param("sign_control",0)
|