Aria  2.8.0
ArAction Class Referenceabstract

Base class for actions. More...

#include <ArAction.h>

Inherited by ActionGo, ActionTurn, ArActionAvoidFront, ArActionAvoidSide, ArActionBumpers, ArActionColorFollow, ArActionConstantVelocity, ArActionDeceleratingLimiter, ArActionDriveDistance, ArActionGoto, ArActionGotoStraight, ArActionInput, ArActionIRs, ArActionJoydrive, ArActionKeydrive, ArActionLimiterBackwards, ArActionLimiterForwards, ArActionLimiterRot, ArActionLimiterTableSensor, ArActionMovementParameters, ArActionMovementParametersDebugging, ArActionRatioInput, ArActionRobotJoydrive, ArActionStallRecover, ArActionStop, ArActionTriangleDriveTo, ArActionTurn, Chase, and JoydriveAction.

Public Member Functions

virtual void activate (void)
 Activate the action.
 
 ArAction (const char *name, const char *description="")
 Constructor.
 
virtual void deactivate (void)
 Deactivate the action.
 
virtual ArActionDesiredfire (ArActionDesired currentDesired)=0
 Fires the action, returning what the action wants to do. More...
 
virtual const ArArggetArg (int number) const
 Gets the numbered argument. More...
 
virtual ArArggetArg (int number)
 Gets the numbered argument.
 
virtual const char * getDescription (void) const
 Gets the long description of the action.
 
virtual ArActionDesiredgetDesired (void)
 Gets what this action wants to do (for display purposes)
 
virtual const ArActionDesiredgetDesired (void) const
 Gets what this action wants to do (for display purposes)
 
virtual const char * getName (void) const
 Gets the name of the action.
 
virtual int getNumArgs (void) const
 Find the number of arguments this action takes.
 
ArRobotgetRobot () const
 Get the robot we are controlling, which was set by setRobot()
 
virtual bool isActive (void) const
 Returns whether the action is active or not.
 
virtual void log (bool verbose=true) const
 Log information about this action using ArLog.
 
virtual void setRobot (ArRobot *robot)
 Sets the robot this action is driving. More...
 
virtual ~ArAction ()
 Desructor.
 

Static Public Member Functions

static bool getDefaultActivationState (void)
 Gets the default activation state for all ArActions.
 
static void setDefaultActivationState (bool defaultActivationState)
 Sets the default activation state for all ArActions.
 

Protected Member Functions

void setNextArgument (ArArg const &arg)
 Sets the argument type for the next argument (must only be used in a constructor!)
 

Protected Attributes

std::map< int, ArArgmyArgumentMap
 
std::string myDescription
 
bool myIsActive
 
std::string myName
 
int myNumArgs
 
ArRobotmyRobot
 The robot we are controlling, set by the action resolver using setRobot()
 

Static Protected Attributes

static bool ourDefaultActivationState = true
 

Detailed Description

Base class for actions.

Actions Actions are objects queried for desired behavior by ArActionResolver to determine robot movement commands.

To implement an action object, define a subclass of ArAction, and implement the fire() method. You may also override setRobot() to obtain information from ArRobot, but you must also call ArAction::setRobot() so that the ArRobot pointer is stored by ArAction.

Several predefined action objects are also included in ARIA, they are listed here as ArActions's subclasses.

If an action is not active (it has been deactivated), then it will be ignored by the action resolver. Actions may be grouped using ArActionGroup, and activated/deactivated as a group. For example, ArMode, and ArServerMode (from ArNetworking), activate/deactivate action groups when switching modes.

See also
Actions description in the ARIA overview.
ArActionGroup
ArResolver
ArRobot
Examples:
actionExample.cpp, actsColorFollowingExample.cpp, and joydriveActionExample.cpp.

Member Function Documentation

◆ fire()

virtual ArActionDesired* ArAction::fire ( ArActionDesired  currentDesired)
pure virtual

Fires the action, returning what the action wants to do.

Parameters
currentDesiredthis is the tentative result, based on the resolver's processing of previous, higher-priority actions. This is only for the purpose of giving information to the action, changing it has no effect.
Returns
pointer to what this action wants to do, NULL if it wants to do nothing. Common practice is to keep an ArActionDesired object in your action subclass, and return a pointer to that object. This avoids the need to create new objects during each invocation (which could never be deleted). Clear your stored ArActionDesired before modifying it with ArActionDesired::reset().

Implemented in ArActionGoto.

Examples:
actionExample.cpp, actsColorFollowingExample.cpp, and joydriveActionExample.cpp.

◆ getArg()

const ArArg * ArAction::getArg ( int  number) const
virtual

Gets the numbered argument.

Java and Python Wrappers: Not available

◆ setRobot()

void ArAction::setRobot ( ArRobot robot)
virtual

Sets the robot this action is driving.

Java and Python Wrappers: If you override this method in a Java or Python subclass, use setActionRobotObj(ArRobot) instead of trying to call super.setRobot() or ArAction.setRobot(). (SWIG's subclassing "directors" feature cannot properly direct the call to the parent class, an infinite recursion results instead.)

Examples:
actionExample.cpp.

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