ab_filter_height.cpp
Go to the documentation of this file.
00001 /*
00002  *  Alpha-Beta Filter
00003  *  Copyright (C) 2011, CCNY Robotics Lab
00004  *  Ivan Dryanovski <ivan.dryanovski@gmail.com>
00005  *
00006  *  http://robotics.ccny.cuny.edu
00007  *
00008  *  This program is free software: you can redistribute it and/or modify
00009  *  it under the terms of the GNU General Public License as published by
00010  *  the Free Software Foundation, either version 3 of the License, or
00011  *  (at your option) any later version.
00012  *
00013  *  This program is distributed in the hope that it will be useful,
00014  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  *  GNU General Public License for more details.
00017  *
00018  *  You should have received a copy of the GNU General Public License
00019  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00020  */
00021 
00022 #include "ab_filter/ab_filter_height.h"
00023 
00024 namespace mav
00025 {
00026 
00027 ABFilterHeight::ABFilterHeight(ros::NodeHandle nh, ros::NodeHandle nh_private):
00028   nh_(nh), 
00029   nh_private_(nh_private),
00030   initialized_(false)
00031 {
00032   ROS_INFO("Starting ABFilterHeight"); 
00033 
00034   ros::NodeHandle nh_mav (nh_, "mav");
00035 
00036   // **** initialize vaiables
00037 
00038   // **** get parameters
00039 
00040   initializeParams();
00041 
00042   // *** register publishers
00043 
00044   publisher_  = nh_mav.advertise<HeightMsg>(
00045     "laser_height_f", 10);
00046 
00047   // **** register subscribers
00048 
00049   height_subscriber_ = nh_mav.subscribe(
00050     "laser_height", 10, &ABFilterHeight::heightCallback, this);
00051 }
00052 
00053 ABFilterHeight::~ABFilterHeight()
00054 {
00055   ROS_INFO("Destroying ABFilterHeight"); 
00056 
00057 }
00058 
00059 void ABFilterHeight::heightCallback(const HeightMsg::ConstPtr height_msg)
00060 {
00061   //ros::Time time = ros::Time::now();
00062   ros::Time time = height_msg->header.stamp;
00063 
00064   if(!initialized_)
00065   {
00066     // first message
00067   
00068     initialized_ = true;
00069 
00070     height_.height = height_msg->height;
00071     height_.climb  = 0.0;
00072   }
00073   else
00074   {
00075     double dt = (time - last_update_time_).toSec();
00076 
00077     double z_pred = (height_.height + dt * height_.climb);
00078 
00079     double r_z = height_msg->height - z_pred;
00080 
00081     height_.height = z_pred + alpha_ * r_z;
00082     height_.climb += beta_  * r_z   / dt;
00083   }
00084 
00085   last_update_time_ = time;
00086   height_.header.stamp = time;
00087   publishHeight();
00088 }
00089 
00090 void ABFilterHeight::publishHeight()
00091 {
00092   HeightMsg::Ptr msg;
00093   msg = boost::make_shared<HeightMsg>(height_);
00094   publisher_.publish(msg);
00095 }
00096 
00097 void ABFilterHeight::initializeParams()
00098 {
00099   if (!nh_private_.getParam ("alpha", alpha_))
00100     alpha_ = 0.9;
00101   if (!nh_private_.getParam ("beta", beta_))
00102     beta_ = 0.9;
00103 }
00104 
00105 } // end namespace asctec


ab_filter
Author(s): Ivan Dryanovski
autogenerated on Thu Jan 2 2014 11:28:26