一。配置realsense-ros:
已经新建了ROS工作空间,可以直接在工作空间的src目录下克隆相关功能包,然后进行编译,具体命令参考下方:
1、已建好工作空间Realsense_D435i:
cd Realsense_D435i/src
git clone -b 2.2.11 https://github.com/IntelRealSense/realsense-ros.git
git clone https://github.com/pal-robotics/ddynamic_reconfigure.git
原文链接:https://blog.csdn.net/hltt3838/article/details/120691764
2.完成上述步骤后,使用以下命令进行测试:
cd Realsense_D435i
catkin_make
source devel/setup.bash
roslaunch realsense2_camera rs_camera.launch
3.打开新的终端查看节点:
rostopic list
可以看到,只有图片信息的话题,!!!!!!!!!!!!!!!!没有IMU信息的话题,因为这是原launch文件中默认的!!!!!!,想要打开IMU 信息话题,需要在相应的launch文件作修改,因此不建议使用一键安装realsense-ros方法
https://blog.csdn.net/weixin_50508111/article/details/121087220 。
二。打开IMU话题
- 针对相机的各种配置参数,通过 /realsense-ros/realsense2_camera/launch/rs_camera.launch 文件传给ROS系统。
将rs_camera.launch 复制了一份命令成lee_test.launch,在其中更改打开IMU话题的相关命令。
设备默认打开深度图,深度自信度,RGB图像,关闭IMU数据,
在这里将最后两个标识符设置为true,即可打开陀螺仪和加速计的数据流。 - 删除build和devel文件重新catkin_make编译一下,使用命令:
roslaunch realsense2_camera lee_test.launch
打开,报错
原因是没有添加环境变量,有俩个方法
(1.)添加:
echo “source ~/Realsense_D435i/devel/setup.bash” >> ~/.bashrc
source ~/.bashrc
(2.)终端输入:cd Realsense_D435i
source devel/setup.bash
成功打开
realsense d455在ROS中发布的IMU数据分红了两个:
“/camera/gyro/sample” 发布角速度
“/camera/accel/sample” 发布线加速度app
同时这两个的时间戳也不太同样,在launch文件中的频率也不同:
<arg name="gyro_fps" default="400"/>
<arg name="accel_fps" default="250"/>
设置同步选项,以下部分参考自https://blog.csdn.net/weixin_46363611/article/details/114643088
IMU数据是不同步的,即accel和gyro互相独立。
可修改的配置介绍:https://github.com/IntelRealSense/realsense-ros#launch-parameters
其中影响IMU数据同步的为:
r其中realsense2_camera\src**base_realsense_node.cpp**就是写了如何发布全部topic,代码很长,一开始绕了很多弯路。
其中void BaseRealSenseNode::setupStreams():
if (gyro_profile != _enabled_profiles.end() &&
accel_profile != _enabled_profiles.end())
{
ROS_INFO("starting imu...");
std::vector<rs2::stream_profile> profiles;
profiles.insert(profiles.begin(), gyro_profile->second.begin(), gyro_profile->second.end());
profiles.insert(profiles.begin(), accel_profile->second.begin(), accel_profile->second.end());
auto& sens = _sensors[GYRO];
sens.open(profiles);
auto imu_callback_inner = [this](rs2::frame frame){
imu_callback(frame);
};
auto imu_callback_sync_inner = [this](rs2::frame frame){
imu_callback_sync(frame, _imu_sync_method);
};
if (_imu_sync_method > imu_sync_method::NONE)
{
std::string unite_method_str;
int expected_fps(_fps[GYRO] + _fps[ACCEL]);
unite_method_str = "COPY";
if (_imu_sync_method == imu_sync_method::LINEAR_INTERPOLATION)
{
unite_method_str = "LINEAR_INTERPOLATION";
expected_fps = 2 * std::min(_fps[GYRO], _fps[ACCEL]);
}
ROS_INFO_STREAM("Gyro and accelometer are enabled and combined to IMU message at "
<< expected_fps << " fps by method:" << unite_method_str);
sens.start(imu_callback_sync_inner);
}
else
{
sens.start(imu_callback_inner);
if (_enable[GYRO])
{
ROS_INFO_STREAM(_stream_name[GYRO] << " stream is enabled - " << "fps: " << _fps[GYRO]);
auto gyroInfo = getImuInfo(GYRO);
_info_publisher[GYRO].publish(gyroInfo);
}
if (_enable[ACCEL])
{
ROS_INFO_STREAM(_stream_name[ACCEL] << " stream is enabled - " << "fps: " << _fps[ACCEL]);
auto accelInfo = getImuInfo(ACCEL);
_info_publisher[ACCEL].publish(accelInfo);
}
}
}
能够看到这里的条件判断:
if (_imu_sync_method > imu_sync_method::NONE),最后讲执行回调函数sens.start(imu_callback_sync_inner);
否则就执行
_info_publisher[GYRO].publish(gyroInfo)和_info_publisher[ACCEL].publish(accelInfo)
。
而咱们一开始的launch文件就是采用了后面一种,最后直接发布了GYRO和ACCEL。
当unite_imu_method_str
是 "copy"或者“linear_interpolation”就好了!
而这又是读取了launch文件中的unite_imu_method,因此在rs_camera.launch中直接修改:
若使用linear_interpolation选项,可以将加速计的数据以插值的方式对齐到陀螺仪数据时间轴上;
若使用copy选项,则是在每一个陀螺仪数据上,附加上时间最近邻的加速计数据。
默认选项为:None。
在.launch文件中,将unite_imu_method对应设置为“linear_interpolation”,两路数据即可以同步为同一个topic: /camera/imu:
测试一下
测试成功!
使用命令行
rostopic echo /camera/imu
查看IMU数据,同一个数据中同时包含两个传感器数据:
IMU与图像的同步
修改了enable_sync参数,是对相机和IMU进行同步的。
<arg name="enable_sync" default="true"/>
三。IMU数据集录制
数据记录与播放
说明:运行上面的 roslaunch realsense2_camera demo_pointcloud.launch 指令时,便可以进行下面bag的录制
rosbag record -a
#录制所有topic到bag文件,注意-终端的地址就是bag包存放的地址,
bag的名字是时间;
比如记录IMU的数据bag
rosbag record /camera/accel/imu_info -O imu.bag
变成了 rosbag record /camera/imu -O imu.bag // 因为修改了realsense2_camera的程序
rosbag record /camera/imu /camera/color/image_raw -o Cam-imu.bag // 录制两个话题的bag包
- rosbag play xxx.bag #播放bag文件
- rosbag info xxx.bag #查看bag文件
- 注意:rosbag play bag 的同时,也可以提取bag包发布的特定topic,保存成txt或者csv文件,如下所示:
rostopic echo /camera/imu > imu.txt - rostopic hz /camera/color/image_raw
用来查看话题的发布频率
原文链接:https://blog.csdn.net/hltt3838/article/details/120691764