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.
00001 /* 00002 MobileRobots Advanced Robotics Interface for Applications (ARIA) 00003 Copyright (C) 2004,2005 ActivMedia Robotics LLC 00004 Copyright (C) 2006 MobileRobots, Inc. 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 00020 If you wish to redistribute ARIA under different terms, contact 00021 MobileRobots for information about a commercial version of ARIA at 00022 robots@mobilerobots.com or 00023 MobileRobots Inc, 19 Columbia Drive, Amherst, NH 03031; 800-639-9481 00024 */ 00025 00026 #include "Aria.h" 00027 00036 int main(int argc, char **argv) 00037 { 00038 Aria::init(); 00039 ArSimpleConnector con(&argc, argv); 00040 ArRobot robot; 00041 ArP2Arm arm; 00042 00043 00044 if(!Aria::parseArgs()) 00045 { 00046 Aria::logOptions(); 00047 Aria::shutdown(); 00048 return 1; 00049 } 00050 00051 ArLog::log(ArLog::Normal, "armExample: Connecting to the robot."); 00052 if(!con.connectRobot(&robot)) 00053 { 00054 ArLog::log(ArLog::Terse, "armExample: Could not connect to the robot. Exiting."); 00055 Aria::shutdown(); 00056 return 1; 00057 } 00058 robot.runAsync(true); 00059 00060 // turn off sonar 00061 robot.comInt(28, 0); 00062 00063 // Set up and initialize the arm 00064 arm.setRobot(&robot); 00065 if (arm.init() != ArP2Arm::SUCCESS) 00066 { 00067 ArLog::log(ArLog::Terse, "armExample: Error initializing the P2 Arm!"); 00068 return 1; 00069 } 00070 00071 // Print out some of the settings 00072 P2ArmJoint *joint; 00073 printf("Current joint info:\nJoint Vel Home Center\n"); 00074 for (int i=1; i<=ArP2Arm::NumJoints; i++) 00075 { 00076 joint = arm.getJoint(i); 00077 printf(" %2i: %5i %5i %5i\n", i, joint->myVel, joint->myHome, joint->myCenter); 00078 } 00079 printf("\n"); 00080 00081 // Put the arm to work 00082 printf("Powering on (takes a couple seconds to stabilize)\n"); 00083 arm.powerOn(); 00084 00085 // Request one status packet and print out the arm's status 00086 printf("Current arm status:\n"); 00087 arm.requestStatus(ArP2Arm::StatusSingle); 00088 ArUtil::sleep(200); // Give time to get the packet 00089 printf("Arm Status: "); 00090 if (arm.getStatus() & ArP2Arm::ArmGood) 00091 printf("Good=1 "); 00092 else 00093 printf("Good=0 "); 00094 if (arm.getStatus() & ArP2Arm::ArmInited) 00095 printf("Inited=1 "); 00096 else 00097 printf("Inited=0 "); 00098 if (arm.getStatus() & ArP2Arm::ArmPower) 00099 printf("Power=1 "); 00100 else 00101 printf("Power=0 "); 00102 if (arm.getStatus() & ArP2Arm::ArmHoming) 00103 printf("Homing=1 "); 00104 else 00105 printf("Homing=0 "); 00106 printf("\n\n"); 00107 00108 // Move the arm joints to specific positions 00109 printf("Moving Arm...\n"); 00110 int deploy_offset[] = {0, -100, 10, 40, 80, -55, 20}; 00111 for (int i=1; i<=ArP2Arm::NumJoints; i++) 00112 { 00113 joint = arm.getJoint(i); 00114 arm.moveToTicks(i, joint->myCenter + deploy_offset[i]); 00115 } 00116 00117 // Wait for arm to achieve new position, printing joint positions and M for 00118 // moving, NM for not moving. 00119 arm.requestStatus(ArP2Arm::StatusContinuous); 00120 ArUtil::sleep(300); // wait a moment for arm status packet update with joints moving 00121 bool moving = true; 00122 while (moving) 00123 { 00124 moving = false; 00125 printf("Joints: "); 00126 for (int i=1; i<=ArP2Arm::NumJoints; i++) 00127 { 00128 printf("[%d] %.0f, ", i, arm.getJointPos(i)); 00129 if (arm.getMoving(i)) 00130 { 00131 printf("M; "); 00132 moving = true; 00133 } 00134 else 00135 { 00136 printf("NM; "); 00137 } 00138 } 00139 printf("\r"); 00140 } 00141 printf("\n\n"); 00142 00143 // Return arm to park, wait, and disconnect. (Though the arm will automatically park 00144 // on client disconnect) 00145 printf("Parking arm.\n"); 00146 arm.park(); 00147 00148 // Wait 5 seconds or until arm shuts off 00149 for(int i = 5; (i > 0) && (arm.getStatus() & ArP2Arm::ArmPower); i--) 00150 { 00151 ArUtil::sleep(1000); 00152 } 00153 00154 // Disconnect from robot, etc., and exit. 00155 printf("Shutting down ARIA and exiting.\n"); 00156 Aria::shutdown(); 00157 00158 return(0); 00159 } 00160
1.4.7