add mycobot280_jetsonanno socket control

This commit is contained in:
wangWking 2022-05-20 17:25:00 +08:00
parent e0f2fd3331
commit c3c3c2812d
14 changed files with 81 additions and 48 deletions

View file

@ -1,7 +1,7 @@
<launch> <launch>
<!-- Select connecting device and serial port ,选择连接设备及串口--> <!-- Select connecting device and serial port ,选择连接设备及串口-->
<arg name="port" default="/dev/ttyTHS1" /> <arg name="ip" default="192.168.125.226" />
<arg name="baud" default="1000000" /> <arg name="port" default="9000" />
<!-- Load URDF, rviz, etc. on the parameter server,加载参数服务器上的URDF、rviz等 --> <!-- Load URDF, rviz, etc. on the parameter server,加载参数服务器上的URDF、rviz等 -->
<arg name="model" default="$(find mycobot_description)/urdf/280jn/mycobot_urdf.urdf"/> <arg name="model" default="$(find mycobot_description)/urdf/280jn/mycobot_urdf.urdf"/>
<arg name="rvizconfig" default="$(find mycobot_280jn)/config/mycobot.rviz" /> <arg name="rvizconfig" default="$(find mycobot_280jn)/config/mycobot.rviz" />
@ -15,8 +15,8 @@
<node name="rviz" pkg="rviz" type="rviz" args="-d $(arg rvizconfig)" required="true" /> <node name="rviz" pkg="rviz" type="rviz" args="-d $(arg rvizconfig)" required="true" />
<include file="$(find mycobot_communication)/launch/communication_service.launch"> <include file="$(find mycobot_communication)/launch/communication_service.launch">
<arg name="ip" value="$(arg ip)" />
<arg name="port" value="$(arg port)" /> <arg name="port" value="$(arg port)" />
<arg name="baud" value="$(arg baud)" />
</include> </include>
<!-- listen and pub the real angles ,监听并发布真实的角度--> <!-- listen and pub the real angles ,监听并发布真实的角度-->
<node name="real_listener" pkg="mycobot_280jn" type="listen_real.py" /> <node name="real_listener" pkg="mycobot_280jn" type="listen_real.py" />

View file

@ -1,7 +1,7 @@
<launch> <launch>
<!-- Select connecting device and serial port ,选择连接设备及串口--> <!-- Select connecting device and serial port ,选择连接设备及串口-->
<arg name="port" default="/dev/ttyTHS1" /> <arg name="ip" default="192.168.125.226" />
<arg name="baud" default="1000000" /> <arg name="port" default="9000" />
<!-- Load URDF, rviz, etc. on the parameter server,加载参数服务器上的URDF、rviz等 --> <!-- Load URDF, rviz, etc. on the parameter server,加载参数服务器上的URDF、rviz等 -->
<arg name="model" default="$(find mycobot_description)/urdf/280jn/mycobot_urdf.urdf"/> <arg name="model" default="$(find mycobot_description)/urdf/280jn/mycobot_urdf.urdf"/>
<arg name="rvizconfig" default="$(find mycobot_280jn)/config/mycobot.rviz" /> <arg name="rvizconfig" default="$(find mycobot_280jn)/config/mycobot.rviz" />
@ -15,8 +15,8 @@
<node name="rviz" pkg="rviz" type="rviz" args="-d $(arg rvizconfig)" required="true" /> <node name="rviz" pkg="rviz" type="rviz" args="-d $(arg rvizconfig)" required="true" />
<include file="$(find mycobot_communication)/launch/communication_service.launch"> <include file="$(find mycobot_communication)/launch/communication_service.launch">
<arg name="ip" value="$(arg ip)" />
<arg name="port" value="$(arg port)" /> <arg name="port" value="$(arg port)" />
<arg name="baud" value="$(arg baud)" />
</include> </include>
<!-- listen and pub the real angles ,监听并发布真实的角度--> <!-- listen and pub the real angles ,监听并发布真实的角度-->
<node name="real_listener" pkg="mycobot_280jn" type="listen_real.py" /> <node name="real_listener" pkg="mycobot_280jn" type="listen_real.py" />

0
mycobot_280/mycobot_280jn/scripts/detect_marker.py Normal file → Executable file
View file

0
mycobot_280/mycobot_280jn/scripts/follow_and_pump.py Normal file → Executable file
View file

15
mycobot_280/mycobot_280jn/scripts/follow_display.py Normal file → Executable file
View file

@ -1,4 +1,5 @@
#!/usr/bin/env python2 #!/usr/bin/env python2
# encoding:utf8
import time import time
import rospy import rospy
@ -8,16 +9,22 @@ from visualization_msgs.msg import Marker
from pymycobot.mycobot import MyCobot from pymycobot.mycobot import MyCobot
from pymycobot import MyCobotSocket
def talker(): def talker():
rospy.init_node("display", anonymous=True) rospy.init_node("display", anonymous=True)
print("Try connect real mycobot...") print("Try connect real mycobot...")
port = rospy.get_param("~port", "/dev/ttyTHS1") # port = rospy.get_param("~port", "/dev/ttyTHS1")
baud = rospy.get_param("~baud", 1000000) # baud = rospy.get_param("~baud", 1000000)
print("port: {}, baud: {}\n".format(port, baud)) ip=rospy.get_param('~ip','192.168.125.226')
netport=rospy.get_param('~netport',9000)
# print("port: {}, baud: {}\n".format(port, baud))
print('ip:{},port:{}'.format(ip,netport))
try: try:
mycobot = MyCobot(port, baud) # mycobot = MyCobot(port, baud)
mycobot=MyCobotSocket(ip,netport)
mycobot.connect(serialport="/dev/ttyTHS1", baudrate="1000000")
except Exception as e: except Exception as e:
print(e) print(e)
print( print(

0
mycobot_280/mycobot_280jn/scripts/following_marker.py Normal file → Executable file
View file

1
mycobot_280/mycobot_280jn/scripts/listen_real.py Normal file → Executable file
View file

@ -1,4 +1,5 @@
#!/usr/bin/env python2 #!/usr/bin/env python2
# encoding:utf-8
# license removed for brevity # license removed for brevity
import time import time
import math import math

View file

0
mycobot_280/mycobot_280jn/scripts/simple_gui.py Normal file → Executable file
View file

22
mycobot_280/mycobot_280jn/scripts/slider_control.py Normal file → Executable file
View file

@ -1,5 +1,5 @@
#!/usr/bin/env python2 #!/usr/bin/env python2
# encoding:utf-8
"""[summary] """[summary]
This file obtains the joint angle of the manipulator in ROS, This file obtains the joint angle of the manipulator in ROS,
and then sends it directly to the real manipulator using `pymycobot` API. and then sends it directly to the real manipulator using `pymycobot` API.
@ -13,9 +13,10 @@ import rospy
from sensor_msgs.msg import JointState from sensor_msgs.msg import JointState
from pymycobot.mycobot import MyCobot from pymycobot.mycobot import MyCobot
from pymycobot.mycobotsocket import MyCobotSocket
mc = None ms = None
def callback(data): def callback(data):
@ -25,19 +26,24 @@ def callback(data):
for index, value in enumerate(data.position): for index, value in enumerate(data.position):
data_list.append(value) data_list.append(value)
mc.send_radians(data_list, 80) ms.send_radians(data_list, 80)
# time.sleep(0.5) # time.sleep(0.5)
def listener(): def listener():
global mc global ms
rospy.init_node("control_slider", anonymous=True) rospy.init_node("control_slider", anonymous=True)
rospy.Subscriber("joint_states", JointState, callback) rospy.Subscriber("joint_states", JointState, callback)
port = rospy.get_param("~port", "/dev/ttyTHS1") # port = rospy.get_param("~port", "/dev/ttyTHS1")
baud = rospy.get_param("~baud", 1000000) # baud = rospy.get_param("~baud", 1000000)
print(port, baud) # print(port, baud)
mc = MyCobot(port, baud) # mc = MyCobot(port, baud)
ip=rospy.get_param("~ip",'192.168.125.226')
port=rospy.get_param("~port",9000)
print(ip,port)
ms=MyCobotSocket(ip,port)
ms.connect(serialport="/dev/ttyTHS1", baudrate="1000000")
# spin() simply keeps python from exiting until this node is stopped # spin() simply keeps python from exiting until this node is stopped
# spin()只是阻止python退出直到该节点停止 # spin()只是阻止python退出直到该节点停止

0
mycobot_280/mycobot_280jn/scripts/teleop_keyboard.py Normal file → Executable file
View file

View file

@ -0,0 +1,12 @@
import time
from pymycobot.mycobotsocket import MyCobotSocket
# from pymycobot.mycobot import MyCobot
ms=MyCobotSocket('192.168.125.226',9000)
ms.connect(serialport="/dev/ttyTHS1", baudrate="1000000")
ms.send_angles([50,0,0,0,0,0],50)
time.sleep(2)
print(ms.get_angles())
ms.release_all_servos()

View file

@ -1,11 +1,11 @@
<launch> <launch>
<!-- Select connecting device and serial port ,选择连接设备及串口--> <!-- Select connecting device and serial port ,选择连接设备及串口-->
<arg name="port" default="/dev/ttyUSB0" /> <arg name="ip" default="192.168.125.226" />
<arg name="baud" default="115200" /> <arg name="port" default="9000" />
<!-- 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="port" type="string" value="$(arg port)" /> <param name="ip" type="string" value="$(arg ip)" />
<param name="baud" type="int" value="$(arg baud)" /> <param name="port" type="int" value="$(arg port)" />
</node> </node>
</launch> </launch>

View file

@ -5,18 +5,25 @@ 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")
# baud = rospy.get_param("~baud")
# rospy.loginfo("%s,%s" % (port, baud))
# ms = MyCobot(port, baud)
ip=rospy.get_param("~ip")
port=rospy.get_param("~port") port=rospy.get_param("~port")
baud = rospy.get_param("~baud") rospy.loginfo("%s,%s" % (ip,port))
rospy.loginfo("%s,%s" % (port, baud)) ms=MyCobotSocket(ip,port)
mc = MyCobot(port, baud) ms.connect(serialport="/dev/ttyTHS1", baudrate="1000000")
def create_services(): def create_services():
@ -42,16 +49,16 @@ def set_angles(req):
] ]
sp = req.speed sp = req.speed
if mc: if ms:
mc.send_angles(angles, sp) ms.send_angles(angles, sp)
return SetAnglesResponse(True) return SetAnglesResponse(True)
def get_angles(req): def get_angles(req):
"""get angles,获取角度""" """get angles,获取角度"""
if mc: if ms:
angles = mc.get_angles() angles = ms.get_angles()
return GetAnglesResponse(*angles) return GetAnglesResponse(*angles)
@ -67,38 +74,38 @@ def set_coords(req):
sp = req.speed sp = req.speed
mod = req.model mod = req.model
if mc: if ms:
mc.send_coords(coords, sp, mod) ms.send_coords(coords, sp, mod)
return SetCoordsResponse(True) return SetCoordsResponse(True)
def get_coords(req): def get_coords(req):
if mc: if ms:
coords = mc.get_coords() coords = ms.get_coords()
return GetCoordsResponse(*coords) return GetCoordsResponse(*coords)
def switch_status(req): def switch_status(req):
"""Gripper switch status""" """Gripper switch status"""
"""夹爪开关状态""" """夹爪开关状态"""
if mc: if ms:
if req.Status: if req.Status:
mc.set_gripper_state(0, 80) ms.set_gripper_state(0, 80)
else: else:
mc.set_gripper_state(1, 80) ms.set_gripper_state(1, 80)
return GripperStatusResponse(True) return GripperStatusResponse(True)
def toggle_pump(req): def toggle_pump(req):
if mc: if ms:
if req.Status: if req.Status:
mc.set_basic_output(req.Pin1, 0) ms.set_basic_output(req.Pin1, 0)
mc.set_basic_output(req.Pin2, 0) ms.set_basic_output(req.Pin2, 0)
else: else:
mc.set_basic_output(req.Pin1, 1) ms.set_basic_output(req.Pin1, 1)
mc.set_basic_output(req.Pin2, 1) ms.set_basic_output(req.Pin2, 1)
return PumpStatusResponse(True) return PumpStatusResponse(True)
@ -130,12 +137,12 @@ def output_robot_message():
servo_temperature = "unknown" servo_temperature = "unknown"
atom_version = "unknown" atom_version = "unknown"
if mc: if ms:
cn = mc.is_controller_connected() cn = ms.is_controller_connected()
if cn == 1: if cn == 1:
connect_status = True connect_status = True
time.sleep(0.1) time.sleep(0.1)
si = mc.is_all_servo_enable() si = ms.is_all_servo_enable()
if si == 1: if si == 1:
servo_infomation = "all connected" servo_infomation = "all connected"