Skip to content

Commit

Permalink
Replace boost::lexical_cast with std::sto*
Browse files Browse the repository at this point in the history
This requires catching an additional out_of_range
exception.
  • Loading branch information
scpeters committed Jul 20, 2016
1 parent 17d8c73 commit 3dc7ee8
Show file tree
Hide file tree
Showing 4 changed files with 275 additions and 81 deletions.
129 changes: 100 additions & 29 deletions urdf_parser/src/joint.cpp
Expand Up @@ -35,8 +35,9 @@
/* Author: John Hsu */

#include <sstream>
#include <stdexcept>
#include <string>
#include <urdf_model/joint.h>
#include <boost/lexical_cast.hpp>
#include <console_bridge/console.h>
#include <tinyxml.h>
#include <urdf_parser/urdf_parser.h>
Expand All @@ -59,13 +60,18 @@ bool parseJointDynamics(JointDynamics &jd, TiXmlElement* config)
{
try
{
jd.damping = boost::lexical_cast<double>(damping_str);
jd.damping = std::stod(damping_str);
}
catch (boost::bad_lexical_cast &e)
catch (std::invalid_argument &e)
{
CONSOLE_BRIDGE_logError("damping value (%s) is not a float: %s",damping_str, e.what());
return false;
}
catch (std::out_of_range &e)
{
CONSOLE_BRIDGE_logError("damping value (%s) out of range: %s",damping_str, e.what());
return false;
}
}

// Get joint friction
Expand All @@ -78,13 +84,18 @@ bool parseJointDynamics(JointDynamics &jd, TiXmlElement* config)
{
try
{
jd.friction = boost::lexical_cast<double>(friction_str);
jd.friction = std::stod(friction_str);
}
catch (boost::bad_lexical_cast &e)
catch (std::invalid_argument &e)
{
CONSOLE_BRIDGE_logError("friction value (%s) is not a float: %s",friction_str, e.what());
return false;
}
catch (std::out_of_range &e)
{
CONSOLE_BRIDGE_logError("friction value (%s) out of range: %s",friction_str, e.what());
return false;
}
}

if (damping_str == NULL && friction_str == NULL)
Expand Down Expand Up @@ -112,13 +123,18 @@ bool parseJointLimits(JointLimits &jl, TiXmlElement* config)
{
try
{
jl.lower = boost::lexical_cast<double>(lower_str);
jl.lower = std::stod(lower_str);
}
catch (boost::bad_lexical_cast &e)
catch (std::invalid_argument &e)
{
CONSOLE_BRIDGE_logError("lower value (%s) is not a float: %s", lower_str, e.what());
return false;
}
catch (std::out_of_range &e)
{
CONSOLE_BRIDGE_logError("lower value (%s) out of range: %s",lower_str, e.what());
return false;
}
}

// Get upper joint limit
Expand All @@ -131,13 +147,18 @@ bool parseJointLimits(JointLimits &jl, TiXmlElement* config)
{
try
{
jl.upper = boost::lexical_cast<double>(upper_str);
jl.upper = std::stod(upper_str);
}
catch (boost::bad_lexical_cast &e)
catch (std::invalid_argument &e)
{
CONSOLE_BRIDGE_logError("upper value (%s) is not a float: %s",upper_str, e.what());
return false;
}
catch (std::out_of_range &e)
{
CONSOLE_BRIDGE_logError("upper value (%s) out of range: %s",upper_str, e.what());
return false;
}
}

// Get joint effort limit
Expand All @@ -150,13 +171,18 @@ bool parseJointLimits(JointLimits &jl, TiXmlElement* config)
{
try
{
jl.effort = boost::lexical_cast<double>(effort_str);
jl.effort = std::stod(effort_str);
}
catch (boost::bad_lexical_cast &e)
catch (std::invalid_argument &e)
{
CONSOLE_BRIDGE_logError("effort value (%s) is not a float: %s",effort_str, e.what());
return false;
}
catch (std::out_of_range &e)
{
CONSOLE_BRIDGE_logError("effort value (%s) out of range: %s",effort_str, e.what());
return false;
}
}

// Get joint velocity limit
Expand All @@ -169,13 +195,18 @@ bool parseJointLimits(JointLimits &jl, TiXmlElement* config)
{
try
{
jl.velocity = boost::lexical_cast<double>(velocity_str);
jl.velocity = std::stod(velocity_str);
}
catch (boost::bad_lexical_cast &e)
catch (std::invalid_argument &e)
{
CONSOLE_BRIDGE_logError("velocity value (%s) is not a float: %s",velocity_str, e.what());
return false;
}
catch (std::out_of_range &e)
{
CONSOLE_BRIDGE_logError("velocity value (%s) out of range: %s",velocity_str, e.what());
return false;
}
}

return true;
Expand All @@ -196,13 +227,18 @@ bool parseJointSafety(JointSafety &js, TiXmlElement* config)
{
try
{
js.soft_lower_limit = boost::lexical_cast<double>(soft_lower_limit_str);
js.soft_lower_limit = std::stod(soft_lower_limit_str);
}
catch (boost::bad_lexical_cast &e)
catch (std::invalid_argument &e)
{
CONSOLE_BRIDGE_logError("soft_lower_limit value (%s) is not a float: %s",soft_lower_limit_str, e.what());
return false;
}
catch (std::out_of_range &e)
{
CONSOLE_BRIDGE_logError("soft_lower_limit value (%s) out of range: %s",soft_lower_limit_str, e.what());
return false;
}
}

// Get soft_upper_limit joint limit
Expand All @@ -216,13 +252,18 @@ bool parseJointSafety(JointSafety &js, TiXmlElement* config)
{
try
{
js.soft_upper_limit = boost::lexical_cast<double>(soft_upper_limit_str);
js.soft_upper_limit = std::stod(soft_upper_limit_str);
}
catch (boost::bad_lexical_cast &e)
catch (std::invalid_argument &e)
{
CONSOLE_BRIDGE_logError("soft_upper_limit value (%s) is not a float: %s",soft_upper_limit_str, e.what());
return false;
}
catch (std::out_of_range &e)
{
CONSOLE_BRIDGE_logError("soft_upper_limit value (%s) out of range: %s",soft_upper_limit_str, e.what());
return false;
}
}

// Get k_position_ safety "position" gain - not exactly position gain
Expand All @@ -236,13 +277,18 @@ bool parseJointSafety(JointSafety &js, TiXmlElement* config)
{
try
{
js.k_position = boost::lexical_cast<double>(k_position_str);
js.k_position = std::stod(k_position_str);
}
catch (boost::bad_lexical_cast &e)
catch (std::invalid_argument &e)
{
CONSOLE_BRIDGE_logError("k_position value (%s) is not a float: %s",k_position_str, e.what());
return false;
}
catch (std::out_of_range &e)
{
CONSOLE_BRIDGE_logError("k_position value (%s) out of range: %s",k_position_str, e.what());
return false;
}
}
// Get k_velocity_ safety velocity gain
const char* k_velocity_str = config->Attribute("k_velocity");
Expand All @@ -255,13 +301,18 @@ bool parseJointSafety(JointSafety &js, TiXmlElement* config)
{
try
{
js.k_velocity = boost::lexical_cast<double>(k_velocity_str);
js.k_velocity = std::stod(k_velocity_str);
}
catch (boost::bad_lexical_cast &e)
catch (std::invalid_argument &e)
{
CONSOLE_BRIDGE_logError("k_velocity value (%s) is not a float: %s",k_velocity_str, e.what());
return false;
}
catch (std::out_of_range &e)
{
CONSOLE_BRIDGE_logError("k_velocity value (%s) out of range: %s",k_velocity_str, e.what());
return false;
}
}

return true;
Expand All @@ -282,13 +333,18 @@ bool parseJointCalibration(JointCalibration &jc, TiXmlElement* config)
{
try
{
jc.rising.reset(new double(boost::lexical_cast<double>(rising_position_str)));
jc.rising.reset(new double(std::stod(rising_position_str)));
}
catch (boost::bad_lexical_cast &e)
catch (std::invalid_argument &e)
{
CONSOLE_BRIDGE_logError("risingvalue (%s) is not a float: %s",rising_position_str, e.what());
return false;
}
catch (std::out_of_range &e)
{
CONSOLE_BRIDGE_logError("risingvalue (%s) out of range: %s",rising_position_str, e.what());
return false;
}
}

// Get falling edge position
Expand All @@ -302,13 +358,18 @@ bool parseJointCalibration(JointCalibration &jc, TiXmlElement* config)
{
try
{
jc.falling.reset(new double(boost::lexical_cast<double>(falling_position_str)));
jc.falling.reset(new double(std::stod(falling_position_str)));
}
catch (boost::bad_lexical_cast &e)
catch (std::invalid_argument &e)
{
CONSOLE_BRIDGE_logError("fallingvalue (%s) is not a float: %s",falling_position_str, e.what());
return false;
}
catch (std::out_of_range &e)
{
CONSOLE_BRIDGE_logError("fallingvalue (%s) out of range: %s",falling_position_str, e.what());
return false;
}
}

return true;
Expand Down Expand Up @@ -341,13 +402,18 @@ bool parseJointMimic(JointMimic &jm, TiXmlElement* config)
{
try
{
jm.multiplier = boost::lexical_cast<double>(multiplier_str);
jm.multiplier = std::stod(multiplier_str);
}
catch (boost::bad_lexical_cast &e)
catch (std::invalid_argument &e)
{
CONSOLE_BRIDGE_logError("multiplier value (%s) is not a float: %s",multiplier_str, e.what());
return false;
}
catch (std::out_of_range &e)
{
CONSOLE_BRIDGE_logError("multiplier value (%s) out of range: %s",multiplier_str, e.what());
return false;
}
}


Expand All @@ -362,13 +428,18 @@ bool parseJointMimic(JointMimic &jm, TiXmlElement* config)
{
try
{
jm.offset = boost::lexical_cast<double>(offset_str);
jm.offset = std::stod(offset_str);
}
catch (boost::bad_lexical_cast &e)
catch (std::invalid_argument &e)
{
CONSOLE_BRIDGE_logError("offset value (%s) is not a float: %s",offset_str, e.what());
return false;
}
catch (std::out_of_range &e)
{
CONSOLE_BRIDGE_logError("offset value (%s) out of range: %s",offset_str, e.what());
return false;
}
}

return true;
Expand Down

0 comments on commit 3dc7ee8

Please sign in to comment.