版權聲明:本文爲博主原創文章,轉載請聯繫博主。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=;