|
@@ -40,7 +40,7 @@ class MoveIt_Control:
|
|
|
self.arm.set_goal_joint_tolerance(0.0001)
|
|
|
self.arm.set_goal_position_tolerance(0.0005)
|
|
|
self.arm.set_goal_orientation_tolerance(0.1)
|
|
|
- self.arm.set_planner_id("RRTConnet")#不知道能不能用
|
|
|
+ #self.arm.set_planner_id("RRTConnet")#不知道能不能用
|
|
|
|
|
|
self.end_effector_link = self.arm.get_end_effector_link()
|
|
|
# 设置机械臂基座的参考系
|
|
@@ -48,7 +48,7 @@ class MoveIt_Control:
|
|
|
self.arm.set_pose_reference_frame(self.reference_frame)
|
|
|
|
|
|
# # 设置最大规划时间和是否允许重新规划
|
|
|
- self.arm.set_planning_time(10)
|
|
|
+ self.arm.set_planning_time(10.0)
|
|
|
self.arm.allow_replanning(True)
|
|
|
|
|
|
self.arm.set_max_acceleration_scaling_factor(1)
|
|
@@ -70,7 +70,7 @@ class MoveIt_Control:
|
|
|
self.arm.set_joint_value_target(joint_configuration)
|
|
|
rospy.loginfo("move_j:"+str(joint_configuration))
|
|
|
self.arm.go()
|
|
|
- rospy.sleep(1)
|
|
|
+ #rospy.sleep(1)
|
|
|
|
|
|
def get_now_pose(self):
|
|
|
# 获取机械臂当前位姿
|
|
@@ -87,11 +87,11 @@ class MoveIt_Control:
|
|
|
# 打印位姿信息
|
|
|
#rospy.lohome_poseinfo("Current Pose: {}".format(pose))
|
|
|
return pose
|
|
|
-
|
|
|
+
|
|
|
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]])
|
|
|
- height = np.linalg.norm(vector)+0.006 #计算向量或矩阵的范数 用于度量向量或矩阵的大小或长度
|
|
|
+ height = np.linalg.norm(vector)+0.16 #高度延长16cm
|
|
|
radius = r
|
|
|
|
|
|
# 位置约束
|
|
@@ -101,7 +101,6 @@ class MoveIt_Control:
|
|
|
position_constraint.target_point_offset = Vector3(0, 0, 0)#目标点的偏移量
|
|
|
position_constraint.weight = 1.0#质量 OR 加权因子?
|
|
|
|
|
|
-
|
|
|
#构建 shape_msgs/SolidPrimitive 消息
|
|
|
bounding_volume = SolidPrimitive()
|
|
|
bounding_volume.type = SolidPrimitive.CYLINDER#圆柱
|
|
@@ -109,7 +108,6 @@ class MoveIt_Control:
|
|
|
bounding_volume.dimensions = [height,radius]#尺寸 高度 半径
|
|
|
position_constraint.constraint_region.primitives.append(bounding_volume)
|
|
|
|
|
|
-
|
|
|
#构建 geometry_msgs/Pose 消息,用于指定圆柱体在空间中的位置和姿态
|
|
|
pose = Pose()
|
|
|
pose.position.x = start_point[0] + vector[0] / 2#定义位置(找了个几何中心)
|
|
@@ -153,7 +151,7 @@ class MoveIt_Control:
|
|
|
self.arm.set_start_state(state)#起点位置设置为规划组最后一个点 或者当前状态(第一个点时)
|
|
|
|
|
|
#尝试规划次数
|
|
|
- b = 16 #尝试规划10次
|
|
|
+ b = 10 #尝试规划5次 无约束5次
|
|
|
for i in range(b):
|
|
|
traj = self.arm.plan()#调用plan进行规划
|
|
|
error=traj[3]
|
|
@@ -168,15 +166,19 @@ class MoveIt_Control:
|
|
|
trajectory.append(trajj)
|
|
|
break
|
|
|
else:
|
|
|
+ rospy.loginfo(error)
|
|
|
rospy.loginfo("移动规划失败-开始第{}次重新规划".format(i+1))
|
|
|
self.arm.clear_path_constraints()
|
|
|
rrr=rrr+0.2#每次增加10厘米
|
|
|
- rospy.loginfo("R值:{}次重新规划".format(rrr))
|
|
|
+ rospy.loginfo("R值:{}".format(rrr))
|
|
|
path_constraints = self.create_path_constraints2(points[-1],point,rrr)#将最后一个点和输入的点(焊缝的起始点)做圆柱轨迹约束
|
|
|
self.arm.set_path_constraints(path_constraints)#设定约束
|
|
|
- if(i==(b-1)):
|
|
|
- rospy.loginfo("所有移动规划尝试失败 规划器停止---请检查工件")
|
|
|
+ if(i>=(b-5)):
|
|
|
+ rospy.loginfo("所有移动规划尝试失败 取消路径约束")
|
|
|
self.arm.clear_path_constraints()
|
|
|
+ if(i==(b-1)):
|
|
|
+ rospy.loginfo("所有移动规划尝试失败 程序退出")
|
|
|
+ rospy.set_param("sign_control",0)
|
|
|
sys.exit(0)
|
|
|
#清除约束
|
|
|
self.arm.clear_path_constraints()
|
|
@@ -270,7 +272,6 @@ class MoveIt_Control:
|
|
|
rospy.loginfo("go_home start")
|
|
|
self.arm.set_max_acceleration_scaling_factor(a)
|
|
|
self.arm.set_max_velocity_scaling_factor(v)
|
|
|
- # “up”为自定义姿态,你可以使用“home”或者其他姿态
|
|
|
self.arm.set_named_target('home')
|
|
|
rospy.loginfo("get_home end")
|
|
|
self.arm.go()
|
|
@@ -280,7 +281,6 @@ class MoveIt_Control:
|
|
|
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_velocity_scaling_factor(v)
|
|
|
- # “up”为自定义姿态,你可以使用“home”或者其他姿态
|
|
|
state = self.arm.get_current_state()
|
|
|
state.joint_state.position = trajectory[-1].joint_trajectory.points[-1].positions
|
|
|
self.arm.set_start_state(state)
|
|
@@ -439,13 +439,16 @@ def ROS2PY_msgs(msgs,m_sr):
|
|
|
py_msgs.point.type.append(msgs.points[i].type)
|
|
|
py_msgs.fail=m_sr.hf_fail.copy()
|
|
|
py_msgs.shun_xv=msgs.points[0].sequence.copy()
|
|
|
- for i in range(len(py_msgs.point.type)):
|
|
|
- print(py_msgs.point.xyz_list[i])
|
|
|
- print(py_msgs.point.type[i])
|
|
|
+
|
|
|
+ # for i in range(len(py_msgs.point.type)):
|
|
|
+ # print(py_msgs.point.xyz_list[i])
|
|
|
+ # print(py_msgs.point.type[i])
|
|
|
print(py_msgs.shun_xv)
|
|
|
print(py_msgs.fial)
|
|
|
|
|
|
-
|
|
|
+ # for i in range(len(py_msgs.point.type)):
|
|
|
+ # moveit_server.move_j(py_msgs.point.xyz_list[i])
|
|
|
+ # #input("任意键继续")
|
|
|
|
|
|
if __name__ =="__main__":
|
|
|
|
|
@@ -459,7 +462,8 @@ if __name__ =="__main__":
|
|
|
# trajectory,trajectory_merge,trajectory_with_type_merge = moveit_server.path_planning_test(folder_path,1,True)
|
|
|
#执行动作
|
|
|
|
|
|
- ROS2PY_msgs(trajectory_with_type_merge,moveit_server)
|
|
|
+ #ROS2PY_msgs(trajectory_with_type_merge,moveit_server)
|
|
|
+
|
|
|
|
|
|
moveit_server.arm.execute(trajectory_merge)
|
|
|
|