Module Robot :: Class MyRobot
[hide private]
[frames] | no frames]

Class MyRobot

source code

object --+
         |
        MyRobot

Singleton class that represents a robot. Signature for the butten event callback: buttonEvent(int). (BUTTON_PRESSED, BUTTON_RELEASED, BUTTON_LONGPRESSED defined in ShareConstants.)

Instance Methods [hide private]
 
__init__(self, ipAddress="", buttonEvent=None)
Creates an instance of MyRobot and initalizes the GPIO.
source code
 
registerSensor(self, sensor) source code
 
exit(self)
Cleans-up and releases all resources.
source code
 
isButtonDown(self)
Checks if button is currently pressed.
source code
 
isButtonHit(self)
Checks, if the button was ever hit or hit since the last invocation.
source code
 
isEscapeHit(self)
Same as isButtonHit() for compatibility with remote mode.
source code
 
isEnterHit(self)
Empty method for compatibility with remote mode.
source code
 
isUpHit(self)
Empty method for compatibility with remote mode.
source code
 
isDownHit(self)
Empty method for compatibility with remote mode.
source code
 
isLeftHit(self)
Empty method for compatibility with remote mode.
source code
 
isRightHit(self)
Empty method for compatibility with remote mode.
source code
 
addButtonListener(self, listener, enableClick=False, doubleClickTime=SharedConstants.BUTTON_DOUBLECLICK_TIME)
Registers a listener function to get notifications when the pushbutton is pressed, released or long pressed.
source code
 
setButtonEnabled(self, enable)
Enables/disables the push button.
source code
 
addBatteryMonitor(self, listener)
There is a small processor on the PCB (an STM8S003F3P6) which handles the voltage monitoring, as well as trying to reduce the impact of direct light on the IR sensors.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Static Methods [hide private]
 
getVersion()
Returns: the module library version
source code
 
playTone(frequency, duration)
Plays a single sine tone with given frequency and duration.
source code
 
getIPAddresses()
Returns: List of all IP addresses of machine
source code
 
initSound(soundFile, volume)
Prepares the given wav or mp3 sound file for playing with given volume (0..100).
source code
 
closeSound()
Stops any playing sound and closes the sound channel.
source code
 
playSound()
Starts playing.
source code
 
fadeoutSound(time)
Decreases the volume slowly and stops playing.
source code
 
setSoundVolume(volume)
Sets the volume while the sound is playing.
source code
 
stopSound()
Stops playing sound.
source code
 
pauseSound()
Temporarily stops playing at current position.
source code
 
resumeSound()
Resumes playing from stop position.
source code
 
rewindSound()
Resumes playing from the beginning.
source code
 
isSoundPlaying()
Returns: True, if the sound is playing; otherwise False
source code
Class Variables [hide private]
  _myInstance = None
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, ipAddress="", buttonEvent=None)
(Constructor)

source code 

Creates an instance of MyRobot and initalizes the GPIO.

Parameters:
  • ipAddress, the, IP, address, (default - None for autonomous mode)
  • buttonEvent, the, callback, function, for, pushbutton, events, (default - None)
Overrides: object.__init__

isButtonDown(self)

source code 

Checks if button is currently pressed.

Returns:
True, if the button is actually pressed

isButtonHit(self)

source code 

Checks, if the button was ever hit or hit since the last invocation.

Returns:
True, if the button was hit; otherwise False

addButtonListener(self, listener, enableClick=False, doubleClickTime=SharedConstants.BUTTON_DOUBLECLICK_TIME)

source code 

Registers a listener function to get notifications when the pushbutton is pressed, released or long pressed. If enableClick = True, in addition click and double-click events are reported. The click event not immediately reported, but only if within the doubleClickTime no other click is gererated. The value are defined as ShareConstants.BUTTON_PRESSED, ShareConstants.BUTTON_LONGPRESSED, ShareConstants.BUTTON_RELEASED, ShareConstants.BUTTON_CLICKED, ShareConstants.BUTTON_DOUBLECLICKED. With enableClick = False and the button is long pressed and released the sequence is: BUTTON_PRESSED, BUTTON_LONGPRESSED, BUTTON_RELEASED. With enableClick = True the sequences are the following: click: BUTTON_PRESSED, BUTTON_RELEASED, BUTTON_CLICKED double-click: BUTTON_PRESSED, BUTTON_RELEASED, BUTTON_PRESSED, BUTTON_RELEASED, BUTTON_DOUBLECLICKED long pressed: BUTTON_PRESSED, BUTTON_LONGPRESSED, BUTTON_RELEASED

Parameters:
  • listener - the listener function (with boolean parameter event) to register.
  • enableClick - if True, the click/double-click is also registered (default: False)
  • doubleClickTime - the time (in seconds) to wait for a double click (default: set in SharedContants)

setButtonEnabled(self, enable)

source code 

Enables/disables the push button. The button is enabled, when the Robot is created.

Parameters:
  • enable - if True, the button is enabled; otherwise disabled

addBatteryMonitor(self, listener)

source code 

There is a small processor on the PCB (an STM8S003F3P6) which handles the voltage monitoring, as well as trying to reduce the impact of direct light on the IR sensors. It has 2 threshold voltages: At about 6.5V (3 consecutive readings) it flashes the red LED and disables the motor drivers. At about 6.2V it turns the red LED on permanently and sends a signal on GPIO24 pin 18 to the Pi. The software on the Pi can monitor this and shut down gracefully if required. If the voltage goes back above 7.0V then the system resets to Green LED and all enabled.

Registers a listener function to get notifications when battery voltage is getting low.

Parameters:
  • listener - the listener function (with no parameter) to register

getVersion()
Static Method

source code 
Returns:
the module library version

playTone(frequency, duration)
Static Method

source code 

Plays a single sine tone with given frequency and duration.

Parameters:
  • frequency - the frequency in Hz
  • duration - the duration in ms

getIPAddresses()
Static Method

source code 
Returns:
List of all IP addresses of machine

initSound(soundFile, volume)
Static Method

source code 

Prepares the given wav or mp3 sound file for playing with given volume (0..100). The sound sound channel is opened and a background noise is emitted.

Parameters:
  • soundFile - the sound file in the local file system
Returns:
True, if successful; False if the sound system is not available or the sound file cannot be loaded

fadeoutSound(time)
Static Method

source code 

Decreases the volume slowly and stops playing.

Parameters:
  • time - the fade out time in ms

setSoundVolume(volume)
Static Method

source code 

Sets the volume while the sound is playing.

Parameters:
  • volume - the sound volume (0..100)

isSoundPlaying()
Static Method

source code 
Returns:
True, if the sound is playing; otherwise False