Source code for mobrob_behcon.connectors.gripper

#!/usr/bin/env python

import rospy
from myrobot_model.srv import AttinyCommand

[docs]class Gripper(object): """ The class Gripper Represents a connector to the gripper service of the robot. Provides multiple functions to control the gripper. """
[docs] def __init__(self, ros_service = 'attiny_command'): """ constructor :param ros_service: name of service for attiny (default: **'attiny_command'**) :type ros_service: string """ rospy.wait_for_service(ros_service) self.attiny_command = rospy.ServiceProxy(ros_service , AttinyCommand)
[docs] def send_command(self, command): try: resp = self.attiny_command(command) return resp.output except rospy.ServiceException as e: print("Service call failed: %s"%e)
[docs] def setActivServo(self, value): print(self.send_command("sv_ac(" + ("1" if value else "0") + ")"))
[docs] def writeServo(self, angle): print(self.send_command("sv_wr(" + str(angle) + ")\n"))
[docs] def refreshServo(self): print(self.send_command("sv_rf(1)\n"))
[docs] def initGRIP(self): print(self.send_command("gr_it(1)\n"))
[docs] def initVERT(self): print(self.send_command("vt_it(1)\n"))
[docs] def setSpeedGRIP(self, value): print(self.send_command("gr_sp(" + str(abs(value)) + ")\n"))
[docs] def setSpeedVERT(self, value): print(self.send_command("vt_sp(" + str(abs(value)) + ")\n"))
[docs] def moveAbsGRIP(self, value): print(self.send_command("gr_ma(" + str(value) + ")\n"))
[docs] def moveAbsVERT(self, value): print(self.send_command("vt_ma(" + str(value) + ")\n"))
[docs] def moveRelGRIP(self, value): print(self.send_command("gr_mr(" + str(value) + ")\n"))
[docs] def moveRelVERT(self, value): print(self.send_command("vt_mr(" + str(value) + ")\n"))
[docs] def stopGRIP(self): print(self.send_command("gr_st(1)\n"))
[docs] def stopVERT(self): print(self.send_command("vt_st(1)\n"))
[docs] def stopAll(self): print(self.send_command("st_st(1)\n"))
[docs] def setStayActivStepper(self, value): print(self.send_command("st_ac(" + ("1" if value else "0") + ")\n"))
[docs] def getPosVERT(self): print(self.send_command("vt_gp(1)\n"))
[docs] def getPosGRIP(self): print(self.send_command("gr_gp(1)\n"))