mirror of
https://github.com/elephantrobotics/mycobot_ros.git
synced 2026-07-05 19:47:04 +00:00
commit
bd5c257fcd
2 changed files with 30 additions and 37 deletions
|
|
@ -1,13 +1,13 @@
|
||||||
<launch>
|
<launch>
|
||||||
<!-- Select connecting device and serial port ,选择连接设备及串口-->
|
<!-- Select connecting device and serial port ,选择连接设备及串口-->
|
||||||
|
|
||||||
<arg name="port" default="/dev/ttyAMA0" />
|
<arg name="port" default="/dev/ttyUSB0" />
|
||||||
<arg name="baud" default="1000000" />
|
<arg name="baud" default="115200" />
|
||||||
|
|
||||||
|
|
||||||
<!-- Open communication service ,开启通讯服务-->
|
<!-- Open communication service ,开启通讯服务-->
|
||||||
<node name="mycobot_services" pkg="mycobot_communication" type="mycobot_services.py" output="screen">
|
<node name="mycobot_services" pkg="mycobot_communication" type="mycobot_services.py" output="screen">
|
||||||
<param name="ip" type="string" value="$(arg ip)" />
|
<param name="port" type="string" value="$(arg port)" />
|
||||||
<param name="port" type="int" value="$(arg port)" />
|
<param name="baud" type="int" value="$(arg baud)" />
|
||||||
</node>
|
</node>
|
||||||
</launch>
|
</launch>
|
||||||
|
|
|
||||||
|
|
@ -5,25 +5,18 @@ import rospy
|
||||||
from mycobot_communication.srv import *
|
from mycobot_communication.srv import *
|
||||||
|
|
||||||
from pymycobot.mycobot import MyCobot
|
from pymycobot.mycobot import MyCobot
|
||||||
from pymycobot.mycobotsocket import MyCobotSocket
|
|
||||||
|
|
||||||
# mc = None
|
mc = None
|
||||||
ms = None
|
|
||||||
|
|
||||||
def create_handle():
|
def create_handle():
|
||||||
# global mc
|
global mc
|
||||||
global ms
|
|
||||||
rospy.init_node("mycobot_services")
|
rospy.init_node("mycobot_services")
|
||||||
rospy.loginfo("start ...")
|
rospy.loginfo("start ...")
|
||||||
# port = rospy.get_param("~port")
|
port = rospy.get_param("~port")
|
||||||
# baud = rospy.get_param("~baud")
|
baud = rospy.get_param("~baud")
|
||||||
# rospy.loginfo("%s,%s" % (port, baud))
|
rospy.loginfo("%s,%s" % (port, baud))
|
||||||
# ms = MyCobot(port, baud)
|
mc = MyCobot(port, baud)
|
||||||
ip=rospy.get_param("~ip")
|
|
||||||
port=rospy.get_param("~port")
|
|
||||||
rospy.loginfo("%s,%s" % (ip,port))
|
|
||||||
ms=MyCobotSocket(ip,port)
|
|
||||||
ms.connect()
|
|
||||||
|
|
||||||
|
|
||||||
def create_services():
|
def create_services():
|
||||||
|
|
@ -49,16 +42,16 @@ def set_angles(req):
|
||||||
]
|
]
|
||||||
sp = req.speed
|
sp = req.speed
|
||||||
print('angles1:',angles)
|
print('angles1:',angles)
|
||||||
if ms:
|
if mc:
|
||||||
ms.send_angles(angles, sp)
|
mc.send_angles(angles, sp)
|
||||||
|
|
||||||
return SetAnglesResponse(True)
|
return SetAnglesResponse(True)
|
||||||
|
|
||||||
|
|
||||||
def get_angles(req):
|
def get_angles(req):
|
||||||
"""get angles,获取角度"""
|
"""get angles,获取角度"""
|
||||||
if ms:
|
if mc:
|
||||||
angles = ms.get_angles()
|
angles = mc.get_angles()
|
||||||
print('angles2:',angles)
|
print('angles2:',angles)
|
||||||
return GetAnglesResponse(*angles)
|
return GetAnglesResponse(*angles)
|
||||||
|
|
||||||
|
|
@ -75,15 +68,15 @@ def set_coords(req):
|
||||||
sp = req.speed
|
sp = req.speed
|
||||||
mod = req.model
|
mod = req.model
|
||||||
|
|
||||||
if ms:
|
if mc:
|
||||||
ms.send_coords(coords, sp, mod)
|
mc.send_coords(coords, sp, mod)
|
||||||
|
|
||||||
return SetCoordsResponse(True)
|
return SetCoordsResponse(True)
|
||||||
|
|
||||||
|
|
||||||
def get_coords(req):
|
def get_coords(req):
|
||||||
if ms:
|
if mc:
|
||||||
coords = ms.get_coords()
|
coords = mc.get_coords()
|
||||||
print('coords:',coords)
|
print('coords:',coords)
|
||||||
return GetCoordsResponse(*coords)
|
return GetCoordsResponse(*coords)
|
||||||
|
|
||||||
|
|
@ -91,23 +84,23 @@ def get_coords(req):
|
||||||
def switch_status(req):
|
def switch_status(req):
|
||||||
"""Gripper switch status"""
|
"""Gripper switch status"""
|
||||||
"""夹爪开关状态"""
|
"""夹爪开关状态"""
|
||||||
if ms:
|
if mc:
|
||||||
if req.Status:
|
if req.Status:
|
||||||
ms.set_gripper_state(0, 80)
|
mc.set_gripper_state(0, 80)
|
||||||
else:
|
else:
|
||||||
ms.set_gripper_state(1, 80)
|
mc.set_gripper_state(1, 80)
|
||||||
|
|
||||||
return GripperStatusResponse(True)
|
return GripperStatusResponse(True)
|
||||||
|
|
||||||
|
|
||||||
def toggle_pump(req):
|
def toggle_pump(req):
|
||||||
if ms:
|
if mc:
|
||||||
if req.Status:
|
if req.Status:
|
||||||
ms.set_basic_output(req.Pin1, 0)
|
mc.set_basic_output(req.Pin1, 0)
|
||||||
ms.set_basic_output(req.Pin2, 0)
|
mc.set_basic_output(req.Pin2, 0)
|
||||||
else:
|
else:
|
||||||
ms.set_basic_output(req.Pin1, 1)
|
mc.set_basic_output(req.Pin1, 1)
|
||||||
ms.set_basic_output(req.Pin2, 1)
|
mc.set_basic_output(req.Pin2, 1)
|
||||||
|
|
||||||
return PumpStatusResponse(True)
|
return PumpStatusResponse(True)
|
||||||
|
|
||||||
|
|
@ -139,12 +132,12 @@ def output_robot_message():
|
||||||
servo_temperature = "unknown"
|
servo_temperature = "unknown"
|
||||||
atom_version = "unknown"
|
atom_version = "unknown"
|
||||||
|
|
||||||
if ms:
|
if mc:
|
||||||
cn = ms.is_controller_connected()
|
cn = mc.is_controller_connected()
|
||||||
if cn == 1:
|
if cn == 1:
|
||||||
connect_status = True
|
connect_status = True
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
si = ms.is_all_servo_enable()
|
si = mc.is_all_servo_enable()
|
||||||
if si == 1:
|
if si == 1:
|
||||||
servo_infomation = "all connected"
|
servo_infomation = "all connected"
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue