output_recorder.h
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 #ifndef OUTPUT_RECORDER_H
00019 #define OUTPUT_RECORDER_H
00020 
00021 #include <termios.h>
00022 #include <signal.h>
00023 #include <string>
00024 #include <vector>
00025 
00026 #include <ros/ros.h>
00027 
00028 #include <std_srvs/Empty.h>
00029 #include <geometry_msgs/Pose.h>
00030 #include <geometry_msgs/Twist.h>
00031 #include <sensor_msgs/JointState.h>
00032 
00033 #include <tf/transform_broadcaster.h>
00034 #include <tf/transform_listener.h>
00035 
00036 #include <Eigen/Dense>
00037 #include <Eigen/SVD>
00038 
00039 #include <kdl_parser/kdl_parser.hpp>
00040 #include <kdl/chainiksolvervel_pinv.hpp>
00041 #include <kdl/chainfksolvervel_recursive.hpp>
00042 #include <kdl/frames.hpp>
00043 #include <kdl/framevel.hpp>
00044 #include <kdl/jntarray.hpp>
00045 #include <kdl/jntarrayvel.hpp>
00046 
00047 #include <boost/thread.hpp>
00048 
00049 
00050 class OutputRecorder
00051 {
00052 public:
00053     bool initialize();
00054     void run();
00055     void stopRecording();
00056     void quit(int sig);
00057 
00058     void jointstateCallback(const sensor_msgs::JointState::ConstPtr& msg);
00059     void twistCallback(const geometry_msgs::TwistStamped::ConstPtr& msg);
00060 
00061     geometry_msgs::Pose getEndeffectorPose();
00062 
00063     double calculateLS(std::vector<double>* vec_out, std::vector<double>* vec_in, int model_order,
00064                        double& a1, double& a2, double& a3,
00065                        double& b1, double& b2, double& b3);
00066     void pseudoInverse(const Eigen::MatrixXd& matrix, Eigen::MatrixXd& matrix_inv, double tolerance);
00067     void euler(std::vector<double>* out, double in, double dt);
00068     void fillDataVectors(double x_dot_lin_in, double x_dot_lin_out,
00069                          double y_dot_lin_in, double y_dot_lin_out,
00070                          double z_dot_lin_in, double z_dot_lin_out,
00071                          double x_dot_rot_in, double x_dot_rot_out,
00072                          double y_dot_rot_in, double y_dot_rot_out,
00073                          double z_dot_rot_in, double z_dot_rot_out,
00074                          double x_lin_out, double y_lin_out, double z_lin_out, double x_rot_out, double y_rot_out, double z_rot_out);
00075     void stepResponsePlot(std::string file_name, std::vector<double>* in,
00076                           std::vector<double>* x_lin_out, std::vector<double>* y_lin_out, std::vector<double>* z_lin_out,
00077                           std::vector<double>* x_rot_out, std::vector<double>* y_rot_out, std::vector<double>* z_rot_out);
00078     void writeToMFile(std::string file_name, std::vector<double>* dot_in, std::vector<double>* dot_out, std::vector<double>* pos_out, std::vector<double>* dot_integrated);
00079 
00080 private:
00081     ros::NodeHandle nh_;
00082     ros::Subscriber twist_sub_;
00083     ros::Subscriber jointstate_sub_;
00084 
00086     KDL::Chain chain_;
00087     std::string output_file_path_;
00088     std::string chain_base_link_;
00089     std::string chain_tip_link_;
00090     KDL::JntArray last_q_;
00091     KDL::JntArray last_q_dot_;
00092     std::vector<std::string> joints_;
00093     KDL::ChainFkSolverVel_recursive* jntToCartSolver_vel_;
00094     unsigned int dof_;
00095     KDL::Vector vector_vel_, vector_rot_;
00096 
00098     // Velocity
00099     std::vector<double> x_dot_lin_vec_out_, y_dot_lin_vec_out_, z_dot_lin_vec_out_;
00100     std::vector<double> x_dot_rot_vec_out_, y_dot_rot_vec_out_, z_dot_rot_vec_out_;
00101 
00102     // Position
00103     std::vector<double> x_lin_vec_out_, y_lin_vec_out_, z_lin_vec_out_;
00104     std::vector<double> x_rot_vec_out_, y_rot_vec_out_, z_rot_vec_out_;
00105     double q_x_lin_out, q_y_lin_out, q_z_lin_out;
00106 
00108     std::vector<double> x_dot_lin_vec_in_, y_dot_lin_vec_in_, z_dot_lin_vec_in_;
00109     std::vector<double> x_dot_rot_vec_in_, y_dot_rot_vec_in_, z_dot_rot_vec_in_;
00110 
00111     double x_dot_lin_in_, y_dot_lin_in_, z_dot_lin_in_;
00112     double x_dot_rot_in_, y_dot_rot_in_, z_dot_rot_in_;
00113 
00115     tf::TransformListener listener_;
00116 
00118     double dt_;
00119 
00120     bool start_;
00121     bool finished_recording_;
00122     std::vector<double> time_vec_;
00123 
00125     char c;
00126     int kfd;
00127     struct termios cooked, raw;
00128 };
00129 
00130 #endif
00131 


cob_model_identifier
Author(s): Christoph Mark
autogenerated on Thu Jun 6 2019 21:19:11