odom.cpp
Go to the documentation of this file.
00001 #include <ros/ros.h>
00002 #include <nav_msgs/Odometry.h>
00003 #include <geometry_msgs/PoseStamped.h>
00004 #include <geometry_msgs/PoseArray.h>
00005 #include <tf/transform_datatypes.h>
00006 #include <tf/transform_listener.h>
00007 #include <pose_cov_ops/pose_cov_ops.h>
00008 #include <sensor_msgs/LaserScan.h>
00009 
00010 
00011 int main(int argc, char** argv)
00012 {
00013     ros::init(argc, argv, "BayesianFilterNode");
00014     ros::NodeHandle nh;
00015     double rate=50.0;
00016     ros::Rate r(rate);
00017     std::string odom_link="odom";
00018     std::string base_link="base_link";
00019 
00020     ros::Time last_update_time=ros::Time::now();
00021     tf::TransformListener listener;
00022 
00023     ros::Publisher odom_publisher=nh.advertise<nav_msgs::Odometry>("/odom",2);
00024 
00025     while(ros::ok())
00026     {
00027         tf::StampedTransform baseDeltaTf;
00028         tf::StampedTransform odomTf;
00029 
00030         // Get delta motion in cartesian coordinates with TF
00031         ros::Time current_time;
00032 
00033         try
00034         {
00035             current_time = ros::Time::now();
00036             listener.waitForTransform(base_link, last_update_time, base_link, current_time, odom_link, ros::Duration(0.1) );
00037             listener.lookupTransform(base_link, last_update_time, base_link, current_time, odom_link, baseDeltaTf); // Velocity
00038 
00039             listener.waitForTransform(base_link, odom_link, ros::Time(0), ros::Duration(0.1) );
00040             listener.lookupTransform(base_link, odom_link, ros::Time(0), odomTf); // Position
00041         }
00042         catch (tf::TransformException &ex)
00043         {
00044             //ROS_WARN("%s",ex.what());
00045             continue;
00046         }
00047 
00048         double dt=current_time.toSec()-last_update_time.toSec();
00049         last_update_time=current_time;
00050 
00051         double delta_yaw=baseDeltaTf.getRotation().getAngle();
00052         double delta_x=baseDeltaTf.getOrigin().getX();
00053 
00054         double v_yaw=delta_yaw/dt;
00055         double v_x=delta_x/dt;
00056 
00057         nav_msgs::Odometry odom_msg;
00058         odom_msg.header.stamp=ros::Time::now();
00059         odom_msg.pose.pose.position.x=odomTf.getOrigin().getX();
00060         odom_msg.pose.pose.position.y=odomTf.getOrigin().getY();
00061         odom_msg.pose.pose.position.z=odomTf.getOrigin().getZ();
00062         odom_msg.pose.pose.orientation.w=odomTf.getRotation().getW();
00063         odom_msg.pose.pose.orientation.x=odomTf.getRotation().getX();
00064         odom_msg.pose.pose.orientation.y=odomTf.getRotation().getY();
00065         odom_msg.pose.pose.orientation.z=odomTf.getRotation().getZ();
00066 
00067         odom_msg.twist.twist.angular.z=v_yaw;
00068         odom_msg.twist.twist.linear.x=v_x;
00069         odom_publisher.publish(odom_msg);
00070         r.sleep();
00071         ros::spinOnce();
00072     }
00073     return 0;
00074 }


ekf_localization
Author(s):
autogenerated on Sat Jun 8 2019 20:11:55