Aria  2.8.0
armExample.cpp

Example program showing use of the original 5DOF P2 arm accessory.Demonstrates how to connect with the Pioneer 2 controller and set up the P2Arm class, including the ARMpac handler. It simply queries and prints the status of the arm, moving it to a position, then exits. Note, The P2Arm class is only for use with the microcontroller-integrated original 5DOF Pioneer 2 arm (Robotica arm). The newer Energid Cyton 7DOF arm is accessed through separate cyton libraries.

/*
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)
{
ArSimpleConnector con(&argc, argv);
ArRobot robot;
ArP2Arm arm;
{
return 1;
}
ArLog::log(ArLog::Normal, "armExample: Connecting to the robot.");
if(!con.connectRobot(&robot))
{
ArLog::log(ArLog::Terse, "armExample: Could not connect to the robot. Exiting.");
return 1;
}
robot.runAsync(true);
// turn off sonar
robot.comInt(28, 0);
// Set up and initialize the arm
arm.setRobot(&robot);
if (arm.init() != ArP2Arm::SUCCESS)
{
ArLog::log(ArLog::Terse, "armExample: Error initializing the P2 Arm!");
return 1;
}
// Print out some of the settings
P2ArmJoint *joint;
printf("Current joint info:\nJoint Vel Home Center\n");
for (int i=1; i<=ArP2Arm::NumJoints; i++)
{
joint = arm.getJoint(i);
printf(" %2i: %5i %5i %5i\n", i, joint->myVel, joint->myHome, joint->myCenter);
}
printf("\n");
// Put the arm to work
printf("Powering on (takes a couple seconds to stabilize)\n");
arm.powerOn();
// Request one status packet and print out the arm's status
printf("Current arm status:\n");
ArUtil::sleep(200); // Give time to get the packet
printf("Arm Status: ");
printf("Good=1 ");
else
printf("Good=0 ");
printf("Inited=1 ");
else
printf("Inited=0 ");
printf("Power=1 ");
else
printf("Power=0 ");
printf("Homing=1 ");
else
printf("Homing=0 ");
printf("\n\n");
// Move the arm joints to specific positions
printf("Moving Arm...\n");
int deploy_offset[] = {0, -100, 10, 40, 80, -55, 20};
for (int i=1; i<=ArP2Arm::NumJoints; i++)
{
joint = arm.getJoint(i);
arm.moveToTicks(i, joint->myCenter + deploy_offset[i]);
}
// Wait for arm to achieve new position, printing joint positions and M for
// moving, NM for not moving.
ArUtil::sleep(300); // wait a moment for arm status packet update with joints moving
bool moving = true;
while (moving)
{
moving = false;
printf("Joints: ");
for (int i=1; i<=ArP2Arm::NumJoints; i++)
{
printf("[%d] %.0f, ", i, arm.getJointPos(i));
if (arm.getMoving(i))
{
printf("M; ");
moving = true;
}
else
{
printf("NM; ");
}
}
printf("\r");
}
printf("\n\n");
// Return arm to park, wait, and disconnect. (Though the arm will automatically park
// on client disconnect)
printf("Parking arm.\n");
arm.park();
// Wait 5 seconds or until arm shuts off
for(int i = 5; (i > 0) && (arm.getStatus() & ArP2Arm::ArmPower); i--)
{
}
// Disconnect from robot, etc., and exit.
printf("Shutting down ARIA and exiting.\n");
return(0);
}
ArP2Arm::getJoint
virtual P2ArmJoint * getJoint(int joint)
Get the joints data structure.
Definition: ArP2Arm.cpp:523
ArP2Arm::SUCCESS
Succeded.
Definition: ArP2Arm.h:86
ArP2Arm::ArmGood
static const int ArmGood
Bit for arm good state in arm status byte.
Definition: ArP2Arm.h:127
ArLog::Terse
Use terse logging.
Definition: ArLog.h:61
ArSimpleConnector
Legacy connector for robot and laser.
Definition: ArSimpleConnector.h:51
ArP2Arm::park
virtual State park()
Home the arm and power if off.
Definition: ArP2Arm.cpp:671
ArRobot::comInt
bool comInt(unsigned char command, short int argument)
Sends a command to the robot with an int for argument.
Definition: ArRobot.cpp:5634
ArP2Arm::NumJoints
static int NumJoints
Number of joints that the arm has.
Definition: ArP2Arm.h:135
ArP2Arm::init
virtual State init()
Init the arm class.
Definition: ArP2Arm.cpp:93
ArSimpleConnector::connectRobot
bool connectRobot(ArRobot *robot)
Sets up the robot then connects it.
Definition: ArSimpleConnector.cpp:209
ArP2Arm::getStatus
virtual int getStatus()
Get the two byts of status info from P2OS.
Definition: ArP2Arm.h:226
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
ArP2Arm::ArmHoming
static const int ArmHoming
Bit for arm homing in arm status byte.
Definition: ArP2Arm.h:133
ArP2Arm::StatusSingle
Send a single status packets.
Definition: ArP2Arm.h:110
ArP2Arm::ArmPower
static const int ArmPower
Bit for arm powered on in arm status byte.
Definition: ArP2Arm.h:131
ArP2Arm::StatusContinuous
Send continous packets. Once every 100ms.
Definition: ArP2Arm.h:111
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
P2ArmJoint
P2 Arm joint info.
Definition: ArP2Arm.h:37
ArRobot
Central class for communicating with and operating the robot.
Definition: ArRobot.h:82
ArP2Arm::requestStatus
virtual State requestStatus(StatusType status)
Request the arm status packet.
Definition: ArP2Arm.cpp:224
Aria::logOptions
static void logOptions(void)
Logs all the options for the program (Calls all the callbacks added with addLogOptionsCB())
Definition: Aria.cpp:794
ArP2Arm::setRobot
void setRobot(ArRobot *robot)
Set the robot to use to talk to the arm.
Definition: ArP2Arm.h:144
ArRobot::runAsync
void runAsync(bool stopRunIfNotConnected, bool runNonThreadedPacketReader=false)
Starts the instance to do processing in its own new thread.
Definition: ArRobot.cpp:301
Aria::parseArgs
static bool parseArgs(void)
Parses the arguments for the program (calls all the callbacks added with addParseArgsCB())
Definition: Aria.cpp:759
ArUtil::sleep
static void sleep(unsigned int ms)
Sleep for the given number of milliseconds.
Definition: ariaUtil.cpp:151
ArP2Arm
ArP2Arm is the interface to the AROS/P2OS-based Pioneer 2 Arm servers, by means of which the robot mi...
Definition: ArP2Arm.h:80
ArLog::Normal
Use normal logging.
Definition: ArLog.h:62
ArP2Arm::getJointPos
virtual float getJointPos(int joint)
Get the joints position in degrees.
Definition: ArP2Arm.cpp:504
ArP2Arm::powerOn
virtual State powerOn(bool doWait=true)
Power on the arm.
Definition: ArP2Arm.cpp:159
ArP2Arm::moveToTicks
virtual State moveToTicks(int joint, unsigned char pos)
Move a joint to a position in low level arm controller ticks.
Definition: ArP2Arm.cpp:388
ArP2Arm::getMoving
virtual bool getMoving(int joint=-1)
Check to see if the arm is moving.
Definition: ArP2Arm.cpp:644
ArP2Arm::ArmInited
static const int ArmInited
Bit for arm initialized in arm status byte.
Definition: ArP2Arm.h:129