Homepage Demos Overview Downloads Tutorials Reference
Credits

ControlBase Class Reference

#include <ControlBase.h>

Inheritance diagram for ControlBase:

Inheritance graph
[legend]
List of all members.

Detailed Description

Base class for all items in the Controller hierarchy.

These are similar to behaviors in that they can do processing and are told when to start and stop.

However, the important difference is that these have to follow a much tighter set of guidelines for a more refined purpose - user interface. Controls do not directly receive events - the Controller will process events for them and call the appropriate functions at the appropriate times. Controls are expected to fit into a heirarchical scheme, where each control (except the root) has a parent which created it, and may return its own children where appropriate.

This base class will do most of the work of maintain submenus for you, and will call appropriate virtual functions which you can override. Controls generally live in Behaviors/Controls/ as the Controller itself is a behavior, and these controls merely its tools.

The ControlBase pointers which are returned at various points are the responsibility of the creator. Controller will not delete them upon deactivation.

GUI Theory:
There are 3 levels to the user interface.

  1. Robot/Local: Uses the LEDs and sounds for immediate feedback. No external resources needed
  2. Text: Uses a console to display/request information.
  3. GUI: Uses a graphical interface on an external screen

Obviously, higher levels require more technological resources, which also means there's more to go wrong and debug. However, another important distinction between the first level and the others is that the first level does not require the user to lose direct contact with the robot. Requiring the user to move back and forth from robot to computer can be much more frustrating than decoding LED signals or press head buttons. There are safety issues when triggering behaviors remotely if the robot is out of immediate reach. But of course, having a GUI and text output is extremely valuable in terms of ease of use and efficiency.

So, the lesson is to try to support all 3 levels so that your interfaces will be robust and efficient in a variety of environments. You'll thank yourself when you're demoing on the road and you can't get wavelan up, or the guest machine you're supposed to use doesn't have Java, or whatever.

Todo:
ControlBase's should use ReferenceCounter so memory management is not an issue
See also:
Controller, NullControl

Definition at line 57 of file ControlBase.h.

Public Member Functions

 ControlBase ()
 Contructor.

 ControlBase (const std::string &n)
 Contructor, initializes with a name.

 ControlBase (const std::string &n, const std::string &d)
 Contructor, initializes with a name.

virtual ~ControlBase ()
 Destructor.

virtual ControlBasesetName (const std::string &n)
 sets the name of the control

virtual std::string getName () const
 returns the name of the control

virtual ControlBasesetDescription (const std::string d)
 sets the description of the control

virtual std::string getDescription () const
 returns a short description of what the control does

const std::vector< ControlBase * > & getSlots () const
 returns the vector of controls

std::string getSlotName (unsigned int i) const
 returns the string that will appear in slot i

unsigned int slotsSize () const
 returns the number of options available

void setSlot (unsigned int i, ControlBase *o)
 sets i'th element of ::options to o

void pushSlot (ControlBase *o)
 sets next unused element of ::options to o

void clearSlots ()
 deletes each slot item and clears the slots

virtual const std::vector<
unsigned int > & 
getHilights () const
 returns a vector of the indicies of hilighted slots

virtual void setHilights (const std::vector< unsigned int > &hi)
 sets the hilighted slots

virtual void hilightFirst ()
 sets the hilight to the first non-null slot

virtual MotionManager::MC_ID getDisplay ()
 returns display being used

virtual ControlBasesetDisplay (MotionManager::MC_ID d)
 sets display to use

Controller Functions
You probably want to override some of these, call the ControlBase functions from your code if you want default sound effects (or look in Config::controller_config).

virtual ControlBaseactivate (MotionManager::MC_ID disp_id, Socket *gui)
 Called when the control is activated (or the control system is reactivating).

virtual void pause ()
 called when a control is being overriden by a child, or the control system is deactivating (e-stop being turned off)

virtual void refresh ()
 called when the child has died and this control should refresh its display, or some other event (such as the user pressing the refresh button) has happened to cause a refresh to be needed

virtual void deactivate ()
 called when this control is being popped from the control stack

virtual ControlBasedoSelect ()
 when the user has trigger an "open selection" - default is to return the hilighted control

virtual ControlBasedoNextItem ()
 when the user wants to increment the control - default is to return the first non-null slot after the last hilight

virtual ControlBasedoPrevItem ()
 when the user wants to decrement the control - default is to return the last non-null slot before the first hilight

virtual ControlBasedoCancel ()
 when the user wants to cancel - you should almost always return NULL now unless you need to confirm something (e.g. "Save changes?")

virtual ControlBasedoReadStdIn (const std::string &prompt=std::string())
 prompt the user for text input on the current input device (cin, tekkotsu console (sout), or GUI)

virtual ControlBasetakeInput (const std::string &msg)
 called when the user has supplied a text string (may not have been prompted by doReadStdIn()!)

virtual bool validInput (const std::string &msg)
 may be called before takeInput to verify this Control can make sense of msg


Protected Member Functions

virtual void clearMenu ()
 clears the display (if use_VT100 is on)

float hilightsAvg () const
 returns the average of the hilighted indicies - used to know to play the "next" sound, or the "prev" sound when the hilight changes


Protected Attributes

std::string name
 the name of this control

std::string description
 the description of this control

std::vector< unsigned int > hilights
 keep sorted - index(es) of current selection - can have multiple if using GUI

std::vector< ControlBase * > options
 vector of controls to select from

bool doRewrite
 toggles using VT100 codes to reposition the cursor at the beginning of the menu

MotionManager::MC_ID display_id
 LedMC to use for displaying selection.

Socketgui_comm
 socket to communicate with the GUI, if it is connected


Private Member Functions

 ControlBase (const ControlBase &)
 you can override, but don't call this...

ControlBaseoperator= (const ControlBase &)
 you can override, but don't call this...


Constructor & Destructor Documentation

ControlBase::ControlBase  )  [inline]
 

Contructor.

Definition at line 60 of file ControlBase.h.

Referenced by EventLogger::EventLogger(), PostureEditor::PostureEditor(), FileBrowserControl::rebuildmenu(), SensorObserverControl::SensorObserverControl(), and WalkCalibration::WalkCalibration().

ControlBase::ControlBase const std::string &  n  )  [inline]
 

Contructor, initializes with a name.

Definition at line 61 of file ControlBase.h.

ControlBase::ControlBase const std::string &  n,
const std::string &  d
[inline]
 

Contructor, initializes with a name.

Definition at line 62 of file ControlBase.h.

virtual ControlBase::~ControlBase  )  [inline, virtual]
 

Destructor.

Definition at line 65 of file ControlBase.h.

ControlBase::ControlBase const ControlBase  )  [private]
 

you can override, but don't call this...


Member Function Documentation

ControlBase * ControlBase::activate MotionManager::MC_ID  disp_id,
Socket gui
[virtual]
 

Called when the control is activated (or the control system is reactivating).

Takes the id number of a LedMC which the control should use, maintained by Controller. Controls share the display which is passed, and may use the socket gui to communicate with the GUI controller, if it is connected.

Returns:
a ControlBase pointer. Return:
  • this if the control should stay active (if it's not a one-shot command)
  • NULL to return to parent
  • other address to spawn a child control

Reimplemented in BatteryCheckControl, BehaviorActivatorControl, BehaviorSwitchActivatorControl, BehaviorSwitchControlBase, FileBrowserControl, HelpControl, NullControl, PostureEditor, ProfilerCheckControl, RebootControl, ShutdownControl, ToggleControl, ValueEditControl< T >, and WalkCalibration.

Definition at line 9 of file ControlBase.cc.

Referenced by WalkCalibration::activate(), ValueEditControl< T >::activate(), PostureEditor::activate(), FileBrowserControl::activate(), BehaviorSwitchControlBase::activate(), and BatteryCheckControl::activate().

void ControlBase::clearMenu  )  [protected, virtual]
 

clears the display (if use_VT100 is on)

Definition at line 391 of file ControlBase.cc.

Referenced by deactivate(), doSelect(), refresh(), and takeInput().

void ControlBase::clearSlots  ) 
 

deletes each slot item and clears the slots

Definition at line 358 of file ControlBase.cc.

Referenced by FileBrowserControl::rebuildmenu(), WalkCalibration::setupChoose(), WalkCalibration::setupMoving(), WalkCalibration::setupReading1(), WalkCalibration::setupReading2(), WalkCalibration::setupReady(), WalkCalibration::setupRoot(), ~ControlBase(), and FreeMemReportControl::~FreeMemReportControl().

void ControlBase::deactivate  )  [virtual]
 

called when this control is being popped from the control stack

Reimplemented in BatteryCheckControl, LoadPostureControl, PostureEditor, and WalkCalibration.

Definition at line 89 of file ControlBase.cc.

Referenced by WalkCalibration::deactivate(), and PostureEditor::deactivate().

ControlBase * ControlBase::doCancel  )  [virtual]
 

when the user wants to cancel - you should almost always return NULL now unless you need to confirm something (e.g. "Save changes?")

Definition at line 180 of file ControlBase.cc.

ControlBase * ControlBase::doNextItem  )  [virtual]
 

when the user wants to increment the control - default is to return the first non-null slot after the last hilight

Reimplemented in NullControl, and ValueEditControl< T >.

Definition at line 144 of file ControlBase.cc.

ControlBase * ControlBase::doPrevItem  )  [virtual]
 

when the user wants to decrement the control - default is to return the last non-null slot before the first hilight

Reimplemented in NullControl, and ValueEditControl< T >.

Definition at line 162 of file ControlBase.cc.

ControlBase * ControlBase::doReadStdIn const std::string &  prompt = std::string()  )  [virtual]
 

prompt the user for text input on the current input device (cin, tekkotsu console (sout), or GUI)

Reimplemented in NullControl, and StringInputControl.

Definition at line 186 of file ControlBase.cc.

Referenced by StringInputControl::doReadStdIn(), WalkCalibration::processEvent(), and WalkCalibration::takeInput().

ControlBase * ControlBase::doSelect  )  [virtual]
 

when the user has trigger an "open selection" - default is to return the hilighted control

Reimplemented in BatteryCheckControl, EventLogger, FileBrowserControl, MCValueEditControl< T >, NullControl, PostureEditor, RebootControl, SensorObserverControl, ShutdownControl, ToggleControl, ValueEditControl< T >, and WalkCalibration.

Definition at line 103 of file ControlBase.cc.

Referenced by WalkCalibration::doSelect(), PostureEditor::doSelect(), FileBrowserControl::doSelect(), and takeInput().

virtual std::string ControlBase::getDescription  )  const [inline, virtual]
 

returns a short description of what the control does

Reimplemented in BehaviorSwitchActivatorControl, BehaviorSwitchControlBase, and BehaviorSwitchControl< B, Al >.

Definition at line 95 of file ControlBase.h.

virtual MotionManager::MC_ID ControlBase::getDisplay  )  [inline, virtual]
 

returns display being used

Definition at line 108 of file ControlBase.h.

virtual const std::vector<unsigned int>& ControlBase::getHilights  )  const [inline, virtual]
 

returns a vector of the indicies of hilighted slots

Definition at line 104 of file ControlBase.h.

virtual std::string ControlBase::getName  )  const [inline, virtual]
 

returns the name of the control

Reimplemented in BehaviorSwitchActivatorControl, BehaviorSwitchControlBase, BehaviorSwitchControl< B, Al >, FreeMemReportControl, and ValueEditControl< T >.

Definition at line 92 of file ControlBase.h.

Referenced by SensorObserverControl::checkLogFile(), EventLogger::checkLogFile(), StringInputControl::doReadStdIn(), FileBrowserControl::doSelect(), ValueEditControl< T >::getName(), FreeMemReportControl::getName(), BehaviorSwitchControl< B, Al >::getName(), refresh(), and BatteryCheckControl::refresh().

std::string ControlBase::getSlotName unsigned int  i  )  const
 

returns the string that will appear in slot i

Definition at line 340 of file ControlBase.cc.

Referenced by refresh().

const std::vector<ControlBase*>& ControlBase::getSlots  )  const [inline]
 

returns the vector of controls

Definition at line 97 of file ControlBase.h.

Referenced by SensorObserverControl::processEvent(), and HelpControl::report().

void ControlBase::hilightFirst  )  [virtual]
 

sets the hilight to the first non-null slot

Reimplemented in WalkCalibration.

Definition at line 381 of file ControlBase.cc.

Referenced by activate(), and WalkCalibration::hilightFirst().

float ControlBase::hilightsAvg  )  const [protected]
 

returns the average of the hilighted indicies - used to know to play the "next" sound, or the "prev" sound when the hilight changes

Definition at line 398 of file ControlBase.cc.

Referenced by setHilights().

ControlBase& ControlBase::operator= const ControlBase  )  [private]
 

you can override, but don't call this...

Referenced by ValueSetControl< T >::operator=(), and ValueEditControl< T >::operator=().

void ControlBase::pause  )  [virtual]
 

called when a control is being overriden by a child, or the control system is deactivating (e-stop being turned off)

Reimplemented in BatteryCheckControl, and ValueEditControl< T >.

Definition at line 17 of file ControlBase.cc.

Referenced by ValueEditControl< T >::pause().

void ControlBase::pushSlot ControlBase o  ) 
 

sets next unused element of ::options to o

Definition at line 354 of file ControlBase.cc.

Referenced by EventLogger::EventLogger(), FreeMemReportControl::init(), FileBrowserControl::init(), PostureEditor::PostureEditor(), FileBrowserControl::rebuildmenu(), SensorObserverControl::SensorObserverControl(), WalkCalibration::setupChoose(), WalkCalibration::setupClear(), WalkCalibration::setupMoving(), WalkCalibration::setupReading1(), WalkCalibration::setupReading2(), WalkCalibration::setupReady(), WalkCalibration::setupRoot(), and WalkCalibration::WalkCalibration().

void ControlBase::refresh  )  [virtual]
 

called when the child has died and this control should refresh its display, or some other event (such as the user pressing the refresh button) has happened to cause a refresh to be needed

Reimplemented in BatteryCheckControl, EventLogger, FreeMemReportControl, PostureEditor, SensorObserverControl, StringInputControl, ValueEditControl< T >, and WalkCalibration.

Definition at line 23 of file ControlBase.cc.

Referenced by activate(), doNextItem(), doPrevItem(), FileBrowserControl::doSelect(), WalkCalibration::refresh(), StringInputControl::refresh(), SensorObserverControl::refresh(), PostureEditor::refresh(), FreeMemReportControl::refresh(), EventLogger::refresh(), setHilights(), and takeInput().

virtual ControlBase& ControlBase::setDescription const std::string  d  )  [inline, virtual]
 

sets the description of the control

Definition at line 94 of file ControlBase.h.

virtual ControlBase& ControlBase::setDisplay MotionManager::MC_ID  d  )  [inline, virtual]
 

sets display to use

Definition at line 109 of file ControlBase.h.

void ControlBase::setHilights const std::vector< unsigned int > &  hi  )  [virtual]
 

sets the hilighted slots

Reimplemented in WalkCalibration.

Definition at line 365 of file ControlBase.cc.

Referenced by WalkCalibration::hilightFirst(), and WalkCalibration::setHilights().

virtual ControlBase& ControlBase::setName const std::string &  n  )  [inline, virtual]
 

sets the name of the control

Reimplemented in ToggleControl.

Definition at line 91 of file ControlBase.h.

Referenced by SensorObserverControl::checkLogFile(), EventLogger::checkLogFile(), WalkCalibration::setupClear(), and WalkCalibration::setupRoot().

void ControlBase::setSlot unsigned int  i,
ControlBase o
 

sets i'th element of ::options to o

Definition at line 348 of file ControlBase.cc.

unsigned int ControlBase::slotsSize  )  const [inline]
 

returns the number of options available

Definition at line 99 of file ControlBase.h.

Referenced by BehaviorSwitchControlBase::activate().

ControlBase * ControlBase::takeInput const std::string &  msg  )  [virtual]
 

called when the user has supplied a text string (may not have been prompted by doReadStdIn()!)

Reimplemented in FileBrowserControl, NullControl, SavePostureControl, SaveWalkControl, StringInputControl, ValueEditControl< T >, and WalkCalibration.

Definition at line 215 of file ControlBase.cc.

Referenced by doReadStdIn(), WalkCalibration::takeInput(), FileBrowserControl::takeInput(), and Controller::takeLine().

bool ControlBase::validInput const std::string &  msg  )  [virtual]
 

may be called before takeInput to verify this Control can make sense of msg

Definition at line 335 of file ControlBase.cc.


Member Data Documentation

std::string ControlBase::description [protected]
 

the description of this control

Definition at line 120 of file ControlBase.h.

Referenced by ControlBase(), getDescription(), HelpControl::HelpControl(), and setDescription().

MotionManager::MC_ID ControlBase::display_id [protected]
 

LedMC to use for displaying selection.

Definition at line 127 of file ControlBase.h.

Referenced by activate(), ControlBase(), deactivate(), BatteryCheckControl::deactivate(), doReadStdIn(), doSelect(), getDisplay(), BatteryCheckControl::pause(), refresh(), BatteryCheckControl::report(), and setDisplay().

bool ControlBase::doRewrite [protected]
 

toggles using VT100 codes to reposition the cursor at the beginning of the menu

we don't always want to do this, any time someone else might have written to the display we set this to false so we don't overwrite it.

Definition at line 123 of file ControlBase.h.

Referenced by ControlBase(), deactivate(), doSelect(), pause(), refresh(), DumpFileControl::selectedFile(), and takeInput().

Socket* ControlBase::gui_comm [protected]
 

socket to communicate with the GUI, if it is connected

Definition at line 128 of file ControlBase.h.

Referenced by activate(), ControlBase(), StringInputControl::doReadStdIn(), doReadStdIn(), doSelect(), WalkCalibration::refresh(), ValueEditControl< T >::refresh(), refresh(), and BatteryCheckControl::refresh().

std::vector<unsigned int> ControlBase::hilights [protected]
 

keep sorted - index(es) of current selection - can have multiple if using GUI

Definition at line 121 of file ControlBase.h.

Referenced by clearSlots(), ControlBase(), deactivate(), doNextItem(), doPrevItem(), WalkCalibration::doSelect(), SensorObserverControl::doSelect(), PostureEditor::doSelect(), FileBrowserControl::doSelect(), EventLogger::doSelect(), doSelect(), getHilights(), hilightFirst(), hilightsAvg(), FileBrowserControl::rebuildmenu(), refresh(), setHilights(), WalkCalibration::setupChoose(), and takeInput().

std::string ControlBase::name [protected]
 

the name of this control

Definition at line 119 of file ControlBase.h.

Referenced by ControlBase(), getName(), ToggleControl::getStatusChar(), HelpControl::HelpControl(), SavePostureControl::SavePostureControl(), SaveWalkControl::SaveWalkControl(), ToggleControl::setName(), setName(), ToggleControl::setStatus(), and takeInput().

std::vector<ControlBase*> ControlBase::options [protected]
 

vector of controls to select from

Definition at line 122 of file ControlBase.h.

Referenced by EventLogger::checkLogFile(), clearMenu(), clearSlots(), ControlBase(), doNextItem(), doPrevItem(), WalkCalibration::doSelect(), SensorObserverControl::doSelect(), PostureEditor::doSelect(), FileBrowserControl::doSelect(), EventLogger::doSelect(), doSelect(), getSlotName(), getSlots(), WalkCalibration::hilightFirst(), hilightFirst(), EventLogger::processEvent(), pushSlot(), FileBrowserControl::rebuildmenu(), FreeMemReportControl::refresh(), refresh(), WalkCalibration::setHilights(), setHilights(), setSlot(), EventLogger::setStatus(), WalkCalibration::setupChoose(), WalkCalibration::setupClear(), slotsSize(), FileBrowserControl::takeInput(), takeInput(), validInput(), and WalkCalibration::~WalkCalibration().


The documentation for this class was generated from the following files:
Tekkotsu v2.0
Generated Wed Jan 21 03:23:06 2004 by Doxygen 1.3.4