Example of using ArActionGroup objects to switch between two different kinds of behavior.This program creates two action groups, a teleoperation group and a wander group. Each group contains actions that together effect the desired behavior: in teleoperation mode, input actions allow the robot to be driven by keyboard or joystick, and higher-priority limiter actions help avoid obstacles. In wander mode, a constant-velocity action drives the robot forward, but higher-priority avoidance actions make the robot turn away from obstacles, or back up if an obstacle is hit or the motors stall. Keyboard commands (the T and W keys) are used to switch between the two modes, by activating the action group for the chosen mode.
- See also
- ArActionGroup
-
Actions overview
-
actionExample.cpp
#include "Aria.h"
void teleopMode(void)
{
printf("\n== Teleoperation Mode ==\n");
printf(" Use the arrow keys to drive, and the spacebar to stop.\n For joystick control hold the trigger button.\n Press 'w' to switch to wander mode.\n Press escape to exit.\n");
}
void wanderMode(void)
{
printf("\n== Wander Mode ==\n");
printf(" The robot will now just wander around avoiding things.\n Press 't' to switch to teleop mode.\n Press escape to exit.\n");
}
int main(int argc, char** argv)
{
argParser.loadDefaultArguments();
{
return 1;
}
300, 600, 250), 95);
300, 1100, 400), 90);
if (keyHandler == NULL)
{
}
if (!joydriveAct.joystickInited())
printf("Note: Do not have a joystick, only the arrow keys on the keyboard will work.\n");
joydriveAct.setStopIfNoButtonPressed(false);
if(!con.connectRobot(&robot))
{
}
teleopMode();
}
Action to recover from a stall.
Definition: ArActionStallRecover.h:40
virtual void activateExclusive(void)
Activates all the actions in this group and deactivates all others.
Definition: ArActionGroup.cpp:97
Group a set of ArAction objects together.
Definition: ArActionGroup.h:49
Perform actions when keyboard keys are pressed.
Definition: ArKeyHandler.h:65
static ArKeyHandler * getKeyHandler(void)
Gets a pointer to the global key handler, if one has been set with setKeyHandler()
Definition: Aria.cpp:630
Action to limit speed (and stop) based on whether the "table"-sensors see anything.
Definition: ArActionLimiterTableSensor.h:40
@ Terse
Use terse logging.
Definition: ArLog.h:61
virtual void addAction(ArAction *action, int priority)
Adds an action to this group's robot, and associates the action with this group.
Definition: ArActionGroup.cpp:56
Legacy connector for robot and laser.
Definition: ArSimpleConnector.h:51
void enableMotors()
Enables the motors on the robot.
Definition: ArRobot.cpp:6521
This action does obstacle avoidance, controlling both trans and rot.
Definition: ArActionAvoidFront.h:51
static void setKeyHandler(ArKeyHandler *keyHandler)
Sets the key handler, so that other classes can find it using getKeyHandler()
Definition: Aria.cpp:624
void addRangeDevice(ArRangeDevice *device)
Adds a rangeDevice to the robot's list of them, and set the ArRangeDevice object's robot pointer to t...
Definition: ArRobot.cpp:5757
static void exit(int exitCode=0)
Shutdown all Aria processes/threads, call exit callbacks, and exit the program.
Definition: Aria.cpp:367
static void log(LogLevel level, const char *str,...)
Log a message, with formatting and variable number of arguments.
Definition: ArLog.cpp:93
Action for going straight at a constant velocity.
Definition: ArActionConstantVelocity.h:37
bool addKeyHandler(int keyToHandle, ArFunctor *functor)
This adds a keyhandler, when the keyToHandle is hit, functor will fire.
Definition: ArKeyHandler.cpp:144
static void init(SigHandleMethod method=SIGHANDLE_THREAD, bool initSockets=true, bool sigHandleExitNotShutdown=true)
Initialize Aria global data struture and perform OS-specific initialization, including adding OS sign...
Definition: Aria.cpp:128
Central class for communicating with and operating the robot.
Definition: ArRobot.h:82
Parse and store program command-line arguments for use by other ARIA classes.
Definition: ArArgumentParser.h:64
static void logOptions(void)
Logs all the options for the program (Calls all the callbacks added with addLogOptionsCB())
Definition: Aria.cpp:794
Action to deal with if the bumpers trigger.
Definition: ArActionBumpers.h:45
Keep track of recent sonar readings from a robot as an ArRangeDevice.
Definition: ArSonarDevice.h:51
This action will use the joystick for input to drive the robot.
Definition: ArActionJoydrive.h:51
static bool parseArgs(void)
Parses the arguments for the program (calls all the callbacks added with addParseArgsCB())
Definition: Aria.cpp:759
This action will use the keyboard arrow keys for input to drive the robot.
Definition: ArActionKeydrive.h:37
Functor for a global function with no parameters.
Definition: ArFunctor.h:648
Action to limit the backwards motion of the robot based on range sensor readings.
Definition: ArActionLimiterBackwards.h:40
void run(bool stopRunIfNotConnected, bool runNonThreaded=false)
Starts the instance to do processing in this thread.
Definition: ArRobot.cpp:255
void attachKeyHandler(ArKeyHandler *keyHandler, bool exitOnEscape=true, bool useExitNotShutdown=true)
Attachs a key handler.
Definition: ArRobot.cpp:6641
Action to limit the forwards motion of the robot based on range sensor readings.
Definition: ArActionLimiterForwards.h:39