flat_world_imu_node_main.cc
Go to the documentation of this file.
00001 /*
00002  * Copyright 2016 The Cartographer Authors
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *      http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
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 }  // namespace
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             // The 'imu_data_raw' topic of the Kobuki base will at times publish
00042             // IMU messages out of order. These out of order messages must be
00043             // dropped.
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               // TODO(damonkohler): This relies on the z-axis alignment of the
00049               // IMU with the Kobuki base.
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 }


cartographer_turtlebot
Author(s):
autogenerated on Sat Jun 8 2019 19:39:33