bzx 8 maanden geleden
bovenliggende
commit
fb3b2d81b9

+ 20 - 12
catkin_ws/src/lstrobot_moveit_config_0605/launch/moveit.rviz

@@ -5,12 +5,11 @@ Panels:
     Property Tree Widget:
       Expanded:
         - /MotionPlanning1
-        - /MotionPlanning1/Scene Geometry1
-        - /MotionPlanning1/Planning Request1
+        - /MotionPlanning1/Planned Path1
         - /RobotModel1/Links1
         - /Trajectory1/Links1
-      Splitter Ratio: 0.4285714328289032
-    Tree Height: 371
+      Splitter Ratio: 0.6529411673545837
+    Tree Height: 737
   - Class: rviz/Help
     Name: Help
   - Class: rviz/Views
@@ -351,7 +350,16 @@ Visualization Manager:
       Marker Topic: /rviz_visual_tools
       Name: MarkerArray
       Namespaces:
-        {}
+        Path: true
+        Text: true
+        point0  0.978994  -0.262691  0.279523: true
+        point0  0.980265  0.126875  0.278115: true
+        point0  0.983265  0.126875  0.278115: true
+        point0  0.983265  0.126875  0.473115: true
+        point1  0.978378  0.122593  0.278064: true
+        point1  0.983265  -0.262875  0.473115: true
+        point1  0.983265  0.126875  0.468115: true
+        point1  1.125382  0.127069  0.280059: true
       Queue Size: 100
       Value: true
     - Class: rviz/TF
@@ -387,7 +395,7 @@ Visualization Manager:
   Views:
     Current:
       Class: rviz/Orbit
-      Distance: 1.0678346157073975
+      Distance: 3.102827310562134
       Enable Stereo Rendering:
         Stereo Eye Separation: 0.05999999865889549
         Stereo Focal Distance: 1
@@ -395,17 +403,17 @@ Visualization Manager:
         Value: false
       Field of View: 0.75
       Focal Point:
-        X: 1.0571471452713013
-        Y: -0.049734726548194885
-        Z: 0.29948994517326355
+        X: 1.3195676803588867
+        Y: 0.5246121883392334
+        Z: 0.8483012914657593
       Focal Shape Fixed Size: true
       Focal Shape Size: 0.05000000074505806
       Invert Z Axis: false
       Name: Current View
       Near Clip Distance: 0.009999999776482582
-      Pitch: 0.6502028107643127
+      Pitch: 0.4452030062675476
       Target Frame: base_link
-      Yaw: 5.132473468780518
+      Yaw: 4.942476749420166
     Saved: ~
 Window Geometry:
   Displays:
@@ -419,7 +427,7 @@ Window Geometry:
     collapsed: false
   MotionPlanning - Trajectory Slider:
     collapsed: false
-  QMainWindow State: 000000ff00000000fd0000000100000000000001f3000003b9fc0200000009fb000000100044006900730070006c006100790073010000003d00000204000000c900fffffffb0000000800480065006c00700000000342000000bb0000006e00fffffffb0000000a00560069006500770073000000010c000000a4000000a400fffffffb0000000c00430061006d00650072006100000002ff000001610000000000000000fb0000001e004d006f00740069006f006e00200050006c0061006e006e0069006e00670100000374000001890000000000000000fb00000044004d006f00740069006f006e0050006c0061006e006e0069006e00670020002d0020005400720061006a006500630074006f0072007900200053006c00690064006500720000000000ffffffff0000001600000016fb0000001c004d006f00740069006f006e0050006c0061006e006e0069006e00670100000247000001af0000017d00fffffffb000000280020002d0020005400720061006a006500630074006f0072007900200053006c00690064006500720000000000ffffffff0000000000000000fb0000003c005400720061006a006500630074006f007200790020002d0020005400720061006a006500630074006f0072007900200053006c00690064006500720000000000ffffffff000000160000001600000587000003b900000001000000020000000100000002fc0000000100000002000000010000000a0054006f006f006c00730100000000ffffffff0000000000000000
+  QMainWindow State: 000000ff00000000fd000000010000000000000156000003b9fc0200000009fb000000100044006900730070006c006100790073010000003d00000372000000c900fffffffb0000000800480065006c00700000000342000000bb0000006e00fffffffb0000000a00560069006500770073000000010c000000a4000000a400fffffffb0000000c00430061006d00650072006100000002ff000001610000000000000000fb0000001e004d006f00740069006f006e00200050006c0061006e006e0069006e00670100000374000001890000000000000000fb00000044004d006f00740069006f006e0050006c0061006e006e0069006e00670020002d0020005400720061006a006500630074006f0072007900200053006c006900640065007201000003b5000000410000004100fffffffb0000001c004d006f00740069006f006e0050006c0061006e006e0069006e00670000000210000001e60000017d00fffffffb000000280020002d0020005400720061006a006500630074006f0072007900200053006c00690064006500720000000000ffffffff0000000000000000fb0000003c005400720061006a006500630074006f007200790020002d0020005400720061006a006500630074006f0072007900200053006c006900640065007200000003b500000041000000160000001600000624000003b900000001000000020000000100000002fc0000000100000002000000010000000a0054006f006f006c00730100000000ffffffff0000000000000000
   Trajectory - Trajectory Slider:
     collapsed: false
   Views:

+ 5 - 0
catkin_ws/src/lstrobot_planning/launch/test.launch

@@ -0,0 +1,5 @@
+<launch>
+  <node pkg="lstrobot_planning" name="speed" type="speed.py"  output="screen">
+  </node>
+
+</launch>

BIN
catkin_ws/src/lstrobot_planning/scripts/__pycache__/command.cpython-38.pyc


+ 1 - 1
catkin_ws/src/lstrobot_planning/scripts/command.py

@@ -20,7 +20,7 @@ def close_rviz(terminal_name):
             os.kill(int(pid), signal.SIGTERM)
         except ProcessLookupError:
             pass  # 进程可能已经不存在
-        
+
 def load_visual():
     command = "rosrun visual visual_node"
     subprocess.Popen(['gnome-terminal', '--', 'bash', '-c', command])

+ 55 - 15
catkin_ws/src/lstrobot_planning/scripts/moveitServer2.py

@@ -24,6 +24,7 @@ import math
 import traceback
 from lstrobot_planning.msg import JointTrajectoryPoint_ex,JointTrajectory_ex
 import json
+import termios
 
 pi = np.pi
 
@@ -132,8 +133,8 @@ class MoveIt_Control:
     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_velocity_scaling_factor(v)
-        rrr=0.05#初始允许半径
- 
+        rrr=0.09#初始允许半径 9cm
+        er=0
         if trajectory:
             #起点位置设置为规划组最后一个点
             state = self.arm.get_current_state()
@@ -169,7 +170,7 @@ class MoveIt_Control:
                 rospy.loginfo(error)
                 rospy.loginfo("移动规划失败-开始第{}次重新规划".format(i+1))
                 self.arm.clear_path_constraints()
-                rrr=rrr+0.2#每次增加10厘米
+                rrr=rrr+0.2#每次增加20厘米半径
                 rospy.loginfo("R值:{}".format(rrr))
                 if trajectory:
                     path_constraints = self.create_path_constraints2(points[-1],point,rrr)#将最后一个点和输入的点(焊缝的起始点)做圆柱轨迹约束
@@ -180,13 +181,13 @@ class MoveIt_Control:
                     rospy.loginfo("所有移动规划尝试失败 取消路径约束")
                     self.arm.clear_path_constraints()
                 if(i==(b-1)):
-                    rospy.loginfo("所有移动规划尝试失败  程序退出")
-                    rospy.set_param("sign_control",0)
-                    sys.exit(0)
+                    rospy.loginfo("所有移动规划尝试失败  焊缝起点不可达")
+                    er=1
+                    break
         #清除约束
         self.arm.clear_path_constraints()
         
-        return points,trajectory,trajectory_with_type
+        return points,trajectory,trajectory_with_type,er
     
     
     def move_pl(self,point,points,trajectory,trajectory_with_type,a=1,v=1):#焊缝的规划  只规划当前的点到上一个点
@@ -298,7 +299,7 @@ class MoveIt_Control:
     def path_planning(self,folder_path,gohome=True):
         file_path_result = os.path.join(folder_path, 'result.txt')
         all_data = process_welding_data(file_path_result)
-
+        err=0
         points,trajectory,trajectory_with_type = [],[],[]
         for i in range(len(all_data)):
             rospy.loginfo("共读取到%d条焊缝,开始规划第%d条",len(all_data),i+1)
@@ -308,12 +309,18 @@ class MoveIt_Control:
             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]]
-            points,trajectory,trajectory_with_type = self.move_p_flexible(point11,points,trajectory,trajectory_with_type)
+            points,trajectory,trajectory_with_type,err = self.move_p_flexible(point11,points,trajectory,trajectory_with_type,v=speed_v)
+            if err==1:#焊缝起点不可达 则跳过此次焊缝和移动的规划 并将焊缝添加到失败列表   
+                self.hf_fail.append(welding_sequence[self.hf_num])
+                self.hf_num=self.hf_num+1#焊缝计数
+                continue
+
             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)
+
             rospy.loginfo("第%d条焊缝规划完毕",i+1)
         if gohome:
-            points,trajectory,trajectory_with_type = self.move_p_flexible(self.home_pose,points,trajectory,trajectory_with_type)
+            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)
         traj_merge= merge_trajectories(trajectory)
         trajectory_with_type_merge= merge_trajectories_with_type(trajectory_with_type)
@@ -458,19 +465,52 @@ def ROS2PY_msgs(msgs, m_sr):
     #     moveit_server.move_j(py_msgs.point.xyz_list[i])
     #     #input("任意键继续")
 
+def get_valid_input(factor, default):
+    while True:
+        user_input=input(factor)
+        if user_input=="":
+            return default
+        try:
+            value=float(user_input)
+            if 0<=value<=1:
+                return value
+            else:
+                rospy.logerr("缩放因子必须在[0, 1]范围内,请重新输入!")
+        except ValueError:
+            rospy.logerr("输入值无效,请根据提示重新输入!")
+
+def get_user_input():
+    """获取用户输入的速度和加速度缩放因子,并在控制台中打印信息和错误提示"""
+    DEFUALT_V = 1.0
+    DEFUALT_A = 1.0
+     
+    try:
+        termios.tcflush(sys.stdin, termios.TCIFLUSH)   #清空输入缓存
+        rospy.loginfo("输入缓存区已清空!")
+        
+        vv=get_valid_input("请输入速度缩放因子(0-1, 默认为1): ", DEFUALT_V)
+        #a=get_valid_input("请输入加速度缩放因子(0-1, 默认为1): ", DEFUALT_A)
+          
+        #rospy.loginfo(f"用户输入的速度缩放因子为{vv}")
+        return vv
+    except Exception as e:
+        rospy.logerr(f"发生错误:{e}")
+
+        
 if __name__ =="__main__":
     # from redis_publisher import Publisher
     # publisher = Publisher()
 
     folder_path = rospy.get_param("folder_path")
     rospy.init_node('moveit_control_server', anonymous=False)   
-    moveit_server = MoveIt_Control(is_use_gripper=False)
-    
+    moveit_server = MoveIt_Control(is_use_gripper=False)  
     welding_sequence = rospy.get_param('welding_sequence')
+
+
+    speed_v=get_user_input()
+    rospy.loginfo(f"用户输入的速度缩放因子为{speed_v}")
+
     trajectory,trajectory_merge,trajectory_with_type_merge = moveit_server.path_planning(folder_path)
-    
-    # plan_result = ROS2PY_msgs(trajectory_with_type_merge, moveit_server)
-    # publisher.pub_plan_result(plan_result)
 
     moveit_server.arm.execute(trajectory_merge)
     

+ 3 - 0
catkin_ws/更新记录.txt

@@ -43,4 +43,7 @@
 	六轴翻转问题依旧没有解决  其问题会带来运动碰撞风险 不止是极限角度  也是之前轴翻转的根源
 2024-9-2
 	通过限制6轴自由度解决六轴翻转问题
+2024-9-5
+	隐患: 焊缝周围没有点云的的话会报错  (这个问题不是问题)
+		  T型焊缝未测试   对向焊缝失败处理未测试