mycobot_ros/mypalletizer_260/scripts/slider_control.py
2929ss 69e8c72266
add mypal260 with urdf, communication, moveit (#56)
* add mypal260 with urdf,communication,moveit
2022-03-10 17:22:13 +08:00

51 lines
1.4 KiB
Python
Executable file

#!/usr/bin/env python2
"""[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.mycobot import MyCobot
from pymycobot.mypalletizer import MyPalletizer
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)
del data_list[3] # delete the angle of joint3 to joint4,because it do not exsist actually!
# data_list[3] = data_list[4]
# print(data_list)
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 = MyPalletizer(port, baud)
# spin() simply keeps python from exiting until this node is stopped
print("spin ...")
rospy.spin()
if __name__ == "__main__":
listener()