This describes the BrickPython API in detail.
This manages an arbitrary number of coroutines (implemented as generator functions), supporting invoking each every timeMillisBetweenWorkCalls, and detecting when each has completed.
It supports one special coroutine - the updatorCoroutine, which is invoked before and after all the other ones.
Adds one or more new motor control coroutines to be scheduled, answering the last coroutine to be added. Action coroutines are scheduled after Sensor coroutines
Adds one or more new sensor/program coroutines to be scheduled, answering the last one to be added. Sensor coroutines are scheduled before Action coroutines
Answers the time in floating point milliseconds since program start.
The most recent exception raised by a coroutine:
Coroutine that executes the given coroutines until all have completed or one throws an exception.
Coroutine that executes the given coroutines until the first completes, then stops the others and finishes.
Answers whether any of the given coroutines are still executing
Bases: Scheduler.Scheduler
This extends the Scheduler with functionality specific to the BrickPi
Motors and sensors are identified by their port names: motors are A to D; sensors 1 to 5.
Bases: BrickPiWrapper.BrickPiWrapper
Main application class using the Tk toolkit. Implements the regular calls required by the scheduler.
The default implementation creates a simple small window which exits when it receives the ‘Q’ key, but this can be changed by overriding the doInitialization() method.
Default initialization function with a simple window - override if you want something different
Bases: BrickPiWrapper.BrickPiWrapper
Main application class for command-line only apps. Doesn’t support user input.
An NXT motor connected to a BrickPi port.
A motor is identified by its idChar (‘A’ through ‘D’). It has a current position, relative to the basePosition it has set, and a current speed.
It also defines coroutines to position it using the standard PID servo motor algorithm, and to run at a specific speed.
Identifier for the motor
Coroutine to move the motor to position target, stopping after timeoutMillis if it hasnt reached it yet
Coroutine to move the motor to position target, using the PID algorithm with the current PIDSettings
Coroutine to run the motor at constant speed targetSpeedInClicksPerSecond
Settings for the PID servo algorithm. These may differ between motors. The default values are here.
Distances are in clicks, times in ms, motor power between -255 and +255, the sum of distance is added 20 times/sec. Speeds in clicks per second.
Distance in clicks from the target that we’ll accept as got there.
Speed that we’ll consider as close enough to zero.
Factor for motor power as function of distance - in power units per click distance.
Factor for motor power as a function of the integrated distance - in power units per (click-millisecond)
Factor for motor power as function of speed - in power units per (click per millisecond)
Represents a motor position at a specific time. Time in milliseconds, position in clicks.
Answers the speed in clicks per second coming to this point from other
Position at that time
Time created
Bases: Sensor.Sensor
Represents my NXT color sensor. The BrickPi_Python COLOR_FULL setting didn’t work for me at all - always has value 1. (though it did light up a red LED on the device).
But in RAW mode the sensor does seem to detect the difference between light and dark backgrounds.
value() is either LIGHT or DARK
Detected a dark background:
Detected a light background:
Sensor, representing a sensor attached to one of the BrickPi ports. Parameter port may be either a value (BrickPi.PORT_1) or an integer ‘1’-‘5’
There are class attributes with the types defined in the BrickPi module, e.g. Sensor.ULTRASONIC_CONT You can configure the sensor type for each port in the initialization parameters to BrickPiWrapper (and derived classes)
Used both as class in its own right, and as superclass for other sensor types.
Function that gets called with new value as parameter when the value changes - default, none.
Character identifying the sensor: 1 through 5.
The most recent raw value received from the BrickPi
The most recent value to return
Bases: Sensor.Sensor
TouchSensor, representing an NXT touch sensor attached to one of the BrickPi ports. Parameter port may be either a value (BrickPi.PORT_1) or an integer ‘1’-‘5’
value() is True if the button is pressed; False otherwise.
Bases: Sensor.Sensor
Represents an NXT ultrasonic sensor attached to one of the BrickPi ports. Parameter port may be either a value (BrickPi.PORT_1) or an integer ‘1’-‘5’
value() is distance to the nearest 5 cm, with a maximum of MAX_VALUE
The reading when no object is in sight:
Round readings to nearest centimeters.
How many readings to smooth over.