Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
00037
00038
00039
00040 initializeParams();
00041
00042
00043
00044 publisher_ = nh_mav.advertise<HeightMsg>(
00045 "laser_height_f", 10);
00046
00047
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
00062 ros::Time time = height_msg->header.stamp;
00063
00064 if(!initialized_)
00065 {
00066
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 }