mirror of
https://github.com/elephantrobotics/mycobot_ros.git
synced 2026-07-05 19:47:04 +00:00
49 lines
1.2 KiB
Python
49 lines
1.2 KiB
Python
#!/usr/bin/env python3
|
||
|
||
"""[summary]
|
||
This file obtains the joint angle of the manipulator in ROS,
|
||
and then sends it directly to the real manipulator using `pymycobot` API.
|
||
This file is [slider_control.launch] related script.
|
||
Passable parameters:
|
||
port: serial prot string. Defaults is '/dev/ttyUSB0'
|
||
baud: serial prot baudrate. Defaults is 115200.
|
||
"""
|
||
|
||
import rospy
|
||
from sensor_msgs.msg import JointState
|
||
|
||
from pymycobot.myarm import MyArm
|
||
|
||
|
||
mc = None
|
||
|
||
|
||
def callback(data):
|
||
# rospy.loginfo(rospy.get_caller_id() + "%s", data.position)
|
||
print(data.position)
|
||
data_list = []
|
||
for index, value in enumerate(data.position):
|
||
data_list.append(value)
|
||
|
||
mc.send_radians(data_list, 80)
|
||
# time.sleep(0.5)
|
||
|
||
|
||
def listener():
|
||
global mc
|
||
rospy.init_node("control_slider", anonymous=True)
|
||
|
||
rospy.Subscriber("joint_states", JointState, callback)
|
||
port = rospy.get_param("~port", "/dev/ttyUSB0")
|
||
baud = rospy.get_param("~baud", 115200)
|
||
print(port, baud)
|
||
mc = MyArm(port, baud)
|
||
|
||
# spin() simply keeps python from exiting until this node is stopped
|
||
# spin()只是阻止python退出,直到该节点停止
|
||
print("spin ...")
|
||
rospy.spin()
|
||
|
||
|
||
if __name__ == "__main__":
|
||
listener()
|