constraint_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_TWIST_CONTROLLER_CONSTRAINTS_CONSTRAINT_BASE_H
00019 #define COB_TWIST_CONTROLLER_CONSTRAINTS_CONSTRAINT_BASE_H
00020 
00021 #include <set>
00022 #include <string>
00023 #include <limits>
00024 #include <stdint.h>
00025 #include <boost/shared_ptr.hpp>
00026 #include <kdl/jntarray.hpp>
00027 #include <kdl/jntarrayvel.hpp>
00028 #include <Eigen/Core>
00029 
00030 #include "cob_twist_controller/cob_twist_controller_data_types.h"
00031 #include "cob_twist_controller/constraints/constraint_params.h"
00032 #include "cob_twist_controller/callback_data_mediator.h"
00033 #include "cob_twist_controller/task_stack/task_stack_controller.h"
00038 template
00039 <typename PRIO = uint32_t>
00040 class PriorityBase
00041 {
00042     public:
00043         explicit PriorityBase(PRIO prio): priority_(prio)
00044         {}
00045 
00046         virtual ~PriorityBase()
00047         {}
00048 
00049         inline void setPriority(PRIO prio)
00050         {
00051             this->priority_ = prio;
00052         }
00053 
00054         inline bool operator<(const PriorityBase& other) const
00055         {
00056             return ( this->priority_ < other.priority_ );
00057         }
00058 
00059         inline bool operator>(const PriorityBase& other) const
00060         {
00061             return ( this->priority_ > other.priority_ );
00062         }
00063 
00064         inline bool operator==(const PriorityBase& other) const
00065         {
00066             return ( this->priority_ == other.priority_ );
00067         }
00068 
00069         inline PRIO getPriority() const
00070         {
00071             return priority_;
00072         }
00073 
00075         inline double getPriorityAsNum() const
00076         {
00077             return static_cast<double>(priority_);
00078         }
00079 
00080         virtual Task_t createTask() = 0;
00081         virtual std::string getTaskId() const = 0;
00082         virtual ConstraintState getState() const = 0;
00083         virtual Eigen::MatrixXd getTaskJacobian() const = 0;
00084         virtual Eigen::VectorXd getTaskDerivatives() const = 0;
00085 
00086         virtual void update(const JointStates& joint_states, const KDL::JntArrayVel& joints_prediction, const Matrix6Xd_t& jacobian_data) = 0;
00087         virtual void calculate() = 0;
00088         virtual double getValue() const = 0;
00089         virtual double getDerivativeValue() const = 0;
00090         virtual Eigen::VectorXd getPartialValues() const = 0;
00091         virtual double getPredictionValue() const = 0;
00092 
00093         virtual double getActivationGain() const = 0;
00094         virtual double getSelfMotionMagnitude(const Eigen::MatrixXd& particular_solution,
00095                                               const Eigen::MatrixXd& homogeneous_solution) const = 0;
00096 
00097     protected:
00098         PRIO priority_;
00099 
00100         virtual double getCriticalValue() const = 0;
00101 };
00102 
00103 
00109 template
00110 <typename T_PARAMS, typename PRIO = uint32_t>
00111 class ConstraintBase : public PriorityBase<PRIO>
00112 {
00113     public:
00119         ConstraintBase(PRIO prio,
00120                        T_PARAMS params,
00121                        CallbackDataMediator& cbdm)
00122         : PriorityBase<PRIO>(prio),
00123           constraint_params_(params),
00124           callback_data_mediator_(cbdm),
00125           value_(0.0),
00126           derivative_value_(0.0),
00127           prediction_value_(std::numeric_limits<double>::max()),
00128           last_value_(0.0),
00129           last_time_(ros::Time::now()),
00130           last_pred_time_(ros::Time::now())
00131         {
00132             this->member_inst_cnt_ = instance_ctr_++;
00133         }
00134 
00135         virtual ~ConstraintBase()
00136         {}
00137 
00138         virtual Task_t createTask()
00139         {
00140             Task_t task(this->getPriority(),
00141                         this->getTaskId(),
00142                         this->getTaskJacobian(),
00143                         this->getTaskDerivatives());
00144             return task;
00145         }
00146 
00147         virtual std::string getTaskId() const = 0;
00148 
00149         virtual ConstraintState getState() const
00150         {
00151             return this->state_;
00152         }
00153 
00154         virtual Eigen::MatrixXd getTaskJacobian() const
00155         {
00156             return Eigen::MatrixXd::Zero(1, 1);
00157         }
00158 
00159         virtual Eigen::VectorXd getTaskDerivatives() const
00160         {
00161             return Eigen::VectorXd::Zero(1, 1);
00162         }
00163 
00164         virtual void update(const JointStates& joint_states, const KDL::JntArrayVel& joints_prediction, const Matrix6Xd_t& jacobian_data)
00165         {
00166             // ROS_INFO_STREAM("ConstraintBase::update: joint_states.current_q_.rows: " << joint_states.current_q_.rows());
00167             // ROS_INFO_STREAM("ConstraintBase::update: joints_prediction.q.rows: " << joints_prediction.q.rows());
00168             // ROS_INFO_STREAM("ConstraintBase::update: jacobian_data.cols: " << jacobian_data.cols());
00169 
00170             this->joint_states_ = joint_states;
00171             this->jacobian_data_ = jacobian_data;
00172             this->jnts_prediction_ = joints_prediction;
00173             this->callback_data_mediator_.fill(this->constraint_params_);
00174             this->calculate();
00175         }
00176 
00177         virtual void calculate() = 0;
00178 
00179         virtual double getValue() const
00180         {
00181             return this->value_;
00182         }
00183 
00184         virtual double getDerivativeValue() const
00185         {
00186             return this->derivative_value_;
00187         }
00188 
00189         virtual Eigen::VectorXd getPartialValues() const
00190         {
00191             return this->partial_values_;
00192         }
00193 
00194         virtual double getPredictionValue() const
00195         {
00196             return this->prediction_value_;
00197         }
00198 
00199         virtual double getActivationGain() const = 0;
00200         virtual double getSelfMotionMagnitude(const Eigen::MatrixXd& particular_solution,
00201                                               const Eigen::MatrixXd& homogeneous_solution) const = 0;
00202 
00203     protected:
00204         ConstraintState state_;
00205         T_PARAMS constraint_params_;
00206         CallbackDataMediator& callback_data_mediator_;
00207 
00208         JointStates joint_states_;
00209         KDL::JntArrayVel jnts_prediction_;
00210         Matrix6Xd_t jacobian_data_;
00211 
00212         double value_;
00213         double derivative_value_;
00214         Eigen::VectorXd partial_values_;
00215         double prediction_value_;
00216         double last_value_;
00217         ros::Time last_time_;
00218         ros::Time last_pred_time_;
00219 
00220         uint32_t member_inst_cnt_;
00221         static uint32_t instance_ctr_;
00222 
00223         virtual double getCriticalValue() const
00224         {
00225             return 0.0;
00226         }
00227 };
00228 
00229 template <typename T_PARAMS, typename PRIO>
00230 uint32_t ConstraintBase<T_PARAMS, PRIO>::instance_ctr_ = 0;
00231 
00232 typedef boost::shared_ptr<PriorityBase<uint32_t> > ConstraintBase_t;
00233 
00234 #endif  // COB_TWIST_CONTROLLER_CONSTRAINTS_CONSTRAINT_BASE_H


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