class ROS_ArmServer(): '''Provides ROS topics for controlling a maplin arm''' def __init__(self): # Start the node rospy.init_node('armDriver', anonymous=True) self.armDriver = ArmDriver() # Setup topics so that users can control the motors self.setArmMotorStatesTopic = rospy.Subscriber( "setArmMotorStates", maplin_arm.msg.SetMotorStates, self.setArmMotorStatesCallback) #--------------------------------------------------------------------------- def update(self): self.armDriver.update() #--------------------------------------------------------------------------- def setArmMotorStatesCallback(self, request): for stateRequest in request.motorStates: if stateRequest.motorIdx >= 0 and stateRequest.motorIdx < ArmDriver.NUM_MOTORS: self.armDriver.setMotorState(stateRequest.motorIdx, stateRequest.motorState) else: rospy.logerr("Command sent to invalid motorIdx ({0})".format( stateRequest.motorIdx))
class ROS_ArmServer(): '''Provides ROS topics for controlling a maplin arm''' def __init__( self ): # Start the node rospy.init_node( 'armDriver', anonymous=True ) self.armDriver = ArmDriver() # Setup topics so that users can control the motors self.setArmMotorStatesTopic = rospy.Subscriber( "setArmMotorStates", maplin_arm.msg.SetMotorStates, self.setArmMotorStatesCallback ) #--------------------------------------------------------------------------- def update( self ): self.armDriver.update() #--------------------------------------------------------------------------- def setArmMotorStatesCallback( self, request ): for stateRequest in request.motorStates: if stateRequest.motorIdx >= 0 and stateRequest.motorIdx < ArmDriver.NUM_MOTORS: self.armDriver.setMotorState( stateRequest.motorIdx, stateRequest.motorState ) else: rospy.logerr( "Command sent to invalid motorIdx ({0})".format( stateRequest.motorIdx ) )
class ArmServer(): def listener(self): # In ROS, nodes are uniquely named. If two nodes with the same # name are launched, the previous one is kicked off. The # anonymous=True flag means that rospy will choose a unique # name for our 'listener' node so that multiple listeners can # run simultaneously. rospy.init_node('listener', anonymous=True) self.armDriver = ArmDriver() rospy.Subscriber('setArmMotorStates', SetMotorStates, self.setArmMotorStatesCallback) rospy.Timer(rospy.Duration(2), self.my_callback) rospy.spin() def my_callback(self, event): self.update() #--------------------------------------------------------------------------- def update(self): self.armDriver.update() #--------------------------------------------------------------------------- def setArmMotorStatesCallback(self, request): for stateRequest in request.motorStates: if stateRequest.motorIdx >= 0 and stateRequest.motorIdx < ArmDriver.NUM_MOTORS: self.armDriver.setMotorState(stateRequest.motorIdx, stateRequest.motorState) self.update() else: rospy.logerr("Command sent to invalid motorIdx ({0})".format( stateRequest.motorIdx))
def __init__(self): # Start the node rospy.init_node('armDriver', anonymous=True) self.armDriver = ArmDriver() # Setup topics so that users can control the motors self.setArmMotorStatesTopic = rospy.Subscriber( "setArmMotorStates", maplin_arm.msg.SetMotorStates, self.setArmMotorStatesCallback)
def listener(self): # In ROS, nodes are uniquely named. If two nodes with the same # name are launched, the previous one is kicked off. The # anonymous=True flag means that rospy will choose a unique # name for our 'listener' node so that multiple listeners can # run simultaneously. rospy.init_node('listener', anonymous=True) self.armDriver = ArmDriver() rospy.Subscriber('setArmMotorStates', SetMotorStates, self.setArmMotorStatesCallback) rospy.Timer(rospy.Duration(2), self.my_callback) rospy.spin()
def __init__( self ): # Start the node rospy.init_node( 'armDriver', anonymous=True ) self.armDriver = ArmDriver() # Setup topics so that users can control the motors self.setArmMotorStatesTopic = rospy.Subscriber( "setArmMotorStates", maplin_arm.msg.SetMotorStates, self.setArmMotorStatesCallback )