test_moving_average_node.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *   http://www.apache.org/licenses/LICENSE-2.0
00009 
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
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 }


cob_twist_controller
Author(s): Felix Messmer , Marco Bezzon , Christoph Mark , Francisco Moreno
autogenerated on Thu Jun 6 2019 21:19:26