Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "ros/ros.h"
00018 #include "sensor_msgs/Imu.h"
00019
00020 namespace {
00021
00022 constexpr double kFakeGravity = 9.8;
00023 constexpr int kSubscriberQueueSize = 150;
00024 constexpr char kImuInTopic[] = "imu_in";
00025 constexpr char kImuOutTopic[] = "imu_out";
00026
00027 }
00028
00029 int main(int argc, char** argv) {
00030 ::ros::init(argc, argv, "flat_world_imu_node");
00031
00032 ::ros::NodeHandle node_handle;
00033 ::ros::Publisher publisher =
00034 node_handle.advertise<sensor_msgs::Imu>(kImuOutTopic, 10);
00035
00036 ::ros::Time last_published_time;
00037 ::ros::Subscriber subscriber = node_handle.subscribe(
00038 kImuInTopic, kSubscriberQueueSize,
00039 boost::function<void(const sensor_msgs::Imu::ConstPtr& imu_in)>(
00040 [&](const sensor_msgs::Imu::ConstPtr& imu_in) {
00041
00042
00043
00044 if (last_published_time.isZero() ||
00045 imu_in->header.stamp > last_published_time) {
00046 last_published_time = imu_in->header.stamp;
00047 sensor_msgs::Imu imu_out = *imu_in;
00048
00049
00050 imu_out.linear_acceleration.x = 0.;
00051 imu_out.linear_acceleration.y = 0.;
00052 imu_out.linear_acceleration.z = kFakeGravity;
00053 publisher.publish(imu_out);
00054 }
00055 }));
00056
00057 ::ros::start();
00058 ::ros::spin();
00059 ::ros::shutdown();
00060 }