Esempio n. 1
0
def setupMoveService():
    """Initialize the DriveMotors service

    Establish a connection with the Phidget HC Motor Control and
    then with the ROS Master as the service DriveMotors

    """

    global motorControl, minAcceleration, maxAcceleration

    try:
        motorControl = MotorControl()
    except:
        rospy.logerr("Unable to connect to Phidget HC Motor Control")
        return

    try:
        motorControl.setOnAttachHandler(mcAttached)
        motorControl.setOnDetachHandler(mcDetached)
        motorControl.setOnErrorhandler(mcError)
        motorControl.setOnCurrentChangeHandler(mcCurrentChanged)
        motorControl.setOnInputChangeHandler(mcInputChanged)
        motorControl.setOnVelocityChangeHandler(mcVelocityChanged)
    except:
        rospy.logerr("Unable to register the handlers")
        return

    try:
        motorControl.openPhidget()
    except PhidgetException as e:
        rospy.logerr("Fail to openPhidget() %i: %s", e.code, e.details)
        return

    try:
        motorControl.waitForAttach(10000)
    except PhidgetException as e:
        rospy.logerr("Fail to attach to Phidget %i: %s", e.code, e.details)
        return

    if motorControl.isAttached():
        rospy.loginfo("Device: %s, Serial: %d, Version: %d",
                      motorControl.getDeviceName(),
                      motorControl.getSerialNum(),
                      motorControl.getDeviceVersion())

    minAcceleration = motorControl.getAccelerationMin(leftWheels)
    maxAcceleration = motorControl.getAccelerationMax(leftWheels)

    rospy.init_node('DriveMotors', log_level=rospy.DEBUG)

    phidgetMotorService = rospy.Service('DriveMotors', Move, move)

    rospy.spin()
def setupMoveService():
    """Initialize the PhidgetMotor service

    Establish a connection with the Phidget HC Motor Control and
    then with the ROS Master as the service PhidgetMotor

    """
    node_name = 'PhidgetMotor'

    rospy.init_node(node_name, log_level=rospy.DEBUG)

    serial_no = rospy.get_param("~serial_no", 0)
    if not serial_no == 0:
        rospy.loginfo("Using motor controller with serial number %d",
                      serial_no)
    else:
        rospy.loginfo(
            "No serial number specified.  This is fine for systems with one controller, but may behave unpredictably for systems with multiple motor controllers"
        )

    global motorControl, motorControlRight, minAcceleration, maxAcceleration, timer, motors_inverted, phidget1065, rightWheels, posdataPub
    timer = 0
    try:
        motorControl = MotorControl()
    except:
        rospy.logerr("Unable to connect to Phidget HC Motor Control")
        return

    try:
        motorControl.setOnAttachHandler(mcAttached)
        motorControl.setOnDetachHandler(mcDetached)
        motorControl.setOnErrorhandler(mcError)
        motorControl.setOnCurrentChangeHandler(mcCurrentChanged)
        motorControl.setOnInputChangeHandler(mcInputChanged)
        motorControl.setOnVelocityChangeHandler(mcVelocityChanged)
        if serial_no != 0:
            motorControl.openPhidget(serial_no)
        else:
            motorControl.openPhidget()

        #attach the board
        motorControl.waitForAttach(10000)
        """use the function getMotorCount() to know how many motors the Phidget board can take

        if the result is more than 1, we have a 1064 board and we take care of both motors with one motorControl variable. The corobot_phidgetIK handles the Phidget encoder board that is 
        separated of the phidget 1064.
        if the result is equal to 1, we have two phidget 1065 boards. The one with serial number that is the lowest will be the left will, the other the right weel. The encoder has to be handled 
        in this file as it is part of the 1065 board. 

        """
        if motorControl.getMotorCount() == 1:
            phidget1065 = True
            rightWheels = 0
            motorControlRight.setOnAttachHandler(mcAttached)
            motorControlRight.setOnDetachHandler(mcDetached)
            motorControlRight.setOnErrorhandler(mcError)
            motorControlRight.setOnCurrentChangeHandler(mcCurrentChanged)
            motorControlRight.setOnInputChangeHandler(mcInputChanged)
            motorControlRight.setOnVelocityChangeHandler(mcVelocityChanged)

            if motorControl.getSerialNum() > motorControlRight.getSerialNum():
                """ As a rule, we need the serial number of the left board to be lower than for the right board. This is for consistancy for all the robots
                """
                motorControlTemp = motorControl
                motorControl = motorControlRight
                motorControlRight = motorControlTemp

#Set up the encoders handler
            motorControl.setOnPositionUpdateHandler(leftEncoderUpdated)
            motorControlRight.setOnPositionUpdateHandler(rightEncoderUpdated)

            #attach the board
            motorControlRight.waitForAttach(10000)
    except PhidgetException as e:
        rospy.logerr("Unable to register the handlers: %i: %s", e.code,
                     e.details)
        return
    except AttributeError as e:
        rospy.logerr("Unable to register the handlers: %s", e)
        return
    except:
        rospy.logerr("Unable to register the handlers: %s", sys.exc_info()[0])
        return

    if motorControl.isAttached():
        rospy.loginfo("Device: %s, Serial: %d, Version: %d",
                      motorControl.getDeviceName(),
                      motorControl.getSerialNum(),
                      motorControl.getDeviceVersion())
    if phidget1065 == True:
        if motorControlRight.isAttached():
            rospy.loginfo("Device: %s, Serial: %d, Version: %d",
                          motorControlRight.getDeviceName(),
                          motorControlRight.getSerialNum(),
                          motorControlRight.getDeviceVersion())

    minAcceleration = motorControl.getAccelerationMin(leftWheels)
    maxAcceleration = motorControl.getAccelerationMax(leftWheels)

    motors_inverted = rospy.get_param('~motors_inverted', False)

    phidgetMotorTopic = rospy.Subscriber(node_name, MotorCommand, move)
    phidgetMotorService = rospy.Service(node_name, Move, move)
    if phidget1065 == True:
        posdataPub = rospy.Publisher("position_data", PosMsg)
    rospy.spin()
        exit(1)
    print("Exiting....")
    exit(1)
else:
    displayDeviceInfo()

#print(motorControlL.getAccelerationMin(0))
#print(motorControlR.getAccelerationMin(0))
#print(motorControlL.getAccelerationMax(0))
#print(motorControlR.getAccelerationMax(0))

#no good for automation scripts...
#print("Press Enter to continue....")
#chr = sys.stdin.read(1)

Amax = motorControlL.getAccelerationMax(0)
Amin = motorControlL.getAccelerationMin(0)
print("minimum acceleration = %f, maximum acceleration = %f" % ( Amin, Amax))

context = zmq.Context()
motors_receiver = context.socket(zmq.PULL)
motors_receiver.bind("ipc:///tmp/motors.ipc")
#motors_receiver.bind("tcp://127.0.0.2:1100")

#battery_socket = context.socket(zmq.PUB)
#battery_socket.bind("ipc:///tmp/battery.ipc")

bumper_reciever = context.socket(zmq.SUB)
bumper_reciever.connect("ipc://tmp/bumper.ipc")

# messages passed in as {left acc, left vel, right acc, right vel, rel}
Esempio n. 4
0
except PhidgetException, e:
    print "waitForAttach() failed"
    print "code: %d" % e.code
    print "message", e.message
    
    raise

if motorControl.isAttached():
    print "motor control attached"
else:
    print "motor attach Failed"

encoder.setPosition(whichEncoder, 0)
encoder.setEnabled(whichEncoder, True)
averageAcceleration = (motorControl.getAccelerationMax(whichMotor) - motorControl.getAccelerationMin(whichMotor)) * 0.9
print "averageAcceleration", averageAcceleration
motorControl.setAcceleration(whichMotor, averageAcceleration)

position = encoder.getPosition(whichEncoder)
print "Starting position", position
startTime = time.clock()
motorControl.setVelocity(whichMotor, velocity)
try:
    while position < pulsesWanted:
        position = encoder.getPosition(whichEncoder) * encoderSign
        print "Position", position, "Current", motorControl.getCurrent(whichMotor), "\r",
    
except:
    print "Aborted"
    pass
def setupMoveService():
    """Initialize the PhidgetLinear service

    Establish a connection with the Phidget 1065 Motor Control and
    then with the ROS Master as the service PhidgetLinear

    """

    rospy.init_node('PhidgetLinear', log_level=rospy.DEBUG)

    serial_no = rospy.get_param("~serial_no", 0)
    if not serial_no == 0:
        rospy.loginfo("Using motor controller with serial number %d",
                      serial_no)
    else:
        rospy.loginfo(
            "No serial number specified.  This is fine for systems with one controller, but may behave unpredictably for systems with multiple motor controllers"
        )

    global motorControl, minAcceleration, maxAcceleration, timer, invert_speed, posdataPub
    timer = 0
    try:
        motorControl = MotorControl()
    except:
        rospy.logerr("Unable to connect to Phidget Motor Control")
        return

    try:
        motorControl.setOnAttachHandler(mcAttached)
        motorControl.setOnDetachHandler(mcDetached)
        motorControl.setOnErrorhandler(mcError)
        motorControl.setOnCurrentChangeHandler(mcCurrentChanged)
        motorControl.setOnInputChangeHandler(mcInputChanged)
        motorControl.setOnVelocityChangeHandler(mcVelocityChanged)
        motorControl.setOnSensorUpdateHandler(mcSensorUpdated)
        if serial_no != 0:
            motorControl.openPhidget(serial_no)
        else:
            motorControl.openPhidget()

        #attach the board
        motorControl.waitForAttach(10000)
    except PhidgetException as e:
        rospy.logerr("Unable to register the handlers: %i: %s", e.code,
                     e.details)
        return
    except AttributeError as e:
        rospy.logerr("Unable to register the handlers: %s", e)
        return
    except:
        rospy.logerr("Unable to register the handlers: %s", sys.exc_info()[0])
        return

    if motorControl.isAttached():
        rospy.loginfo("Device: %s, Serial: %d, Version: %d",
                      motorControl.getDeviceName(),
                      motorControl.getSerialNum(),
                      motorControl.getDeviceVersion())
    # ensure the motor controller attempts to brake the linear
    # when velocity is cut to 0
    motorControl.setBraking(linear, 100)
    #    print motorControl.getBraking(linear)
    minAcceleration = motorControl.getAccelerationMin(linear)
    maxAcceleration = motorControl.getAccelerationMax(linear)

    invert_speed = rospy.get_param('~invert_speed', False)
    maxPos = rospy.get_param('~max_pos', 1014)
    minPos = rospy.get_param('~min_pos', 10)

    phidgetMotorTopic = rospy.Subscriber("PhidgetLinear", LinearCommand, move)
    phidgetMotorService = rospy.Service('PhidgetLinear', Move, move)
    posdataPub = rospy.Publisher("position", UInt32, latch=True)
    rospy.spin()
Esempio n. 6
0
def setupMoveService():
    """Initialize the PhidgetMotor service

    Establish a connection with the Phidget HC Motor Control and
    then with the ROS Master as the service PhidgetMotor

    """

    rospy.init_node(
            'PhidgetMotor',
            log_level = rospy.DEBUG
            )

    global motorControl, motorControlRight, minAcceleration, maxAcceleration, timer, motors_inverted, phidget1065, rightWheels, posdataPub
    timer = 0
    try:
        motorControl = MotorControl()
    except:
        rospy.logerr("Unable to connect to Phidget HC Motor Control")
     	return

    try:
        motorControl.setOnAttachHandler(mcAttached)
        motorControl.setOnDetachHandler(mcDetached)
        motorControl.setOnErrorhandler(mcError)
        motorControl.setOnCurrentChangeHandler(mcCurrentChanged)
        motorControl.setOnInputChangeHandler(mcInputChanged)
        motorControl.setOnVelocityChangeHandler(mcVelocityChanged)
        motorControl.openPhidget()

        #attach the board
        motorControl.waitForAttach(10000)
        """use the function getMotorCount() to know how many motors the Phidget board can take

        if the result is more than 1, we have a 1064 board and we take care of both motors with one motorControl variable. The corobot_phidgetIK handles the Phidget encoder board that is 
        separated of the phidget 1064.
        if the result is equal to 1, we have two phidget 1065 boards. The one with serial number that is the lowest will be the left will, the other the right weel. The encoder has to be handled 
        in this file as it is part of the 1065 board. 

        """
        if motorControl.getMotorCount() == 1:
            phidget1065 = True 
            rightWheels = 0
            motorControlRight.setOnAttachHandler(mcAttached)
            motorControlRight.setOnDetachHandler(mcDetached)
            motorControlRight.setOnErrorhandler(mcError)
            motorControlRight.setOnCurrentChangeHandler(mcCurrentChanged)
            motorControlRight.setOnInputChangeHandler(mcInputChanged)
            motorControlRight.setOnVelocityChangeHandler(mcVelocityChanged)
			
            if motorControl.getSerialNum() > motorControlRight.getSerialNum(): 
                """ As a rule, we need the serial number of the left board to be lower than for the right board. This is for consistancy for all the robots
                """
                motorControlTemp = motorControl
                motorControl = motorControlRight
                motorControlRight = motorControlTemp

			#Set up the encoders handler
            motorControl.setOnPositionUpdateHandler(leftEncoderUpdated)
            motorControlRight.setOnPositionUpdateHandler(rightEncoderUpdated)

            #attach the board
            motorControlRight.waitForAttach(10000)
    except PhidgetException as e:
        rospy.logerr("Unable to register the handlers: %i: %s", e.code, e.details)
        return
    except:
        rospy.logerr("Unable to register the handlers")
        return
     

    if motorControl.isAttached():
        rospy.loginfo(
                "Device: %s, Serial: %d, Version: %d",
                motorControl.getDeviceName(),
                motorControl.getSerialNum(),
                motorControl.getDeviceVersion()
                )
    if phidget1065 == True:
        if motorControlRight.isAttached():
            rospy.loginfo(
		            "Device: %s, Serial: %d, Version: %d",
		            motorControlRight.getDeviceName(),
		            motorControlRight.getSerialNum(),
		            motorControlRight.getDeviceVersion()
		            )

    minAcceleration = motorControl.getAccelerationMin(leftWheels)
    maxAcceleration = motorControl.getAccelerationMax(leftWheels)

    motors_inverted = rospy.get_param('~motors_inverted', False)

    phidgetMotorTopic = rospy.Subscriber("PhidgetMotor", MotorCommand ,move)
    phidgetMotorService = rospy.Service('PhidgetMotor',Move, move)
    if phidget1065 == True:
        posdataPub = rospy.Publisher("position_data", PosMsg)
    rospy.spin()
Esempio n. 7
0
        exit(1)
    print("Exiting....")
    exit(1)
else:
    displayDeviceInfo()

#print(motorControlL.getAccelerationMin(0))
#print(motorControlR.getAccelerationMin(0))
#print(motorControlL.getAccelerationMax(0))
#print(motorControlR.getAccelerationMax(0))

#no good for automation scripts...
#print("Press Enter to continue....")
#chr = sys.stdin.read(1)

Amax = motorControlL.getAccelerationMax(0)
Amin = motorControlL.getAccelerationMin(0)
print("minimum acceleration = %f, maximum acceleration = %f" % (Amin, Amax))

context = zmq.Context()
motors_receiver = context.socket(zmq.PULL)
motors_receiver.bind("ipc:///tmp/motors.ipc")
#motors_receiver.bind("tcp://127.0.0.2:1100")

#battery_socket = context.socket(zmq.PUB)
#battery_socket.bind("ipc:///tmp/battery.ipc")

bumper_reciever = context.socket(zmq.SUB)
bumper_reciever.connect("ipc://tmp/bumper.ipc")

# messages passed in as {left acc, left vel, right acc, right vel, rel}