c++ - 'this' 参数丢弃限定符 [-fpermissive]
问题描述
这是我使用 ROS 的自适应蒙特卡洛定位 (AMCL) 算法的代码。
#include <ignition/plugin/Register.hh>
#include <ignition/gazebo/Model.hh>
#include <ignition/gazebo/EntityComponentManager.hh>
#include <ignition/gazebo/Util.hh>
#include <ignition/gazebo/System.hh>
//ROS libraries
#include <ros/ros.h>
#include <ros/callback_queue.h>
// Dependencies
#include <geometry_msgs/PoseWithCovarianceStamped.h>
#include <tf2_ros/transform_listener.h>
#include <geometry_msgs/TransformStamped.h>
// STL
#include <memory>
#include <thread>
#include <string>
using namespace ignition;
using namespace gazebo;
using namespace systems;
////////////////////////////////////////////////////////////////////////////
class ignition::gazebo::systems::amclPrivate
{
public: Model model{kNullEntity};
public: bool updateAmclPose(const UpdateInfo &_info,
const EntityComponentManager &_ecm);
};
/////////////////////////////////////////////////////////////////////////////
amcl::amcl() :
System(), dataPtr(std::make_unique<amclPrivate>())
{
tfListener_(tfBuffer_)
}
/////////////////////////////////////////////////////////////////////////////
amcl::~amcl() = default;
{
// Disable callback queue
amcl_queue_.clear();
amcl_queue_.disable();
// Shutdown ROS node handle
amcl_nh_.shutdown();
// Wait for child thread to join
if(thread_ptr_->joinable())
thread_ptr_->join();
}
/////////////////////////////////////////////////////////////////////////////
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>(); ########################line 95
}
else
{
rate_ = 10.0;
}
if(_sdf->HasElement("fixedFrame"))
{
fixed_frame_ = _sdf->GetElement("fixedFrame")->Get<std::string>(); ############################line 107
}
else
{
fixed_frame_ = "map";
}
if(_sdf->HasElement("robotFrame"))
{
robot_frame_ = _sdf->GetElement("robotFrame")->Get<std::string>(); ######################line 118
}
else
{
robot_frame_ = "base_link";
}
// Ensure that ROS node for Gazebo has been initialized
if(!ros::isInitialized())
{
int argc = 0; char ** argv = NULL;
ros::init(argc, argv, "ignition_gazebo_robot", ros::init_options::NoSigintHandler);
}
// Set callback queue
amcl_nh_.setCallbackQueue(& amcl_queue_);
amcl_pub_ = amcl_nh_.advertise<geometry_msgs::PoseWithCovarianceStamped>("amcl",1,true);
thread_ptr_ = std::make_shared<std::thread>([this]()
{
// Set process rate
ros::Rate r(this->rate_);
while (this->amcl_nh_.ok())
{
this->updateAmclPose(const UpdateInfo &_info,
const EntityComponentManager &_ecm);
this->amcl_pub_.publish(this->msg_);
this->amcl_queue_.callAvailable(ros::WallDuration(0.0));
r.sleep();
}
}
// Notify plugin status
ROS_INFO_STREAM(
ros::this_node::getName() << " plugin amcl pose successfully loaded."
);
}
//////////////////////////////////////////////////////////////////////////////////////
void amcl::PreUpdate(const ignition::gazebo::UpdateInfo &_info,
ignition::gazebo::EntityComponentManager &_ecm)
{
IGN_PROFILE("amcl::PreUpdate");
if (_info.dt < std::chrono::steady_clock::duration::zero())
{
ignwarn << "Detected jump back in time ["
<< std::chrono::duration_cast<std::chrono::seconds>(_info.dt).count()
<< "s]. System may not work properly." << std::endl;
}
///////////////////////////////////////////////////////////////////////////////////////
void amcl::PostUpdate(const ignition::gazebo::UpdateInfo &_info,
ignition::gazebo::EntityComponentManager &_ecm)
{
IGN_PROFILE("amcl::PostUpdate");
// Nothing left to do if paused.
if (_info.paused)
return;
this->dataPtr->updateAmclPose(const UpdateInfo &_info,const EntityComponentManager &_ecm)
///////////////////////////////////////////////////////////////////////////////////////
bool amcl::updateAmclPose(const UpdateInfo &_info,
const EntityComponentManager &_ecm)
{
IGN_PROFILE("amcl::updateAmclPose");
bool isok {false};
try
{
if(tfBuffer_.canTransform(fixed_frame_, robot_frame_, ros::Time(0)))
{
read_transformation_ = tfBuffer_.lookupTransform(fixed_frame_, robot_frame_, ros::Time(0), ros::Duration(60.0));
msg_.header.frame_id = fixed_frame_;
msg_.header.stamp = ros::Time::now();
msg_.pose.pose.position.x = read_transformation_.transform.translation.x;
msg_.pose.pose.position.y = read_transformation_.transform.translation.y;
msg_.pose.pose.position.z = read_transformation_.transform.translation.z;
msg_.pose.pose.orientation.x = read_transformation_.transform.rotation.x;
msg_.pose.pose.orientation.y = read_transformation_.transform.rotation.y;
msg_.pose.pose.orientation.z = read_transformation_.transform.rotation.z;
msg_.pose.pose.orientation.w = read_transformation_.transform.rotation.w;
}
isok = true;
}
catch(const tf2::TimeoutException & e)
{
ROS_ERROR_STREAM(
ros::this_node::getName() << " " << __func__ <<
" timeout exception: " << e.what()
);
return isok;
}
catch(const tf2::TransformException & e)
{
ROS_ERROR_STREAM(
ros::this_node::getName() << " " << __func__ <<
" transform exception: " << e.what()
);
return isok;
}
return isok;
}
}
}
错误(在第 95、107 和 118 行)
错误:传递 'std::__shared_ptr_access<const sdf::v9::Element, (__gnu_cxx:: Lock_policy)2, false, false>::element_type' {aka 'const sdf::v9::Element'} 作为 'this ' 参数丢弃限定符 [-fpermissive] rate = _sdf->GetElement("topicRate")->Get();
完全错误(如终端所示)
/home/adwaitnaik/plugin_ws/src/amcl/Amcl.cc:在成员函数'虚空点火::gazebo::v3::systems::amcl::Configure(const Entity&,const std::shared_ptr&,点火:: Gazebo::v3::EntityComponentManager&,ignition::gazebo::v3::EventManager&)': /home/adwaitnaik/plugin_ws/src/amcl/Amcl.cc:95:45: 错误: 传递'std::__shared_ptr_access<const sdf::v9::Element, (__gnu_cxx:: Lock_policy)2, false, false>::element_type' {aka 'const sdf::v9::Element'} as 'this' 参数丢弃限定符 [-fpermissive] 率= _sdf->GetElement("topicRate")->Get(); ^ 在 /usr/include/ignition/gazebo3/ignition/gazebo/System.hh:28、/home/adwaitnaik/plugin_ws/src/amcl/Amcl.hh:18、/home/adwaitnaik/plugin_ws/ 中包含的文件中src/amcl/Amcl.cc:10: /usr/include/sdformat-9.5/sdf/Element.hh:330:24: 注意:在调用'sdf::v9::ElementPtr sdf::v9::Element: :GetElement(const string&)' public: ElementPtr GetElement(const std::string &_name); ^~~~~~~~~~ /home/adwaitnaik/plugin_ws/src/amcl/Amcl.cc:107:53: 错误: 传递'std::__shared_ptr_access<const sdf::v9::Element, (__gnu_cxx: : Lock_policy)2, false, false>::element_type' {aka 'const sdf::v9::Element'} as 'this' 参数丢弃限定符 [-fpermissive] fixed_frame= _sdf->GetElement("fixedFrame")->Getstd::string(); ^ 在 /usr/include/ignition/gazebo3/ignition/gazebo/System.hh:28、/home/adwaitnaik/plugin_ws/src/amcl/Amcl.hh:18、/home/adwaitnaik/plugin_ws/ 中包含的文件中src/amcl/Amcl.cc:10: /usr/include/sdformat-9.5/sdf/Element.hh:330:24: 注意:在调用'sdf::v9::ElementPtr sdf::v9::Element: :GetElement(const string&)' public: ElementPtr GetElement(const std::string &_name); ^~~~~~~~~~ /home/adwaitnaik/plugin_ws/src/amcl/Amcl.cc:118:53: 错误: 传递'std::__shared_ptr_access<const sdf::v9::Element, (__gnu_cxx: : Lock_policy)2, false, false>::element_type' {aka 'const sdf::v9::Element'} as 'this' 参数丢弃限定符 [-fpermissive] robot_frame = _sdf->GetElement("robotFrame")-> Getstd::string(); ^
该行在代码中被标记。
我提到了这个链接,但无法得到解决方案
有人可以提出解决方法吗?
PS:我在第 107 行和第 118 行遇到了同样的错误(在代码中用 '#######' 标记)
解决方案
要了解提议的更改,应该熟悉与点火凉亭相关的概念
用以下几行更改第 95、107、118 行
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
可能的解释
参考这个
推荐阅读
- typescript - 没有“新”就无法调用类构造函数构造 - aws cdk
- c# - 如何使用 ClosedXML 读取 Excel 下拉列表值
- javascript - 这算作 GA 中的两次综合浏览量,我需要第二次综合浏览量吗?
- c++ - 在 getBuildTasks() 中找不到客户端 URI - VSCode - C++
- javascript - 可见性断言差异
- list - 在涉及算术运算和计数元素的列表上递归?
- ios - 如何使用 swift 从 ios Healthkit 应用程序获取低心率通知?
- c++ - C++ //动态内存分配
- c# - Azure Webjob 中的“SqlConnection 不支持并行事务”
- javascript - 复制 chrome://offline-internals/ 功能 - chrome.send 不是函数