|
@@ -25,6 +25,8 @@ import traceback
|
|
from lstrobot_planning.msg import JointTrajectoryPoint_ex,JointTrajectory_ex
|
|
from lstrobot_planning.msg import JointTrajectoryPoint_ex,JointTrajectory_ex
|
|
import json
|
|
import json
|
|
import termios
|
|
import termios
|
|
|
|
+from decorator_time import decorator_time
|
|
|
|
+import check
|
|
|
|
|
|
pi = np.pi
|
|
pi = np.pi
|
|
|
|
|
|
@@ -36,6 +38,7 @@ class MoveIt_Control:
|
|
self.hf_fail=[]
|
|
self.hf_fail=[]
|
|
# Init ros config
|
|
# Init ros config
|
|
moveit_commander.roscpp_initialize(sys.argv)
|
|
moveit_commander.roscpp_initialize(sys.argv)
|
|
|
|
+ self.robot = moveit_commander.RobotCommander()
|
|
|
|
|
|
self.arm = moveit_commander.MoveGroupCommander('manipulator')
|
|
self.arm = moveit_commander.MoveGroupCommander('manipulator')
|
|
self.arm.set_goal_joint_tolerance(0.0001)
|
|
self.arm.set_goal_joint_tolerance(0.0001)
|
|
@@ -73,6 +76,73 @@ class MoveIt_Control:
|
|
self.arm.go()
|
|
self.arm.go()
|
|
#rospy.sleep(1)
|
|
#rospy.sleep(1)
|
|
|
|
|
|
|
|
+
|
|
|
|
+ def plan_cartesian_path_LLL(self,point,points,trajectory,trajectory_with_type,a=1,v=1):
|
|
|
|
+ fraction = 0.0 # 路径规划覆盖率
|
|
|
|
+ maxtries = 100 # 最大尝试规划次数
|
|
|
|
+ attempts = 0 # 已经尝试规划次数
|
|
|
|
+
|
|
|
|
+ self.arm.set_max_acceleration_scaling_factor(a)
|
|
|
|
+ self.arm.set_max_velocity_scaling_factor(v)
|
|
|
|
+
|
|
|
|
+ waypoints=[]
|
|
|
|
+ if trajectory:
|
|
|
|
+ #起点位置设置为规划组最后一个点
|
|
|
|
+ pose = self.arm.get_current_pose(self.end_effector_link).pose
|
|
|
|
+ wpose = deepcopy(pose)
|
|
|
|
+ wpose.position.x=points[-1][0]
|
|
|
|
+ wpose.position.y=points[-1][1]
|
|
|
|
+ wpose.position.z=points[-1][2]
|
|
|
|
+ wpose.orientation.x=points[-1][3]
|
|
|
|
+ wpose.orientation.y=points[-1][4]
|
|
|
|
+ wpose.orientation.z=points[-1][5]
|
|
|
|
+ wpose.orientation.w=points[-1][6]
|
|
|
|
+ waypoints.append(deepcopy(wpose))
|
|
|
|
+
|
|
|
|
+ wpose.position.x=point[0]
|
|
|
|
+ wpose.position.y=point[1]
|
|
|
|
+ wpose.position.z=point[2]
|
|
|
|
+ wpose.orientation.x=point[3]
|
|
|
|
+ wpose.orientation.y=point[4]
|
|
|
|
+ wpose.orientation.z=point[5]
|
|
|
|
+ wpose.orientation.w=point[6]
|
|
|
|
+ waypoints.append(deepcopy(wpose))
|
|
|
|
+ else:
|
|
|
|
+ rospy.loginfo("error empty trajectory")
|
|
|
|
+ return
|
|
|
|
+ # 尝试规划一条笛卡尔空间下的路径,依次通过所有路点
|
|
|
|
+ while fraction < 1.0 and attempts < maxtries:
|
|
|
|
+ (plan, fraction) = self.arm.compute_cartesian_path(
|
|
|
|
+ waypoints, # waypoint poses,路点列表
|
|
|
|
+ 0.001, # eef_step,终端步进值
|
|
|
|
+ 0.0, # jump_threshold,跳跃阈值
|
|
|
|
+ True) # avoid_collisions,避障规划
|
|
|
|
+ attempts += 1
|
|
|
|
+
|
|
|
|
+ if fraction == 1.0 :
|
|
|
|
+ rospy.loginfo("Path computed successfully.")
|
|
|
|
+ #traj = plan
|
|
|
|
+ trajj = plan #取出规划的信息
|
|
|
|
+ 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"
|
|
|
|
+ points.append(point)
|
|
|
|
+ trajectory.append(trajj)
|
|
|
|
+ trajectory_with_type.append(trajj_with_type)
|
|
|
|
+ else:
|
|
|
|
+ rospy.loginfo(plan[3].val)
|
|
|
|
+ rospy.loginfo(
|
|
|
|
+ "fraction=" + str(fraction) + " success after " + str(maxtries))
|
|
|
|
+
|
|
|
|
+ # rospy.loginfo("本次焊缝规划失败")
|
|
|
|
+ # points.pop()#将本条焊缝的起点从规划中删除
|
|
|
|
+ # trajectory.pop()
|
|
|
|
+ # trajectory_with_type.pop()
|
|
|
|
+ # self.hf_fail.append(welding_sequence[self.hf_num])#将焊缝添加到失败列表
|
|
|
|
+ #self.hf_num=self.hf_num+1#焊缝计数
|
|
|
|
+ return points,trajectory,trajectory_with_type
|
|
|
|
+
|
|
|
|
+
|
|
def get_now_pose(self):
|
|
def get_now_pose(self):
|
|
# 获取机械臂当前位姿
|
|
# 获取机械臂当前位姿
|
|
current_pose = self.arm.get_current_pose(self.end_effector_link).pose
|
|
current_pose = self.arm.get_current_pose(self.end_effector_link).pose
|
|
@@ -88,7 +158,8 @@ class MoveIt_Control:
|
|
# 打印位姿信息
|
|
# 打印位姿信息
|
|
#rospy.lohome_poseinfo("Current Pose: {}".format(pose))
|
|
#rospy.lohome_poseinfo("Current Pose: {}".format(pose))
|
|
return pose
|
|
return pose
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ #TODO move_p_path_constraints
|
|
def create_path_constraints2(self,start_point,end_point,r):#创建路径约束
|
|
def create_path_constraints2(self,start_point,end_point,r):#创建路径约束
|
|
#计算起点指向终点的向量
|
|
#计算起点指向终点的向量
|
|
vector = np.array([end_point[0]- start_point[0], end_point[1]- start_point[1], end_point[2]- start_point[2]])
|
|
vector = np.array([end_point[0]- start_point[0], end_point[1]- start_point[1], end_point[2]- start_point[2]])
|
|
@@ -130,6 +201,7 @@ class MoveIt_Control:
|
|
# constraints.orientation_constraints.append(orientation_constraint)
|
|
# constraints.orientation_constraints.append(orientation_constraint)
|
|
return constraints
|
|
return constraints
|
|
|
|
|
|
|
|
+ #TODO move_p_flexible
|
|
def move_p_flexible(self,point,points,trajectory,trajectory_with_type,a=1,v=1):
|
|
def move_p_flexible(self,point,points,trajectory,trajectory_with_type,a=1,v=1):
|
|
self.arm.set_max_acceleration_scaling_factor(a)
|
|
self.arm.set_max_acceleration_scaling_factor(a)
|
|
self.arm.set_max_velocity_scaling_factor(v)
|
|
self.arm.set_max_velocity_scaling_factor(v)
|
|
@@ -157,17 +229,21 @@ class MoveIt_Control:
|
|
traj = self.arm.plan()#调用plan进行规划
|
|
traj = self.arm.plan()#调用plan进行规划
|
|
error=traj[3]
|
|
error=traj[3]
|
|
if error.val == moveit_msgs.msg._MoveItErrorCodes.MoveItErrorCodes.SUCCESS:
|
|
if error.val == moveit_msgs.msg._MoveItErrorCodes.MoveItErrorCodes.SUCCESS:
|
|
- rospy.loginfo("本次移动OK")
|
|
|
|
trajj = traj[1] #取出规划的信息
|
|
trajj = traj[1] #取出规划的信息
|
|
- trajj_with_type = mark_the_traj(trajj,"during-p",welding_sequence)
|
|
|
|
- trajj_with_type.points[-len(trajj.joint_trajectory.points)].type = "start"
|
|
|
|
- trajj_with_type.points[-1].type = "end"
|
|
|
|
- trajectory_with_type.append(trajj_with_type)
|
|
|
|
- points.append(point)
|
|
|
|
- trajectory.append(trajj)
|
|
|
|
- break
|
|
|
|
|
|
+ rospy.loginfo("正在检查移动轨迹有效性...")
|
|
|
|
+ error_c, limit_margin=check.check_joint_positions(trajj)
|
|
|
|
+ if not error_c:
|
|
|
|
+ rospy.loginfo("本次移动OK")
|
|
|
|
+ rospy.loginfo("*******************")
|
|
|
|
+ trajj_with_type = mark_the_traj(trajj,"during-p",welding_sequence)
|
|
|
|
+ trajj_with_type.points[-len(trajj.joint_trajectory.points)].type = "start"
|
|
|
|
+ trajj_with_type.points[-1].type = "end"
|
|
|
|
+ trajectory_with_type.append(trajj_with_type)
|
|
|
|
+ points.append(point)
|
|
|
|
+ trajectory.append(trajj)
|
|
|
|
+ break
|
|
else:
|
|
else:
|
|
- rospy.loginfo(error)
|
|
|
|
|
|
+ rospy.loginfo("check failed! 移动轨迹无效")
|
|
rospy.loginfo("移动规划失败-开始第{}次重新规划".format(i+1))
|
|
rospy.loginfo("移动规划失败-开始第{}次重新规划".format(i+1))
|
|
self.arm.clear_path_constraints()
|
|
self.arm.clear_path_constraints()
|
|
rrr=rrr+0.2#每次增加20厘米半径
|
|
rrr=rrr+0.2#每次增加20厘米半径
|
|
@@ -189,7 +265,7 @@ class MoveIt_Control:
|
|
|
|
|
|
return points,trajectory,trajectory_with_type,er
|
|
return points,trajectory,trajectory_with_type,er
|
|
|
|
|
|
-
|
|
|
|
|
|
+
|
|
def move_pl(self,point,points,trajectory,trajectory_with_type,a=1,v=1):#焊缝的规划 只规划当前的点到上一个点
|
|
def move_pl(self,point,points,trajectory,trajectory_with_type,a=1,v=1):#焊缝的规划 只规划当前的点到上一个点
|
|
|
|
|
|
self.arm.set_max_acceleration_scaling_factor(a)
|
|
self.arm.set_max_acceleration_scaling_factor(a)
|
|
@@ -197,21 +273,22 @@ class MoveIt_Control:
|
|
|
|
|
|
#设定约束
|
|
#设定约束
|
|
if trajectory:
|
|
if trajectory:
|
|
- #起点位置设置为规划组最后一个点
|
|
|
|
|
|
+ #起点位置设置为规划组最后一个点
|
|
state = self.arm.get_current_state()
|
|
state = self.arm.get_current_state()
|
|
state.joint_state.position = trajectory[-1].joint_trajectory.points[-1].positions
|
|
state.joint_state.position = trajectory[-1].joint_trajectory.points[-1].positions
|
|
self.arm.set_start_state(state)
|
|
self.arm.set_start_state(state)
|
|
-
|
|
|
|
|
|
+
|
|
self.arm.set_pose_target(point, self.end_effector_link)#设定目标点为传入的点
|
|
self.arm.set_pose_target(point, self.end_effector_link)#设定目标点为传入的点
|
|
-
|
|
|
|
|
|
+
|
|
# 创建路径约束
|
|
# 创建路径约束
|
|
path_constraints = self.create_path_constraints(points[-1],point)#将最后一个点和输入的点(焊缝的起始点)做圆柱轨迹约束
|
|
path_constraints = self.create_path_constraints(points[-1],point)#将最后一个点和输入的点(焊缝的起始点)做圆柱轨迹约束
|
|
self.arm.set_path_constraints(path_constraints)#设定约束
|
|
self.arm.set_path_constraints(path_constraints)#设定约束
|
|
-
|
|
|
|
|
|
+
|
|
traj = self.arm.plan()#调用plan进行规划
|
|
traj = self.arm.plan()#调用plan进行规划
|
|
error=traj[3]
|
|
error=traj[3]
|
|
if error.val == moveit_msgs.msg._MoveItErrorCodes.MoveItErrorCodes.SUCCESS:
|
|
if error.val == moveit_msgs.msg._MoveItErrorCodes.MoveItErrorCodes.SUCCESS:
|
|
rospy.loginfo("本次焊缝规划 OK")
|
|
rospy.loginfo("本次焊缝规划 OK")
|
|
|
|
+ rospy.loginfo("*******************")
|
|
trajj = traj[1] #取出规划的信息
|
|
trajj = traj[1] #取出规划的信息
|
|
trajj_with_type = mark_the_traj(trajj,"during-l",welding_sequence)
|
|
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[-len(trajj.joint_trajectory.points)].type = "start"
|
|
@@ -224,17 +301,77 @@ class MoveIt_Control:
|
|
points.pop()#将本条焊缝的起点从规划中删除
|
|
points.pop()#将本条焊缝的起点从规划中删除
|
|
trajectory.pop()
|
|
trajectory.pop()
|
|
trajectory_with_type.pop()
|
|
trajectory_with_type.pop()
|
|
- self.hf_fail.append(welding_sequence[self.hf_num])
|
|
|
|
|
|
+ self.hf_fail.append(welding_sequence[self.hf_num])#将焊缝添加到失败列表
|
|
#清除约束
|
|
#清除约束
|
|
self.arm.clear_path_constraints()
|
|
self.arm.clear_path_constraints()
|
|
self.hf_num=self.hf_num+1#焊缝计数
|
|
self.hf_num=self.hf_num+1#焊缝计数
|
|
return points,trajectory,trajectory_with_type
|
|
return points,trajectory,trajectory_with_type
|
|
|
|
|
|
|
|
+ def move_pl_check(self,point,points,trajectory,trajectory_with_type,a=1,v=1):
|
|
|
|
+ self.arm.set_max_acceleration_scaling_factor(a)
|
|
|
|
+ self.arm.set_max_velocity_scaling_factor(v)
|
|
|
|
+
|
|
|
|
+ #重新规划起点次数
|
|
|
|
+ a=10
|
|
|
|
+ for j in range(a):
|
|
|
|
+ if trajectory:
|
|
|
|
+ state=self.arm.get_current_state()
|
|
|
|
+ state.joint_state.position = trajectory[-1].joint_trajectory.points[-1].positions
|
|
|
|
+ self.arm.set_start_state(state)
|
|
|
|
+
|
|
|
|
+ self.arm.set_pose_target(point, self.end_effector_link)
|
|
|
|
+
|
|
|
|
+ path_constraints = self.create_path_constraints(points[-1],point)
|
|
|
|
+ self.arm.set_path_constraints(path_constraints)
|
|
|
|
+
|
|
|
|
+ #当前起点规划次数
|
|
|
|
+ b=10
|
|
|
|
+ for i in range(b):
|
|
|
|
+ traj = self.arm.plan()
|
|
|
|
+ error=traj[3]
|
|
|
|
+ if error.val == moveit_msgs.msg._MoveItErrorCodes.MoveItErrorCodes.SUCCESS:
|
|
|
|
+ trajj = traj[1] #取出规划的信息
|
|
|
|
+ rospy.loginfo("正在检查焊缝轨迹有效性...")
|
|
|
|
+ error_c,limit_margin=check.check_joint_positions(trajj)
|
|
|
|
+ if not error_c:
|
|
|
|
+ rospy.loginfo("本次焊缝规划OK")
|
|
|
|
+ rospy.loginfo("*******************")
|
|
|
|
+ break
|
|
|
|
+ if not limit_margin or i==b-1:
|
|
|
|
+ prepoint=points.pop()
|
|
|
|
+ trajectory.pop()
|
|
|
|
+ trajectory_with_type.pop()
|
|
|
|
+ #清除约束
|
|
|
|
+ self.arm.clear_path_constraints()
|
|
|
|
+ points,trajectory,trajectory_with_type,er1= self.move_p_flexible(prepoint,points,trajectory,trajectory_with_type)
|
|
|
|
+ break
|
|
|
|
+ rospy.loginfo("The {}-{}th replanning".format(j,i+1))
|
|
|
|
+ if not error_c:
|
|
|
|
+ break
|
|
|
|
+ if error_c:
|
|
|
|
+ rospy.loginfo("本次焊缝规划失败")
|
|
|
|
+ rospy.loginfo("*******************")
|
|
|
|
+ self.hf_fail.append(welding_sequence[self.hf_num])
|
|
|
|
+
|
|
|
|
+ self.arm.clear_path_constraints()
|
|
|
|
+ self.hf_num=self.hf_num+1#焊缝计数
|
|
|
|
+
|
|
|
|
+ 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"
|
|
|
|
+
|
|
|
|
+ points.append(point)
|
|
|
|
+ trajectory.append(trajj)
|
|
|
|
+ trajectory_with_type.append(trajj_with_type)
|
|
|
|
+
|
|
|
|
+ return points,trajectory,trajectory_with_type
|
|
|
|
+
|
|
|
|
+ #TODO move_pl_path_constraints
|
|
def create_path_constraints(self,start_point,end_point):
|
|
def create_path_constraints(self,start_point,end_point):
|
|
#计算起点指向终点的向量
|
|
#计算起点指向终点的向量
|
|
vector = np.array([end_point[0]- start_point[0], end_point[1]- start_point[1], end_point[2]- start_point[2]])
|
|
vector = np.array([end_point[0]- start_point[0], end_point[1]- start_point[1], end_point[2]- start_point[2]])
|
|
height = np.linalg.norm(vector)+0.002
|
|
height = np.linalg.norm(vector)+0.002
|
|
- radius = 0.001
|
|
|
|
|
|
+ radius = 0.01
|
|
|
|
|
|
constraints = Constraints()
|
|
constraints = Constraints()
|
|
|
|
|
|
@@ -271,7 +408,9 @@ class MoveIt_Control:
|
|
constraints.position_constraints.append(position_constraint)
|
|
constraints.position_constraints.append(position_constraint)
|
|
|
|
|
|
return constraints
|
|
return constraints
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ #TODO go_home
|
|
|
|
+ @decorator_time
|
|
def go_home(self,a=1,v=1):
|
|
def go_home(self,a=1,v=1):
|
|
rospy.loginfo("go_home start")
|
|
rospy.loginfo("go_home start")
|
|
self.arm.set_max_acceleration_scaling_factor(a)
|
|
self.arm.set_max_acceleration_scaling_factor(a)
|
|
@@ -282,6 +421,7 @@ class MoveIt_Control:
|
|
rospy.loginfo("go_home end")
|
|
rospy.loginfo("go_home end")
|
|
# rospy.sleep(1)
|
|
# rospy.sleep(1)
|
|
|
|
|
|
|
|
+ #TODO go_home_justplan
|
|
def go_home_justplan(self,trajectory,trajectory_with_type,a=1,v=1):
|
|
def go_home_justplan(self,trajectory,trajectory_with_type,a=1,v=1):
|
|
self.arm.set_max_acceleration_scaling_factor(a)
|
|
self.arm.set_max_acceleration_scaling_factor(a)
|
|
self.arm.set_max_velocity_scaling_factor(v)
|
|
self.arm.set_max_velocity_scaling_factor(v)
|
|
@@ -296,6 +436,8 @@ class MoveIt_Control:
|
|
trajectory_with_type.append(traj_with_type)
|
|
trajectory_with_type.append(traj_with_type)
|
|
return trajectory,trajectory_with_type
|
|
return trajectory,trajectory_with_type
|
|
|
|
|
|
|
|
+ #TODO path_planning
|
|
|
|
+ @decorator_time
|
|
def path_planning(self,folder_path,gohome=True):
|
|
def path_planning(self,folder_path,gohome=True):
|
|
file_path_result = os.path.join(folder_path, 'result.txt')
|
|
file_path_result = os.path.join(folder_path, 'result.txt')
|
|
all_data = process_welding_data(file_path_result)
|
|
all_data = process_welding_data(file_path_result)
|
|
@@ -309,16 +451,17 @@ class MoveIt_Control:
|
|
q2 = all_data[i][3]
|
|
q2 = all_data[i][3]
|
|
|
|
|
|
point11 = [start_point[0]/1000, start_point[1]/1000, start_point[2]/1000, q1[0],q1[1],q1[2],q1[3]]
|
|
point11 = [start_point[0]/1000, start_point[1]/1000, start_point[2]/1000, q1[0],q1[1],q1[2],q1[3]]
|
|
- points,trajectory,trajectory_with_type,err = self.move_p_flexible(point11,points,trajectory,trajectory_with_type,v=speed_v)
|
|
|
|
|
|
+ points,trajectory,trajectory_with_type,err = self.move_p_flexible(point11,points,trajectory,trajectory_with_type)
|
|
if err==1:#焊缝起点不可达 则跳过此次焊缝和移动的规划 并将焊缝添加到失败列表
|
|
if err==1:#焊缝起点不可达 则跳过此次焊缝和移动的规划 并将焊缝添加到失败列表
|
|
self.hf_fail.append(welding_sequence[self.hf_num])
|
|
self.hf_fail.append(welding_sequence[self.hf_num])
|
|
self.hf_num=self.hf_num+1#焊缝计数
|
|
self.hf_num=self.hf_num+1#焊缝计数
|
|
continue
|
|
continue
|
|
|
|
|
|
point22 = [end_point[0]/1000, end_point[1]/1000, end_point[2]/1000, q2[0],q2[1],q2[2],q2[3]]
|
|
point22 = [end_point[0]/1000, end_point[1]/1000, end_point[2]/1000, q2[0],q2[1],q2[2],q2[3]]
|
|
- points,trajectory,trajectory_with_type = self.move_pl(point22,points,trajectory,trajectory_with_type)
|
|
|
|
|
|
+ points,trajectory,trajectory_with_type = self.plan_cartesian_path_LLL(point22,points,trajectory,trajectory_with_type,v=speed_v)
|
|
|
|
|
|
rospy.loginfo("第%d条焊缝规划完毕",i+1)
|
|
rospy.loginfo("第%d条焊缝规划完毕",i+1)
|
|
|
|
+ rospy.loginfo("*******************")
|
|
if gohome:
|
|
if gohome:
|
|
points,trajectory,trajectory_with_type,err= self.move_p_flexible(self.home_pose,points,trajectory,trajectory_with_type,v=speed_v)
|
|
points,trajectory,trajectory_with_type,err= self.move_p_flexible(self.home_pose,points,trajectory,trajectory_with_type,v=speed_v)
|
|
trajectory,trajectory_with_type = self.go_home_justplan(trajectory,trajectory_with_type)
|
|
trajectory,trajectory_with_type = self.go_home_justplan(trajectory,trajectory_with_type)
|
|
@@ -345,6 +488,7 @@ def process_welding_data(filename):
|
|
|
|
|
|
return all_data
|
|
return all_data
|
|
|
|
|
|
|
|
+
|
|
def mark_the_traj(traj,TYPE,SEQUENCE):
|
|
def mark_the_traj(traj,TYPE,SEQUENCE):
|
|
traj_with_type = JointTrajectory_ex()
|
|
traj_with_type = JointTrajectory_ex()
|
|
traj_with_type.header = traj.joint_trajectory.header
|
|
traj_with_type.header = traj.joint_trajectory.header
|
|
@@ -361,6 +505,7 @@ def mark_the_traj(traj,TYPE,SEQUENCE):
|
|
]
|
|
]
|
|
return traj_with_type
|
|
return traj_with_type
|
|
|
|
|
|
|
|
+
|
|
def merge_trajectories(trajectories):
|
|
def merge_trajectories(trajectories):
|
|
if not trajectories:
|
|
if not trajectories:
|
|
return None
|
|
return None
|
|
@@ -389,6 +534,7 @@ def merge_trajectories(trajectories):
|
|
|
|
|
|
return merged_trajectory
|
|
return merged_trajectory
|
|
|
|
|
|
|
|
+
|
|
def merge_trajectories_with_type(trajectory_with_type):
|
|
def merge_trajectories_with_type(trajectory_with_type):
|
|
if not trajectory_with_type:
|
|
if not trajectory_with_type:
|
|
return None
|
|
return None
|
|
@@ -472,10 +618,10 @@ def get_valid_input(factor, default):
|
|
return default
|
|
return default
|
|
try:
|
|
try:
|
|
value=float(user_input)
|
|
value=float(user_input)
|
|
- if 0<=value<=1:
|
|
|
|
|
|
+ if 0<value<=1:
|
|
return value
|
|
return value
|
|
else:
|
|
else:
|
|
- rospy.logerr("缩放因子必须在[0, 1]范围内,请重新输入!")
|
|
|
|
|
|
+ rospy.logerr("缩放因子必须在(0, 1]范围内,请重新输入!")
|
|
except ValueError:
|
|
except ValueError:
|
|
rospy.logerr("输入值无效,请根据提示重新输入!")
|
|
rospy.logerr("输入值无效,请根据提示重新输入!")
|
|
|
|
|
|
@@ -495,8 +641,41 @@ def get_user_input():
|
|
return vv
|
|
return vv
|
|
except Exception as e:
|
|
except Exception as e:
|
|
rospy.logerr(f"发生错误:{e}")
|
|
rospy.logerr(f"发生错误:{e}")
|
|
-
|
|
|
|
|
|
|
|
|
|
+def ROS2_msgs(msgs, m_sr):
|
|
|
|
+ for i in range(len(msgs.points)):
|
|
|
|
+ py_msgs.point.xyz_list.append(msgs.points[i].positions)
|
|
|
|
+
|
|
|
|
+ f_p = os.path.join(folder_path, 'outtt.txt')
|
|
|
|
+ with open(f_p,'w') as file:
|
|
|
|
+ for point in py_msgs.point.xyz_list:
|
|
|
|
+ file.write(' '.join(str(value) for value in point)+ "\n")
|
|
|
|
+
|
|
|
|
+# def write_ee(msgs, m_sr):
|
|
|
|
+# for i in range(len(msgs.points)):
|
|
|
|
+# py_msgs.point.xyz_list.append(msgs.points[i].positions)
|
|
|
|
+
|
|
|
|
+# f_p1 = os.path.join(folder_path, 'ee_pos.txt')
|
|
|
|
+# with open(f_p1,'w') as file:
|
|
|
|
+# for point in py_msgs.point.xyz_list:
|
|
|
|
+# #更新机械臂状态
|
|
|
|
+# state=m_sr.arm.get_current_state()
|
|
|
|
+# #state.joint_state.position=point
|
|
|
|
+
|
|
|
|
+# #获取末端执行器的位姿
|
|
|
|
+# fk_result=m_sr.arm.get_current_pose(moveit_server.end_effector_link)
|
|
|
|
+
|
|
|
|
+# #获取位置信息
|
|
|
|
+# position=fk_result.pose.position
|
|
|
|
+# orientation=fk_result.pose.orientation
|
|
|
|
+
|
|
|
|
+# #格式化数据
|
|
|
|
+# pose_data = f"Position: x={position.x}, y={position.y}, z={position.z}\n"
|
|
|
|
+# pose_data += f"Orientation (Quaternion): x={orientation.x}, y={orientation.y}, z={orientation.z}, w={orientation.w}\n"
|
|
|
|
+# pose_data += "-" * 50 + "\n"
|
|
|
|
+
|
|
|
|
+# file.write(pose_data)
|
|
|
|
+
|
|
if __name__ =="__main__":
|
|
if __name__ =="__main__":
|
|
# from redis_publisher import Publisher
|
|
# from redis_publisher import Publisher
|
|
# publisher = Publisher()
|
|
# publisher = Publisher()
|
|
@@ -506,12 +685,14 @@ if __name__ =="__main__":
|
|
moveit_server = MoveIt_Control(is_use_gripper=False)
|
|
moveit_server = MoveIt_Control(is_use_gripper=False)
|
|
welding_sequence = rospy.get_param('welding_sequence')
|
|
welding_sequence = rospy.get_param('welding_sequence')
|
|
|
|
|
|
-
|
|
|
|
- speed_v=get_user_input()
|
|
|
|
- rospy.loginfo(f"用户输入的速度缩放因子为{speed_v}")
|
|
|
|
|
|
+ speed_v=1
|
|
|
|
+ # speed_v=get_user_input()
|
|
|
|
+ # rospy.loginfo(f"用户输入的速度缩放因子为{speed_v}")
|
|
|
|
|
|
trajectory,trajectory_merge,trajectory_with_type_merge = moveit_server.path_planning(folder_path)
|
|
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.arm.execute(trajectory_merge)
|
|
moveit_server.arm.execute(trajectory_merge)
|
|
|
|
|
|
rospy.set_param("sign_control",0)
|
|
rospy.set_param("sign_control",0)
|