00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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 }