JointControlActualWrist.cpp
Go to the documentation of this file.
00001 
00005 #include "robodyn_mechanisms/JointControlActualWrist.h"
00006 /***************************************************************************/
00015 JointControlActualWrist::JointControlActualWrist(const std::string& mechanism, IoFunctions ioFunctions)
00016     : JointControlActualInterface(mechanism, ioFunctions), logCategory("gov.nasa.JointControlActualWrist")
00017 {
00018     if (io.hasLiveCoeff.empty()    or
00019             io.getLiveCoeff.empty()    or
00020             io.setLiveCoeff.empty())
00021     {
00022         std::stringstream err;
00023         err << "Constructor requires 'io.hasLiveCoeff', 'io.getLiveCoeff', 'io.setLiveCoeff' be non-empty.";
00024         NasaCommonLogging::Logger::log(logCategory, log4cpp::Priority::FATAL, err.str());
00025         throw std::invalid_argument(err.str());
00026     }
00027 
00028     setParameters();
00029 }
00030 
00031 JointControlActualWrist::~JointControlActualWrist()
00032 {
00033     // Nothing
00034 }
00035 
00036 void JointControlActualWrist::setParameters()
00037 {
00038     std::string parameterFile = io.getControlFile(mechanism);
00039 
00041     TiXmlDocument file(parameterFile.c_str());
00042     bool loadOkay = file.LoadFile();
00043 
00044     if (!loadOkay)
00045     {
00046         std::stringstream err;
00047         err << "Failed to load file [" << parameterFile << "]";
00048         NasaCommonLogging::Logger::log(logCategory, log4cpp::Priority::FATAL, err.str());
00049         throw std::runtime_error(err.str());
00050     }
00051 
00052     TiXmlHandle doc(&file);
00053     NasaCommonLogging::Logger::log(logCategory, log4cpp::Priority::INFO, "File [" + parameterFile + "] successfully loaded.");
00054 
00055     // Check for ApiMap
00056     TiXmlHandle parametersElement(doc.FirstChildElement("ApiMap"));
00057 
00058     if (parametersElement.ToElement())
00059     {
00060         // Live coeffs names
00061         PitchLimitLiveCoeffName            = StringUtilities::makeFullyQualifiedRoboDynElement(mechanism, ApiMap::getXmlElementValue(parametersElement, "PitchLimitLiveCoeff"));
00062         YawLimitLiveCoeffName              = StringUtilities::makeFullyQualifiedRoboDynElement(mechanism, ApiMap::getXmlElementValue(parametersElement, "YawLimitLiveCoeff"));
00063         LittlesideSliderLimitLiveCoeffName = StringUtilities::makeFullyQualifiedRoboDynElement(mechanism, ApiMap::getXmlElementValue(parametersElement, "LittlesideSliderLimitLiveCoeff"));
00064         ThumbsideSliderLimitLiveCoeffName  = StringUtilities::makeFullyQualifiedRoboDynElement(mechanism, ApiMap::getXmlElementValue(parametersElement, "ThumbsideSliderLimitLiveCoeff"));
00065         SensorErrorLiveCoeffName           = StringUtilities::makeFullyQualifiedRoboDynElement(mechanism, ApiMap::getXmlElementValue(parametersElement, "SensorErrorLiveCoeff"));
00066         SliderDiffErrorLiveCoeffName       = StringUtilities::makeFullyQualifiedRoboDynElement(mechanism, ApiMap::getXmlElementValue(parametersElement, "SliderDiffErrorLiveCoeff"));
00067         ControlModeLiveCoeffName           = StringUtilities::makeFullyQualifiedRoboDynElement(mechanism, ApiMap::getXmlElementValue(parametersElement, "ControlModeLiveCoeff"));
00068         CommandModeLiveCoeffName           = StringUtilities::makeFullyQualifiedRoboDynElement(mechanism, ApiMap::getXmlElementValue(parametersElement, "CommandModeLiveCoeff"));
00069         CalibrationModeLiveCoeffName       = StringUtilities::makeFullyQualifiedRoboDynElement(mechanism, ApiMap::getXmlElementValue(parametersElement, "CalibrationModeLiveCoeff"));
00070         CoeffStateLiveCoeffName            = StringUtilities::makeFullyQualifiedRoboDynElement(mechanism, ApiMap::getXmlElementValue(parametersElement, "CoeffStateLiveCoeff"));
00071         ClearFaultStateLiveCoeffName       = StringUtilities::makeFullyQualifiedRoboDynElement(mechanism, ApiMap::getXmlElementValue(parametersElement, "ClearFaultStateLiveCoeff"));
00072     }
00073     else
00074     {
00075         std::stringstream err;
00076         err << "The file " << parameterFile << " has no element named [ApiMap]";
00077         NasaCommonLogging::Logger::log(logCategory, log4cpp::Priority::ERROR, err.str());
00078         throw std::runtime_error(err.str());
00079     }
00080 
00081     // Set up expected values @bootup
00082     io.setLiveCoeff(ControlModeLiveCoeffName,     r2_msgs::JointControlMode::BOOTLOADER);
00083     io.setLiveCoeff(CommandModeLiveCoeffName,     r2_msgs::JointControlCommandMode::MULTILOOPSMOOTH);
00084     io.setLiveCoeff(CalibrationModeLiveCoeffName, r2_msgs::JointControlCalibrationMode::UNCALIBRATED);
00085     io.setLiveCoeff(CoeffStateLiveCoeffName,      r2_msgs::JointControlCoeffState::LOADED);
00086     io.setLiveCoeff(ClearFaultStateLiveCoeffName, r2_msgs::JointControlClearFaultMode::DISABLE);
00087 
00088     // Set up default values @bootup (these will get overwritten in JointCommandApi)
00089     io.setLiveCoeff(PitchLimitLiveCoeffName,            0);
00090     io.setLiveCoeff(YawLimitLiveCoeffName,              0);
00091     io.setLiveCoeff(LittlesideSliderLimitLiveCoeffName, 0);
00092     io.setLiveCoeff(ThumbsideSliderLimitLiveCoeffName,  0);
00093     io.setLiveCoeff(SensorErrorLiveCoeffName,           0);
00094     io.setLiveCoeff(SliderDiffErrorLiveCoeffName,       0);
00095 }
00096 
00097 /***************************************************************************/
00103 void JointControlActualWrist::getStates(r2_msgs::JointControlData& actualStates)
00104 {
00105     updateCommandModeState(); // Must come before updateControlModeState()
00106     updateControlModeState();
00107     updateCalibrationModeState();
00108     updateClearFaultModeState();
00109     updateCoeffState();
00110     actualStates = states;
00111 }
00112 /***************************************************************************/
00117 void JointControlActualWrist::updateControlModeState(void)
00118 {
00119 
00120     states.controlMode.state = r2_msgs::JointControlMode::INVALID;
00121 
00122     // Verify existence of live coeffs
00123     if (not(io.hasLiveCoeff(ControlModeLiveCoeffName)))
00124     {
00125         NasaCommonLogging::Logger::getCategory(logCategory) << log4cpp::Priority::ERROR << mechanism << ": Missing live coeff: " << ControlModeLiveCoeffName;
00126         return;
00127     }
00128 
00129     if (not(io.hasLiveCoeff(PitchLimitLiveCoeffName)))
00130     {
00131         NasaCommonLogging::Logger::getCategory(logCategory) << log4cpp::Priority::ERROR << mechanism << ": Missing live coeff: " << PitchLimitLiveCoeffName;
00132         return;
00133     }
00134 
00135     if (not(io.hasLiveCoeff(YawLimitLiveCoeffName)))
00136     {
00137         NasaCommonLogging::Logger::getCategory(logCategory) << log4cpp::Priority::ERROR << mechanism << ": Missing live coeff: " << YawLimitLiveCoeffName;
00138         return;
00139     }
00140 
00141     if (not(io.hasLiveCoeff(LittlesideSliderLimitLiveCoeffName)))
00142     {
00143         NasaCommonLogging::Logger::getCategory(logCategory) << log4cpp::Priority::ERROR << mechanism << ": Missing live coeff: " << LittlesideSliderLimitLiveCoeffName;
00144         return;
00145     }
00146 
00147     if (not(io.hasLiveCoeff(ThumbsideSliderLimitLiveCoeffName)))
00148     {
00149         NasaCommonLogging::Logger::getCategory(logCategory) << log4cpp::Priority::ERROR << mechanism << ": Missing live coeff: " << ThumbsideSliderLimitLiveCoeffName;
00150         return;
00151     }
00152 
00153     if (not(io.hasLiveCoeff(SensorErrorLiveCoeffName)))
00154     {
00155         NasaCommonLogging::Logger::getCategory(logCategory) << log4cpp::Priority::ERROR << mechanism << ": Missing live coeff: " << SensorErrorLiveCoeffName;
00156         return;
00157     }
00158 
00159     if (not(io.hasLiveCoeff(SliderDiffErrorLiveCoeffName)))
00160     {
00161         NasaCommonLogging::Logger::getCategory(logCategory) << log4cpp::Priority::ERROR << mechanism << ": Missing live coeff: " << SliderDiffErrorLiveCoeffName;
00162         return;
00163     }
00164 
00165     states.controlMode.state = io.getLiveCoeff(ControlModeLiveCoeffName);
00166 
00167     // Check for FAULTED state
00168     if ((io.getLiveCoeff(PitchLimitLiveCoeffName)            == 1) ||
00169             (io.getLiveCoeff(YawLimitLiveCoeffName)              == 1) ||
00170             (io.getLiveCoeff(LittlesideSliderLimitLiveCoeffName) == 1) ||
00171             (io.getLiveCoeff(ThumbsideSliderLimitLiveCoeffName)  == 1) ||
00172             (io.getLiveCoeff(SensorErrorLiveCoeffName)           == 1) ||
00173             (io.getLiveCoeff(SliderDiffErrorLiveCoeffName)       == 1))
00174     {
00175         if (states.controlMode.state != r2_msgs::JointControlMode::FAULTED)
00176         {
00177             NasaCommonLogging::Logger::getCategory(logCategory) << log4cpp::Priority::DEBUG << "Transition to JointControlMode::FAULTED on joint: " << mechanism;
00178             states.controlMode.state = r2_msgs::JointControlMode::FAULTED;
00179         }
00180 
00181         return;
00182     }
00183 
00184     // Check for valid DRIVE ( DRIVE cannot occur unless calibration is DISABLE )
00185     if (states.controlMode.state == r2_msgs::JointControlMode::DRIVE &&
00186             (io.getLiveCoeff(CalibrationModeLiveCoeffName) != r2_msgs::JointControlCalibrationMode::DISABLE))
00187     {
00188         NasaCommonLogging::Logger::getCategory(logCategory) << log4cpp::Priority::ERROR << mechanism << ": Can not DRIVE until JointControlCalibrationMode is DISABLE";
00189         states.controlMode.state = r2_msgs::JointControlMode::PARK;
00190     }
00191 
00192 }
00193 /***************************************************************************/
00198 void JointControlActualWrist::updateCommandModeState(void)
00199 {
00200     if (not(io.hasLiveCoeff(CommandModeLiveCoeffName)))
00201     {
00202         states.commandMode.state = r2_msgs::JointControlCommandMode::INVALID;
00203         NasaCommonLogging::Logger::getCategory(logCategory) << log4cpp::Priority::ERROR << mechanism << ": Missing live coeff: " << CommandModeLiveCoeffName;
00204         return;
00205     }
00206 
00207     states.commandMode.state = io.getLiveCoeff(CommandModeLiveCoeffName);
00208 }
00209 /***************************************************************************/
00214 void JointControlActualWrist::updateCalibrationModeState(void)
00215 {
00216     if (not(io.hasLiveCoeff(CalibrationModeLiveCoeffName)))
00217     {
00218         states.calibrationMode.state = r2_msgs::JointControlCalibrationMode::UNCALIBRATED;
00219         NasaCommonLogging::Logger::getCategory(logCategory) << log4cpp::Priority::ERROR << mechanism << ": Missing live coeff: " << CalibrationModeLiveCoeffName;
00220         return;
00221     }
00222 
00223     states.calibrationMode.state = io.getLiveCoeff(CalibrationModeLiveCoeffName);
00224 }
00225 /***************************************************************************/
00230 void JointControlActualWrist::updateClearFaultModeState(void)
00231 {
00232     if (not(io.hasLiveCoeff(ClearFaultStateLiveCoeffName)))
00233     {
00234         states.clearFaultMode.state = r2_msgs::JointControlClearFaultMode::DISABLE;
00235         NasaCommonLogging::Logger::getCategory(logCategory) << log4cpp::Priority::ERROR << mechanism << ": Missing live coeff: " << ClearFaultStateLiveCoeffName;
00236         return;
00237     }
00238 
00239     states.clearFaultMode.state = io.getLiveCoeff(ClearFaultStateLiveCoeffName);
00240 }
00241 /***************************************************************************/
00246 void JointControlActualWrist::updateCoeffState(void)
00247 {
00248     if (not(io.hasLiveCoeff(CoeffStateLiveCoeffName)))
00249     {
00250         states.coeffState.state = r2_msgs::JointControlCoeffState::NOTLOADED;
00251         NasaCommonLogging::Logger::getCategory(logCategory) << log4cpp::Priority::ERROR << mechanism << ": Missing live coeff: " << CoeffStateLiveCoeffName;
00252         return;
00253     }
00254 
00255     states.coeffState.state = io.getLiveCoeff(CoeffStateLiveCoeffName);
00256 }
00257 
00258 void JointControlActualWrist::getFaults(diagnostic_msgs::DiagnosticStatus& faultStatus)
00259 {
00260     faultStatus.name = mechanism.c_str();
00261     faultStatus.hardware_id = mechanism.c_str();
00262     faultStatus.level = diagnostic_msgs::DiagnosticStatus::OK;
00263     faultStatus.message = "OK";
00264 
00265     if (states.controlMode.state == r2_msgs::JointControlMode::FAULTED)
00266     {
00267         faultStatus.level = diagnostic_msgs::DiagnosticStatus::ERROR;
00268         std::stringstream message;
00269         message << "FAULT state detected on " << mechanism << ": FAULT";
00270 
00271         if (io.getLiveCoeff(PitchLimitLiveCoeffName)            == 1)
00272         {
00273             message << ", PitchLimit";
00274         }
00275 
00276         if (io.getLiveCoeff(YawLimitLiveCoeffName)              == 1)
00277         {
00278             message << ", YawLimit";
00279         }
00280 
00281         if (io.getLiveCoeff(LittlesideSliderLimitLiveCoeffName) == 1)
00282         {
00283             message << ", LittlesideSliderLimit";
00284         }
00285 
00286         if (io.getLiveCoeff(ThumbsideSliderLimitLiveCoeffName)  == 1)
00287         {
00288             message << ", ThumbsideSliderLimit";
00289         }
00290 
00291         if (io.getLiveCoeff(SensorErrorLiveCoeffName)           == 1)
00292         {
00293             message << ", SensorError";
00294         }
00295 
00296         if (io.getLiveCoeff(SliderDiffErrorLiveCoeffName)       == 1)
00297         {
00298             message << ", SliderDiffError";
00299         }
00300 
00301         faultStatus.message = message.str().c_str();
00302     }
00303 }


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