当前位置:   article > 正文

gazebo 仿真 kinect 获取点云数据_gazebo 双目相机点云

gazebo 双目相机点云

项目地址:https://github.com/yym68686/ros-slam

简介

使用 urdf 文件构建仿真机器人,在 gazebo 搭建仿真环境,导入人造卫星的 stl 文件,利用仿真 kinect 深度相机获取人造卫星的点云数据并在 RVIZ 中可视化,将 PointCloud2 数据类型转化为 pcd 文件。

使用指南

进入目录

mkdir catkin_ws
cd catkin_ws
mkdir src
cd src
  • 1
  • 2
  • 3
  • 4

下载软件包

git clone https://github.com/yym68686/ros-slam.git
  • 1

回到根目录编译

cd ~/catkin_ws
catkin_make
  • 1
  • 2

让 ROS 找到软件包

source ~/catkin_ws/devel/setup.bash
  • 1

启动 ROS 内核

roscore
  • 1

结合 URDF 打开 gazebo 仿真环境

roslaunch ros-slam env.launch
  • 1

打开机器人深度相机 kinect 等传感器并在 rviz 可视化

roslaunch ros-slam sensor.launch
  • 1

打开机器人运动控制

rosrun teleop_twist_keyboard teleop_twist_keyboard.py
  • 1

按照提示使用键盘控制小车方向。运动控制需要下载依赖

sudo apt-get install -y ros-noetic-teleop-twist-keyboard
  • 1

订阅 kinect 点云话题转化为点云 pcd 文件

rosrun ros-slam pcd_write
  • 1

上条命令在哪个目录执行,就在哪个目录生成 pcd 文件,查看 pcd 点云文件

pcl_viewer file.pcd
  • 1

软件包搭建过程

测试环境

从头开始,不管前面的项目,创建文件夹

mkdir catkin_ws
cd catkin_ws
mkdir src
cd src
  • 1
  • 2
  • 3
  • 4

创建软件包

catkin_create_pkg ros-slam rospy roscpp std_msgs urdf xacro gazebo_ros gazebo_ros_control gazebo_plugins
  • 1

进入 ros-slam/src 文件夹创建文件 hello.cpp

cd ros-slam/src
touch hello.cpp
  • 1
  • 2

写入

#include <ros/ros.h>

int main(int argc, char const *argv[])
{
    printf("Hello World!\n");
    return 0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

在 CMakeLists.txt 添加

echo "add_executable(hello src/hello.cpp)" >> CMakeLists.txt
  • 1

编译

cd ~/catkin_ws
catkin_make
  • 1
  • 2

让 ROS 找到软件包

source ~/catkin_ws/devel/setup.bash
  • 1

运行节点

rosrun ros-slam hello
  • 1

运行成功。

运行仿真环境

sudo apt-get install -y ros-noetic-teleop-twist-keyboard
cd ~
git clone -b kinect https://github.com/yym68686/ROS-Lab.git
cd ~/catkin_ws/src
roslaunch ros-slam env.launch
roslaunch ros-slam sensor.launch
rosrun teleop_twist_keyboard teleop_twist_keyboard.py
rostopic pub -r 10 /cmd_vel geometry_msgs/Twist "linear:
  x: 1.0
  y: 0.0
  z: 0.0
angular:
  x: 0.0
  y: 0.0
  z: 1.0"
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

CMakeLists.txt 增加

find_package(PCL 1.2 REQUIRED)

include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})

# add_executable (pcd_write src/test_pcl.cpp)
add_executable (pcd_write src/pcl_write.cpp)
target_link_libraries(pcd_write
  ${catkin_LIBRARIES}
)
target_link_libraries (pcd_write ${PCL_LIBRARIES})
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

编译

catkin_make
  • 1

查看当前是否有 camera/depth/ros-slams 话题

rostopic list
  • 1

点云数据格式:http://docs.ros.org/en/api/sensor_msgs/html/msg/ros-slamCloud2.html

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

闽ICP备14008679号