当前位置:   article > 正文

运行cartographer的landmark demo与建立发布静态landmark节点_cartographer的landmark如何设定绝对坐标

cartographer的landmark如何设定绝对坐标

官网链接:Running Cartographer ROS on a demo bag — Cartographer ROS documentation

1.运行landmark dmeo

1.1 下载数据包

wget -P ~/Downloads https://storage.googleapis.com/cartographer-public-data/bags/mir/landmarks_demo_uncalibrated.bag

1.2 在src下 下载cartographer_mir

  1. cd car2_ws/src
  2. git clone https://github.com/googlecartographer/cartographer_mir.git

1.3 重新编译car2_ws

  1. catkin_make_isolated --install --use-ninja
  2. source install_isolated/setup.bash

1.4 运行demo:

roslaunch cartographer_mir offline_mir_100_rviz.launch bag_filenames:=${HOME}/Downloads/landmarks_demo_uncalibrated.bag

1.5 运行结果:

 2. 建立发布静态landmark节点

参考链接:cartographer使用landmark_花生啤酒八宝粥的博客-CSDN博客

2.1 创建工作空间和节点

参考链接:如何在ROS中使用VScode创建功能包并编写cpp文件_ros创建.cpp文件命令_舟同学的博客的博客-CSDN博客

2.1.1.创建工作空间

mkdir -p pl/src

2.1.2.编译

catkin_make

2.1.3.创建功能包

  1. cd src
  2. catkin_create_pkg pub_landmark roscpp rospy std_msgs

2.2 配置头文件

~/car2_ws/install_isolated/include/cartographer_ros_msgs下的两个配置文件放入~/pl/src/pub_landmark/include/pub_landmark

将头文件存在路径加入c_cpp_properties.json文件

 2.3 创建自定义消息类型

1.定义msg文件

功能包下新建 msg 目录,添加文件 LandmarkEntry.msg、LandmarkList.h

 

 

2.编辑配置文件

package.xml中添加编译依赖与执行依赖

  1. <build_depend>message_generation</build_depend>
  2. <exec_depend>message_runtime</exec_depend>

2.4 创建cpp文件

文件内容:

  1. #include "ros/ros.h"
  2. #include "pub_landmark/LandmarkList.h"
  3. #include "pub_landmark/LandmarkEntry.h"
  4. #include "geometry_msgs/Pose.h"
  5. #include "std_msgs/String.h"
  6. #include "std_msgs/Header.h"
  7. int main(int argc, char *argv[])
  8. {
  9. ros::init(argc, argv, "pub_landmark");
  10. ros::NodeHandle nh;
  11. ros::NodeHandle n("~");
  12. ros::Publisher landmark_pub = n.advertise<cartographer_ros_msgs::LandmarkList>("landmark", 10);
  13. cartographer_ros_msgs::LandmarkList landmark_0;
  14. ros::Rate loop_rate(10);
  15. int count=0;
  16. while (ros::ok())
  17. {
  18. landmark_0.header.stamp = ros::Time::now();
  19. landmark_0.header.frame_id = "base_link";
  20. landmark_0.landmarks.resize(10);
  21. for(int t=0;t<10;t++)
  22. {
  23. std::stringstream ss;
  24. ss << t;//"landmark_" ;//<< count/ << "_" t;
  25. landmark_0.landmarks[t].id = ss.str();
  26. landmark_0.landmarks[t].tracking_from_landmark_transform.position.x = 1.0*t;
  27. landmark_0.landmarks[t].tracking_from_landmark_transform.position.y = 2.0*t;
  28. landmark_0.landmarks[t].tracking_from_landmark_transform.position.z = 3.0*t;
  29. landmark_0.landmarks[t].tracking_from_landmark_transform.orientation.w = 1.0*t;
  30. landmark_0.landmarks[t].tracking_from_landmark_transform.orientation.x = 0.0*t;
  31. landmark_0.landmarks[t].tracking_from_landmark_transform.orientation.y = 0.0*t;
  32. landmark_0.landmarks[t].tracking_from_landmark_transform.orientation.z = 0.0*t;
  33. landmark_0.landmarks[t].translation_weight = 1.0*t;
  34. landmark_0.landmarks[t].rotation_weight = 2.0*t;
  35. }
  36. landmark_pub.publish(landmark_0);
  37. ROS_INFO("%d", count);
  38. loop_rate.sleep();
  39. count++;
  40. }
  41. return 0;
  42. }

2.5 CMakeList.txt文件配置

如下:

  1. cmake_minimum_required(VERSION 3.0.2)
  2. project(pub_landmark)
  3. find_package(catkin REQUIRED COMPONENTS
  4. roscpp
  5. rospy
  6. std_msgs
  7. message_generation
  8. sensor_msgs
  9. )
  10. add_message_files(
  11. FILES
  12. LandmarkEntry.msg
  13. LandmarkList.msg
  14. )
  15. generate_messages(
  16. DEPENDENCIES
  17. std_msgs
  18. sensor_msgs
  19. geometry_msgs
  20. )
  21. catkin_package(
  22. # INCLUDE_DIRS include
  23. # LIBRARIES pub_landmark
  24. CATKIN_DEPENDS roscpp rospy std_msgs message_runtime
  25. # DEPENDS system_lib
  26. )
  27. include_directories(
  28. include
  29. ${catkin_INCLUDE_DIRS}
  30. )
  31. add_executable(pub src/pub_landmark.cpp)
  32. add_dependencies(pub ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
  33. target_link_libraries(pub
  34. ${catkin_LIBRARIES}
  35. )

2.6 测试发布【与imu、雷达一起发布测试】

节点图:

 效果图:

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/寸_铁/article/detail/876888
推荐阅读
相关标签
  

闽ICP备14008679号