Package barobo :: Module linkbot :: Class Linkbot
[hide private]
[frames] | no frames]

Class Linkbot

source code

mobot.Mobot --+
              |
             Linkbot

The Linkbot Class

Each instance of this class can be used to represent a physical Linkbot. The member functions of this class can be used to get data, set motor angles, beep the buzzer, scan for button events, and more.

Blocking and Non-Blocking Member Functions

The member functions of the Linkbot class which are responsible for moving the joints of the Linkbot can be categorized into two general types of functions; "blocking" functions and "non-blocking" functions. A blocking function is a function that "hangs" until the complete motion is done, whereas a "non-blocking" function returns as soon as the motion begins, but does not wait until it is done. In the Linkbot class, all functions are blocking unless the have the suffix "NB", such as "Linkbot.moveNB()".

For example, consider the following lines of code:

   linkbot.move(360, 0, 0)
   linkbot.setBuzzerFrequency(440)

When the above lines of code are executed, the Linkbot will rotate joint 1 360 degrees. Once the joint has rotated the full revolution, the buzzer will sound. Now consider the following code:

   linkbot.moveNB(360, 0, 0)
   linkbot.setBuzzerFrequency(440)

For these lines of code, joint 1 also moves 360 degrees. The difference is that with these lines of code, the buzzer will begin emitting a tone as soon as the joint begins turning, instead of waiting for the motion to finish. This is because the non-blocking version of move() was used, which returns immediately after the joint begins moving allowing the setBuzzerFrequency() function to execute as the joint begins moving.

The moveWait() function can be used to block until non-blocking motion functions are finished. For instance, the following two blocks of code will accomplish the same task:

   linkbot.move(360, 0, 0)
   linkbot.setBuzzerFrequency(440)

   linkbot.moveNB(360, 0, 0)
   linkbot.moveWait()
   linkbot.setBuzzerFrequency(440)
Instance Methods [hide private]
 
__init__(self, *args, **kwargs) source code
 
connectBluetooth(self, bluetooth_mac_addr)
Connect to a bluetooth enabled Linkbot.
source code
 
driveTo(self, angle1, angle2, angle3)
Drive the joints to angles as fast as possible using on-board PID controller.
source code
 
driveToNB(self, angle1, angle2, angle3)
Non-blocking version of driveTo().
source code
 
disableAccelEventCallback(self) source code
 
disableJointEventCallback(self) source code
 
enableJointEventCallback(self, cb)
Enable the joint event callback.
source code
 
enableAccelEventCallback(self, cb)
Enable the acceleration event callback.
source code
 
_getADCVolts(self, adc) source code
[number, number, number]
getAccelerometerData(self)
Get the current accelerometer readings
source code
number
getBatteryVoltage(self)
Get the current battery voltage of the Linkbot.
source code
number
getBreakoutADC(self, adc)
Get the ADC (Analog-to-digital) reading from a breakout-board's ADC channel.
source code
number
getBreakoutADCVolts(self, adc)
Get the voltage reading of an ADC pin.
source code
integer
getBreakoutDigitalPin(self, pin)
Read value from digital I/O pin.
source code
[number, number, number]
getColorRGB(self)
Get the current RGB values of the rgbled
source code
[major, minor, micro]
getHWRev(self)
Get the hardware revision of the Linkbot
source code
 
getLinkbot(self, addr)
Use an instance of a Linkbot to get instances to other Linkbots.
source code
 
getSerialID(self)
Get the serial ID from the Linkbot
source code
 
isMoving(self) source code
 
move(self, angle1, angle2, angle3)
Move all of the joints on a robot by a number of degrees.
source code
 
moveNB(self, angle1, angle2, angle3)
Non-blocking version of move().
source code
 
moveContinuous(self, dir1, dir2, dir3)
Make the joints begin moving continuously.
source code
 
moveTo(self, angle1, angle2, angle3) source code
 
moveToNB(self, angle1, angle2, angle3)
Move all joints on the Linkbot.
source code
 
_pairParent(self) source code
 
ping(self, numbytes=4, sendbytes=[]) source code
 
reboot(self)
Reboot the connect robot.
source code
 
recordAnglesBegin(self, delay=0.05)
Begin recording joint angles.
source code
 
recordAnglesEnd(self)
End recording angles and return a list consisting of [time_values, joint1angles, joint2angles, joint3angles]
source code
 
recordAnglesPlot(self) source code
 
setAcceleration(self, accel)
Set the acceleration of all joints.
source code
 
startJointAcceleration(self, joint, accel, timeout=0)
Make a robot's joint start accelerating forwards (positive accel value) or backwards.
source code
 
setBreakoutAnalogPin(self, pin, value)
Set an analog output pin (PWM) to a value between 0-255.
source code
 
setBreakoutAnalogRef(self, ref)
Set the reference voltage of an analog input pin.
source code
 
setBreakoutDigitalPin(self, pin, value)
Set a digital I/O pin to either a high or low value.
source code
 
setBreakoutPinMode(self, pin, mode)
Set the mode of a digital I/O pin on the breakout board.
source code
 
setBuzzerFrequency(self, freq)
Set the buzzer to begin playing a tone.
source code
 
setAccelEventThreshold(self, g_force)
Set the minimum change in g-force required for the robot to report an acceleration event.
source code
 
setJointEventThreshold(self, joint, angle)
Set the minimum amount the joint must move before a joint motion event is reported.
source code
 
setHWRev(self, major, minor, micro)
Set the HW revision of the Linkbot.
source code
 
setJointSpeeds(self, speed1, speed2, speed3)
Set all three motor speed simultaneously.
source code
 
setLEDColor(self, r, g, b)
Set the LED color
source code
 
setMotorPowers(self, power1, power2, power3) source code
 
setMovementState(self, state1, state2, state3, time=-1)
Set the movement state for all three motors.
source code
 
smoothMoveTo(self, joint, accel0, accelf, vmax, angle)
See: smoothMoveToNB()
source code
 
smoothMoveToNB(self, joint, accel0, accelf, vmax, angle)
Move a joint to a desired position with a specified amount of starting and stopping acceleration.
source code
 
_setSerialID(self, text) source code
bytearray
twiRecv(self, addr, size)
Receive data from a TWI device.
source code
 
twiSend(self, addr, data)
Send data onto the Two-Wire Interface (TWI) (aka I2c) of the Linkbot.
source code
bytearray
twiSendRecv(self, addr, senddata, recvsize)
Send and receive data from a TWI device attached to the Linkbot.
source code

Inherited from mobot.Mobot: checkStatus, connect, connectMobotBluetooth, disableButtonCallback, disconnect, driveJointTo, driveJointToNB, enableButtonCallback, getFormFactor, getJointAngle, getJointAngles, getJointAnglesTime, getJointSpeed, getJointSpeeds, getJointState, getVersion, moveJoint, moveJointNB, moveJointTo, moveJointToNB, moveWait, reset, resetToZero, resetToZeroNB, setJointMovementState, setJointSpeed, setJointState, setJointStates, setMotorPower, stop

Inherited from mobot.Mobot (private): _transactMessage

Method Details [hide private]

__init__(self, *args, **kwargs)
(Constructor)

source code 
Overrides: mobot.Mobot.__init__

connectBluetooth(self, bluetooth_mac_addr)

source code 

Connect to a bluetooth enabled Linkbot. Note that you must have a bluetooth enabled LinkPod connected to your Linkbot for this function to work. Most Linkbots do not come with BlueTooth, and instead use a ZigBee like protocol to communicate with each other.

Parameters:
  • bluetooth_mac_addr (string) - The MAC address of the bluetooth Linkbot. Should be something like '00:06:66:6D:12:34'
Overrides: mobot.Mobot.connectBluetooth

driveTo(self, angle1, angle2, angle3)

source code 

Drive the joints to angles as fast as possible using on-board PID controller.

Parameters:
  • angle1 - Position to move the joint, in degrees
  • angle2 - Position to move the joint, in degrees
  • angle3 - Position to move the joint, in degrees
Overrides: mobot.Mobot.driveTo
(inherited documentation)

driveToNB(self, angle1, angle2, angle3)

source code 

Non-blocking version of driveTo(). See driveTo() for more details

Overrides: mobot.Mobot.driveToNB
(inherited documentation)

enableJointEventCallback(self, cb)

source code 

Enable the joint event callback. Whenever any joint on the robot moves, the callback function 'cb' will be called. The callback function should be of the form cb(millis_timestamp, j1, j2, j3, mask) where 'millis_timestamp' will contain a timestamp from the robot, and j1, j2, and j3 will contain the new angles of all of the joints in degrees, and mask will be a mask of all of the joints that triggered the event.

enableAccelEventCallback(self, cb)

source code 

Enable the acceleration event callback. Whenever a change in acceleration happens on the robot, the callback function will be called.

getAccelerometerData(self)

source code 

Get the current accelerometer readings

Returns: [number, number, number]
A list of acceleration values in the x, y, and z directions. Accelerometer values are in units of "G's", where 1 G is standard earth gravitational acceleration (9.8m/s/s)

getBatteryVoltage(self)

source code 

Get the current battery voltage of the Linkbot.

Returns: number
Returns a value in Volts

getBreakoutADC(self, adc)

source code 

Get the ADC (Analog-to-digital) reading from a breakout-board's ADC channel.

Parameters:
  • adc (number) - The ADC channel to get the value from [0, 7]
Returns: number
Value from 0-1023

getBreakoutADCVolts(self, adc)

source code 

Get the voltage reading of an ADC pin.

Note that the voltage is calibrated using the AVCC reference. If the reference is changed using the setBreakoutADCReference() function, the values reported by this function may no longer be accurate.

Parameters:
  • adc (number) - The ADC channel to get the value from [0, 7]
Returns: number
Floating point voltage from 0 to 5

getBreakoutDigitalPin(self, pin)

source code 

Read value from digital I/O pin.

Returns: integer
Returns 0 if pin is grounded, or 1 in pin is high.

getColorRGB(self)

source code 

Get the current RGB values of the rgbled

Returns: [number, number, number]
The red, green, and blue values from 0 to 255

getHWRev(self)

source code 

Get the hardware revision of the Linkbot

Returns: [major, minor, micro]
The major, minor, and micro version numbers

getLinkbot(self, addr)

source code 

Use an instance of a Linkbot to get instances to other Linkbots. Note that this only works for Linkbots that are connected via Bluetooth or TTY, but does not work for Linkbots that are connected to BaroboLink.

getSerialID(self)

source code 

Get the serial ID from the Linkbot

Returns:
A four character string

isMoving(self)

source code 
Overrides: mobot.Mobot.isMoving

move(self, angle1, angle2, angle3)

source code 

Move all of the joints on a robot by a number of degrees.

Parameters:
  • angle1 - Number of degrees to move joint 1. Similar for parameters 'angle2' and 'angle3'.
Overrides: mobot.Mobot.move
(inherited documentation)

moveNB(self, angle1, angle2, angle3)

source code 

Non-blocking version of move(). See move() for more details

Overrides: mobot.Mobot.moveNB
(inherited documentation)

moveContinuous(self, dir1, dir2, dir3)

source code 

Make the joints begin moving continuously.

Parameters:
  • dir1 - This parameter may take the following values:
    • ROBOT_NEUTRAL: Makes the joint relax
    • ROBOT_FORWARD: Rotates the joint to move the robot in the "forward" direction, if the robot has wheels.
    • ROBOT_BACKWARD: Same as above but backwards
    • ROBOT_HOLD: Hold the joint at its current position
    • ROBOT_POSITIVE: Rotates the joint in the "positive" direction, according to the right-hand-rule.
    • ROBOT_NEGATIVE: Same as above but in the negative direction.
Overrides: mobot.Mobot.moveContinuous
(inherited documentation)

moveTo(self, angle1, angle2, angle3)

source code 
Overrides: mobot.Mobot.moveTo

moveToNB(self, angle1, angle2, angle3)

source code 

Move all joints on the Linkbot. Linkbot-I modules will ignore the 'angle2' parameter and Linkbot-L modules will ignore the 'angle3' parameter.

This function is the non-blocking version of moveTo(), meaning this function will return immediately after the robot has begun moving and will not wait until the motion is finished.

Parameters:
  • angle1 - Position to move the joint, in degrees
  • angle2 - Position to move the joint, in degrees
  • angle3 - Position to move the joint, in degrees
Overrides: mobot.Mobot.moveToNB
(inherited documentation)

reboot(self)

source code 

Reboot the connect robot. Note that communications with the robot will not succeed while the robot is booting back up.

recordAnglesBegin(self, delay=0.05)

source code 

Begin recording joint angles.

Parameters:
  • delay (number) - The number of seconds to delay between joint angles readings.
Overrides: mobot.Mobot.recordAnglesBegin

recordAnglesEnd(self)

source code 

End recording angles and return a list consisting of [time_values, joint1angles, joint2angles, joint3angles]

Overrides: mobot.Mobot.recordAnglesEnd

recordAnglesPlot(self)

source code 
Overrides: mobot.Mobot.recordAnglesPlot

setAcceleration(self, accel)

source code 

Set the acceleration of all joints. Each joint motion will begin with this acceleration after calling this function. Set the acceleration to 0 to disable this feature.

startJointAcceleration(self, joint, accel, timeout=0)

source code 

Make a robot's joint start accelerating forwards (positive accel value) or backwards.

Parameters:
  • joint (number)
  • accel (float, degrees/s/s)
  • timeout (float, number of seconds. After this number of seconds, accel for the joint will be set to 0.)

setBreakoutAnalogPin(self, pin, value)

source code 

Set an analog output pin (PWM) to a value between 0-255. This can be used to set the power of a motor, dim a LED, or more.

Parameters:
  • pin (integer from 0-7) - The pin parameter must be a pin the supports analog output. These pins are indicated by a tilde (~) symbol next to the pin number printed on the breakout board.
  • value (integer from 0-255) - The amount to power the pin: 0 is equivalent to no power, 255 is maximum power.

setBreakoutAnalogRef(self, ref)

source code 

Set the reference voltage of an analog input pin.

Parameters:
  • ref (integer from 0-7) - Valid values are barobo.AREF_DEFAULT, barobo.AREF_INTERNAL, barobo.AREF_INTERNAL1V1, barobo.AREF_INTERNAL2V56, and barobo.AREF_EXTERNAL.

setBreakoutDigitalPin(self, pin, value)

source code 

Set a digital I/O pin to either a high or low value. The pin will be set high if the parameter 'value' is non-zero, or set to ground otherwise.

setBreakoutPinMode(self, pin, mode)

source code 

Set the mode of a digital I/O pin on the breakout board. Valid modes are barobo.PINMODE_INPUT, barobo.PINMODE_OUTPUT, and barobo.PINMODE_INPUTPULLUP.

setBuzzerFrequency(self, freq)

source code 

Set the buzzer to begin playing a tone.

Parameters:
  • freq (number in Hz) - The frequency in Hertz (Hz) for the buzzer to play. Set to zero to turn the buzzer off.

setAccelEventThreshold(self, g_force)

source code 

Set the minimum change in g-force required for the robot to report an acceleration event.

See also: enableAccelEventCallback()

Parameters:
  • g_force (floating point number) - The acceleration in standard earth gravity "G's".

setJointEventThreshold(self, joint, angle)

source code 

Set the minimum amount the joint must move before a joint motion event is reported.

Also see enableJointEventCallback()

Parameters:
  • angle (floating point number) - An angle in degrees.

setJointSpeeds(self, speed1, speed2, speed3)

source code 

Set all three motor speed simultaneously. Parameters in degrees/second.

Overrides: mobot.Mobot.setJointSpeeds
(inherited documentation)

setLEDColor(self, r, g, b)

source code 

Set the LED color

Parameters:
  • r (number [0, 255])
  • b (number [0, 255])
  • g (number [0, 255])

setMotorPowers(self, power1, power2, power3)

source code 
Overrides: mobot.Mobot.setMotorPowers

setMovementState(self, state1, state2, state3, time=-1)

source code 

Set the movement state for all three motors.

Parameters:
  • state1 - This parameter may take the following values:
    • ROBOT_NEUTRAL: Makes the joint relax
    • ROBOT_FORWARD: Rotates the joint to move the robot in the "forward" direction, if the robot has wheels.
    • ROBOT_BACKWARD: Same as above but backwards
    • ROBOT_HOLD: Hold the joint at its current position
    • ROBOT_POSITIVE: Rotates the joint in the "positive" direction, according to the right-hand-rule.
    • ROBOT_NEGATIVE: Same as above but in the negative direction.
Overrides: mobot.Mobot.setMovementState
(inherited documentation)

smoothMoveToNB(self, joint, accel0, accelf, vmax, angle)

source code 

Move a joint to a desired position with a specified amount of starting and stopping acceleration.

Parameters:
  • joint (number) - The joint to move
  • accel0 (number) - The starting acceleration, in deg/sec/sec
  • accelf (number) - The stopping deceleration, in deg/sec/sec
  • vmax (number) - The maximum velocity for the joint during the motion, in deg/sec
  • angle (number) - The absolute angle to move the joint to, in degrees

twiRecv(self, addr, size)

source code 

Receive data from a TWI device. See twiSend() for more details.

Parameters:
  • addr - The TWI address to send data to.
Returns: bytearray

twiSend(self, addr, data)

source code 

Send data onto the Two-Wire Interface (TWI) (aka I2c) of the Linkbot. Many Linkbot peripherals are located on the TWI bus, including the accelerometer, breakout boards, and some sensors. The black phone-jack on top of the Linkbot exposes TWI pins where custom or prebuild peripherals may be attached.

Parameters:
  • addr - The TWI address to send data to.
  • data (iterable bytes) - The byte data to send to the peripheral

twiSendRecv(self, addr, senddata, recvsize)

source code 

Send and receive data from a TWI device attached to the Linkbot. See twiSend() and twiRecv() for more details.

Parameters:
  • addr - The TWI address to send data to.
  • senddata (iterable) - The byte data to send to the peripheral
  • recvsize (number) - Number of bytes expected from TWI device
Returns: bytearray