test_simpson_integrator_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 <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 }


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