home

Documentation RaspiBrick Robotics

Module imports:

from raspisim import *
from raspibrick import *

Method Action
Robot()

creates a robot instance (without motors) and starts an IP connection trial

Robot(ip)

same, but starts the connection using the given IP/Alias (string) without prompting

exit()

stops the robot, releases all resources and disconnects the IP link

getIPAdresses()()

returns all IP addresses of the robot

isEscapeHit()

True, if the robot push button (autonomous) or the keyboard ESC key (remote) was hit

isLeftHit()

True, if the keyboard Cursor-Left key was hit (only remote mode)

isRightHit() True, if the keyboard Cursor-Right key was hit (only remote mode)
isUpHit() True, if the keyboard Cursor-Up key was hit (only remote mode)
isDownHit() True, if the keyboard Cursor-Down key was hit (only remote mode)
playTone(frequency, duration)

plays a tone with given frequency (in Hz) and duration (in ms)

setSoundVolume(volume) sets the sound volume (0..100)
initSound(soundFile, volume) prepares the given wav or mp3 sound file for playing with given volume (0..100)
playSound() starts playing
stopSound() stops playing
fadeoutSound(time) decreases the volume slowly during the given time (in ms) and stops playing
pauseSound() temporarily stops playing at current position
resumeSound() resumes playing from stop position
rewindSound() resumes playing from the beginning
isSoundPlaying() True, if the sound is playing


Gear:

Gear()

creates a vehicle with 2 synchronized motors

backward() starts moving backward (non-blocking method)
backward(ms) moves backward for the given time interval (in ms) and stops (blocking method)
forward() starts moving forward (non-blocking method)
forward(ms) moves forward for the given time interval (in ms) and stops (blocking method)
left() starts moving left (non-blocking method)
left(ms) moves left for the given time interval (in ms) and stops (blocking method)
leftArc(radius) starts moving on left circle with given radius (in m) (non-blocking method)
leftArc(radius, ms) moves on left circle with given radius (in m) for the given time (in ms) (non-blocking method)
right() starts moving right (non-blocking method)
right(ms) moves right for the given time interval (in ms) and stops (blocking method)
rightArc(radius) starts moving on right circle with given radius (in m) (non-blocking method)
rightArc(radius, ms) moves on right circle with given radius (in m) for given time (in ms) (non-blocking method)
setSpeed(speed) sets the speed (0..100). Effects only the next movement call
stop() stops the vehicle


Motor:

Motor(MOTOR_LEFT) creates a left motor instance
Motor(MOTOR_RIGHT) creates a right motor instance
backward() starts the backward rotation
forward() starts the forward rotation
setSpeed(speed) sets the speed (0..100). Effects only the next movement call
stop() stops the motor


LightSensor:

LightSensor(id) creates an instance of a light sensor with given id (LS_FRONT_LEFT=0, LS_FRONT_RIGHT=1, LS_REAR_LEFT=2, LS_REAR_RIGHT=3)
LightSensor(id, bright = onBright, dark = onDark) same with registered event callbacks onBright(id, value), onDark(id, value) while crossing the trigger level
LightSensor(id, True) (simulation mode only) creates an instance of an upwards directed light sensor with given id (LS_FRONT_LEFT=0, LS_FRONT_RIGHT=1, LS_REAR_LEFT=2, LS_REAR_RIGHT=3)
LightSensor(id, True, bright = onBright, dark = onDark) same with registered event callbacks onBright(id, value), onDark(id, value) while crossing the trigger level
getValue() returns the measured light intensity (0..255)
setTriggerLevel(level) sets a new trigger level


UltrasonicSensor:

UltrasonicSensor() creates an instance of an ultrasonic sensor

UltrasonicSensor(far = onFar, near = onNear)

same with registered event callbacks onFar(value), onNear(value) while crossing the trigger level
getValue() returns the distance (in cm, -1 if error)
setTriggerLevel(level) sets a new trigger level


InfraredSensor:

InfraredSensor(id) creates an instance of a infrared sensor with given id (IR_CENTER = 0, IR_LEFT = 1, IR_RIGHT = 2, IR_LINE_LEFT = 3, IR_LINE_RIGHT = 4)
InfraredSensor(id, activated = onActivated, passivated = onPassivated same with registered event callbacks onActivated(id), onPassivated(id)
getValue() returns 1, if the sensor detects a light source; otherwise 0
setTriggerLevel(level) sets a new trigger level


Camera:

Camera() creates an instance of a Raspberry Pi camera
captureJPEG(width, height) takes a camera snapshot with given pixel resolution and retuns the image as string in JPEG format
saveData(data, filename) writes the content of data as byte stream into the binary file (e.g. an image in JPEG format)
captureAndSave(width, height, filename) takes a camera snapshot with given pixel resolution and stores it in JPEG format in the Raspberry Pi Linux file system
setHorzPos(pos) positions the camera horizontally with the horizontal servo motor (approx. in degrees, zero to the forward direction)
captureAndTransfer(width, height) (only remote mode) takes a camera snapshot with given pixel resolution, transfers it to the remote device and returns it in JPEG format (as string)
readImage(jpeg) converts an image in JPEG format to a Bitmap used by GPanel
(from gpanel import *)


ServoMotor:

ServoMotor(id, home, inc) creates an instance of a servo motor connected to header S12 (id = 0), S13 (id = 1), S14 (id = 2), S15 (id = 3). home: PWM duty cycle for home position (0..4095), inc: duty/position factor. Moves the motor to the home position
setPos(pos) positions the motor relative to the home position (pos <>0)
setPosAbs(pos) positions the motor to given absolute position (PWM duty cycle 0..4995)
setHome() positions the motor at home position


Beeper:

Beeper() creates an instance of a beeper (active buzzer at given GPIO port and ground, observe the polarity)
Beeper(pin = 40) same, but attached at given port
turnOn() turns the beeper on
turnOff() turns the beeper off
start(onTime, offTime, count = 0, blocking = False) starts an on-off cycle with count number of periods (count = 0: endless) and given turn-on and turn-off times (in ms). When blocking = True, the call blocks until all cycles are played; otherwise returns after starting the cycle
stop() terminates the playing cycle
setOnTime(onTime) sets the turn-on time (in ms, also while playing)
setOffTime(offTime) sets the turn-off time (in ms, also while playing)
setOnOffTime(onTime, offTime) sets the turn-on and turn-off times (in ms, also while playing)
isBeeping() returns true, while playing
beep(count = 1) short beep count times (default: 1)


Led:

Led(id)

creates an instance of a LED pair with give id (LED_FRONT = 0, LED_LEFT = 1, LED_REAR = 2, LED_RIGHT = 3)

setColor(red, green, blue)

turns the LED pair on using the given RGB color (values 0..255)

setColor(colorStr) same, but X11-color string
startBlinker(onColorStr, offColorStr, onTime,offTime, count, blocking = False) starts blinker with onColorStr, offColorStr (X11-color strings) and onTime, offTime (in ms). count: number of periods (0: endless). Returns immediately, if blocking = False; otherwise blocking until blinking is finished
stopBlinker() stops blinker and turns the led off
isBlinkerAlive() True, if blinker is active
Led.setColorAll(red, green, blue) turns all 8 LEDs on using the given RGB color (values 0..255) (static method)
Led.setColorAll(colorStr) same, but X11-color string
Led.clearAll() turns all LEDs off (static method)


Display:

Display() creates an instance of the 7-segment display
clear() clears the display (and stops the display multiplexer)
isAvailable() returns True, the a display is installed; otherwise False
isBlinkerAlive()() returns True, if the blinker is active; otherwise False
isTickerAlive()() returns True, if the ticker is active; otherwise False
scrollToLeft() scrolls the text one step to the left
scrollToRight() scrolls the text one step to the right
setToStart() sets the scrollable text at the starting positions
showText(text, pos=0, dp=[0, 0, 0, 0]]

shows the given text. Optional: Position pos and list of decimal points (0: hidden, 1: shown)

showBlnker(text, dp=[0, 0, 0, 0], count=3, speed=1, blocking=False]

shows the blinking text. Options: list of decimal points (0: hidden, 1: shown), number of repetitions, blinking speed, blocking until the blinker has finished

showTicker(text, count=1, speed=2, blocking=False)

shows a running ticker text scrolling to the left until the last 4 characters are displayed. Options: number of repetitions, scroll speed, blocking until the ticker has finished

stopBlinker() stops a running blinker
stopTicker() stops a running ticker


OLED1306:

OLED1306() creates an instance of an alphanumeric OLED display with 128x64 pixels (based on SSD1306 chip) attached at the I2C port (using the address 0x3C)
OLED1306(filename) same with given background image (image format: PPM 128x64 B/W) (Only autonomous mode)
setBkImage(filename) sets the background image (image format: PPM 128x64 B/W). None: the background image is removed. (Only autonomous mode)
setFont(ttfFile, fontSize) takes the text font from given TTF font file. (Only autonomous mode)
setFontSize(fontSize) sets the font size (in pixel)
setText(text, lineNum, fontSize = None, indent = 0)

displays the given text at given line number (0, 1,...) with given font size. indent is the text indentation in pixel (default: 0)

println(text) appends the given text (including a line break) in the text buffer and shows the content. If needed, the text is scrolled upwards, so that the last line is visible
clear() clears the display and the content of the text buffer
setInverse(inverse = True) selects black pixels on white background
startBlinker(count = 3, offTime = 1000, onTime = 1000, blocking = False) starts an on-off cycle with count number of periods (count = 0: endless) and given turn-on and turn-off times (in ms). When blocking = True, the call blocks until all cycles are shown; otherwise returns after starting the cycle
stopBlinker() stops the blinking cycle
isBlinking() returns True, while the display is blinking


Tools:

delay(time) halts the program for the given time interval (in milliseconds)


(Simulation mode only:) RobotContext

setStartDirection(angle) sets the starting direction (0 to east, positive clockwise)
setStartPosition(x, y) sets the starting position (in pixels, zero at upper-left vertex)
showStatusBar(height) adds a status bar with given height at the bottom of the window
setStatusText(text) inserts text into the status bar (old text is erased)
useBackground(filename) inserts the given image into the background to be used by a light sensor
useObstacle(filename, x, y) inserts an obstacle at given position to be used by a the infrared sensor
useTarget(filename, mesh, x, y) inserts a target at given position to be used by the ultrasonic sensor
useTorch(power, x, y, z) inserts a draggable torch (spotlight) with given power at given location (z: height) (used by upwards directed light sensors)
useShadow(ulx, uly, lrx, lry) inserts a rectangular shadow at given upper left/lower right vertex (absorbs light from torches)

 

Complete documentation : RaspiPyLib (Python Doc)
  RaspiJLib (JavaDoc)
  RaspiSim (JavaDoc, simulation mode)
   

RaspiBrick Firmware: State selection and LED/display information

State

Switch on

Search Access Point (AP)

AP found

AP not found
 

Ready

BrickGate server is running and waits for a client

BrickGate server connection established

Display
(if installed)

empty

AP--

Ticker:
shows IP

Ticker:
#0-0-0-0

m-n
m: selected program id
n: number of programs

HOLd

Conn for a short while, then empty (free for user program)

LEDs
(near pushbutton)

off

white

green

yellow

blue, blicking selected program id

green blinking

off
(free for user program)

Possible Actions

Wait

Cancel
by a click

Cancel
by a click

Cancel by a click

Click starts selected Python program, double-click selects current program, long press starts BrickGate server, long press with front IRS active starts shutdown, click with front IRS active shows IP, double-click with front IRS active deletes all programs

Click starts autonomous Java program, long press stops BrickGate server

free for user program

 

Processor Shutdown

State

IdLE

Shutdown "Are you sure?"

Shutdown confirmed

Shutdown canceled

Display

m-n

oooo

BYE.

IdLE

LEDs

blue

red

off, then faint red

blue

Possible Actions

Long press and front IR sensor activated

Confirm: Click and front IR sensor activated
Cancel: Click with non-activated sensor

Wait until Raspberry Pi's green LED stops blinking. Then switch-off

Normal use

 

RaspiBrick Overview

home