Go to the documentation of this file.00001
00005 #include "robodyn_mechanisms/JointControlCommandWrist.h"
00006
00011 JointControlCommandWrist::JointControlCommandWrist(const std::string& mechanism, IoFunctions ioFunctions)
00012 : JointControlCommandInterface(mechanism, ioFunctions), logCategory("gov.nasa.JointControlCommandWrist")
00013 {
00014 if (io.setLiveCoeff.empty())
00015 {
00016 std::stringstream err;
00017 err << "Constructor requires 'io.setLiveCoeff' be non-empty.";
00018 NasaCommonLogging::Logger::log(logCategory, log4cpp::Priority::FATAL, err.str());
00019 throw std::invalid_argument(err.str());
00020 }
00021
00022 setParameters();
00023
00024 bootLoader();
00025 multiLoopSmooth();
00026 resetCalibrationMode();
00027 disableClearFaultMode();
00028 }
00029
00030 JointControlCommandWrist::~JointControlCommandWrist()
00031 {
00032
00033 }
00034 void JointControlCommandWrist::setParameters()
00035 {
00036 std::string parameterFile = io.getControlFile(mechanism);
00037
00039 TiXmlDocument file(parameterFile.c_str());
00040
00041 if (!file.LoadFile())
00042 {
00043 std::stringstream err;
00044 err << "Failed to load file [" << parameterFile << "]";
00045 NasaCommonLogging::Logger::log(logCategory, log4cpp::Priority::FATAL, err.str());
00046 throw std::runtime_error(err.str());
00047 }
00048
00049 TiXmlHandle doc(&file);
00050 NasaCommonLogging::Logger::log(logCategory, log4cpp::Priority::INFO, "File [" + parameterFile + "] successfully loaded.");
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 TiXmlHandle parametersElement(doc.FirstChildElement("ApiMap"));
00061
00062 if (parametersElement.ToElement())
00063 {
00064
00065 ControlModeLiveCoeffName = StringUtilities::makeFullyQualifiedRoboDynElement(mechanism, ApiMap::getXmlElementValue(parametersElement, "ControlModeLiveCoeff"));
00066 CommandModeLiveCoeffName = StringUtilities::makeFullyQualifiedRoboDynElement(mechanism, ApiMap::getXmlElementValue(parametersElement, "CommandModeLiveCoeff"));
00067 CalibrationModeLiveCoeffName = StringUtilities::makeFullyQualifiedRoboDynElement(mechanism, ApiMap::getXmlElementValue(parametersElement, "CalibrationModeLiveCoeff"));
00068 ClearFaultStateLiveCoeffName = StringUtilities::makeFullyQualifiedRoboDynElement(mechanism, ApiMap::getXmlElementValue(parametersElement, "ClearFaultStateLiveCoeff"));
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
00079
00085 void JointControlCommandWrist::getStates(r2_msgs::JointControlData& commandStates)
00086 {
00087 commandStates = states;
00088 }
00089
00090
00091
00096 void JointControlCommandWrist::bootLoader(void)
00097 {
00098 NasaCommonLogging::Logger::getCategory(logCategory) << log4cpp::Priority::DEBUG << "Command transition to JointControlMode::BOOTLOADER successful on mechanism: " << mechanism;
00099 states.controlMode.state = r2_msgs::JointControlMode::BOOTLOADER;
00100 io.setLiveCoeff(ControlModeLiveCoeffName, r2_msgs::JointControlMode::BOOTLOADER);
00102 resetCalibrationMode();
00103 }
00104
00109 void JointControlCommandWrist::off(void)
00110 {
00111 NasaCommonLogging::Logger::getCategory(logCategory) << log4cpp::Priority::DEBUG << "Command transition to JointControlMode::OFF successful on mechanism: " << mechanism;
00112 states.controlMode.state = r2_msgs::JointControlMode::OFF;
00113 io.setLiveCoeff(ControlModeLiveCoeffName, r2_msgs::JointControlMode::OFF);
00114 }
00115
00120 void JointControlCommandWrist::park(void)
00121 {
00122 NasaCommonLogging::Logger::getCategory(logCategory) << log4cpp::Priority::DEBUG << "Command transition to JointControlMode::PARK successful on mechanism: " << mechanism;
00123 states.controlMode.state = r2_msgs::JointControlMode::PARK;
00124 io.setLiveCoeff(ControlModeLiveCoeffName, r2_msgs::JointControlMode::PARK);
00125
00126 }
00127
00132 void JointControlCommandWrist::neutral(void)
00133 {
00134 NasaCommonLogging::Logger::getCategory(logCategory) << log4cpp::Priority::DEBUG << "Command transition to JointControlMode::NEUTRAL successful on mechanism: " << mechanism;
00135 states.controlMode.state = r2_msgs::JointControlMode::NEUTRAL;
00136 io.setLiveCoeff(ControlModeLiveCoeffName, r2_msgs::JointControlMode::NEUTRAL);
00137 }
00138
00143 void JointControlCommandWrist::drive(void)
00144 {
00145 NasaCommonLogging::Logger::getCategory(logCategory) << log4cpp::Priority::DEBUG << "Command transition to JointControlMode::DRIVE successful on mechanism: " << mechanism;
00146 states.controlMode.state = r2_msgs::JointControlMode::DRIVE;
00147 io.setLiveCoeff(ControlModeLiveCoeffName, r2_msgs::JointControlMode::DRIVE);
00148 }
00149
00150
00151
00156 void JointControlCommandWrist::motCom(void)
00157 {
00158 NasaCommonLogging::Logger::getCategory(logCategory) << log4cpp::Priority::DEBUG << "Command transition to JointControlCommandMode::MOTCOM successful on mechanism: " << mechanism;
00159 states.commandMode.state = r2_msgs::JointControlCommandMode::MOTCOM;
00160 io.setLiveCoeff(CommandModeLiveCoeffName, r2_msgs::JointControlCommandMode::MOTCOM);
00161 }
00162
00167 void JointControlCommandWrist::stallMode(void)
00168 {
00169 NasaCommonLogging::Logger::getCategory(logCategory) << log4cpp::Priority::INFO << "Command transition to JointControlCommandMode::STALLMODE not allowed on mechanism: " << mechanism << ", Transitioning to MULTILOOPSMOOTH";
00170 multiLoopSmooth();
00171 }
00172
00177 void JointControlCommandWrist::multiLoopStep(void)
00178 {
00179 NasaCommonLogging::Logger::getCategory(logCategory) << log4cpp::Priority::DEBUG << "Command transition to JointControlCommandMode::MULTILOOPSTEP successful on mechanism: " << mechanism;
00180 states.commandMode.state = r2_msgs::JointControlCommandMode::MULTILOOPSTEP;
00181 io.setLiveCoeff(CommandModeLiveCoeffName, r2_msgs::JointControlCommandMode::MULTILOOPSTEP);
00182 }
00183
00188 void JointControlCommandWrist::multiLoopSmooth(void)
00189 {
00190 NasaCommonLogging::Logger::getCategory(logCategory) << log4cpp::Priority::DEBUG << "Command transition to JointControlCommandMode::MULTILOOPSMOOTH successful on mechanism: " << mechanism;
00191 states.commandMode.state = r2_msgs::JointControlCommandMode::MULTILOOPSMOOTH;
00192 io.setLiveCoeff(CommandModeLiveCoeffName, r2_msgs::JointControlCommandMode::MULTILOOPSMOOTH);
00193 }
00194
00195 void JointControlCommandWrist::actuator(void)
00196 {
00197 NasaCommonLogging::Logger::getCategory(logCategory) << log4cpp::Priority::DEBUG << "Command transition to JointControlCommandMode::ACTUATOR successful on mechanism: " << mechanism;
00198 states.commandMode.state = r2_msgs::JointControlCommandMode::ACTUATOR;
00199 io.setLiveCoeff(CommandModeLiveCoeffName, r2_msgs::JointControlCommandMode::ACTUATOR);
00200 }
00201
00202
00203
00208 void JointControlCommandWrist::disableCalibrationMode(void)
00209 {
00210 NasaCommonLogging::Logger::getCategory(logCategory) << log4cpp::Priority::DEBUG << "Command transition to JointControlCalibrationMode::DISABLE successful on mechanism: " << mechanism;
00211 states.calibrationMode.state = r2_msgs::JointControlCalibrationMode::DISABLE;
00212 }
00213
00218 void JointControlCommandWrist::enableCalibrationMode(void)
00219 {
00220 NasaCommonLogging::Logger::getCategory(logCategory) << log4cpp::Priority::DEBUG << "Command transition to JointControlCalibrationMode::ENABLE successful on mechanism: " << mechanism;
00221 io.setLiveCoeff(CalibrationModeLiveCoeffName, r2_msgs::JointControlCalibrationMode::ENABLE);
00222 states.calibrationMode.state = r2_msgs::JointControlCalibrationMode::ENABLE;
00223 }
00224
00225
00230 void JointControlCommandWrist::resetCalibrationMode(void)
00231 {
00232 NasaCommonLogging::Logger::getCategory(logCategory) << log4cpp::Priority::DEBUG << "Command transition to JointControlCalibrationMode::ENABLE successful on mechanism: " << mechanism;
00233 io.setLiveCoeff(CalibrationModeLiveCoeffName, r2_msgs::JointControlCalibrationMode::UNCALIBRATED);
00234 states.calibrationMode.state = r2_msgs::JointControlCalibrationMode::UNCALIBRATED;
00235 }
00236
00237
00238
00243 void JointControlCommandWrist::disableClearFaultMode(void)
00244 {
00245 NasaCommonLogging::Logger::getCategory(logCategory) << log4cpp::Priority::DEBUG << "Command transition to JointControlClearFaultMode::DISABLE successful on mechanism: " << mechanism;
00246 io.setLiveCoeff(ClearFaultStateLiveCoeffName, r2_msgs::JointControlClearFaultMode::DISABLE);
00247 states.clearFaultMode.state = r2_msgs::JointControlClearFaultMode::DISABLE;
00248 }
00249
00254 void JointControlCommandWrist::enableClearFaultMode(void)
00255 {
00256 NasaCommonLogging::Logger::getCategory(logCategory) << log4cpp::Priority::DEBUG << "Command transition to JointControlClearFaultMode::ENABLE successful on mechanism: " << mechanism;
00257 io.setLiveCoeff(ClearFaultStateLiveCoeffName, r2_msgs::JointControlClearFaultMode::ENABLE);
00258 states.clearFaultMode.state = r2_msgs::JointControlClearFaultMode::ENABLE;
00259 }