From 1995275b8388a1098931c5b4394507ffa0d966ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=AB=8B=E5=86=9B?= Date: Fri, 8 Jan 2021 11:42:28 +0800 Subject: [PATCH] refactor: modify for new api, fix control_marker.py bug --- scripts/control_marker.py | 25 ++++++++++++++----------- scripts/control_slider.py | 6 ++++-- scripts/display.py | 6 ++++-- scripts/pythonAPI/mycobot.py | 4 ++-- scripts/pythonAPI/mycobot3.py | 4 ++-- 5 files changed, 26 insertions(+), 19 deletions(-) diff --git a/scripts/control_marker.py b/scripts/control_marker.py index c70ae31..25dba05 100755 --- a/scripts/control_marker.py +++ b/scripts/control_marker.py @@ -1,6 +1,6 @@ #!/usr/bin/env python2 # from std_msgs.msg import String -import time +import time, subprocess import rospy from interactive_markers.interactive_marker_server import * @@ -210,21 +210,24 @@ def listener(): joint_state_send.header.stamp = rospy.Time.now() angles = mycobot.get_angles_of_radian() - data_list = [] - for index, value in enumerate(angles): - if index != 2: - value *= -1 - data_list.append(value) + rospy.loginfo(angles) + if angles: + data_list = [] + for index, value in enumerate(angles): + if index != 2: + value *= -1 + data_list.append(value) - rospy.loginfo(data_list) - - joint_state_send.position = data_list + + joint_state_send.position = data_list - pub.publish(joint_state_send) + pub.publish(joint_state_send) rate.sleep() if __name__ == '__main__': - mycobot = MyCobot() + port = subprocess.check_output(['echo -n /dev/ttyUSB*'], + shell=True) + mycobot = MyCobot(port) listener() diff --git a/scripts/control_slider.py b/scripts/control_slider.py index de68cd8..8ea0b31 100755 --- a/scripts/control_slider.py +++ b/scripts/control_slider.py @@ -1,6 +1,6 @@ #!/usr/bin/env python2 # from std_msgs.msg import String -import time +import time, subprocess import rospy from sensor_msgs.msg import JointState @@ -29,5 +29,7 @@ def listener(): rospy.spin() if __name__ == '__main__': - mc = MyCobot() + port = subprocess.check_output(['echo -n /dev/ttyUSB*'], + shell=True) + mc = MyCobot(port) listener() diff --git a/scripts/display.py b/scripts/display.py index 79f823e..2c750de 100755 --- a/scripts/display.py +++ b/scripts/display.py @@ -1,6 +1,6 @@ #!/usr/bin/env python2 # license removed for brevity -import time +import time, subprocess import rospy from sensor_msgs.msg import JointState @@ -77,7 +77,9 @@ def talker(): rate.sleep() if __name__ == '__main__': - mycobot = MyCobot() + port = subprocess.check_output(['echo -n /dev/ttyUSB*'], + shell=True) + mycobot = MyCobot(port) try: talker() except rospy.ROSInterruptException: diff --git a/scripts/pythonAPI/mycobot.py b/scripts/pythonAPI/mycobot.py index 377d0b7..ce7ad5a 100755 --- a/scripts/pythonAPI/mycobot.py +++ b/scripts/pythonAPI/mycobot.py @@ -203,7 +203,7 @@ class MyCobot(): # print(command) self._write(command) - def jog_angle(joint_id, direction, speed): + def jog_angle(self, joint_id, direction, speed): '''Joint control joint_id: string @@ -218,7 +218,7 @@ class MyCobot(): command += '{}{}{}fa'.format(joint_id, direction, speed) self._write(command) - def jog_coord(coord, direction, speed): + def jog_coord(self, coord, direction, speed): '''Coord control coord: string diff --git a/scripts/pythonAPI/mycobot3.py b/scripts/pythonAPI/mycobot3.py index f9c1d63..c284e23 100755 --- a/scripts/pythonAPI/mycobot3.py +++ b/scripts/pythonAPI/mycobot3.py @@ -204,7 +204,7 @@ class MyCobot(): # print(command) self._write(command) - def jog_angle(joint_id, direction, speed): + def jog_angle(self, joint_id, direction, speed): '''Joint control joint_id: string @@ -219,7 +219,7 @@ class MyCobot(): command += '{}{}{}fa'.format(joint_id, direction, speed) self._write(command) - def jog_coord(coord, direction, speed): + def jog_coord(self, coord, direction, speed): '''Coord control coord: string