mirror of
https://github.com/elephantrobotics/mycobot_ros.git
synced 2026-07-05 19:47:04 +00:00
add robot information output.
This commit is contained in:
parent
7da31f6034
commit
05db4baccb
2 changed files with 51 additions and 7 deletions
|
|
@ -3,8 +3,8 @@
|
||||||
<arg name="BAUD" default="115200" />
|
<arg name="BAUD" default="115200" />
|
||||||
|
|
||||||
<!-- Open communication service -->
|
<!-- Open communication service -->
|
||||||
<node name="mycobot_services" pkg="myCobotROS" type="mycobot_ros.py">
|
<node name="mycobot_services" pkg="myCobotROS" type="mycobot_ros.py" output="screen">
|
||||||
<param name="port" type="string" value="$(arg PORT)" />
|
<param name="port" type="string" value="$(arg PORT)" />
|
||||||
<param name="baud" type="int" value="$(arg BAUD)" />
|
<param name="baud" type="int" value="$(arg BAUD)" />
|
||||||
</node>
|
</node>
|
||||||
</launch>
|
</launch>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
#!/usr/bin/env python2
|
#!/usr/bin/env python2
|
||||||
|
import time
|
||||||
import rospy
|
import rospy
|
||||||
from myCobotROS.srv import *
|
from myCobotROS.srv import *
|
||||||
|
|
||||||
|
|
@ -7,7 +8,7 @@ from pymycobot.mycobot import MyCobot
|
||||||
mc = None
|
mc = None
|
||||||
|
|
||||||
|
|
||||||
def mycobot_services():
|
def create_handle():
|
||||||
global mc
|
global mc
|
||||||
rospy.init_node('mycobot_services')
|
rospy.init_node('mycobot_services')
|
||||||
rospy.loginfo('start ...')
|
rospy.loginfo('start ...')
|
||||||
|
|
@ -16,6 +17,8 @@ def mycobot_services():
|
||||||
rospy.loginfo("%s,%s" % (port, baud))
|
rospy.loginfo("%s,%s" % (port, baud))
|
||||||
mc = MyCobot(port, baud)
|
mc = MyCobot(port, baud)
|
||||||
|
|
||||||
|
|
||||||
|
def create_services():
|
||||||
rospy.Service('set_joint_angles', SetAngles, set_angles)
|
rospy.Service('set_joint_angles', SetAngles, set_angles)
|
||||||
rospy.Service('get_joint_angles', GetAngles, get_angles)
|
rospy.Service('get_joint_angles', GetAngles, get_angles)
|
||||||
rospy.Service('set_joint_coords', SetCoords, set_coords)
|
rospy.Service('set_joint_coords', SetCoords, set_coords)
|
||||||
|
|
@ -43,7 +46,6 @@ def set_angles(req):
|
||||||
def get_angles(req):
|
def get_angles(req):
|
||||||
if mc:
|
if mc:
|
||||||
angles = mc.get_angles()
|
angles = mc.get_angles()
|
||||||
print(angles)
|
|
||||||
return GetAnglesResponse(*angles)
|
return GetAnglesResponse(*angles)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -79,6 +81,48 @@ def switch_status(req):
|
||||||
mc.set_gripper_state(1, 80)
|
mc.set_gripper_state(1, 80)
|
||||||
|
|
||||||
|
|
||||||
|
robot_msg = '''
|
||||||
|
MyCobot Status
|
||||||
|
--------------------------------
|
||||||
|
Joint Limit:
|
||||||
|
joint 1: -170 ~ +170
|
||||||
|
joint 2: -170 ~ +170
|
||||||
|
joint 3: -170 ~ +170
|
||||||
|
joint 4: -170 ~ +170
|
||||||
|
joint 5: -170 ~ +170
|
||||||
|
joint 6: -180 ~ +180
|
||||||
|
|
||||||
|
Connect Status: %s
|
||||||
|
|
||||||
|
Servo Infomation: %s
|
||||||
|
|
||||||
|
Servo Temperature: %s
|
||||||
|
|
||||||
|
Atom Version: %s
|
||||||
|
'''
|
||||||
|
|
||||||
|
|
||||||
|
def output_robot_message():
|
||||||
|
connect_status = False
|
||||||
|
servo_infomation = 'unknown'
|
||||||
|
servo_temperature = 'unknown'
|
||||||
|
atom_version = 'unknown'
|
||||||
|
|
||||||
|
if mc:
|
||||||
|
cn = mc.is_controller_connected()
|
||||||
|
if cn == 1:
|
||||||
|
connect_status = True
|
||||||
|
time.sleep(.1)
|
||||||
|
si = mc.is_all_servo_enable()
|
||||||
|
if si == 1:
|
||||||
|
servo_infomation = 'all connected'
|
||||||
|
|
||||||
|
print(robot_msg % (connect_status, servo_infomation,
|
||||||
|
servo_temperature, atom_version))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# print(MyCobot.__dict__)
|
# print(MyCobot.__dict__)
|
||||||
mycobot_services()
|
create_handle()
|
||||||
|
output_robot_message()
|
||||||
|
create_services()
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue