Homepage Demos Overview Downloads Tutorials Reference
Credits
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages | Search

Controller Class Reference

#include <Controller.h>

Inheritance diagram for Controller:

Inheritance graph
[legend]
List of all members.

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:

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

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 ;)

Definition at line 81 of file Controller.h.

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 bool trapEvent (const EventBase &e)
 passes an event to the top control

virtual void processEvent (const EventBase &e)
 just for e-stop activation/deactivation

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 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 getName () const
 Identifies the behavior in menus and such.


Static Public Member Functions

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

void loadGUI (const std::string &type, const std::string &name, unsigned int port)
 attempts to open a Java object on the desktop

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

void closeGUI (const std::string &name)
 calls close() on a Java object loaded with loadGUI() (on the desktop)

int gui_comm_callback (char *buf, int bytes)
 called by wireless when there's new data from the GUI

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

EventBase nextItem
 event masks used by processEvent()

EventBase prevItem
 event masks used by processEvent()

EventBase nextItemFast
 event masks used by processEvent()

EventBase prevItemFast
 event masks used by processEvent()

EventBase selectItem
 event masks used by processEvent()

EventBase cancel
 event masks used by processEvent()


Protected Member Functions

void init ()
 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

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

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

std::string makeLower (const std::string &s)
 returns lower case version of s

std::string removePrefix (const std::string &str, const std::string &pre)
 returns str with pre removed - if pre is not fully matched, str is returned unchanged


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

Socketgui_comm
 the socket to listen on for the gui


Static Protected Attributes

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


Private Member Functions

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

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


Constructor & Destructor Documentation

Controller::Controller  )  [inline]
 

Constructor.

Definition at line 83 of file Controller.h.

References alreadyGotBoth, cmdstack, cur_time, display, estop_id, gui_comm, init(), last_time, nextEv_dur, nextEv_val, prevEv_dur, prevEv_val, root, SocketNS::SOCK_STREAM, and wireless.

Controller::Controller ControlBase r  )  [inline]
 

Constructor, sets a default root control.

Definition at line 84 of file Controller.h.

References alreadyGotBoth, cmdstack, cur_time, display, estop_id, gui_comm, init(), last_time, nextEv_dur, nextEv_val, prevEv_dur, prevEv_val, root, SocketNS::SOCK_STREAM, and wireless.

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

Destructor.

Definition at line 85 of file Controller.h.

References root.

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 314 of file Controller.cc.

References MotionManager::addMotion(), EventRouter::addTrapper(), EventBase::buttonEGID, chkCmdStack(), cmdstack, display, erouter, ERS210Info::FaceLEDMask, gui_comm, MotionManager::kEmergencyPriority, and motman.

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

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

Definition at line 166 of file Controller.h.

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 336 of file Controller.cc.

References cmdstack, display, gui_comm, push(), and root.

void Controller::closeGUI const std::string &  name  )  [static]
 

calls close() on a Java object loaded with loadGUI() (on the desktop)

Definition at line 175 of file Controller.cc.

References gui_comm, Socket::printf(), and theOneController.

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 203 of file Controller.cc.

References erouter, gui_comm, Wireless::isConnected(), EventRouter::postEvent(), Socket::sock, takeLine(), theOneController, and wireless.

void Controller::deactivate  )  [protected]
 

called when the estop switches off

causes the top control to deactivate, stops listening for buttons

Definition at line 326 of file Controller.cc.

References cmdstack, display, erouter, MotionManager::invalid_MC_ID, ERS210Info::LEDOffset, motman, ERS210Info::NumLEDs, MotionManager::removeMotion(), EventRouter::removeTrapper(), and MotionManager::setOutput().

void Controller::DoStart  )  [virtual]
 

register for events and resets the cmdstack

Reimplemented from BehaviorBase.

Definition at line 25 of file Controller.cc.

References EventRouter::addListener(), Config::controller_config::cancel_snd, config, Config::controller, BehaviorBase::DoStart(), erouter, EventBase::estopEGID, gui_comm, gui_comm_callback(), Config::controller_config::gui_port, Wireless::listen(), SoundManager::LoadFile(), Config::controller_config::next_snd, Config::controller_config::prev_snd, Config::controller_config::read_snd, reset(), Config::controller_config::select_snd, Wireless::setReceiver(), sndman, Socket::sock, theOneController, and wireless.

void Controller::DoStop  )  [virtual]
 

stop listening for events and resets the cmdstack

Reimplemented from BehaviorBase.

Definition at line 40 of file Controller.cc.

References Config::controller_config::cancel_snd, Wireless::close(), config, Config::controller, BehaviorBase::DoStop(), erouter, EventRouter::forgetListener(), gui_comm, Config::controller_config::next_snd, Config::controller_config::prev_snd, Config::controller_config::read_snd, SoundManager::ReleaseFile(), reset(), Config::controller_config::select_snd, sndman, theOneController, and wireless.

std::string Controller::getClassDescription  )  [inline, static]
 

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

Reimplemented from BehaviorBase.

Definition at line 117 of file Controller.h.

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

Identifies the behavior in menus and such.

Implements BehaviorBase.

Definition at line 116 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 179 of file Controller.cc.

References takeLine(), and theOneController.

void Controller::init  )  [protected]
 

assigns appropriate values to the static event bases

Definition at line 231 of file Controller.cc.

References EventBase::buttonEGID, cancel, EventBase::deactivateETID, WorldState::ERS210Mask, WorldState::ERS220Mask, nextItem, nextItemFast, prevItem, prevItemFast, WorldState::robotDesign, selectItem, state, and EventBase::statusETID.

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 159 of file Controller.cc.

References gui_comm, theOneController, and Socket::write().

void Controller::loadGUI const std::string &  type,
const std::string &  name,
unsigned int  port
[inline, static]
 

attempts to open a Java object on the desktop

Definition at line 121 of file Controller.h.

std::string Controller::makeLower const std::string &  s  )  [static, protected]
 

returns lower case version of s

Definition at line 350 of file Controller.cc.

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

shouldn't be called...

void Controller::pop  ) 
 

kills the top control, goes to previous

Definition at line 134 of file Controller.cc.

References cmdstack, and refresh().

void Controller::processEvent const EventBase e  )  [virtual]
 

just for e-stop activation/deactivation

Reimplemented from BehaviorBase.

Definition at line 101 of file Controller.cc.

References activate(), EventBase::activateETID, deactivate(), display, EventBase::getTypeID(), and MotionManager::invalid_MC_ID.

void Controller::push ControlBase c  ) 
 

puts a new control on top

Definition at line 126 of file Controller.cc.

References chkCmdStack(), cmdstack, display, gui_comm, 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 120 of file Controller.cc.

References chkCmdStack(), and cmdstack.

std::string Controller::removePrefix const std::string &  str,
const std::string &  pre
[static, protected]
 

returns str with pre removed - if pre is not fully matched, str is returned unchanged

Definition at line 359 of file Controller.cc.

void Controller::reset  ) 
 

will take the command stack back down to the root

Definition at line 111 of file Controller.cc.

References cmdstack, and pop().

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

Sets the emergency stop MC to monitor for pausing.

Definition at line 147 of file Controller.cc.

References activate(), deactivate(), display, estop_id, MotionManager::invalid_MC_ID, motman, and MotionManager::peekMotion().

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 306 of file Controller.cc.

References cmdstack, pop(), and push().

Controller & Controller::setRoot ControlBase r  ) 
 

sets the root level control

Definition at line 140 of file Controller.cc.

References refresh(), reset(), and root.

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 254 of file Controller.cc.

References cmdstack, erouter, EventRouter::postEvent(), refresh(), reset(), and setNext().

ControlBase* Controller::top  )  [inline]
 

returns the current control

Definition at line 110 of file Controller.h.

References cmdstack.

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

passes an event to the top control

Implements EventTrapper.

Definition at line 53 of file Controller.cc.

References alreadyGotBoth, calcPulse(), cancel, chkCmdStack(), cmdstack, cur_time, get_time(), EventBase::getDuration(), EventBase::getMagnitude(), EventBase::getTypeID(), last_time, nextEv_dur, nextEv_val, nextItem, nextItemFast, prevEv_dur, prevEv_val, prevItem, prevItemFast, EventBase::sameGenSource(), selectItem, and setNext().


Member Data Documentation

bool Controller::alreadyGotBoth [protected]
 

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

Definition at line 185 of file Controller.h.

EventBase Controller::cancel [static]
 

event masks used by processEvent()

Definition at line 22 of file Controller.cc.

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

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

Definition at line 163 of file Controller.h.

unsigned int Controller::cur_time [protected]
 

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

Definition at line 180 of file Controller.h.

MotionManager::MC_ID Controller::display [protected]
 

invalid_MC_ID if not active, otherwise id of high priority LEDs

Definition at line 153 of file Controller.h.

MotionManager::MC_ID Controller::estop_id [protected]
 

the EmergencyStopMC MC_ID that this Controller is monitoring

Definition at line 156 of file Controller.h.

Socket* Controller::gui_comm [protected]
 

the socket to listen on for the gui

Definition at line 187 of file Controller.h.

unsigned int Controller::last_time [protected]
 

the time of the last event

Definition at line 179 of file Controller.h.

unsigned int Controller::nextEv_dur [protected]
 

the duration of the last next event (::nextItem)

Definition at line 182 of file Controller.h.

float Controller::nextEv_val [protected]
 

the magnitude of the last next event (::nextItem)

Definition at line 181 of file Controller.h.

EventBase Controller::nextItem [static]
 

event masks used by processEvent()

Definition at line 17 of file Controller.cc.

EventBase Controller::nextItemFast [static]
 

event masks used by processEvent()

Definition at line 19 of file Controller.cc.

unsigned int Controller::prevEv_dur [protected]
 

the duration of the last prev event (::prevItem)

Definition at line 184 of file Controller.h.

float Controller::prevEv_val [protected]
 

the magnitude of the last prev event (::prevItem)

Definition at line 183 of file Controller.h.

EventBase Controller::prevItem [static]
 

event masks used by processEvent()

Definition at line 18 of file Controller.cc.

EventBase Controller::prevItemFast [static]
 

event masks used by processEvent()

Definition at line 20 of file Controller.cc.

ControlBase* Controller::root [protected]
 

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

Definition at line 159 of file Controller.h.

EventBase Controller::selectItem [static]
 

event masks used by processEvent()

Definition at line 21 of file Controller.cc.

Controller * Controller::theOneController = NULL [static, protected]
 

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

Definition at line 14 of file Controller.cc.


The documentation for this class was generated from the following files:
Tekkotsu v1.4
Generated Sat Jul 19 00:08:53 2003 by Doxygen 1.3.2