Gazebo | Ignition | Community
Ask Your Question
0

error: ‘this’ argument discards qualifiers [-fpermissive]

asked 2021-04-07 09:46:56 -0500

This is my code for the Adaptive Monte Carlo localization(AMCL) algorithm, a plugin using for ign gazebo(citadel) and ROS(melodic).

void amcl::Configure(const Entity &_entity, const std::shared_ptr<const sdf::element=""> &_sdf, EntityComponentManager &_ecm, EventManager &_eventMgr)

{ this->dataPtr->model = Model(_entity); if (!this->dataPtr->model.Valid(_ecm)) {

ignerr << "amcl plugin should be attached to a model entity. "
       << "Failed to initialize." << std::endl;
return;
}

// Obtain parameters from xacro file

if(_sdf->HasElement("topicRate"))
{
    rate_ = _sdf->GetElement("topicRate")->Get<double>(); #############ERROR IN THIS LINE 

}
else
{
  rate_ = 10.0;
}


if(_sdf->HasElement("fixedFrame"))

{
    fixed_frame_ = _sdf->GetElement("fixedFrame")->Get<std::string>(); ########ERROR IN THIS LINE 

}
else
{
    fixed_frame_ = "map";
}

if(_sdf->HasElement("robotFrame"))

{
    robot_frame_ = _sdf->GetElement("robotFrame")->Get<std::string>(); #####ERROR IN THIS LINE

}
else
{
    robot_frame_ = "base_link";
}

Error (as shown in the terminal)

error: passing ‘std::__shared_ptr_access<const sdf::v9::element,="" (__gnu_cxx::lock_policy)2,="" false,="" false="">::element_type’ {aka ‘const sdf::v9::Element’} as ‘this’ argument discards qualifiers [-fpermissive] rate = _sdf->GetElement("topicRate")->Get();

I have marked the lines in the code which throw this error.

Complete code can be found here with the header file (Amcl.hh)

Can anybody suggest a solution?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2021-04-07 11:20:45 -0500

I am answering my own question To understand the proposed changes, one should have some familiarity with concepts related to ignition gazebo

change Line 95, 107, 118 with the following lines

auto rate_ = _sdf->Get<double>("topicRate"); //line 95

auto fixed_frame_ = _sdf->Get<std::string>("fixedFrame"); //107

auto robot_frame_ = _sdf->Get<std::string>("robotFrame"); //118
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2021-04-07 09:46:56 -0500

Seen: 351 times

Last updated: Apr 07 '21