Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

Controller Class Reference

Handles the menu/command system... when it detects the EmergencyStopMC is activated, it'll kick into high priority. More...

#include <Controller.h>

Inheritance diagram for Controller:

Detailed Description

Handles the menu/command system... when it detects the EmergencyStopMC is activated, it'll kick into high priority.

Keeps track of a command stack. A Control can designate another sub-control, which will receive events until it finishes
Events will then be sent to the parent again.

The GUI uses the same commands as the user (makes it much easier to have only one parser). The commands are:

  • '!refresh' - redisplays the current control (handy on first connecting, or when other output has scrolled it off the screen)
  • '!reset' - return to the root control
  • '!next' - calls ControlBase::doNextItem() of the current control
  • '!prev' - calls ControlBase::doPrevItem() of the current control
  • '!select [item]' - calls ControlBase::doSelect() of the current control, unless item is specified, in which case it is searched for, starting at the root.
  • '!cancel' - calls current ControlBase::doCancel(), indicates control should cease activity and return to parent (e.g. "Back" button)
  • '!dump_stack' - requests a dump of the current stack of submenus (useful if the GUI (re)connects and thus current robot state is unknown)
  • '!post generator source type [duration]' - posts an event of your choosing; Generator should be an entry in EventBase::EventGeneratorNames (e.g. timerEGID) or numeric value; source should be a numeric value (unless generator is buttonEGID, in which case it could be an entry from buttonNames); type can be a numeric value, EventBase::EventTypeNames (e.g. activate), or EventBase::EventTypeAbbr (e.g. A); duration, if specified, gives the value for EventBase::duration
  • '!msg text' - sends text out as a TextMsgEvent; also note that any text entered on the console port while a GUI is also connected will also be sent as a TextMsgEvent, without needing the !input.
  • '!root text' - calls ControlBase::takeInput(text) on the root control
  • '!hello' - responds with 'hello\ncount\n' where count is the number of times '!hello' has been sent. Good for detecting first connection after boot vs. a reconnect.
  • '!hilight [n1 [n2 [...]]]' - hilights zero, one, or more items in the menu
  • '!input text' - calls ControlBase::takeInput(text) on the currently hilighted control(s)
  • '!set section.key=value' - will be sent to Config::setValue(section,key,value)
  • '!refreshsketchworld' - refresh world sketch
  • '!refreshsketchlocal' - refresh local sketch
  • '!refreshsketchcamera' - refresh camera sketch
  • any text not beginning with '!' - sent to ControlBase::takeInput() of the current control

In return, to send the menus to the GUI, the following messages are sent: (newlines are required where shown)

  • 'push' - signals a submenu has been activated
  • 'pop' - signals a submenu has been closed
  • 'refresh
    text:title
    int:numitems
    bool:hasSubmenus1
    bool:hilighted1
    text:item-title1
    text:item-description1
    ...
    bool:hasSubmenusnumitems
    bool:hilightednumitems
    text:item-titlenumitems
    text:item-descriptionnumitems' - refreshes the current menu
  • 'status
    text' - sets the status bar to text (until the next refresh)
  • 'load
    text:classname
    text:instancename
    int:port
    [arg1 [arg2 [...]]]' - tells the GUI to load the java class named classname, and have it connect to port, passing it the argument list. classname should contain a constructor of the form Classname(String host, int port, String args[]) the argument list is parsed as if it were on the console - unescaped or unquoted spaces will separate args into elements in the array
  • 'close
    text:instancename' - calls close() on an object previously created by a load message. The Java object is expected to contain a function void close().
  • 'stack_dump
    int:depth
    text:item-title1
    ...
    text:item-titledepth' - a listing of the current stack, first item is root, last item is current control
  • 'goodbye' - Indicates the connection is about to be closed purposefully, to differentiate from an accidental cut off.

bool types are expected to be numerical values, 0 for false, non-zero for true.

load and close are intended to allow pop-up windows for custom displays.

The upstream is the responsibility of the individual Controls, but the protocol is listed here to keep it together. When a control's state changes, it's that control's responsiblity to refresh the UI (LEDs, console, and GUI as appropriate). Thus, future extensions to the upstream protocol are between the control which will use it and the GUI. Future extensions to the downstream protocol would involve changing Controller and the GUI.

The Controller may connect to serr in the future to pop-up an alert anytime output to serr occurs.

Note that all state is maintained on the robot - even if the GUI is connected, you can still use the buttons to interact with the controller, and the GUI will update to reflect the changes. In HCI (Human Computer Interaction) parlance, this is the MVC, Model-View-Controller architecture, almost by necessity. (HCI happens to be my double major when I was an undergrad ;)

Also, the Controller is responsible for sending out TextMsgEvents from user input it receives - either a !msg command from the console or GUI, or any text at all which is received on the console if there is already a GUI connected.

These TextMsgEvents are always status events, and the duration field is always 0.

Definition at line 105 of file Controller.h.

List of all members.

Public Member Functions

 Controller ()
 Constructor.
 Controller (ControlBase *r)
 Constructor, sets a default root control.
virtual ~Controller ()
 Destructor.
virtual void doStart ()
 register for events and resets the cmdstack
virtual void doStop ()
 stop listening for events and resets the cmdstack
virtual void doEvent ()
 just for e-stop activation/deactivation
virtual bool trapEvent (const EventBase &e)
 passes an event to the top control
void reset ()
 will take the command stack back down to the root
void refresh ()
 refreshes the display, for times like sub-control dying, the previous control needs to reset it's display
void refreshSketchWorld ()
 refresh world sketches
void refreshSketchLocal ()
 refresh local sketches
void refreshSketchCamera ()
 refresh camera sketches
void push (ControlBase *c)
 puts a new control on top
void pop ()
 kills the top control, goes to previous
ControlBasetop ()
 returns the current control
ControllersetRoot (ControlBase *r)
 sets the root level control
ControllersetEStopID (MotionManager::MC_ID estopid)
 Sets the emergency stop MC to monitor for pausing.
virtual std::string getDescription () const
 Gives a short description of what this particular instantiation does (in case a more specific description is needed on an individual basis).

Static Public Member Functions

static std::string getClassDescription ()
 Gives a short description of what this class of behaviors does... you should override this (but don't have to).
static void loadGUI (const std::string &type, const std::string &name, unsigned int port)
 attempts to open a Java object on the desktop
static void loadGUI (const std::string &type, const std::string &name, unsigned int port, const std::vector< std::string > &args)
 attempts to open a Java object on the desktop
static void closeGUI (const std::string &name)
 calls close() on a Java object loaded with loadGUI() (on the desktop)
static int gui_comm_callback (char *buf, int bytes)
 called by wireless when there's new data from the GUI
static int console_callback (char *buf, int bytes)
 called by wireless when someone has entered new data on the tekkotsu console (NOT cin)

Static Public Attributes

static ControllertheOneController = NULL
 currently can't pull connection socket off of server socket, so only one Controller

static EventBase nextItem
 event masks used by processEvent()
static EventBase prevItem
 event masks used by processEvent()
static EventBase nextItemFast
 event masks used by processEvent()
static EventBase prevItemFast
 event masks used by processEvent()
static EventBase selectItem
 event masks used by processEvent()
static EventBase cancel
 event masks used by processEvent()

Protected Member Functions

void init ()
 calls initButtons with the appropriate button offsets for the host robot model
void initButtons (unsigned fastTime, unsigned downTime, unsigned nextB, unsigned prevB, unsigned nextFastB, unsigned prevFastB, unsigned selectB, unsigned cancelB)
 assigns appropriate values to the static event bases
void takeLine (const std::string &s)
 called with each line that's entered on the tekkotsu console or from the GUI
void dumpStack ()
 sends stack of currently active controls
bool select (ControlBase *item, const std::string &name)
 called with slots (options), a name to lookup; will select the named control
int setConfig (const std::string &str)
 sets a config value - some values may require additional processing (done here) to have the new values take effect
bool setNext (ControlBase *next)
 maintains top Control
void activate ()
 called when the estop switches on
void deactivate ()
 called when the estop switches off

bool chkCmdStack ()
 returns true if a valid control is available on the stack

Static Protected Member Functions

static bool calcPulse (unsigned int t, unsigned int last, unsigned int period)
 returns true when the current time and last time are in different periods

Protected Attributes

MotionManager::MC_ID display
 invalid_MC_ID if not active, otherwise id of high priority LEDs
MotionManager::MC_ID estop_id
 the EmergencyStopMC MC_ID that this Controller is monitoring
ControlBaseroot
 the base control, if cmdstack underflows, it will be reset to this
std::stack< ControlBase * > cmdstack
 the stack of the current control hierarchy
should never contain NULL entries
unsigned int last_time
 the time of the last event
unsigned int cur_time
 the time of the current event (do*() can check this instead of calling get_time() )
float nextEv_val
 the magnitude of the last next event (nextItem)
unsigned int nextEv_dur
 the duration of the last next event (nextItem)
float prevEv_val
 the magnitude of the last prev event (prevItem)
unsigned int prevEv_dur
 the duration of the last prev event (prevItem)
bool alreadyGotBoth
 if doReadStdIn() was already called, but the buttons are both still down
bool isControlling
 true if the Controller is currently active (in the activate()/deactivate() sense, not doStart()/doStop() sense - use isActive() for that...)
bool usesButtons
 true if ControllerGUI knows how to use the buttons for menu navigation, will intercept button presses
Socketgui_comm
 the socket to listen on for the gui

Private Member Functions

 Controller (const Controller &)
 shouldn't be called...
Controlleroperator= (const Controller &)
 shouldn't be called...

Constructor & Destructor Documentation

Controller::Controller (  ) 

Constructor.

Definition at line 107 of file Controller.h.

Controller::Controller ( ControlBase r  ) 

Constructor, sets a default root control.

Definition at line 108 of file Controller.h.

virtual Controller::~Controller (  )  [virtual]

Destructor.

Definition at line 109 of file Controller.h.

Controller::Controller ( const Controller  )  [private]

shouldn't be called...


Member Function Documentation

void Controller::activate (  )  [protected]

called when the estop switches on

causes the top control to activate, registers for button events

Definition at line 583 of file Controller.cc.

Referenced by doEvent(), and setEStopID().

static bool Controller::calcPulse ( unsigned int  t,
unsigned int  last,
unsigned int  period 
) [static, protected]

returns true when the current time and last time are in different periods

Definition at line 204 of file Controller.h.

Referenced by trapEvent().

bool Controller::chkCmdStack (  )  [protected]

returns true if a valid control is available on the stack

if the stack is empty, will push root if it's non-null

Definition at line 608 of file Controller.cc.

Referenced by activate(), push(), refresh(), takeLine(), and trapEvent().

void Controller::closeGUI ( const std::string &  name  )  [static]
int Controller::console_callback ( char *  buf,
int  bytes 
) [static]

called by wireless when someone has entered new data on the tekkotsu console (NOT cin)

Definition at line 269 of file Controller.cc.

void Controller::deactivate (  )  [protected]

called when the estop switches off

causes the top control to deactivate, stops listening for buttons

Definition at line 596 of file Controller.cc.

Referenced by doEvent(), and setEStopID().

void Controller::doEvent (  )  [virtual]

just for e-stop activation/deactivation

Reimplemented from BehaviorBase.

Definition at line 85 of file Controller.cc.

void Controller::doStart (  )  [virtual]

register for events and resets the cmdstack

Reimplemented from BehaviorBase.

Definition at line 40 of file Controller.cc.

void Controller::doStop (  )  [virtual]

stop listening for events and resets the cmdstack

Reimplemented from BehaviorBase.

Definition at line 63 of file Controller.cc.

void Controller::dumpStack (  )  [protected]

sends stack of currently active controls

Definition at line 539 of file Controller.cc.

Referenced by takeLine().

static std::string Controller::getClassDescription (  )  [static]

Gives a short description of what this class of behaviors does... you should override this (but don't have to).

If you do override this, also consider overriding getDescription() to return it

Reimplemented from BehaviorBase.

Definition at line 143 of file Controller.h.

Referenced by getDescription().

virtual std::string Controller::getDescription (  )  const [virtual]

Gives a short description of what this particular instantiation does (in case a more specific description is needed on an individual basis).

By default simply returns getName(), because any calls from a BehaviorBase function to getClassDescription() are going to call BehaviorBase::getClassDescription(), not ~YourSubClass~getClassDescription(), because static functions can't be virtual in C++ (doh!)

This means that getDescription called on a pointer to a BehaviorBase of unknown subtype would always return an empty string, which is pretty useless. So instead we return the name in this situation. If you want getDescription to return getClassDescription, you'll have to override it in your subclass to do so.

Reimplemented from BehaviorBase.

Definition at line 144 of file Controller.h.

int Controller::gui_comm_callback ( char *  buf,
int  bytes 
) [static]

called by wireless when there's new data from the GUI

Definition at line 238 of file Controller.cc.

Referenced by doStart().

void Controller::init (  )  [protected]

calls initButtons with the appropriate button offsets for the host robot model

Select which model is running and call initButtons with the appropriate button offsets This could be somewhat simplified by using capabilities.getButtonOffset(), (wouldn't need the ERS2xx case with essentially duplicated ERS210 and ERS220 cases), but this style has the advantage that the symbols are checked by the compiler so there's no chance of a typo in a button name going unnoticed.

Definition at line 316 of file Controller.cc.

Referenced by Controller().

void Controller::initButtons ( unsigned  fastTime,
unsigned  downTime,
unsigned  nextB,
unsigned  prevB,
unsigned  nextFastB,
unsigned  prevFastB,
unsigned  selectB,
unsigned  cancelB 
) [protected]

assigns appropriate values to the static event bases

Definition at line 357 of file Controller.cc.

Referenced by init().

void Controller::loadGUI ( const std::string &  type,
const std::string &  name,
unsigned int  port,
const std::vector< std::string > &  args 
) [static]

attempts to open a Java object on the desktop

Definition at line 212 of file Controller.cc.

static void Controller::loadGUI ( const std::string &  type,
const std::string &  name,
unsigned int  port 
) [static]
Controller& Controller::operator= ( const Controller  )  [private]

shouldn't be called...

void Controller::pop (  ) 

kills the top control, goes to previous

Definition at line 186 of file Controller.cc.

Referenced by reset(), and setNext().

void Controller::push ( ControlBase c  ) 

puts a new control on top

Definition at line 177 of file Controller.cc.

Referenced by chkCmdStack(), and setNext().

void Controller::refresh (  ) 

refreshes the display, for times like sub-control dying, the previous control needs to reset it's display

Definition at line 159 of file Controller.cc.

Referenced by pop(), reset(), setRoot(), and takeLine().

void Controller::refreshSketchCamera (  ) 

refresh camera sketches

Definition at line 173 of file Controller.cc.

void Controller::refreshSketchLocal (  ) 

refresh local sketches

Definition at line 169 of file Controller.cc.

void Controller::refreshSketchWorld (  ) 

refresh world sketches

Definition at line 165 of file Controller.cc.

void Controller::reset (  ) 

will take the command stack back down to the root

Definition at line 149 of file Controller.cc.

Referenced by doStart(), doStop(), setRoot(), and takeLine().

bool Controller::select ( ControlBase item,
const std::string &  name 
) [protected]

called with slots (options), a name to lookup; will select the named control

Definition at line 368 of file Controller.cc.

Referenced by takeLine().

int Controller::setConfig ( const std::string &  str  )  [protected]

sets a config value - some values may require additional processing (done here) to have the new values take effect

Definition at line 554 of file Controller.cc.

Referenced by takeLine().

Controller & Controller::setEStopID ( MotionManager::MC_ID  estopid  ) 

Sets the emergency stop MC to monitor for pausing.

Definition at line 200 of file Controller.cc.

bool Controller::setNext ( ControlBase next  )  [protected]

maintains top Control

Parameters:
next one of:

  • NULL: pop() cmdstack
  • cmdstack.top(): nothing
  • other address: push(next)
Returns:
true, all the time, for convenience from trapEvent()

Definition at line 575 of file Controller.cc.

Referenced by push(), select(), takeLine(), and trapEvent().

Controller & Controller::setRoot ( ControlBase r  ) 

sets the root level control

Definition at line 193 of file Controller.cc.

void Controller::takeLine ( const std::string &  s  )  [protected]

called with each line that's entered on the tekkotsu console or from the GUI

Definition at line 390 of file Controller.cc.

Referenced by console_callback(), and gui_comm_callback().

ControlBase* Controller::top (  ) 

returns the current control

Definition at line 137 of file Controller.h.

bool Controller::trapEvent ( const EventBase e  )  [virtual]

passes an event to the top control

Implements EventTrapper.

Definition at line 95 of file Controller.cc.


Member Data Documentation

bool Controller::alreadyGotBoth [protected]

if doReadStdIn() was already called, but the buttons are both still down

Definition at line 219 of file Controller.h.

Referenced by trapEvent().

event masks used by processEvent()

Definition at line 121 of file Controller.h.

Referenced by initButtons(), and trapEvent().

std::stack< ControlBase* > Controller::cmdstack [protected]

the stack of the current control hierarchy
should never contain NULL entries

Definition at line 201 of file Controller.h.

Referenced by activate(), chkCmdStack(), deactivate(), dumpStack(), pop(), push(), refresh(), reset(), setNext(), takeLine(), top(), and trapEvent().

unsigned int Controller::cur_time [protected]

the time of the current event (do*() can check this instead of calling get_time() )

Definition at line 214 of file Controller.h.

Referenced by trapEvent().

invalid_MC_ID if not active, otherwise id of high priority LEDs

Definition at line 191 of file Controller.h.

Referenced by activate(), chkCmdStack(), deactivate(), doStart(), doStop(), and push().

the EmergencyStopMC MC_ID that this Controller is monitoring

Definition at line 194 of file Controller.h.

Referenced by setEStopID().

bool Controller::isControlling [protected]

true if the Controller is currently active (in the activate()/deactivate() sense, not doStart()/doStop() sense - use isActive() for that...)

Definition at line 220 of file Controller.h.

Referenced by activate(), deactivate(), doEvent(), doStart(), setEStopID(), and takeLine().

unsigned int Controller::last_time [protected]

the time of the last event

Definition at line 213 of file Controller.h.

Referenced by trapEvent().

unsigned int Controller::nextEv_dur [protected]

the duration of the last next event (nextItem)

Definition at line 216 of file Controller.h.

Referenced by trapEvent().

the magnitude of the last next event (nextItem)

Definition at line 215 of file Controller.h.

Referenced by trapEvent().

event masks used by processEvent()

Definition at line 118 of file Controller.h.

Referenced by initButtons(), and trapEvent().

unsigned int Controller::prevEv_dur [protected]

the duration of the last prev event (prevItem)

Definition at line 218 of file Controller.h.

Referenced by trapEvent().

the magnitude of the last prev event (prevItem)

Definition at line 217 of file Controller.h.

Referenced by trapEvent().

event masks used by processEvent()

Definition at line 119 of file Controller.h.

Referenced by initButtons(), and trapEvent().

the base control, if cmdstack underflows, it will be reset to this

Definition at line 197 of file Controller.h.

Referenced by chkCmdStack(), setRoot(), takeLine(), and ~Controller().

event masks used by processEvent()

Definition at line 120 of file Controller.h.

Referenced by initButtons(), and trapEvent().

currently can't pull connection socket off of server socket, so only one Controller

Definition at line 225 of file Controller.h.

Referenced by closeGUI(), console_callback(), doStart(), doStop(), dumpStack(), gui_comm_callback(), loadGUI(), pop(), push(), refreshSketchCamera(), refreshSketchLocal(), refreshSketchWorld(), takeLine(), and ~Controller().

bool Controller::usesButtons [protected]

true if ControllerGUI knows how to use the buttons for menu navigation, will intercept button presses

Definition at line 221 of file Controller.h.

Referenced by activate(), init(), initButtons(), and takeLine().


The documentation for this class was generated from the following files:

Tekkotsu v5.1CVS
Generated Mon May 9 04:59:06 2016 by Doxygen 1.6.3