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 #include <string>
00019 #include <ros/ros.h>
00020 #include <std_msgs/Float64.h>
00021 #include <cob_twist_controller/utils/moving_average.h>
00022
00023
00024 class MovingAverageTester
00025 {
00026 public:
00027 MovingAverageTester(std::string out, MovingAvgBase_double_t* ma)
00028 {
00029 ma_.reset(ma);
00030 output_pub_ = nh_.advertise<std_msgs::Float64>(out, 1);
00031 input_sub_ = nh_.subscribe("input", 1, &MovingAverageTester::input_cb, this);
00032 }
00033
00034 ~MovingAverageTester()
00035 {}
00036
00037 void input_cb(const std_msgs::Float64::ConstPtr& input)
00038 {
00039 std_msgs::Float64 output;
00040
00041 ma_->addElement(input->data);
00042 if (ma_->calcMovingAverage(output.data))
00043 {
00044 output_pub_.publish(output);
00045 }
00046 }
00047
00048 ros::NodeHandle nh_;
00049 ros::Subscriber input_sub_;
00050 ros::Publisher output_pub_;
00051
00052 boost::shared_ptr< MovingAvgBase_double_t > ma_;
00053 };
00054
00055
00056
00057 int main(int argc, char **argv)
00058 {
00059 ros::init(argc, argv, "test_moving_average_node");
00060
00061 MovingAvgSimple_double_t* ma_3 = new MovingAvgSimple_double_t(3);
00062 MovingAverageTester mat("output_ma", ma_3);
00063 MovingAvgWeighted_double_t* maw_3 = new MovingAvgWeighted_double_t(3);
00064 MovingAverageTester maw_3t("output_maw", maw_3);
00065 MovingAvgExponential_double_t* mae_03 = new MovingAvgExponential_double_t(0.3);
00066 MovingAverageTester mae_03t("output_mae", mae_03);
00067 MovingAvgExponential_double_t* mae_05 = new MovingAvgExponential_double_t(0.5);
00068 MovingAverageTester mae_05t("output_mae05", mae_05);
00069
00070 ros::spin();
00071 return 0;
00072 }