flat_world_imu_node.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2016 The Cartographer Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
20 {
21  bool init_result = init();
22  ROS_ASSERT(init_result);
23 }
24 
26 {
27 }
28 
30 {
31  publisher_ = nh_.advertise<sensor_msgs::Imu>("imu_out", 10);
32  subscriber_ = nh_.subscribe("imu_in", 150, &FlatWorldImuNode::msgCallback, this);
33 
34  return true;
35 }
36 
37 void FlatWorldImuNode::msgCallback(const sensor_msgs::ImuConstPtr imu_in)
38 {
39  if (last_published_time_.isZero() || imu_in->header.stamp > last_published_time_)
40  {
41  last_published_time_ = imu_in->header.stamp;
42  sensor_msgs::Imu imu_out = *imu_in;
43  imu_out.linear_acceleration.x = 0.0;
44  imu_out.linear_acceleration.y = 0.0;
45  imu_out.linear_acceleration.z = GRAVITY;
46  publisher_.publish(imu_out);
47  }
48 }
49 
50 int main(int argc, char* argv[])
51 {
52  ros::init(argc, argv, "flat_world_imu_node");
53 
54  FlatWorldImuNode flat_world_imu_node;
55 
56  ros::spin();
57 
58  return 0;
59 }
ros::Publisher publisher_
void publish(const boost::shared_ptr< M > &message) const
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
ros::Subscriber subscriber_
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
#define GRAVITY
ROSCPP_DECL void spin(Spinner &spinner)
void msgCallback(const sensor_msgs::ImuConstPtr imu_in)
int main(int argc, char *argv[])
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
ros::NodeHandle nh_
#define ROS_ASSERT(cond)
ros::Time last_published_time_


turtlebot3_slam
Author(s): Pyo , Darby Lim , Gilbert , Leon Jung
autogenerated on Wed Apr 7 2021 02:10:39