版权声明:本文为博主原创文章,转载请联系博主。https://mp.csdn.net/mdeditor/82948567#
接口概述
- 车辆Footprint主要表示了车辆在俯视图中的大小尺寸;
- 通常设置的数值是根据车辆的实际尺寸来表示;
- 可以选用长方形或者五边形来表示车辆的具体尺寸;
- 此处的topic消息类型选用的是自定义的消息类型,如何自定义消息请见代码详述部分;
代码详述
1. 相关footprint消息类型自定义
1.1 新建msg文件:perception_msg
/**
* @brief define the new message type
* @reference link: https://blog.csdn.net/u013453604/article/details/72903398
*/
std_msgs/Header header
geometry_msgs/Point[i] points//此处Point[i] 预设footprint的数组大小
1.2 修改package.xml
需要利用message_generation生成c++能使用的代码
<build_depend>message_generation</build_depend>
<run_depend>message_runtime</run_depend>
1.3 修改CMakeLists.txt
(1)首先调用find_package查找依赖的包,必备的有roscpp rospy message_generation,其他根据具体类型添加,比如上面的msg文件中用到了geometry_msgs类型,那么必须查找geometry_msgs
find_package(catkin REQUIRED
COMPONENTS
roscpp
rospy
message_generation
std_msgs
geometry_msgs)
(2) add_message_files,指定msg文件
add_message_files(
FILES
perception_msg.msg
)
(3) generate_messages,指定生成消息文件时的依赖项,比如上面嵌套了其他消息类型如geometry_msgs,那么必须注明
generate_messages(
DEPENDENCIES
std_msgs
geometry_msgs
)
(4) catkin_package设置运行依赖
catkin_package(
INCLUDE_DIRS include
LIBRARIES dwa_local_planner
CATKIN_DEPENDS
roscpp
message_runtime
geometry_msgs
)
2.footprint点的读取
/**
* @brief read footprint size
* @param periception_msg 自定义新的消息类型
* @param my The y coordinate of the cell
* @param cost The cost to set the cell to
*/
void dwa_planner_node::footprint_cb(dwa_local_planner::perception_msg footprint_spec_msg)
{
std::vector<geometry_msgs::Point> footprint_spec;
for (int i = 0; i < footprint_spec_msg.points.size(); i++)
{
footprint_spec.push_back(footprint_spec_msg.points[i]);
}
3.footprint点的数值设置
/**
* @brief set the value of the footprint points
*/
dwa_local_planner::perception_msg output;
output.points[0].x=;
output.points[0].y=;
output.points[0].z=;
output.points[1].x=;
output.points[1].y=;
output.points[1].z=;
output.points[2].x=;
output.points[2].y=;
output.points[2].z=;
output.points[3].x=;
output.points[3].y=;
output.points[3].z=;
output.points[4].x=;
output.points[4].y=;
output.points[4].z=;
.
.
.
output.points[i].x=;
output.points[i].y=;
output.points[i].z=;