Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages | Examples

ArRobotConfig.cpp

00001 /*
00002 MobileRobots Advanced Robotics Interface for Applications (ARIA)
00003 Copyright (C) 2004, 2005 ActivMedia Robotics LLC
00004 Copyright (C) 2006, 2007 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 "ariaOSDef.h"
00027 #include "ArExport.h"
00028 #include "ArConfig.h"
00029 #include "ArRobotConfig.h"
00030 #include "ArRobot.h"
00031 #include "ArAnalogGyro.h"
00032 #include "ariaInternal.h"
00033 
00034 AREXPORT ArRobotConfig::ArRobotConfig(ArRobot *robot) : 
00035   myConnectCB(this, &ArRobotConfig::connectCallback),
00036   myProcessFileCB(this, &ArRobotConfig::processFile)
00037 {
00038   myRobot = robot;
00039 
00040   myAddedMovementParams = false;
00041   myTransVelMax = 0;
00042   myTransAccel = 0;
00043   myTransDecel = 0;
00044   myRotVelMax = 0;
00045   myRotAccel= 0;
00046   myRotDecel = 0;
00047 
00048   mySavedOriginalMovementParameters = false;
00049   myOriginalTransVelMax = 0;
00050   myOriginalTransAccel = 0;
00051   myOriginalTransDecel = 0;
00052   myOriginalRotVelMax = 0;
00053   myOriginalRotAccel= 0;
00054   myOriginalRotDecel = 0;
00055 
00056 
00057   myAnalogGyro = NULL;
00058   myUseGyro = false;
00059   myAddedGyro = false;
00060 
00061   myConnectCB.setName("ArRobotConfig");
00062   myProcessFileCB.setName("ArRobotConfig");
00063 
00064   myRobot->addConnectCB(&myConnectCB, ArListPos::FIRST);
00065   Aria::getConfig()->addProcessFileCB(&myProcessFileCB, 98);
00066 
00067   if (myRobot->isConnected())
00068     connectCallback();
00069 }
00070 
00071 AREXPORT ArRobotConfig::~ArRobotConfig()
00072 {
00073 }
00074 
00075 AREXPORT bool ArRobotConfig::processFile(void)
00076 {
00077     if (myTransVelMax != 0)
00078     myRobot->setTransVelMax(myTransVelMax);
00079   else
00080     myRobot->setTransVelMax(myOriginalTransVelMax);
00081 
00082   if (myTransAccel != 0)
00083     myRobot->setTransAccel(myTransAccel);
00084   else
00085     myRobot->setTransAccel(myOriginalTransAccel);
00086 
00087   if (myTransDecel != 0)
00088     myRobot->setTransDecel(myTransDecel);
00089   else
00090     myRobot->setTransDecel(myOriginalTransDecel);
00091 
00092   if (myRotVelMax != 0)
00093     myRobot->setRotVelMax(myRotVelMax);
00094   else
00095     myRobot->setRotVelMax(myOriginalRotVelMax);
00096 
00097   if (myRotAccel!= 0)
00098     myRobot->setRotAccel(myRotAccel);
00099   else
00100     myRobot->setRotAccel(myOriginalRotAccel);
00101 
00102   if (myRotDecel != 0)
00103     myRobot->setRotDecel(myRotDecel);
00104   else
00105     myRobot->setRotDecel(myOriginalRotDecel);
00106 
00107   if (myAnalogGyro != NULL && myAddedGyro)
00108   {
00109     if (myUseGyro && !myAnalogGyro->isActive())
00110     {
00111       ArLog::log(ArLog::Normal, "Gyro(analog) activated");
00112       myAnalogGyro->activate();
00113     }
00114     else if (!myUseGyro && myAnalogGyro->isActive())
00115     {
00116       ArLog::log(ArLog::Normal, "Gyro(analog) deactivated");
00117       myAnalogGyro->deactivate();
00118     }
00119   }
00120   
00121   return true;
00122 }
00123 
00124 AREXPORT void ArRobotConfig::addAnalogGyro(ArAnalogGyro *gyro)
00125 {
00126   myAnalogGyro = gyro;
00127   if (myRobot->isConnected())
00128     connectCallback();
00129 }
00130 
00131 AREXPORT void ArRobotConfig::connectCallback(void)
00132 {
00133   std::string section;
00134   section = "Robot config";
00135 
00136   if (!mySavedOriginalMovementParameters)
00137   {
00138     mySavedOriginalMovementParameters = true;
00139     myOriginalTransVelMax = ArMath::roundInt(myRobot->getTransVelMax());
00140     myOriginalTransAccel = ArMath::roundInt(myRobot->getTransAccel());
00141     myOriginalTransDecel = ArMath::roundInt(myRobot->getTransDecel());
00142     myOriginalRotVelMax = ArMath::roundInt(myRobot->getRotVelMax());
00143     myOriginalRotAccel = ArMath::roundInt(myRobot->getRotAccel());
00144     myOriginalRotDecel = ArMath::roundInt(myRobot->getRotDecel());
00145   }
00146 
00147   if (!myAddedMovementParams)
00148   {
00149     myAddedMovementParams = true;
00150     Aria::getConfig()->addParam(
00151         ArConfigArg("TransVelMax", &myTransVelMax, 
00152             "maximum translational speed (mm/sec) (0 means use original value)",
00153             0, (int)myRobot->getAbsoluteMaxTransVel()), 
00154         section.c_str(), ArPriority::TRIVIAL);
00155     Aria::getConfig()->addParam(
00156         ArConfigArg("TransAccel", &myTransAccel, 
00157             "translational acceleration (mm/sec/sec) (0 means use original value)",
00158             0, (int)myRobot->getAbsoluteMaxTransAccel()), 
00159         section.c_str(), ArPriority::TRIVIAL);
00160     Aria::getConfig()->addParam(
00161         ArConfigArg("TransDecel", &myTransDecel, 
00162             "translational deceleration (mm/sec/sec) (0 means use original value)",
00163             0, (int)myRobot->getAbsoluteMaxTransDecel()), 
00164         section.c_str(), ArPriority::TRIVIAL);
00165     Aria::getConfig()->addParam(
00166         ArConfigArg("RotVelMax", &myRotVelMax, 
00167             "maximum rotational speed (deg/sec) (0 means use original value)",
00168             0, (int)myRobot->getAbsoluteMaxRotVel()), 
00169         section.c_str(), ArPriority::TRIVIAL);
00170     Aria::getConfig()->addParam(
00171         ArConfigArg("RotAccel", &myRotAccel, 
00172             "rotational acceleration (deg/sec/sec) (0 means use original value)",
00173             0, (int)myRobot->getAbsoluteMaxRotAccel()), 
00174         section.c_str(), ArPriority::TRIVIAL);
00175     Aria::getConfig()->addParam(
00176         ArConfigArg("RotDecel", &myRotDecel, 
00177             "rotational deceleration (deg/sec/sec) (0 means use original value)",
00178             0, (int)myRobot->getAbsoluteMaxRotDecel()), 
00179         section.c_str(), ArPriority::TRIVIAL);
00180   }
00181 
00182   if (myAnalogGyro != NULL && !myAddedGyro && 
00183       myAnalogGyro->haveGottenData())
00184   {
00185     myAddedGyro = true;
00186     Aria::getConfig()->addParam(
00187         ArConfigArg("UseGyro", &myUseGyro, 
00188             "True to use the gyro, false not to"),
00189         section.c_str(), ArPriority::TRIVIAL);
00190 
00191   }
00192 
00193 }

Generated on Tue Feb 20 10:51:41 2007 for Aria by  doxygen 1.4.0