mycobot_ros/ultraArm/ultraarm_moveit/scripts/sync_plan.py
2023-12-12 18:33:17 +08:00

42 lines
1.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
import math
import rospy
from sensor_msgs.msg import JointState
from pymycobot.ultraArm import ultraArm
ua = 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):
radians_to_angles = round(math.degrees(value), 2)
data_list.append(radians_to_angles)
rospy.loginfo(rospy.get_caller_id() + "%s", data_list)
ua.set_angles(data_list, 25)
def listener():
global ua
rospy.init_node("control_slider", anonymous=True)
rospy.Subscriber("joint_states", JointState, callback)
port = rospy.get_param("~port", "/dev/ttyUSB0") # Select connected device. 选择连接设备
baud = rospy.get_param("~baud", 115200)
print(port, baud)
ua = ultraArm(port, baud)
ua.power_on()
ua.go_zero()
# spin() simply keeps python from exiting until this node is stopped
# spin() 只是阻止python退出直到该节点停止
print("spin ...")
rospy.spin()
if __name__ == "__main__":
listener()