trajectory_profile_generator_base.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 COB_CARTESIAN_CONTROLLER_TRAJECTORY_PROFILE_GENERATOR_TRAJECTORY_PROFILE_GENERATOR_BASE_H
00019 #define COB_CARTESIAN_CONTROLLER_TRAJECTORY_PROFILE_GENERATOR_TRAJECTORY_PROFILE_GENERATOR_BASE_H
00020 
00021 #include <vector>
00022 #include <ros/ros.h>
00023 #include <cob_cartesian_controller/cartesian_controller_data_types.h>
00024 #include <cob_cartesian_controller/cartesian_controller_utils.h>
00025 
00026 
00027 #define MIN_VELOCITY_THRESHOLD 0.001
00028 
00029 class TrajectoryProfileBase
00030 {
00031 public:
00032     explicit TrajectoryProfileBase(const cob_cartesian_controller::CartesianActionStruct& params)
00033     :    params_(params)
00034     {}
00035 
00036     virtual ~TrajectoryProfileBase()
00037     {}
00038 
00039     virtual bool calculateProfile(std::vector<double>* path_matrix,
00040                                   const double Se_lin, const double Se_rot)
00041     {
00042         CartesianControllerUtils ccu;
00043         std::vector<double> linear_path, angular_path;
00044 
00045         cob_cartesian_controller::PathArray lin(Se_lin, linear_path);
00046         cob_cartesian_controller::PathArray rot(Se_rot, angular_path);
00047 
00048         cob_cartesian_controller::PathMatrix pm(lin, rot);
00049 
00050         // Get the profile timings from the longest path
00051         bool success = getProfileTimings(pm.getMaxSe(), 0, true, pt_max_);
00052 
00053         // Calculate the paths
00054         for (unsigned int i = 0; i < pm.pm_.size(); i++)
00055         {
00056             generatePath(pm.pm_[i]);
00057         }
00058 
00059         // Adjust the array length
00060         // If no trajectory was interpolated, then this path array contains only one constant value.
00061         // This constant value needs to be duplicated N_max times for matrix conversion purposes.
00062         ccu.adjustArrayLength(pm.pm_);
00063 
00064         ccu.copyMatrix(path_matrix, pm.pm_);
00065 
00066         return true;
00067     }
00068 
00069 protected:
00070     virtual bool generatePath(cob_cartesian_controller::PathArray& pa)
00071     {
00072         std::vector<double> array;
00073         cob_cartesian_controller::ProfileTimings pt;
00074 
00075         // Calculate the Profile Timings
00076         if (getProfileTimings(pa.Se_, pt_max_.te, false, pt))
00077         {
00078             array = getTrajectory(pa.Se_, pt);
00079         }
00080         else
00081         {
00082             array.push_back(0);
00083         }
00084 
00085         pa.array_ = array;
00086         return true;
00087     }
00088 
00089     virtual bool getProfileTimings(double Se, double te, bool calcMaxTe, cob_cartesian_controller::ProfileTimings& pt) = 0;
00090     virtual std::vector<double> getTrajectory(double se, cob_cartesian_controller::ProfileTimings pt) = 0;
00091 
00092     const cob_cartesian_controller::CartesianActionStruct& params_;
00093     cob_cartesian_controller::ProfileTimings pt_max_;
00094 };
00095 
00096 #endif  // COB_CARTESIAN_CONTROLLER_TRAJECTORY_PROFILE_GENERATOR_TRAJECTORY_PROFILE_GENERATOR_BASE_H


cob_cartesian_controller
Author(s): Christoph Mark
autogenerated on Thu Jun 6 2019 21:19:40