mirror of
https://github.com/elephantrobotics/mycobot_ros.git
synced 2026-07-14 09:00:53 +00:00
Adapted to seeed
This commit is contained in:
parent
5b630bb6de
commit
74eb9b3dcf
6 changed files with 50 additions and 25 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -3,6 +3,7 @@
|
||||||
.VSCodeCounter/
|
.VSCodeCounter/
|
||||||
|
|
||||||
.vscode/
|
.vscode/
|
||||||
|
.history
|
||||||
|
|
||||||
# Editor directories and files
|
# Editor directories and files
|
||||||
.idea
|
.idea
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
#!/usr/bin/env python2
|
#!/usr/bin/env python2
|
||||||
|
# coding:utf-8
|
||||||
import rospy
|
import rospy
|
||||||
from visualization_msgs.msg import Marker
|
from visualization_msgs.msg import Marker
|
||||||
import time
|
import time
|
||||||
|
import os
|
||||||
|
|
||||||
# 与 mycobot 通信的消息类型
|
# 与 mycobot 通信的消息类型
|
||||||
from mycobot_communication.msg import MycobotSetAngles, MycobotSetCoords, MycobotPumpStatus
|
from mycobot_communication.msg import MycobotSetAngles, MycobotSetCoords, MycobotPumpStatus
|
||||||
|
|
@ -10,9 +12,20 @@ from mycobot_communication.msg import MycobotSetAngles, MycobotSetCoords, Mycobo
|
||||||
rospy.init_node("gipper_subscriber", anonymous=True)
|
rospy.init_node("gipper_subscriber", anonymous=True)
|
||||||
|
|
||||||
# 控制 mycobot 的 topic,依次是角度、坐标、夹爪
|
# 控制 mycobot 的 topic,依次是角度、坐标、夹爪
|
||||||
angle_pub = rospy.Publisher("mycobot/angles_goal", MycobotSetAngles, queue_size=5)
|
angle_pub = rospy.Publisher("mycobot/angles_goal",
|
||||||
coord_pub = rospy.Publisher("mycobot/coords_goal", MycobotSetCoords, queue_size=5)
|
MycobotSetAngles, queue_size=5)
|
||||||
pump_pub = rospy.Publisher("mycobot/pump_status", MycobotPumpStatus, queue_size=5)
|
coord_pub = rospy.Publisher("mycobot/coords_goal",
|
||||||
|
MycobotSetCoords, queue_size=5)
|
||||||
|
# Judging equipment: ttyUSB* is M5;ttyACM* is wio
|
||||||
|
robot = os.popen("ls /dev/ttyUSB*").readline()
|
||||||
|
|
||||||
|
if "dev" in robot:
|
||||||
|
Pin = [2, 5]
|
||||||
|
else:
|
||||||
|
Pin = [20, 21]
|
||||||
|
|
||||||
|
pump_pub = rospy.Publisher("mycobot/pump_status",
|
||||||
|
MycobotPumpStatus, queue_size=5)
|
||||||
|
|
||||||
# 实例化消息对象
|
# 实例化消息对象
|
||||||
angles = MycobotSetAngles()
|
angles = MycobotSetAngles()
|
||||||
|
|
@ -59,9 +72,11 @@ def pub_angles(a, b, c, d, e, f, sp):
|
||||||
angle_pub.publish(angles)
|
angle_pub.publish(angles)
|
||||||
|
|
||||||
|
|
||||||
def pub_pump(flag):
|
def pub_pump(flag, Pin):
|
||||||
"""发布夹爪状态"""
|
"""发布夹爪状态"""
|
||||||
pump.Status = flag
|
pump.Status = flag
|
||||||
|
pump.Pin1 = Pin[0]
|
||||||
|
pump.Pin2 = Pin[1]
|
||||||
pump_pub.publish(pump)
|
pump_pub.publish(pump)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -79,7 +94,7 @@ def target_is_moving(x, y, z):
|
||||||
|
|
||||||
|
|
||||||
def grippercallback(data):
|
def grippercallback(data):
|
||||||
"""回调函数""""
|
"""回调函数"""
|
||||||
global flag, temp_x, temp_y, temp_z
|
global flag, temp_x, temp_y, temp_z
|
||||||
# rospy.loginfo('gripper_subscriber get date :%s', data)
|
# rospy.loginfo('gripper_subscriber get date :%s', data)
|
||||||
if flag:
|
if flag:
|
||||||
|
|
@ -124,7 +139,7 @@ def grippercallback(data):
|
||||||
|
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
|
|
||||||
pub_pump(True)
|
pub_pump(True, Pin)
|
||||||
# pump on
|
# pump on
|
||||||
|
|
||||||
pub_coords(x, y, z + 20, -165)
|
pub_coords(x, y, z + 20, -165)
|
||||||
|
|
@ -138,10 +153,11 @@ def grippercallback(data):
|
||||||
time.sleep(1.5)
|
time.sleep(1.5)
|
||||||
|
|
||||||
for i in range(1, 8):
|
for i in range(1, 8):
|
||||||
pub_coords(39.4, -174.7, put_z - i * 5, -177.13, -4.13, -152.59, 15, 2)
|
pub_coords(39.4, -174.7, put_z - i * 5, -
|
||||||
|
177.13, -4.13, -152.59, 15, 2)
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
|
||||||
pub_pump(False)
|
pub_pump(False, Pin)
|
||||||
|
|
||||||
time.sleep(0.5)
|
time.sleep(0.5)
|
||||||
|
|
||||||
|
|
@ -159,11 +175,12 @@ def main():
|
||||||
# pub_angles(random.randint(-30, 30), random.randint(-30, 30), random.randint(-30, 30), random.randint(-30, 30), random.randint(-30, 30), random.randint(-30, 30), 70)
|
# pub_angles(random.randint(-30, 30), random.randint(-30, 30), random.randint(-30, 30), random.randint(-30, 30), random.randint(-30, 30), random.randint(-30, 30), 70)
|
||||||
time.sleep(0.5)
|
time.sleep(0.5)
|
||||||
|
|
||||||
pub_pump(False)
|
pub_pump(False, Pin)
|
||||||
# time.sleep(2.5)
|
# time.sleep(2.5)
|
||||||
|
|
||||||
# mark 信息的订阅者
|
# mark 信息的订阅者
|
||||||
rospy.Subscriber("visualization_marker", Marker, grippercallback, queue_size=1)
|
rospy.Subscriber("visualization_marker", Marker,
|
||||||
|
grippercallback, queue_size=1)
|
||||||
|
|
||||||
print("gripper test")
|
print("gripper test")
|
||||||
rospy.spin()
|
rospy.spin()
|
||||||
|
|
|
||||||
|
|
@ -1 +1,3 @@
|
||||||
bool Status
|
bool Status
|
||||||
|
int8 Pin1
|
||||||
|
int8 Pin2
|
||||||
|
|
|
||||||
|
|
@ -89,11 +89,11 @@ def switch_status(req):
|
||||||
def toggle_pump(req):
|
def toggle_pump(req):
|
||||||
if mc:
|
if mc:
|
||||||
if req.Status:
|
if req.Status:
|
||||||
mc.set_basic_output(2, 0)
|
mc.set_basic_output(req.Pin1, 0)
|
||||||
mc.set_basic_output(5, 0)
|
mc.set_basic_output(req.Pin2, 0)
|
||||||
else:
|
else:
|
||||||
mc.set_basic_output(2, 1)
|
mc.set_basic_output(req.Pin1, 1)
|
||||||
mc.set_basic_output(5, 1)
|
mc.set_basic_output(req.Pin2, 1)
|
||||||
|
|
||||||
return PumpStatusResponse(True)
|
return PumpStatusResponse(True)
|
||||||
|
|
||||||
|
|
@ -135,7 +135,8 @@ def output_robot_message():
|
||||||
servo_infomation = "all connected"
|
servo_infomation = "all connected"
|
||||||
|
|
||||||
print(
|
print(
|
||||||
robot_msg % (connect_status, servo_infomation, servo_temperature, atom_version)
|
robot_msg % (connect_status, servo_infomation,
|
||||||
|
servo_temperature, atom_version)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -104,7 +104,8 @@ class MycobotTopics(object):
|
||||||
sp.join()
|
sp.join()
|
||||||
|
|
||||||
def pub_real_angles(self):
|
def pub_real_angles(self):
|
||||||
pub = rospy.Publisher("mycobot/angles_real", MycobotAngles, queue_size=5)
|
pub = rospy.Publisher("mycobot/angles_real",
|
||||||
|
MycobotAngles, queue_size=5)
|
||||||
ma = MycobotAngles()
|
ma = MycobotAngles()
|
||||||
while not rospy.is_shutdown():
|
while not rospy.is_shutdown():
|
||||||
self.lock.acquire()
|
self.lock.acquire()
|
||||||
|
|
@ -121,7 +122,8 @@ class MycobotTopics(object):
|
||||||
time.sleep(0.25)
|
time.sleep(0.25)
|
||||||
|
|
||||||
def pub_real_coords(self):
|
def pub_real_coords(self):
|
||||||
pub = rospy.Publisher("mycobot/coords_real", MycobotCoords, queue_size=5)
|
pub = rospy.Publisher("mycobot/coords_real",
|
||||||
|
MycobotCoords, queue_size=5)
|
||||||
ma = MycobotCoords()
|
ma = MycobotCoords()
|
||||||
|
|
||||||
while not rospy.is_shutdown():
|
while not rospy.is_shutdown():
|
||||||
|
|
@ -183,11 +185,11 @@ class MycobotTopics(object):
|
||||||
def sub_pump_status(self):
|
def sub_pump_status(self):
|
||||||
def callback(data):
|
def callback(data):
|
||||||
if data.Status:
|
if data.Status:
|
||||||
self.mc.set_basic_output(2, 0)
|
self.mc.set_basic_output(data.Pin1, 0)
|
||||||
self.mc.set_basic_output(5, 0)
|
self.mc.set_basic_output(data.Pin2, 0)
|
||||||
else:
|
else:
|
||||||
self.mc.set_basic_output(2, 1)
|
self.mc.set_basic_output(data.Pin1, 1)
|
||||||
self.mc.set_basic_output(5, 1)
|
self.mc.set_basic_output(data.Pin2, 1)
|
||||||
|
|
||||||
sub = rospy.Subscriber(
|
sub = rospy.Subscriber(
|
||||||
"mycobot/pump_status", MycobotPumpStatus, callback=callback
|
"mycobot/pump_status", MycobotPumpStatus, callback=callback
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
bool Status
|
bool Status
|
||||||
|
int8 Pin1
|
||||||
|
int8 Pin2
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue