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 <vector>
00019 #include <ros/ros.h>
00020 #include <std_msgs/Float64.h>
00021 #include <kdl/jntarray.hpp>
00022 #include <cob_twist_controller/utils/simpson_integrator.h>
00023
00024
00025 class SimpsonIntegratorTester
00026 {
00027 public:
00028 SimpsonIntegratorTester()
00029 {
00030 unsigned int dof = 1;
00031 q_.resize(dof);
00032 KDL::SetToZero(q_);
00033 q_dot_.resize(dof);
00034 KDL::SetToZero(q_dot_);
00035
00036 integrator_.reset(new SimpsonIntegrator(dof));
00037 output_q_pub_ = nh_.advertise<std_msgs::Float64>("output_q", 1);
00038 output_q_dot_pub_ = nh_.advertise<std_msgs::Float64>("output_q_dot", 1);
00039 input_sub_ = nh_.subscribe("input", 1, &SimpsonIntegratorTester::input_cb, this);
00040 }
00041
00042 ~SimpsonIntegratorTester()
00043 {}
00044
00045 void input_cb(const std_msgs::Float64::ConstPtr& input)
00046 {
00047 q_dot_(0) = input->data;
00048
00049 std::vector<double> next_q;
00050 std::vector<double> next_q_dot;
00051
00052 if (integrator_->updateIntegration(q_dot_, q_, next_q, next_q_dot))
00053 {
00054 for (unsigned int i = 0; i < next_q.size(); i++)
00055 {
00056 q_(i) = next_q[i];
00057 q_dot_(i) = next_q_dot[i];
00058 }
00059
00060 std_msgs::Float64 output_q;
00061 output_q.data = q_(0);
00062 std_msgs::Float64 output_q_dot;
00063 output_q_dot.data = q_dot_(0);
00064
00065 output_q_pub_.publish(output_q);
00066 output_q_dot_pub_.publish(output_q_dot);
00067 }
00068 }
00069
00070 ros::NodeHandle nh_;
00071 ros::Subscriber input_sub_;
00072 ros::Publisher output_q_pub_;
00073 ros::Publisher output_q_dot_pub_;
00074
00075 KDL::JntArray q_;
00076 KDL::JntArray q_dot_;
00077
00078 boost::shared_ptr<SimpsonIntegrator> integrator_;
00079 };
00080
00081
00082
00083 int main(int argc, char **argv)
00084 {
00085 ros::init(argc, argv, "test_simpson_integrator_node");
00086
00087 SimpsonIntegratorTester sit;
00088
00089 ros::spin();
00090 return 0;
00091 }