JointControlCommandSeriesElastic.cpp
Go to the documentation of this file.
00001 
00005 #include "robodyn_mechanisms/JointControlCommandSeriesElastic.h"
00006 /***************************************************************************/
00011 JointControlCommandSeriesElastic::JointControlCommandSeriesElastic(const std::string& mechanism, IoFunctions ioFunctions, NodeRegisterManagerPtr nodeRegisterManager)
00012     : JointControlCommandInterface(mechanism, ioFunctions), nodeRegisterManager(nodeRegisterManager), logCategory("gov.nasa.JointControlCommandSeriesElastic")
00013 {
00014     setParameters();
00015     bootLoader();
00016     motCom();
00017     disableCalibrationMode();
00018     disableClearFaultMode();
00019 }
00020 
00021 JointControlCommandSeriesElastic::~JointControlCommandSeriesElastic()
00022 {
00023     // Nothing
00024 }
00025 void JointControlCommandSeriesElastic::setParameters()
00026 {
00027     std::string parameterFile = io.getControlFile(mechanism);
00028 
00030     TiXmlDocument file(parameterFile.c_str());
00031 
00032     if (!file.LoadFile())
00033     {
00034         std::stringstream err;
00035         err << "Failed to load file [" << parameterFile << "]";
00036         NasaCommonLogging::Logger::log(logCategory, log4cpp::Priority::FATAL, err.str());
00037         throw std::runtime_error(err.str());
00038     }
00039 
00040     TiXmlHandle doc(&file);
00041     NasaCommonLogging::Logger::log(logCategory, log4cpp::Priority::INFO, "File [" + parameterFile + "] successfully loaded.");
00042 
00043     // Print the XML file's contents
00044     //cout << "Successfully loaded file: " << parameterFile << endl;
00045     //TiXmlPrinter printer;
00046     //printer.SetIndent("\t");
00047     //file.Accept(&printer);
00048     //cout << printer.Str() << endl;
00049 
00050     // Check for ApiMap
00051     TiXmlHandle parametersElement(doc.FirstChildElement("ApiMap"));
00052 
00053     if (parametersElement.ToElement())
00054     {
00055         // Control bit names
00056         BootEnableControlName      = ApiMap::getXmlElementValue(parametersElement, "BootEnableControl");
00057         BridgeEnableControlName    = ApiMap::getXmlElementValue(parametersElement, "BridgeEnableControl");
00058         BrakeReleaseControlName    = ApiMap::getXmlElementValue(parametersElement, "BrakeReleaseControl");
00059         MotorEnableControlName     = ApiMap::getXmlElementValue(parametersElement, "MotorEnableControl");
00060         MotComSourceControlName    = ApiMap::getXmlElementValue(parametersElement, "MotComSourceControl");
00061         ControlModeControlName     = ApiMap::getXmlElementValue(parametersElement, "ControlModeControl");
00062         PosComVelocityControlName  = ApiMap::getXmlElementValue(parametersElement, "PosComVelocityControl");
00063         CalibrationModeControlName = ApiMap::getXmlElementValue(parametersElement, "CalibrationModeControl");
00064         ClearFaultControlName      = ApiMap::getXmlElementValue(parametersElement, "ClearFaultControl");
00065         InitAPS2toAPS1ControlName  = ApiMap::getXmlElementValue(parametersElement, "InitAPS2toAPS1Control");
00066         HeadLightControlName       = ApiMap::getXmlElementValue(parametersElement, "HeadLightControl");
00067         LaserEnableControlName     = ApiMap::getXmlElementValue(parametersElement, "LaserEnableControl");
00068         AwareControlName           = ApiMap::getXmlElementValue(parametersElement, "AwareControl");
00069     }
00070     else
00071     {
00072         std::stringstream err;
00073         err << "The file " << parameterFile << " has no element named [ApiMap]";
00074         NasaCommonLogging::Logger::log(logCategory, log4cpp::Priority::ERROR, err.str());
00075         throw std::runtime_error(err.str());
00076     }
00077 
00078     HeadLightName   = StringUtilities::makeFullyQualifiedRoboDynElement(mechanism, HeadLightControlName);
00079     LaserEnableName = StringUtilities::makeFullyQualifiedRoboDynElement(mechanism, LaserEnableControlName);
00080 
00081     if (nodeRegisterManager->hasControlProperty(mechanism, HeadLightControlName))
00082     {
00083         headLight = nodeRegisterManager->getControlValue(mechanism, HeadLightControlName);
00084         io.setIntParam(HeadLightName, headLight);
00085     }
00086 
00087     if (nodeRegisterManager->hasControlProperty(mechanism, LaserEnableControlName))
00088     {
00089         laserEnable = nodeRegisterManager->getControlValue(mechanism, LaserEnableControlName);
00090         io.setIntParam(LaserEnableName, laserEnable);
00091     }
00092 
00093     if (nodeRegisterManager->hasControlProperty(mechanism, InitAPS2toAPS1ControlName))
00094     {
00095         nodeRegisterManager->setControlValue(mechanism, InitAPS2toAPS1ControlName, 0); // We think this is used for neck
00096     }
00097 
00098 }
00099 
00100 /***************************************************************************/
00106 void JointControlCommandSeriesElastic::getStates(r2_msgs::JointControlData& commandStates)
00107 {
00108     updateParameters();
00109     commandStates = states;
00110 }
00111 
00112 void JointControlCommandSeriesElastic::updateParameters()
00113 {
00114     if (nodeRegisterManager->hasControlProperty(mechanism, HeadLightControlName))
00115     {
00116         io.getIntParam(HeadLightName, headLight);
00117         nodeRegisterManager->setControlValue(mechanism, HeadLightControlName, headLight);
00118     }
00119 
00120     if (nodeRegisterManager->hasControlProperty(mechanism, LaserEnableControlName))
00121     {
00122         io.getIntParam(LaserEnableName, laserEnable);
00123         nodeRegisterManager->setControlValue(mechanism, LaserEnableControlName, laserEnable);
00124     }
00125 }
00126 
00127 // controlMode functions
00128 /***************************************************************************/
00133 void JointControlCommandSeriesElastic::bootLoader(void)
00134 {
00135     NasaCommonLogging::Logger::getCategory(logCategory) << log4cpp::Priority::DEBUG << "Command transition to JointControlMode::BOOTLOADER successful on joint: " << mechanism;
00136     nodeRegisterManager->setControlValue(mechanism, BootEnableControlName,   0);
00137     nodeRegisterManager->setControlValue(mechanism, BridgeEnableControlName, 1);
00138     nodeRegisterManager->setControlValue(mechanism, BrakeReleaseControlName, 0);
00139     nodeRegisterManager->setControlValue(mechanism, MotorEnableControlName,  0);
00140     states.controlMode.state = r2_msgs::JointControlMode::BOOTLOADER;
00141 }
00142 /***************************************************************************/
00147 void JointControlCommandSeriesElastic::off(void)
00148 {
00149     NasaCommonLogging::Logger::getCategory(logCategory) << log4cpp::Priority::DEBUG << "Command transition to JointControlMode::OFF successful on joint: " << mechanism;
00150     nodeRegisterManager->setControlValue(mechanism, BootEnableControlName,   1);
00151     nodeRegisterManager->setControlValue(mechanism, BridgeEnableControlName, 1); //setting bridge enabled to 1 in off as per harrison's suggestion
00152     nodeRegisterManager->setControlValue(mechanism, BrakeReleaseControlName, 0);
00153     nodeRegisterManager->setControlValue(mechanism, MotorEnableControlName,  0);
00154     states.controlMode.state = r2_msgs::JointControlMode::OFF;
00155 }
00156 /***************************************************************************/
00161 void JointControlCommandSeriesElastic::park(void)
00162 {
00163     NasaCommonLogging::Logger::getCategory(logCategory) << log4cpp::Priority::DEBUG << "Command transition to JointControlMode::PARK successful on joint: " << mechanism;
00164     nodeRegisterManager->setControlValue(mechanism, BridgeEnableControlName, 1);
00165     nodeRegisterManager->setControlValue(mechanism, BrakeReleaseControlName, 0);
00166     nodeRegisterManager->setControlValue(mechanism, MotorEnableControlName,  1);
00167     states.controlMode.state = r2_msgs::JointControlMode::PARK;
00168 }
00169 /***************************************************************************/
00174 void JointControlCommandSeriesElastic::neutral(void)
00175 {
00176     NasaCommonLogging::Logger::getCategory(logCategory) << log4cpp::Priority::DEBUG << "Command transition to JointControlMode::NEUTRAL successful on joint: " << mechanism;
00177     nodeRegisterManager->setControlValue(mechanism, BridgeEnableControlName, 1);
00178     nodeRegisterManager->setControlValue(mechanism, BrakeReleaseControlName, 1);
00179     nodeRegisterManager->setControlValue(mechanism, MotorEnableControlName,  0);
00180     states.controlMode.state = r2_msgs::JointControlMode::NEUTRAL;
00181 }
00182 /***************************************************************************/
00187 void JointControlCommandSeriesElastic::drive(void)
00188 {
00189     NasaCommonLogging::Logger::getCategory(logCategory) << log4cpp::Priority::DEBUG << "Command transition to JointControlMode::DRIVE successful on joint: " << mechanism;
00190     nodeRegisterManager->setControlValue(mechanism, BrakeReleaseControlName, 1);
00191     nodeRegisterManager->setControlValue(mechanism, MotorEnableControlName,  1);
00192     states.controlMode.state = r2_msgs::JointControlMode::DRIVE;
00193 }
00194 
00195 // commandMode functions
00196 /***************************************************************************/
00201 void JointControlCommandSeriesElastic::motCom(void)
00202 {
00203     NasaCommonLogging::Logger::getCategory(logCategory) << log4cpp::Priority::DEBUG << "Command transition to JointControlMode::MOTCOM successful on joint: " << mechanism;
00204     nodeRegisterManager->setControlValue(mechanism, MotComSourceControlName, 0); // Brainstem mot com
00205     nodeRegisterManager->setControlValue(mechanism, ControlModeControlName,  0); // MotCom control mode
00206     states.commandMode.state = r2_msgs::JointControlCommandMode::MOTCOM;
00207 }
00208 /***************************************************************************/
00213 void JointControlCommandSeriesElastic::stallMode(void)
00214 {
00215     NasaCommonLogging::Logger::getCategory(logCategory) << log4cpp::Priority::DEBUG << "Command transition to JointControlMode::STALLMODE successful on joint: " << mechanism;
00216     nodeRegisterManager->setControlValue(mechanism, MotComSourceControlName, 1); // Embedded mot com
00217     nodeRegisterManager->setControlValue(mechanism, ControlModeControlName,  1); // StallMode control mode
00218 
00219     states.commandMode.state = r2_msgs::JointControlCommandMode::STALLMODE;
00220     return;
00221 }
00222 /***************************************************************************/
00227 void JointControlCommandSeriesElastic::multiLoopStep(void)
00228 {
00229     NasaCommonLogging::Logger::getCategory(logCategory) << log4cpp::Priority::DEBUG << "Command transition to JointControlMode::MULTILOOPSTEP successful on joint: " << mechanism;
00230 
00231     nodeRegisterManager->setControlValue(mechanism, MotComSourceControlName,   1); // Embedded mot com
00232     nodeRegisterManager->setControlValue(mechanism, ControlModeControlName,    3); // MultiLoop control mode
00233     nodeRegisterManager->setControlValue(mechanism, PosComVelocityControlName, 0); // Step
00234 
00235     states.commandMode.state = r2_msgs::JointControlCommandMode::MULTILOOPSTEP;
00236     return;
00237 }
00238 /***************************************************************************/
00243 void JointControlCommandSeriesElastic::multiLoopSmooth(void)
00244 {
00245     NasaCommonLogging::Logger::getCategory(logCategory) << log4cpp::Priority::DEBUG << "Command transition to JointControlMode::MULTILOOPSMOOTH successful on joint: " << mechanism;
00246 
00247     nodeRegisterManager->setControlValue(mechanism, MotComSourceControlName,   1); // Embedded mot com
00248     nodeRegisterManager->setControlValue(mechanism, ControlModeControlName,    3); // MultiLoop control mode
00249     nodeRegisterManager->setControlValue(mechanism, PosComVelocityControlName, 1); // Smooth
00250 
00251     states.commandMode.state = r2_msgs::JointControlCommandMode::MULTILOOPSMOOTH;
00252     return;
00253 }
00254 
00255 void JointControlCommandSeriesElastic::actuator(void)
00256 {
00257     NasaCommonLogging::Logger::getCategory(logCategory) << log4cpp::Priority::WARN << "ACTUATOR is not a valid JointControlCommandMode for " << mechanism;
00258 }
00259 
00260 // calibrationMode functions
00261 /***************************************************************************/
00266 void JointControlCommandSeriesElastic::disableCalibrationMode(void)
00267 {
00268     NasaCommonLogging::Logger::getCategory(logCategory) << log4cpp::Priority::DEBUG << "Command transition to JointControlCalibrationMode::DISABLE successful on joint: " << mechanism;
00269     nodeRegisterManager->setControlValue(mechanism, CalibrationModeControlName, 0);
00270     states.calibrationMode.state = r2_msgs::JointControlCalibrationMode::DISABLE;
00271 }
00272 /***************************************************************************/
00277 void JointControlCommandSeriesElastic::enableCalibrationMode(void)
00278 {
00279     NasaCommonLogging::Logger::getCategory(logCategory) << log4cpp::Priority::DEBUG << "Command transition to JointControlCalibrationMode::ENABLE successful on joint: " << mechanism;
00280     nodeRegisterManager->setControlValue(mechanism, CalibrationModeControlName, 1);
00281     states.calibrationMode.state = r2_msgs::JointControlCalibrationMode::ENABLE;
00282 }
00283 /***************************************************************************/
00288 void JointControlCommandSeriesElastic::resetCalibrationMode(void)
00289 {
00290     NasaCommonLogging::Logger::getCategory(logCategory) << log4cpp::Priority::DEBUG << "Command transition to JointControlCalibrationMode::ENABLE successful on joint: " << mechanism;
00291     nodeRegisterManager->setControlValue(mechanism, CalibrationModeControlName, 0);
00292     states.calibrationMode.state = r2_msgs::JointControlCalibrationMode::DISABLE;
00293 }
00294 
00295 
00296 // clearFaultMode functions
00297 /***************************************************************************/
00302 void JointControlCommandSeriesElastic::disableClearFaultMode(void)
00303 {
00304     NasaCommonLogging::Logger::getCategory(logCategory) << log4cpp::Priority::DEBUG << "Command transition to JointControlClearFaultMode::DISABLE successful on joint: " << mechanism;
00305     nodeRegisterManager->setControlValue(mechanism, ClearFaultControlName, 0);
00306     states.clearFaultMode.state = r2_msgs::JointControlClearFaultMode::DISABLE;
00307 }
00308 /***************************************************************************/
00313 void JointControlCommandSeriesElastic::enableClearFaultMode(void)
00314 {
00315     NasaCommonLogging::Logger::getCategory(logCategory) << log4cpp::Priority::DEBUG << "Command transition to JointControlClearFaultMode::ENABLE successful on joint: " << mechanism;
00316     nodeRegisterManager->setControlValue(mechanism, ClearFaultControlName, 1);
00317     states.clearFaultMode.state = r2_msgs::JointControlClearFaultMode::ENABLE;
00318 }


robodyn_mechanisms
Author(s):
autogenerated on Thu Jun 6 2019 21:22:48