BeoChip Class Reference

BeoChip.H Interface to Brian Hudson's BeoChip device. More...

#include <Devices/BeoChip.H>

Inheritance diagram for BeoChip:
Inheritance graph
[legend]
Collaboration diagram for BeoChip:
Collaboration graph
[legend]

List of all members.

Public Member Functions

void run ()
 This is our main running thread - don't call directly.
bool writeByte (const byte val, const bool uselock=true)
 send a byte to the BeoChip
Constructors, destructors and debugging

 BeoChip (OptionManager &mgr, const std::string &descrName="BeoChip", const std::string &tagName="BeoChip")
 Default constructor. See ModelComponent.H.
 ~BeoChip ()
 Destructor.
void setListener (rutz::shared_ptr< BeoChipListener > &listener)
 Install a callback (listener) for BeoChip events.
bool echoRequest ()
 Send an echo request.
bool debugMode (const bool on)
 Turn debug mode on/off.
bool resetChip ()
 Reset the BeoChip.
LCD functions

bool lcdGotoXY (const int x=0, const int y=0)
 Go to given cursor position.
bool lcdGoto (const int i=0)
 Go to given cursor position.
bool lcdPrintf (const char *fmt,...) __attribute__((format(__printf__
 Print some text.
bool bool lcdPrintf (const int x, const int y, const char *fmt,...) __attribute__((format(__printf__
 Print some text starting at given cursor position.
bool bool bool lcdClear ()
 Clear LCD screen.
bool lcdScrollLeft (const int i=1)
 Scroll display left by i positions.
bool lcdScrollRight (const int i=1)
 Scroll display right by i positions.
bool lcdMoveCursorLeft (const int i=1)
 Move cursor left by i positions.
bool lcdMoveCursorRight (const int i=1)
 Move cursor right by i positions.
bool lcdCursorBlock ()
 Make cursor a blinking block.
bool lcdCursorUnderline ()
 Make cursor a blinking underline.
bool lcdCursorInvisible ()
 Make cursor invisible (not recommended).
bool lcdLoadFont (const int font)
 Load one of the pre-programmed custom fonts.
bool lcdLoadFont (const byte data[64])
 Load a new font from an array of 64 bytes.
bool lcdSetAnimation (const int anim=0)
 Select an LCD animation and start it.
bool lcdSendRaw (const byte val, const bool RS, const bool uselock=true)
 Send a raw byte to the LCD.
Servo control functions

bool shimServos (const byte shim)
 Shim the BeoChip's servo pulses.
void calibrateServo (const int servo, const byte neutralval, const byte minval, const byte maxval)
 Calibrate a servo.
bool setServo (const int servo, const float position)
 Moves servo # to given position in [-1.0 .. 1.0].
float getServo (const int servo) const
 Gets the current position of given servo.
bool setServoRaw (const int servo, const byte val)
 Sets servo number servo to value val.
byte getServoRaw (const int servo) const
 Gets the current raw position of given servo.
Pulse acquisition functions

bool capturePulse (const int whichone, const bool on)
 Turn pulse captures on/off.
void calibratePulse (const int whichone, const int neutralval, const int minval, const int maxval)
 Calibrate a pulse.
float getPulse (const int whichone)
 Get current pulse value, between [-1.0..1.0].
short int getPulseRaw (const int whichone)
 Get current pulse value, raw uncalibrated.
Analog acquisition functions

bool captureAnalog (const int whichone, const bool on)
 Turn A/D captures on/off.
void calibrateAnalog (const int whichone, const int neutralval, const int minval, const int maxval)
 Calibrate an A/D converter.
float getAnalog (const int whichone)
 Get current calibrated Analog value.
byte getAnalogRaw (const int whichone)
 Get current raw Analog value.
Keyboard acquisition functions

bool captureKeyboard (const bool on)
 Turn keyboard capture on/off.
bool debounceKeyboard (const bool on)
 Turn keyboard debouncing on/off.
int getKeyboard ()
 Get current Keyboard value.
Digital output function

bool setDigitalOut (const int outnum, const bool on)
 Turn a given digital output on/off.

Protected Member Functions

float rawToCalib (const int raw, const int zero, const int mini, const int maxi) const
 Convert from raw (int) to calibrated (-1.0..1.0) position.
int calibToRaw (const float calibrated, const int zero, const int mini, const int maxi, const int bits=8) const
 Convert from calibrated (-1.0..1.0) to raw (int) position.
void start1 ()
 open the port and get started
void stop2 ()
 close the port and get stopped

Protected Attributes

NModelParam< std::stringitsDevName
 name of our serial device
NModelParam< int > itsLCDrows
 number of rows of LCD screen (lines of text)
NModelParam< int > itsLCDcols
 number of columns of LCD screen
rutz::shared_ptr< NModelParam
< int > > * 
zeroS
 zero calibration value, for 0.0F (servo)
rutz::shared_ptr< NModelParam
< int > > * 
minS
 minimum raw value, for -1.0F (servo)
rutz::shared_ptr< NModelParam
< int > > * 
maxS
 maximum raw value, for 1.0F (servo)
byteservopos
 raw servo positions [0..255]
rutz::shared_ptr< NModelParam
< int > > * 
zeroP
 zero calibration value, for 0.0F (pulse)
rutz::shared_ptr< NModelParam
< int > > * 
minP
 minimum raw value, for -1.0F (pulse)
rutz::shared_ptr< NModelParam
< int > > * 
maxP
 maximum raw value, for 1.0F (pulse)
short int * pulseval
 raw pulse values (11bit int)
rutz::shared_ptr< NModelParam
< int > > * 
zeroA
 zero calibration value, for 0.0F (pulse)
rutz::shared_ptr< NModelParam
< int > > * 
minA
 minimum raw value, for -1.0F (servo)
rutz::shared_ptr< NModelParam
< int > > * 
maxA
 maximum raw value, for 1.0F (servo)
NModelParam< bool > itsUseRTSCTS
 Use RTS/CTS flow control.
byteadcval
 raw adc values [0..255]
byte keyboard
 our current keyboard state

Detailed Description

BeoChip.H Interface to Brian Hudson's BeoChip device.

Hardware interface Class. Contains interfaces to display to an LCD, read servo pulse values (2), set servo positions (8), get A/D conversion values (2), manipulate four digital outs, and finally, get some intput from 5 pushbuttons.

Definition at line 104 of file BeoChip.H.


Constructor & Destructor Documentation

BeoChip::BeoChip ( OptionManager mgr,
const std::string descrName = "BeoChip",
const std::string tagName = "BeoChip" 
)

Default constructor. See ModelComponent.H.

Definition at line 79 of file BeoChip.C.

References adcval, keyboard, maxA, maxP, maxS, minA, minP, minS, pulseval, rutz::shared_ptr< T >::reset(), servopos, zeroA, zeroP, and zeroS.

BeoChip::~BeoChip (  ) 

Destructor.

Definition at line 199 of file BeoChip.C.

References adcval, maxA, maxP, maxS, minA, minP, minS, pulseval, servopos, zeroA, zeroP, and zeroS.


Member Function Documentation

void BeoChip::calibrateAnalog ( const int  whichone,
const int  neutralval,
const int  minval,
const int  maxval 
)

Calibrate an A/D converter.

Calibration will be made so that getAnalog() returns 0.0F when raw value width is 'neutralval', returns -1.0F when the raw value is minval and returns 1.0F when the raw value is maxval.

Definition at line 566 of file BeoChip.C.

References ASSERT, maxA, minA, and zeroA.

void BeoChip::calibratePulse ( const int  whichone,
const int  neutralval,
const int  minval,
const int  maxval 
)

Calibrate a pulse.

Calibration will be made so that getPulse() returns 0.0F when raw pulse width is 'neutralval', returns -1.0F when the raw pulse value is minval and returns 1.0F when the raw pulse value is maxval.

Definition at line 528 of file BeoChip.C.

References ASSERT, maxP, minP, and zeroP.

void BeoChip::calibrateServo ( const int  servo,
const byte  neutralval,
const byte  minval,
const byte  maxval 
)

Calibrate a servo.

Calibration will be made so that setServo(servo, 0.0F) will send the value 'neutralval' to the servo, setServo(servo, -1.0F) will send minval and setServo(servo, 1.0F) will send maxval.

Definition at line 464 of file BeoChip.C.

References ASSERT, maxS, minS, and zeroS.

int BeoChip::calibToRaw ( const float  calibrated,
const int  zero,
const int  mini,
const int  maxi,
const int  bits = 8 
) const [protected]

Convert from calibrated (-1.0..1.0) to raw (int) position.

Definition at line 768 of file BeoChip.C.

Referenced by setServo().

bool BeoChip::captureAnalog ( const int  whichone,
const bool  on 
)

Turn A/D captures on/off.

Definition at line 557 of file BeoChip.C.

References ASSERT, and writeByte().

bool BeoChip::captureKeyboard ( const bool  on  ) 

Turn keyboard capture on/off.

Definition at line 595 of file BeoChip.C.

References writeByte().

bool BeoChip::capturePulse ( const int  whichone,
const bool  on 
)

Turn pulse captures on/off.

Definition at line 519 of file BeoChip.C.

References ASSERT, and writeByte().

bool BeoChip::debounceKeyboard ( const bool  on  ) 

Turn keyboard debouncing on/off.

Definition at line 602 of file BeoChip.C.

References writeByte().

bool BeoChip::debugMode ( const bool  on  ) 

Turn debug mode on/off.

When in debug mode, the BeoChip sends an EchoReply for each command it receives.

Definition at line 232 of file BeoChip.C.

References writeByte().

bool BeoChip::echoRequest (  ) 

Send an echo request.

The BeoChip should reply with an EchoReply event if it is alive

Definition at line 225 of file BeoChip.C.

References writeByte().

float BeoChip::getAnalog ( const int  whichone  ) 

Get current calibrated Analog value.

Definition at line 576 of file BeoChip.C.

References ASSERT, getAnalogRaw(), maxS, minS, rawToCalib(), and zeroS.

byte BeoChip::getAnalogRaw ( const int  whichone  ) 

Get current raw Analog value.

Definition at line 585 of file BeoChip.C.

References adcval, and ASSERT.

Referenced by getAnalog().

int BeoChip::getKeyboard (  ) 

Get current Keyboard value.

Definition at line 609 of file BeoChip.C.

References keyboard.

float BeoChip::getPulse ( const int  whichone  ) 

Get current pulse value, between [-1.0..1.0].

Definition at line 538 of file BeoChip.C.

References ASSERT, getPulseRaw(), maxP, minP, rawToCalib(), and zeroP.

short int BeoChip::getPulseRaw ( const int  whichone  ) 

Get current pulse value, raw uncalibrated.

Definition at line 547 of file BeoChip.C.

References ASSERT, and pulseval.

Referenced by getPulse().

float BeoChip::getServo ( const int  servo  )  const

Gets the current position of given servo.

Definition at line 483 of file BeoChip.C.

References ASSERT, getServoRaw(), maxS, minS, rawToCalib(), and zeroS.

byte BeoChip::getServoRaw ( const int  servo  )  const

Gets the current raw position of given servo.

Definition at line 512 of file BeoChip.C.

References ASSERT, and servopos.

Referenced by getServo().

bool BeoChip::lcdClear (  ) 

Clear LCD screen.

Definition at line 312 of file BeoChip.C.

References lcdSendRaw().

bool BeoChip::lcdCursorBlock (  ) 

Make cursor a blinking block.

Definition at line 370 of file BeoChip.C.

References lcdSendRaw().

bool BeoChip::lcdCursorInvisible (  ) 

Make cursor invisible (not recommended).

Definition at line 378 of file BeoChip.C.

References lcdSendRaw().

bool BeoChip::lcdCursorUnderline (  ) 

Make cursor a blinking underline.

Definition at line 374 of file BeoChip.C.

References lcdSendRaw().

bool BeoChip::lcdGoto ( const int  i = 0  ) 

Go to given cursor position.

Definition at line 268 of file BeoChip.C.

References lcdSendRaw().

Referenced by lcdGotoXY().

bool BeoChip::lcdGotoXY ( const int  x = 0,
const int  y = 0 
)

Go to given cursor position.

Definition at line 246 of file BeoChip.C.

References NModelParam< T >::getVal(), itsLCDcols, itsLCDrows, and lcdGoto().

Referenced by lcdPrintf().

bool BeoChip::lcdLoadFont ( const byte  data[64]  ) 

Load a new font from an array of 64 bytes.

Definition at line 395 of file BeoChip.C.

References lcdSendRaw().

bool BeoChip::lcdLoadFont ( const int  font  ) 

Load one of the pre-programmed custom fonts.

Valid font values are [0..7]. Font 0 is an all-blank font.

Definition at line 382 of file BeoChip.C.

References writeByte().

bool BeoChip::lcdMoveCursorLeft ( const int  i = 1  ) 

Move cursor left by i positions.

Definition at line 344 of file BeoChip.C.

References lcdSendRaw().

bool BeoChip::lcdMoveCursorRight ( const int  i = 1  ) 

Move cursor right by i positions.

Definition at line 357 of file BeoChip.C.

References lcdSendRaw().

bool BeoChip::lcdPrintf ( const int  x,
const int  y,
const char *  fmt,
  ... 
)

Print some text starting at given cursor position.

syntax is the same as printf(), plus the x, y coordinates. Returns true on success.

Definition at line 297 of file BeoChip.C.

References NModelParam< T >::getVal(), itsLCDcols, lcdGotoXY(), and lcdPrintf().

bool BeoChip::lcdPrintf ( const char *  fmt,
  ... 
)

Print some text.

syntax is the same as printf(). Returns true on success.

Definition at line 278 of file BeoChip.C.

References NModelParam< T >::getVal(), itsLCDcols, and lcdSendRaw().

Referenced by lcdPrintf().

bool BeoChip::lcdScrollLeft ( const int  i = 1  ) 

Scroll display left by i positions.

Definition at line 318 of file BeoChip.C.

References lcdSendRaw().

bool BeoChip::lcdScrollRight ( const int  i = 1  ) 

Scroll display right by i positions.

Definition at line 331 of file BeoChip.C.

References lcdSendRaw().

bool BeoChip::lcdSendRaw ( const byte  val,
const bool  RS,
const bool  uselock = true 
)
bool BeoChip::lcdSetAnimation ( const int  anim = 0  ) 

Select an LCD animation and start it.

Valid anim values are [0..7]. Anim 0 is no animation.

Definition at line 412 of file BeoChip.C.

References writeByte().

float BeoChip::rawToCalib ( const int  raw,
const int  zero,
const int  mini,
const int  maxi 
) const [protected]

Convert from raw (int) to calibrated (-1.0..1.0) position.

Definition at line 755 of file BeoChip.C.

Referenced by getAnalog(), getPulse(), getServo(), and run().

bool BeoChip::resetChip (  ) 

Reset the BeoChip.

Definition at line 239 of file BeoChip.C.

References writeByte().

void BeoChip::run (  ) 

This is our main running thread - don't call directly.

Should have been protected, but is not because of pthread hack.

Definition at line 644 of file BeoChip.C.

References adcval, rutz::shared_ptr< T >::get(), keyboard, maxA, maxP, minA, minP, MYLOGVERB, pulseval, rawToCalib(), zeroA, and zeroP.

bool BeoChip::setDigitalOut ( const int  outnum,
const bool  on 
)

Turn a given digital output on/off.

Valid range for outnum is [0..3]

Definition at line 618 of file BeoChip.C.

References ASSERT, and writeByte().

void BeoChip::setListener ( rutz::shared_ptr< BeoChipListener > &  listener  ) 

Install a callback (listener) for BeoChip events.

This callback will be called with the corresponding BeoChipEvenType each time an event is received from the BeoChip.

Definition at line 221 of file BeoChip.C.

bool BeoChip::setServo ( const int  servo,
const float  position 
)

Moves servo # to given position in [-1.0 .. 1.0].

Returns true on success, false if some serial error occurred.

Definition at line 474 of file BeoChip.C.

References ASSERT, calibToRaw(), maxS, minS, setServoRaw(), and zeroS.

bool BeoChip::setServoRaw ( const int  servo,
const byte  val 
)

Sets servo number servo to value val.

Definition at line 493 of file BeoChip.C.

References ASSERT, servopos, and writeByte().

Referenced by setServo().

bool BeoChip::shimServos ( const byte  shim  ) 

Shim the BeoChip's servo pulses.

Valid shim values are [0..7]. The default at bootup of the BeoChip is 4. Higher values will increase pulse length and lower values will decrease them. This may allow you to shim the pulses so as to maximally exploit the range of your servos.

Definition at line 451 of file BeoChip.C.

References writeByte().

void BeoChip::start1 (  )  [protected, virtual]

open the port and get started

Reimplemented from ModelComponent.

Definition at line 141 of file BeoChip.C.

References NModelParam< T >::getVal(), itsDevName, and itsUseRTSCTS.

void BeoChip::stop2 (  )  [protected, virtual]

close the port and get stopped

Reimplemented from ModelComponent.

Definition at line 186 of file BeoChip.C.

bool BeoChip::writeByte ( const byte  val,
const bool  uselock = true 
)

send a byte to the BeoChip

You should never have to use this, use the other functions instead. This function is made public just for testing the chip's robustness against a flood of random junk hitting it... See test-BeoChip.C

Definition at line 626 of file BeoChip.C.

References MYLOGVERB.

Referenced by captureAnalog(), captureKeyboard(), capturePulse(), debounceKeyboard(), debugMode(), echoRequest(), lcdLoadFont(), lcdSendRaw(), lcdSetAnimation(), resetChip(), setDigitalOut(), setServoRaw(), and shimServos().


Member Data Documentation

byte* BeoChip::adcval [protected]

raw adc values [0..255]

Definition at line 350 of file BeoChip.H.

Referenced by BeoChip(), getAnalogRaw(), run(), and ~BeoChip().

name of our serial device

Definition at line 330 of file BeoChip.H.

Referenced by start1().

NModelParam<int> BeoChip::itsLCDcols [protected]

number of columns of LCD screen

Definition at line 332 of file BeoChip.H.

Referenced by lcdGotoXY(), and lcdPrintf().

NModelParam<int> BeoChip::itsLCDrows [protected]

number of rows of LCD screen (lines of text)

Definition at line 331 of file BeoChip.H.

Referenced by lcdGotoXY().

Use RTS/CTS flow control.

Definition at line 348 of file BeoChip.H.

Referenced by start1().

byte BeoChip::keyboard [protected]

our current keyboard state

Definition at line 352 of file BeoChip.H.

Referenced by BeoChip(), getKeyboard(), and run().

maximum raw value, for 1.0F (servo)

Definition at line 346 of file BeoChip.H.

Referenced by BeoChip(), calibrateAnalog(), run(), and ~BeoChip().

maximum raw value, for 1.0F (pulse)

Definition at line 341 of file BeoChip.H.

Referenced by BeoChip(), calibratePulse(), getPulse(), run(), and ~BeoChip().

maximum raw value, for 1.0F (servo)

Definition at line 336 of file BeoChip.H.

Referenced by BeoChip(), calibrateServo(), getAnalog(), getServo(), setServo(), and ~BeoChip().

minimum raw value, for -1.0F (servo)

Definition at line 345 of file BeoChip.H.

Referenced by BeoChip(), calibrateAnalog(), run(), and ~BeoChip().

minimum raw value, for -1.0F (pulse)

Definition at line 340 of file BeoChip.H.

Referenced by BeoChip(), calibratePulse(), getPulse(), run(), and ~BeoChip().

minimum raw value, for -1.0F (servo)

Definition at line 335 of file BeoChip.H.

Referenced by BeoChip(), calibrateServo(), getAnalog(), getServo(), setServo(), and ~BeoChip().

short int* BeoChip::pulseval [protected]

raw pulse values (11bit int)

Definition at line 342 of file BeoChip.H.

Referenced by BeoChip(), getPulseRaw(), run(), and ~BeoChip().

byte* BeoChip::servopos [protected]

raw servo positions [0..255]

Definition at line 337 of file BeoChip.H.

Referenced by BeoChip(), getServoRaw(), setServoRaw(), and ~BeoChip().

zero calibration value, for 0.0F (pulse)

Definition at line 344 of file BeoChip.H.

Referenced by BeoChip(), calibrateAnalog(), run(), and ~BeoChip().

zero calibration value, for 0.0F (pulse)

Definition at line 339 of file BeoChip.H.

Referenced by BeoChip(), calibratePulse(), getPulse(), run(), and ~BeoChip().

zero calibration value, for 0.0F (servo)

Definition at line 334 of file BeoChip.H.

Referenced by BeoChip(), calibrateServo(), getAnalog(), getServo(), setServo(), and ~BeoChip().


The documentation for this class was generated from the following files:
Generated on Sun May 8 08:43:07 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3