From 3ba7cfb12630b4dc75a5a4b337c1736207228f15 Mon Sep 17 00:00:00 2001 From: weijian Date: Fri, 26 May 2023 17:46:55 +0800 Subject: [PATCH] update myArm --- myArm/myarm/config/ai_mycobot_pi.rviz | 226 -------------------- myArm/myarm/launch/detect_marker.launch | 6 +- myArm/myarm/launch/mycobot_follow.launch | 4 +- myArm/myarm/launch/simple_gui.launch | 10 +- myArm/myarm/launch/slider_control.launch | 4 +- myArm/myarm/launch/teleop_keyboard.launch | 8 +- myArm/myarm/scripts/follow_display.py | 9 +- myArm/myarm/scripts/following_marker.py | 4 +- myArm/myarm/scripts/listen_real.py | 6 +- myArm/myarm/scripts/listen_real_of_topic.py | 6 +- myArm/myarm/scripts/simple_gui.py | 22 +- myArm/myarm/scripts/slider_control.py | 6 +- 12 files changed, 55 insertions(+), 256 deletions(-) delete mode 100755 myArm/myarm/config/ai_mycobot_pi.rviz diff --git a/myArm/myarm/config/ai_mycobot_pi.rviz b/myArm/myarm/config/ai_mycobot_pi.rviz deleted file mode 100755 index 9340fbc..0000000 --- a/myArm/myarm/config/ai_mycobot_pi.rviz +++ /dev/null @@ -1,226 +0,0 @@ -Panels: - - Class: rviz/Displays - Help Height: 78 - Name: Displays - Property Tree Widget: - Expanded: - - /Global Options1 - - /Status1 - - /RobotModel1 - - /TF1 - - /Marker1 - Splitter Ratio: 0.5 - Tree Height: 582 - - Class: rviz/Selection - Name: Selection - - Class: rviz/Tool Properties - Expanded: - - /2D Pose Estimate1 - - /2D Nav Goal1 - - /Publish Point1 - Name: Tool Properties - Splitter Ratio: 0.5886790156364441 - - Class: rviz/Views - Expanded: - - /Current View1 - Name: Views - Splitter Ratio: 0.5 - - Class: rviz/Time - Name: Time - SyncMode: 0 - SyncSource: "" -Preferences: - PromptSaveOnExit: true -Toolbars: - toolButtonStyle: 2 -Visualization Manager: - Class: "" - Displays: - - Alpha: 0.5 - Cell Size: 1 - Class: rviz/Grid - Color: 160; 160; 164 - Enabled: true - Line Style: - Line Width: 0.029999999329447746 - Value: Lines - Name: Grid - Normal Cell Count: 0 - Offset: - X: 0 - Y: 0 - Z: 0 - Plane: XY - Plane Cell Count: 10 - Reference Frame: - Value: true - - Alpha: 1 - Class: rviz/RobotModel - Collision Enabled: false - Enabled: true - Links: - All Links Enabled: true - Expand Joint Details: false - Expand Link Details: false - Expand Tree: false - Link Tree Style: Links in Alphabetic Order - env: - Alpha: 1 - Show Axes: false - Show Trail: false - Value: true - joint1: - Alpha: 1 - Show Axes: false - Show Trail: false - Value: true - joint2: - Alpha: 1 - Show Axes: false - Show Trail: false - Value: true - joint3: - Alpha: 1 - Show Axes: false - Show Trail: false - Value: true - joint4: - Alpha: 1 - Show Axes: false - Show Trail: false - Value: true - joint5: - Alpha: 1 - Show Axes: false - Show Trail: false - Value: true - joint6: - Alpha: 1 - Show Axes: false - Show Trail: false - Value: true - joint6_flange: - Alpha: 1 - Show Axes: false - Show Trail: false - Value: true - Name: RobotModel - Robot Description: robot_description - TF Prefix: "" - Update Interval: 0 - Value: true - Visual Enabled: true - - Class: rviz/TF - Enabled: true - Frame Timeout: 15 - Frames: - All Enabled: true - env: - Value: true - joint1: - Value: true - joint2: - Value: true - joint3: - Value: true - joint4: - Value: true - joint5: - Value: true - joint6: - Value: true - joint6_flange: - Value: true - Marker Alpha: 1 - Marker Scale: 0.30000001192092896 - Name: TF - Show Arrows: true - Show Axes: true - Show Names: true - Tree: - joint1: - env: - {} - joint2: - joint3: - joint4: - joint5: - joint6: - joint6_flange: - {} - Update Interval: 0 - Value: true - - Class: rviz/Marker - Enabled: true - Marker Topic: cube - Name: Marker - Namespaces: - cube: true - Queue Size: 100 - Value: true - Enabled: true - Global Options: - Background Color: 48; 48; 48 - Default Light: true - Fixed Frame: joint1 - Frame Rate: 30 - Name: root - Tools: - - Class: rviz/Interact - Hide Inactive Objects: true - - Class: rviz/MoveCamera - - Class: rviz/Select - - Class: rviz/FocusCamera - - Class: rviz/Measure - - Class: rviz/SetInitialPose - Theta std deviation: 0.2617993950843811 - Topic: /initialpose - X std deviation: 0.5 - Y std deviation: 0.5 - - Class: rviz/SetGoal - Topic: /move_base_simple/goal - - Class: rviz/PublishPoint - Single click: true - Topic: /clicked_point - Value: true - Views: - Current: - Class: rviz/Orbit - Distance: 1.2028908729553223 - Enable Stereo Rendering: - Stereo Eye Separation: 0.05999999865889549 - Stereo Focal Distance: 1 - Swap Stereo Eyes: false - Value: false - Field of View: 0.7853981852531433 - Focal Point: - X: -0.07064759731292725 - Y: -0.0814988762140274 - Z: 0.10758385062217712 - Focal Shape Fixed Size: true - Focal Shape Size: 0.05000000074505806 - Invert Z Axis: false - Name: Current View - Near Clip Distance: 0.009999999776482582 - Pitch: 0.44039833545684814 - Target Frame: - Yaw: 0.43038973212242126 - Saved: ~ -Window Geometry: - Displays: - collapsed: false - Height: 888 - Hide Left Dock: false - Hide Right Dock: false - QMainWindow State: 000000ff00000000fd00000004000000000000016a000002d5fc0200000008fb0000001200530065006c0065006300740069006f006e00000001e10000009b0000006400fffffffb0000001e0054006f006f006c002000500072006f007000650072007400690065007302000001ed000001df00000185000000a3fb000000120056006900650077007300200054006f006f02000001df000002110000018500000122fb000000200054006f006f006c002000500072006f0070006500720074006900650073003203000002880000011d000002210000017afb000000100044006900730070006c0061007900730100000041000002d5000000dd00fffffffb0000002000730065006c0065006300740069006f006e00200062007500660066006500720200000138000000aa0000023a00000294fb00000014005700690064006500530074006500720065006f02000000e6000000d2000003ee0000030bfb0000000c004b0069006e0065006300740200000186000001060000030c0000026100000001000001c2000002d5fc0200000003fb0000001e0054006f006f006c002000500072006f00700065007200740069006500730100000041000000780000000000000000fb0000000a005600690065007700730100000041000002d5000000b000fffffffb0000001200530065006c0065006300740069006f006e010000025a000000b200000000000000000000000200000490000000a9fc0100000001fb0000000a00560069006500770073030000004e00000080000002e100000197000000030000069f0000003efc0100000002fb0000000800540069006d006501000000000000069f000003d000fffffffb0000000800540069006d0065010000000000000450000000000000000000000367000002d500000004000000040000000800000008fc0000000100000002000000010000000a0054006f006f006c00730100000000ffffffff0000000000000000 - Selection: - collapsed: false - Time: - collapsed: false - Tool Properties: - collapsed: false - Views: - collapsed: false - Width: 1695 - X: 222 - Y: 28 diff --git a/myArm/myarm/launch/detect_marker.launch b/myArm/myarm/launch/detect_marker.launch index e8c6998..c6bf52e 100755 --- a/myArm/myarm/launch/detect_marker.launch +++ b/myArm/myarm/launch/detect_marker.launch @@ -1,12 +1,12 @@ - - + + - + diff --git a/myArm/myarm/launch/mycobot_follow.launch b/myArm/myarm/launch/mycobot_follow.launch index 4e3f526..4deb9e2 100755 --- a/myArm/myarm/launch/mycobot_follow.launch +++ b/myArm/myarm/launch/mycobot_follow.launch @@ -1,7 +1,7 @@ - - + + diff --git a/myArm/myarm/launch/simple_gui.launch b/myArm/myarm/launch/simple_gui.launch index 0957433..c389ea9 100755 --- a/myArm/myarm/launch/simple_gui.launch +++ b/myArm/myarm/launch/simple_gui.launch @@ -3,8 +3,8 @@ - - + + @@ -14,10 +14,10 @@ - + - - + + diff --git a/myArm/myarm/launch/slider_control.launch b/myArm/myarm/launch/slider_control.launch index 76c5a1b..06749aa 100755 --- a/myArm/myarm/launch/slider_control.launch +++ b/myArm/myarm/launch/slider_control.launch @@ -2,8 +2,8 @@ - - + + diff --git a/myArm/myarm/launch/teleop_keyboard.launch b/myArm/myarm/launch/teleop_keyboard.launch index a5cf77a..339660f 100755 --- a/myArm/myarm/launch/teleop_keyboard.launch +++ b/myArm/myarm/launch/teleop_keyboard.launch @@ -3,8 +3,8 @@ - - + + @@ -14,10 +14,10 @@ - + - + diff --git a/myArm/myarm/scripts/follow_display.py b/myArm/myarm/scripts/follow_display.py index 6fad77f..465e723 100755 --- a/myArm/myarm/scripts/follow_display.py +++ b/myArm/myarm/scripts/follow_display.py @@ -6,7 +6,7 @@ from sensor_msgs.msg import JointState from std_msgs.msg import Header from visualization_msgs.msg import Marker -from pymycobot.mycobot import MyCobot +from pymycobot.myarm import MyArm def talker(): @@ -17,7 +17,7 @@ def talker(): baud = rospy.get_param("~baud", 115200) print("port: {}, baud: {}\n".format(port, baud)) try: - mycobot = MyCobot(port, baud) + mycobot = MyArm(port, baud) except Exception as e: print(e) print( @@ -41,18 +41,19 @@ def talker(): joint_state_send.header = Header() joint_state_send.name = [ + "joint1_to_base", "joint2_to_joint1", "joint3_to_joint2", "joint4_to_joint3", "joint5_to_joint4", "joint6_to_joint5", - "joint6output_to_joint6", + "joint7_to_joint6", ] joint_state_send.velocity = [0] joint_state_send.effort = [] marker_ = Marker() - marker_.header.frame_id = "/joint1" + marker_.header.frame_id = "/base" marker_.ns = "my_namespace" print("publishing ...") diff --git a/myArm/myarm/scripts/following_marker.py b/myArm/myarm/scripts/following_marker.py index 797ec1e..8f59265 100755 --- a/myArm/myarm/scripts/following_marker.py +++ b/myArm/myarm/scripts/following_marker.py @@ -17,7 +17,7 @@ def talker(): listener = tf.TransformListener() marker_ = Marker() - marker_.header.frame_id = "/joint1" + marker_.header.frame_id = "/base" marker_.ns = "basic_cube" print("publishing ...") @@ -25,7 +25,7 @@ def talker(): now = rospy.Time.now() - rospy.Duration(0.1) try: - trans, rot = listener.lookupTransform("joint1", "basic_shapes", now) + trans, rot = listener.lookupTransform("base", "basic_shapes", now) except Exception as e: print(e) continue diff --git a/myArm/myarm/scripts/listen_real.py b/myArm/myarm/scripts/listen_real.py index 1d38b61..7b79fdf 100755 --- a/myArm/myarm/scripts/listen_real.py +++ b/myArm/myarm/scripts/listen_real.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # encoding:utf-8 # license removed for brevity import time @@ -21,12 +21,13 @@ def talker(): joint_state_send.header = Header() joint_state_send.name = [ + "joint1_to_base", "joint2_to_joint1", "joint3_to_joint2", "joint4_to_joint3", "joint5_to_joint4", "joint6_to_joint5", - "joint6output_to_joint6", + "joint7_to_joint6", ] joint_state_send.velocity = [0] joint_state_send.effort = [] @@ -49,6 +50,7 @@ def talker(): res.joint_4 * (math.pi / 180), res.joint_5 * (math.pi / 180), res.joint_6 * (math.pi / 180), + res.joint_7 * (math.pi / 180), ] rospy.loginfo("res: {}".format(radians_list)) diff --git a/myArm/myarm/scripts/listen_real_of_topic.py b/myArm/myarm/scripts/listen_real_of_topic.py index 2c910da..37e1ff4 100755 --- a/myArm/myarm/scripts/listen_real_of_topic.py +++ b/myArm/myarm/scripts/listen_real_of_topic.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # encoding:utf-8 import math @@ -31,12 +31,13 @@ class Listener(object): joint_state_send.header = Header() joint_state_send.name = [ + "joint1_to_base", "joint2_to_joint1", "joint3_to_joint2", "joint4_to_joint3", "joint5_to_joint4", "joint6_to_joint5", - "joint6output_to_joint6", + "joint7_to_joint6", ] joint_state_send.velocity = [0] joint_state_send.effort = [] @@ -50,6 +51,7 @@ class Listener(object): data.joint_4 * (math.pi / 180), data.joint_5 * (math.pi / 180), data.joint_6 * (math.pi / 180), + data.joint_7 * (math.pi / 180), ] rospy.loginfo("res: {}".format(radians_list)) diff --git a/myArm/myarm/scripts/simple_gui.py b/myArm/myarm/scripts/simple_gui.py index 783e3e4..69ccc0d 100755 --- a/myArm/myarm/scripts/simple_gui.py +++ b/myArm/myarm/scripts/simple_gui.py @@ -102,6 +102,7 @@ class Window: tk.Label(self.frmLT, text="Joint 4 ").grid(row=3) tk.Label(self.frmLT, text="Joint 5 ").grid(row=4) tk.Label(self.frmLT, text="Joint 6 ").grid(row=5) + tk.Label(self.frmLT, text="Joint 7 ").grid(row=6) tk.Label(self.frmRT, text=" x ").grid(row=0) tk.Label(self.frmRT, text=" y ").grid(row=1) # the second row,第二行 @@ -123,6 +124,9 @@ class Window: self.j5_default.set(self.res_angles[4]) self.j6_default = tk.StringVar() self.j6_default.set(self.res_angles[5]) + self.j7_default = tk.StringVar() + self.j7_default.set(self.res_angles[6]) + self.x_default = tk.StringVar() self.x_default.set(self.record_coords[0]) @@ -150,6 +154,8 @@ class Window: self.J_5.grid(row=4, column=1, pady=3) self.J_6 = tk.Entry(self.frmLT, textvariable=self.j6_default) self.J_6.grid(row=5, column=1, pady=3) + self.J_7 = tk.Entry(self.frmLT, textvariable=self.j7_default) + self.J_7.grid(row=5, column=1, pady=3) # coord input box,coord 输入框 self.x = tk.Entry(self.frmRT, textvariable=self.x_default) @@ -166,7 +172,7 @@ class Window: self.rz.grid(row=5, column=1, pady=3) # All input boxes, used to get the input data,所有输入框,用于拿输入的数据 - self.all_j = [self.J_1, self.J_2, self.J_3, self.J_4, self.J_5, self.J_6] + self.all_j = [self.J_1, self.J_2, self.J_3, self.J_4, self.J_5, self.J_6, self.J_7] self.all_c = [self.x, self.y, self.z, self.rx, self.ry, self.rz] # speed input box,速度输入框 @@ -185,6 +191,7 @@ class Window: tk.Label(self.frmLC, text="Joint 4 ").grid(row=3) tk.Label(self.frmLC, text="Joint 5 ").grid(row=4) tk.Label(self.frmLC, text="Joint 6 ").grid(row=5) + tk.Label(self.frmLC, text="Joint 7 ").grid(row=6) # get数据 @@ -201,6 +208,8 @@ class Window: self.cont_5.set(str(self.res_angles[4]) + "°") self.cont_6 = tk.StringVar(self.frmLC) self.cont_6.set(str(self.res_angles[5]) + "°") + self.cont_7 = tk.StringVar(self.frmLC) + self.cont_7.set(str(self.res_angles[6]) + "°") self.cont_all = [ self.cont_1, self.cont_2, @@ -208,6 +217,7 @@ class Window: self.cont_4, self.cont_5, self.cont_6, + self.cont_7, self.speed, self.model, ] @@ -261,6 +271,14 @@ class Window: height=1, bg="white", ).grid(row=5, column=1, padx=5, pady=5) + self.show_j7 = tk.Label( + self.frmLC, + textvariable=self.cont_7, + font=("Arial", 9), + width=7, + height=1, + bg="white", + ).grid(row=5, column=1, padx=5, pady=5) self.all_jo = [ self.show_j1, @@ -269,6 +287,7 @@ class Window: self.show_j4, self.show_j5, self.show_j6, + self.show_j7, ] # show,显示 @@ -444,6 +463,7 @@ class Window: round(self.angles.joint_4, 2), round(self.angles.joint_5, 2), round(self.angles.joint_6, 2), + round(self.angles.joint_7, 2), ] # print('coord:',self.record_coords) # print('angles:',self.res_angles) diff --git a/myArm/myarm/scripts/slider_control.py b/myArm/myarm/scripts/slider_control.py index e3cf6a6..0b722ca 100755 --- a/myArm/myarm/scripts/slider_control.py +++ b/myArm/myarm/scripts/slider_control.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 """[summary] This file obtains the joint angle of the manipulator in ROS, @@ -12,7 +12,7 @@ Passable parameters: import rospy from sensor_msgs.msg import JointState -from pymycobot.mycobot import MyCobot +from pymycobot.myarm import MyArm mc = None @@ -37,7 +37,7 @@ def listener(): port = rospy.get_param("~port", "/dev/ttyUSB0") baud = rospy.get_param("~baud", 115200) print(port, baud) - mc = MyCobot(port, baud) + mc = MyArm(port, baud) # spin() simply keeps python from exiting until this node is stopped # spin()只是阻止python退出,直到该节点停止