rpg_ig_active源码阅读(五)
作者:互联网
今天主要看ig_active_reconstruction
这个文件没有可执行的节点 应该是基础的实现
rpg_ig_active源码阅读
- ig_active_reconstruction.cpp
- robot_communication_interface.hpp
- views_communication_interface.hpp
- world_representation_communication_interface.hpp
最最主要的是
basic_view_planner.cpp
也是主要功能的实现
之前看过了,可以参考 这个,这次粗略看,从整体看
看完感觉它是 比较底层的实现+main函数中的主流程的实现 主要还是看上层的怎么调用
ig_active_reconstruction.cpp
namespace ig_active_reconstruction
只有一个类BasicViewPlanner
- 结构enum struct Status 表征状态
- 结构/类 struct Config 配置文件
- 构造函数
BasicViewPlanner::BasicViewPlanner(Config config)
: config_(config)
, robot_comm_unit_(nullptr)
, views_comm_unit_(nullptr)
, world_comm_unit_(nullptr)
, utility_calculator_(nullptr)
, goal_evaluation_module_(nullptr)
, status_(Status::UNINITIALIZED)
, runProcedure_(false)
, pauseProcedure_(false)
{
}
三个通讯接口
- 机器人的通讯接口
virtual void setRobotCommUnit( boost::shared_ptr<robot::CommunicationInterface> robot_comm_unit );
- 视野空间的通讯接口
virtual void setViewsCommUnit( boost::shared_ptr<views::CommunicationInterface> views_comm_unit );
- 环境表示的通讯接口
virtual void setWorldCommUnit( boost::shared_ptr<world_representation::CommunicationInterface> world_comm_unit );
与此对应的有三个成员变量和三个namespace里的CommunicationInterface通讯接口类
boost::shared_ptr<robot::CommunicationInterface> robot_comm_unit_; //! Robot communication interface with which the view planner corresponds.
boost::shared_ptr<views::CommunicationInterface> views_comm_unit_; //! Viewspace communication interface with which the view planner corresponds.
boost::shared_ptr<world_representation::CommunicationInterface> world_comm_unit_; //! World representation communication interface with which the view planner corresponds.
三个通讯接口都是判断状态然后赋值,比如views_comm_unit_ = views_comm_unit;
计算相关
virtual void setUtility( boost::shared_ptr<UtilityCalculator> utility_calculator );
也是赋值,对应成员变量boost::shared_ptr<UtilityCalculator> utility_calculator_
效用方程的计算virtual void setGoalEvaluationModule( boost::shared_ptr<GoalEvaluationModule> goal_evaluation_module );
对应boost::shared_ptr<GoalEvaluationModule> goal_evaluation_module_
目标的评估机制
表征状态的函数
virtual bool run();
virtual void pause();
virtual void stop();
virtual Status status();
受保护的函数
bool isReady();
void main();
void pausePoint();
其他成员变量
Status status_;
std::thread running_procedure_; //线程
std::mutex mutex_;
bool runProcedure_;
bool pauseProcedure_;
boost::shared_ptr<views::ViewSpace> viewspace_;
main函数
这里写过了,贴一个官方的解释
Iterates through the following steps:
- Issue data collection command
- First iteration only: Demand view space, otherwise calculate viewspace subset based on settings.
- Get cost for each view candidate
- Get predicted information gain for each view candidate
- Calculate utility function.
- Choose next best view with highest utility function result.
- Check if termination criterion is fulfilled.
- Move to next best view
接下来主要看三个通讯接口文档
robot_communication_interface.hpp
没有对应的cpp文件
namespace ig_active_reconstruction 下的namespace robot
只有一个类CommunicationInterface
是一个基类 下面有三个子类
一个在这里写过,是flying_gazebo_stereo_cam工作空间下的,另外两个也是robot空间下的,子类分别为RosClientCI
和RosServerCI
基类没有实现任何,只提供了几个纯虚函数作为接口
virtual views::View getCurrentView()=0;
virtual ReceptionInfo retrieveData()=0;
virtual MovementCost movementCost( views::View& target_view )=0;
virtual MovementCost movementCost( views::View& start_view, views::View& target_view, bool fill_additional_information )=0;
virtual bool moveTo( views::View& target_view )=0;
views_communication_interface.hpp
也是实现了基类
namespace ig_active_reconstruction 下的namespace views
只有一个类CommunicationInterface
是一个基类
包含了两个struct和几个纯虚函数
状态和更新结果
enum struct ViewSpaceStatus
{
OK,
BAD,
NONE_AVAILABLE
};
enum struct ViewSpaceUpdateResult
{
SUCCEEDED=0,
FAILED,
NOT_AVAILABLE
};
纯虚函数
virtual const ViewSpace& getViewSpace()=0;
virtual ViewSpaceUpdateResult addViews( std::vector<View>& new_views )=0;
virtual ViewSpaceUpdateResult addView( View new_view )=0;
virtual ViewSpaceUpdateResult deleteViews( std::vector<View::IdType>& view_ids )=0;
virtual ViewSpaceUpdateResult deleteView( View::IdType view_id )=0;
纯虚函数加const修饰的话,其子类
- 不加const 子类函数覆盖父类
- 加const 标准的多态
继承的子类也有三个,都是views
工作空间内的,分别是类SimpleViewSpaceModule
,RosClientCI
和RosServerCI
可以以SimpleViewSpaceModule
为例 看函数怎么实现的
SimpleViewSpaceModule
只有一个成员变量ViewSpace viewspace_
构造函数
传入文件的路径,使用loadFromFile
函数
SimpleViewSpaceModule::SimpleViewSpaceModule( std::string file_source )
{
if( file_source!="" )
{
loadFromFile(file_source);
}
}
其它函数
- void loadFromFile( std::string path );
viewspace_.loadFromFile(path);
读入 - void saveToFile( std::string filename ); 保存到文件里
- virtual const ViewSpace& getViewSpace(); 直接
ViewSpace viewspace_;
- addViews/addView/deleteViews/deleteView 都是基于viewspace_的修改要么push_back要么deleteView
这几个函数都涉及viewspace
的函数 具体实现在view_space.cpp
这里不展开介绍了
world_representation_communication_interface.hpp
也是实现了基类
namespace ig_active_reconstruction 下的namespace world_representation
只有一个类CommunicationInterface 是一个基类
继承的子类也有三个,一个是octomap
工作空间下的IgCalculator
另外两个都是world_representation
工作空间下的RosClientCI
和RosServerCI
与ig和map有关的几个类
struct ResultInformation
包含被枚举的状态 还有构造函数 以及几个重载操作符operator
枚举状态
IG是否被成功计算的状态
enum Enum
{
SUCCEEDED=0, //! IG was successfully calculated.
FAILED, //! IG could not be calculated, an error occured.
UNKNOWN_METRIC //! The IG name was unknown and hence the IG could not be calculated
}res;
struct IgRetrievalResult
struct IgRetrievalResult
{
ResultInformation status; //! Status.
double predicted_gain; //! Calculated information gain if the call succeeded, undefined otherwise.
};
包含上面那个类 和一个double类型的计算好后的增益
struct IgRetrievalConfig IG计算配置
- struct SubWindow : x和y的最小最大值
- SubWindow ray_window : 图像的一部分
- ray_resolution_x/ray_resolution_y x和y方向分别有多少个射线
- double max_ray_depth 默认是10 射线的最大深度
struct IgRetrievalCommand IG计算要求
movements::PoseVector path; //! Describes the path for which the information gain shall be calculated. Note that in the current octomap-based implementation provided with the framework this is not yet implemented: Only the first pose will be considered and no casts into the future attempted.
//只考虑第一个位姿 不考虑未来的
std::vector<std::string> metric_names; //! Vector with the names of all metrics that shall be calculated. Only considered if metric_ids is empty.
// 指标的名称和id
std::vector<unsigned int> metric_ids; //! Vector with the ids of all metrics that shall be calculated. Takes precedence over metric_names.
IgRetrievalConfig config;
struct MapMetricRetrievalResult 指标计算结果
struct MapMetricRetrievalResult
{
ResultInformation status; //! Status.
double value; //! Calculated information gain if the call succeeded, undefined otherwise.
};
纯虚函数
- computeViewIg
virtual ResultInformation computeViewIg(IgRetrievalCommand& command, ViewIgResult& output_ig)=0;
command里有pose信息和要计算的ig名字 output_ig是计算ig的结果
- computeMapMetric
计算整个地图的指标 - availableIgMetrics
- availableMapMetrics
可以用的指标集合
对应的函数实现文件里world_representation_communication_interface.cpp
只实现了两个 有用的
// 配置的参数 window的范围和xy方向的分辨率 和深度
CommunicationInterface::IgRetrievalConfig::IgRetrievalConfig()
: ray_resolution_x(1.0)
, ray_resolution_y(1.0)
, max_ray_depth(10.0)
{
ray_window.min_x_perc = 0.0;
ray_window.max_x_perc = 1.0;
ray_window.min_y_perc = 0.0;
ray_window.max_y_perc = 1.0;
}
标签:struct,views,函数,virtual,源码,active,ig,view 来源: https://blog.csdn.net/weixin_42518636/article/details/112852179