Skip to content

Commit

Permalink
add resposne for manipulator
Browse files Browse the repository at this point in the history
  • Loading branch information
kshpv committed Feb 6, 2019
1 parent e74944e commit 0ac66b8
Showing 1 changed file with 44 additions and 14 deletions.
58 changes: 44 additions & 14 deletions eurobot_stm/scripts/manipulator.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,71 @@
#!/usr/bin/env python
import time
import re

import rospy
from std_msgs.msg import String



class Manipulator():
def __init__(self):
self.publisher = rospy.Publisher("/secondary_robot/stm_command", String, queue_size=10)
time.sleep(2)
def __init__(self):
self.publisher = rospy.Publisher("/secondary_robot/stm_command", String, queue_size=10)

This comment has been minimized.

Copy link
@MisterMap

MisterMap Feb 7, 2019

Collaborator

Убрать абсолютные пути. Этот код уневерсальный для большого и маленького робота

rospy.Subscriber("/seondary_robot/stm_response", String, self.response_callback)
self.las_response_id = None
self.last_response_args = None
time.sleep(2)

def response_callback(self, data):
response = data.split()
if re.match(r"manipulator-*", response[0]):
self.las_response_id = response[0]
self.last_response_args = response[1]

def send_command(self, id, cmd):
self.publisher.publish(String("manipulator-" + str(id) + " " + str(cmd)))

This comment has been minimized.

Copy link
@MisterMap

MisterMap Feb 7, 2019

Collaborator

Лучше не называть аргументы id - это built-in функция

while(True):
if self.last_response_id == id:
return self.last_response_args

This comment has been minimized.

Copy link
@MisterMap

MisterMap Feb 7, 2019

Collaborator

Мне не очень нравится эта структура, она кажется не безопасной, и не позволяет отправлять паралельно команды





def collect_puck(self):
# Release grabber
print("__1__")
self.publisher.publish(String("manipulator-1 22"))
self.send_command(1, 22)
# self.publisher.publish(String("manipulator-1 22"))
# Set pump to the wall
self.publisher.publish(String("manipulator-2 20"))
self.send_command(2, 20)
# self.publisher.publish(String("manipulator-2 20"))
# Set pump to the ground
self.publisher.publish("manipulator-3 19")
self.send_command(3, 19)
# self.publisher.publish("manipulator-3 19")
# Start pump
self.publisher.publish("manipulator-4 17")
self.send_command(4, 17)
# self.publisher.publish("manipulator-4 17")
# Set pump to the platform
self.publisher.publish("manipulator-5 21")
self.send_command(5, 21)
# self.publisher.publish("manipulator-5 21")
# Prop pack
self.publisher.publish("manipulator-6 23")
self.send_command(6, 23)
# self.publisher.publish("manipulator-6 23")
# Stop pump
self.publisher.publish("manipulator-7 18")
self.send_command(7, 18)
# self.publisher.publish("manipulator-7 18")
# Set pump to the wall
self.publisher.publish("manipulator-8 20")
self.send_command(8, 20)
# self.publisher.publish("manipulator-8 20")
# Grab pack
self.publisher.publish("manipulator-9 24")
self.send_command(9, 24)
# self.publisher.publish("manipulator-9 24")
# Release grabber
self.publisher.publish("manipulator-10 22")
self.send_command(10, 22)

This comment has been minimized.

Copy link
@MisterMap

MisterMap Feb 7, 2019

Collaborator

Можно сделать небольшой вспомогательный клас, который даёт id командам

# self.publisher.publish("manipulator-10 22")

if __name__=="__main__":
print("1")
rospy.init_node("manuipulator_node", anonymous=True)
manipulator = Manipulator()
manipulator.collect_puck()
print("2")
#manipulator.collect_puck()

0 comments on commit 0ac66b8

Please sign in to comment.