Skip to content

Commit

Permalink
Fix for Gazebo 11
Browse files Browse the repository at this point in the history
As mentioned in point 4 of:
https://github.com/osrf/gazebo/blob/gazebo11/Migration.md#modifications

`GetCurrentProfileParam` now returns a `boost::any` which then contains
a std::any. The advice is to just use `PhysicsEngine::any_cast` instead.
  • Loading branch information
julianoes committed May 19, 2020
1 parent f021cdd commit 4acd679
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/gazebo_mavlink_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ GazeboMavlinkInterface::~GazeboMavlinkInterface() {
updateConnection_->~Connection();
}

template <class T>
T our_any_cast(const boost::any &val) {
#if GAZEBO_MAJOR_VERSION >= 11
return gazebo::physics::PhysicsEngine::any_cast<T>(val);
#else
return boost::any_cast<T>(val);
#endif
}


/// \brief A helper class that provides storage for additional parameters that are inserted into the callback.
/// \details GazeboMsgT The type of the message that will be subscribed to the Gazebo framework.
template <typename GazeboMsgT>
Expand Down Expand Up @@ -312,7 +322,7 @@ void GazeboMavlinkInterface::Load(physics::ModelPtr _model, sdf::ElementPtr _sdf
// Therefore we check these params and abort if they won't work.

presetManager->GetCurrentProfileParam("real_time_update_rate", param);
double real_time_update_rate = boost::any_cast<double>(param);
double real_time_update_rate = our_any_cast<double>(param);
const int real_time_update_rate_int = static_cast<int>(real_time_update_rate + 0.5);

if (real_time_update_rate_int % 250 != 0)
Expand All @@ -323,7 +333,7 @@ void GazeboMavlinkInterface::Load(physics::ModelPtr _model, sdf::ElementPtr _sdf
}

presetManager->GetCurrentProfileParam("max_step_size", param);
const double max_step_size = boost::any_cast<double>(param);
const double max_step_size = our_any_cast<double>(param);
if (1.0 / real_time_update_rate != max_step_size)
{
gzerr << "max_step_size of " << max_step_size
Expand Down

0 comments on commit 4acd679

Please sign in to comment.