Aria  2.8.0
teleopActionsExample.cpp

Example using actions for safe teleoperation with keyboard or joystick.This example program creates several "limiting" actions (stop the robot from hitting detected obstacles), as well as Joydrive and Keydrive actions which request movement based on keys pressed or a joystick attached to the computer. The limiting actions are added at a higher priority than the teleoperation actions, so they prevent those actions from driving the robot if nearby obstacles are detected; otherwise, you can drive the robot using they joystick or keyboard.

/*
Adept MobileRobots Robotics Interface for Applications (ARIA)
Copyright (C) 2004, 2005 ActivMedia Robotics LLC
Copyright (C) 2006, 2007, 2008, 2009, 2010 MobileRobots Inc.
Copyright (C) 2011, 2012, 2013 Adept Technology
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
If you wish to redistribute ARIA under different terms, contact
Adept MobileRobots for information about a commercial version of ARIA at
robots@mobilerobots.com or
Adept MobileRobots, 10 Columbia Drive, Amherst, NH 03031; +1-603-881-7960
*/
#include "Aria.h"
int main(int argc, char **argv)
{
ArArgumentParser parser(&argc, argv);
ArRobot robot;
ArRobotConnector robotConnector(&parser, &robot);
if(!robotConnector.connectRobot())
{
ArLog::log(ArLog::Terse, "teleopActionsExample: Could not connect to the robot.");
{
}
}
{
}
ArLog::log(ArLog::Normal, "teleopActionsExample: Connected.");
// limiter for close obstacles
ArActionLimiterForwards limiter("speed limiter near", 300, 600, 250);
// limiter for far away obstacles
ArActionLimiterForwards limiterFar("speed limiter far", 300, 1100, 400);
// limiter that checks IR sensors (like Peoplebot has)
// limiter so we don't bump things backwards
ArActionLimiterBackwards backwardsLimiter;
// the joydrive action
ArActionJoydrive joydriveAct;
// the keydrive action
ArActionKeydrive keydriveAct;
// sonar device, used by the limiter actions.
printf("This program will allow you to use a joystick or keyboard to control the robot.\nYou can use the arrow keys to drive, and the spacebar to stop.\nFor joystick control press the trigger button and then drive.\nPress escape to exit.\n");
// if we don't have a joystick, let 'em know
if (!joydriveAct.joystickInited())
printf("Do not have a joystick, only the arrow keys on the keyboard will work.\n");
// add the sonar to the robot
robot.addRangeDevice(&sonar);
// set the robots maximum velocity (sonar don't work at all well if you're
// going faster)
// enable the motor
robot.enableMotors();
// Add the actions, with the limiters as highest priority, then the teleop.
// actions. This will keep the teleop. actions from being able to drive too
// fast and hit something
robot.addAction(&tableLimiter, 100);
robot.addAction(&limiter, 95);
robot.addAction(&limiterFar, 90);
robot.addAction(&backwardsLimiter, 85);
robot.addAction(&joydriveAct, 50);
robot.addAction(&keydriveAct, 45);
// Configure the joydrive action so it will let the lower priority actions
// (i.e. keydriveAct) request motion if the joystick button is
// not pressed.
joydriveAct.setStopIfNoButtonPressed(false);
// run the robot, true means that the run will exit if connection lost
robot.run(true);
}
ArRobotConnector::connectRobot
bool connectRobot(void)
Sets up the robot then connects it.
Definition: ArRobotConnector.cpp:405
ArRobot::setAbsoluteMaxTransVel
bool setAbsoluteMaxTransVel(double maxVel)
Sets the robot's absolute maximum translational velocity.
Definition: ArRobot.cpp:2144
ArArgumentParser::loadDefaultArguments
void loadDefaultArguments(int positon=1)
Adds args from default files and environmental variables.
Definition: ArArgumentParser.cpp:736
ArActionLimiterTableSensor
Action to limit speed (and stop) based on whether the "table"-sensors see anything.
Definition: ArActionLimiterTableSensor.h:40
ArLog::Terse
Use terse logging.
Definition: ArLog.h:61
ArRobotConnector
Connect to robot or simulator based on program command line parameters.
Definition: ArRobotConnector.h:80
ArRobot::enableMotors
void enableMotors()
Enables the motors on the robot.
Definition: ArRobot.cpp:6521
ArRobot::addRangeDevice
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
Aria::exit
static void exit(int exitCode=0)
Shutdown all Aria processes/threads, call exit callbacks, and exit the program.
Definition: Aria.cpp:367
ArLog::log
static void log(LogLevel level, const char *str,...)
Log a message, with formatting and variable number of arguments.
Definition: ArLog.cpp:93
ArActionJoydrive::joystickInited
bool joystickInited(void)
Whether the joystick is initalized or not.
Definition: ArActionJoydrive.cpp:108
Aria::init
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
ArArgumentParser::checkHelpAndWarnUnparsed
bool checkHelpAndWarnUnparsed(unsigned int numArgsOkay=0)
Checks for the help strings and warns about unparsed arguments.
Definition: ArArgumentParser.cpp:843
ArRobot
Central class for communicating with and operating the robot.
Definition: ArRobot.h:82
ArArgumentParser
Parse and store program command-line arguments for use by other ARIA classes.
Definition: ArArgumentParser.h:64
Aria::logOptions
static void logOptions(void)
Logs all the options for the program (Calls all the callbacks added with addLogOptionsCB())
Definition: Aria.cpp:794
ArSonarDevice
Keep track of recent sonar readings from a robot as an ArRangeDevice.
Definition: ArSonarDevice.h:51
ArActionJoydrive
This action will use the joystick for input to drive the robot.
Definition: ArActionJoydrive.h:51
ArRobot::addAction
bool addAction(ArAction *action, int priority)
Adds an action to the list with the given priority.
Definition: ArRobot.cpp:3278
Aria::parseArgs
static bool parseArgs(void)
Parses the arguments for the program (calls all the callbacks added with addParseArgsCB())
Definition: Aria.cpp:759
ArActionKeydrive
This action will use the keyboard arrow keys for input to drive the robot.
Definition: ArActionKeydrive.h:37
ArLog::Normal
Use normal logging.
Definition: ArLog.h:62
ArActionLimiterBackwards
Action to limit the backwards motion of the robot based on range sensor readings.
Definition: ArActionLimiterBackwards.h:40
ArActionJoydrive::setStopIfNoButtonPressed
void setStopIfNoButtonPressed(bool stopIfNoButtonPressed)
Set if we'll stop if no button is pressed, otherwise just do nothing.
Definition: ArActionJoydrive.cpp:97
ArRobot::run
void run(bool stopRunIfNotConnected, bool runNonThreaded=false)
Starts the instance to do processing in this thread.
Definition: ArRobot.cpp:255
ArActionLimiterForwards
Action to limit the forwards motion of the robot based on range sensor readings.
Definition: ArActionLimiterForwards.h:39