ROS学习笔记 -- IMU in ROS

目录

1. IMU简介

2. ROS IMU msgs

3. 创建IMU消息发布节点node

4. 小结

 

查看电脑链接的串口信息(名称):

dmesg | grep ttyS*

 

1. IMU简介

      请移步本人的另一篇博客文章,详细介绍了IMU工作原理和卡尔曼滤波方法:https://blog.csdn.net/hhaowang/article/details/88846468

2. ROS IMU msgs

官方文档:http://docs.ros.org/api/sensor_msgs/html/msg/Imu.html

IMU 消息类型为ROS中的一种标准传感器消息类型,其定义已经包含在sensor_msgs/Imu.msg文件夹中。在发布IM消息时需要将该消息类型的头文件包含在内。

消息详细描述如下:

# This is a message to hold data from an IMU (Inertial Measurement Unit)
#
# Accelerations should be in m/s^2 (not in g's), and rotational velocity should be in rad/sec
#
# If the covariance of the measurement is known, it should be filled in (if all you know is the 
# variance of each measurement, e.g. from the datasheet, just put those along the diagonal)
# A covariance matrix of all zeros will be interpreted as "covariance unknown", and to use the
# data a covariance will have to be assumed or gotten from some other source
#
# If you have no estimate for one of the data elements (e.g. your IMU doesn't produce an orientation 
# estimate), please set element 0 of the associated covariance matrix to -1
# If you are interpreting this message, please check for a value of -1 in the first element of each 
# covariance matrix, and disregard the associated estimate.
 
Header header
 
geometry_msgs/Quaternion orientation
float64[9] orientation_covariance # Row major about x, y, z axes
 
geometry_msgs/Vector3 angular_velocity
float64[9] angular_velocity_covariance # Row major about x, y, z axes
 
geometry_msgs/Vector3 linear_acceleration
float64[9] linear_acceleration_covariance # Row major x, y z 

3. 创建IMU消息发布节点node

【1】实现了串口IMU数据采集和发布,https://blog.csdn.net/jc15988821760/article/details/102581213

【2】采用rostools,对IMU数据进行滤波处理,https://blog.csdn.net/learning_tortosie/article/details/103189118

【3】发布IMU和GPS消息,https://blog.csdn.net/Tansir94/article/details/81385812

【4】实现了串口接收IMU数据,https://blog.csdn.net/xinmei4275/article/details/85040164?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-task

#include <ros/ros.h>
#include "sensor_msgs/Imu.h"
#include <std_msgs/String.h>
#include <sstream>
 
 
 
/**
 * This tutorial demonstrates simple sending of messages over the ROS system.
 */
 
//回调函数 
void imu_callback(const sensor_msgs::Imu::ConstPtr& imu_raw) 
{ 
    ROS_INFO_STREAM("Imu raw data publish working : "<<imu_raw->header.stamp); 
	ROS_INFO_STREAM("Data samples orientation: " <<imu_raw->orientation); 
     
} 
 
int main(int argc, char *argv[])
{
 
	ros::init(argc, argv, "imu_raw_pub"); // node 
 
	/**
	 * NodeHandle is the main access point to communications with the ROS system.
	 * The first NodeHandle constructed will fully initialize this node, and the last
	 * NodeHandle destructed will close down the node.
	 */
	ros::NodeHandle n;
 
 
	ros::Publisher imu_raw_pub = n.advertise<sensor_msgs::Imu>("imu_data", 10, imu_callback);
	// topic name -- imu_data
 
	ros::Rate loop_rate(1);
 
	while(ros::ok())
    {
 
		sensor_msgs::Imu imu_raw; // sensor messages - named imu_raw 
		imu_raw.header.stamp = ros::Time::now();
		imu_raw.header.frame_id = "imu_link";
		//四元数位姿,所有数据设为固定值,可以自己写代码获取IMU的数据,,然后进行传递
		imu_raw.orientation.x = 0;
		imu_raw.orientation.y = -1;
		imu_raw.orientation.z = -5;
		imu_raw.orientation.w = 6;
		//线加速度
		imu_raw.linear_acceleration.x = 0.01; 
		imu_raw.linear_acceleration.y = 0.02;
		imu_raw.linear_acceleration.z = 0.03;
	//角速度
		imu_raw.angular_velocity.x = 0.05; 
		imu_raw.angular_velocity.y = 0.06; 
		imu_raw.angular_velocity.z = 0.07;
 
 
		imu_raw_pub.publish(imu_raw); //imu_raw_pub 节点发布消息至imu_data topic
  
    }
	ros::spinOnce();  
    loop_rate.sleep();
 
    return 0;
}
 

修改CMakeLists.txt文件:

cmake_minimum_required(VERSION 2.8.3)
project(imu_raw_pub)
 
 
find_package(catkin REQUIRED COMPONENTS
    roscpp
    std_msgs
    sensor_msgs
    tf)
 
 
catkin_package(
  # INCLUDE_DIRS include
# LIBRARIES imu_raw_pub
#  CATKIN_DEPENDS other_catkin_pkg
#  DEPENDS system_lib
)
 
 
 
include_directories(
include
${catkin_INCLUDE_DIRS}
)
 
 
# add_dependencies(${PROJECT_NAME} ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
 
 
add_executable(imu_raw_pub src/imu_raw_pub.cpp)
 
${catkin_EXPORTED_TARGETS})
 
## Specify libraries to link a library or executable target against
target_link_libraries(imu_raw_pub
  ${catkin_LIBRARIES}
)
 
 
 

修改package.xml描述文件:

<?xml version="1.0"?>
<package format="2">
  <name>imu_raw_pub</name>
  <version>0.0.0</version>
  <description>The imu_raw_pub package</description>
 
  <!-- One maintainer tag required, multiple allowed, one person per tag -->
  <!-- Example:  -->
  <!-- <maintainer email="jane.doe@example.com">Jane Doe</maintainer> -->
  <maintainer email="haowanghk@gmail.com">haowang</maintainer>
 
 
  <!-- One license tag required, multiple allowed, one license per tag -->
  <!-- Commonly used license strings: -->
  <!--   BSD, MIT, Boost Software License, GPLv2, GPLv3, LGPLv2.1, LGPLv3 -->
  <license>BSD</license>
 
 
  <!-- Url tags are optional, but multiple are allowed, one per tag -->
  <!-- Optional attribute type can be: website, bugtracker, or repository -->
  <!-- Example: -->
  <!-- <url type="website">http://wiki.ros.org/imu_raw_pub</url> -->
 
 
  <!-- Author tags are optional, multiple are allowed, one per tag -->
  <!-- Authors do not have to be maintainers, but could be -->
  <!-- Example: -->
  <!-- <author email="jane.doe@example.com">Jane Doe</author> -->
 
 
  <!-- The *depend tags are used to specify dependencies -->
  <!-- Dependencies can be catkin packages or system dependencies -->
  <!-- Examples: -->
  <!-- Use depend as a shortcut for packages that are both build and exec dependencies -->
  <!--   Note that this is equivalent to the following: -->
 
  <!--   <exec_depend>roscpp</exec_depend> -->
  <!-- Use build_depend for packages you need at compile time: -->
  <!--   <build_depend>message_generation</build_depend> -->
  <!-- Use build_export_depend for packages you need in order to build against this package: -->
  <!--   <build_export_depend>message_generation</build_export_depend> -->
  <!-- Use buildtool_depend for build tool packages: -->
  <!--   <buildtool_depend>catkin</buildtool_depend> -->
  <!-- Use exec_depend for packages you need at runtime: -->
  <!--   <exec_depend>message_runtime</exec_depend> -->
  <!-- Use test_depend for packages you need only for testing: -->
  <!--   <test_depend>gtest</test_depend> -->
  <!-- Use doc_depend for packages you need only for building documentation: -->
  <!--   <doc_depend>doxygen</doc_depend> -->
  <buildtool_depend>catkin</buildtool_depend>
 
  <build_depend>roscpp</build_depend> 
  <build_depend>sensor_msgs</build_depend>
  <build_depend>std_msgs</build_depend>
 
  <exec_depend>roscpp</exec_depend>
  <exec_depend>sensor_msgs</exec_depend>
  <exec_depend>std_msgs</exec_depend>
  
 
  <!-- The export tag contains other, unspecified, tags -->
  <export>
    <!-- Other tools can request additional information be placed here -->
 
  </export>
</package>

运行结果:

查看topic和node信息

4. 小结

简单的IMU消息类型的发布测试,下一节试验串口接收IMU数据并发布至imu_data topic中去。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值