constraint_base.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 
18 #ifndef COB_TWIST_CONTROLLER_CONSTRAINTS_CONSTRAINT_BASE_H
19 #define COB_TWIST_CONTROLLER_CONSTRAINTS_CONSTRAINT_BASE_H
20 
21 #include <set>
22 #include <string>
23 #include <limits>
24 #include <stdint.h>
25 #include <boost/shared_ptr.hpp>
26 #include <kdl/jntarray.hpp>
27 #include <kdl/jntarrayvel.hpp>
28 #include <Eigen/Core>
29 
38 template
39 <typename PRIO = uint32_t>
41 {
42  public:
43  explicit PriorityBase(PRIO prio): priority_(prio)
44  {}
45 
46  virtual ~PriorityBase()
47  {}
48 
49  inline void setPriority(PRIO prio)
50  {
51  this->priority_ = prio;
52  }
53 
54  inline bool operator<(const PriorityBase& other) const
55  {
56  return ( this->priority_ < other.priority_ );
57  }
58 
59  inline bool operator>(const PriorityBase& other) const
60  {
61  return ( this->priority_ > other.priority_ );
62  }
63 
64  inline bool operator==(const PriorityBase& other) const
65  {
66  return ( this->priority_ == other.priority_ );
67  }
68 
69  inline PRIO getPriority() const
70  {
71  return priority_;
72  }
73 
75  inline double getPriorityAsNum() const
76  {
77  return static_cast<double>(priority_);
78  }
79 
80  virtual Task_t createTask() = 0;
81  virtual std::string getTaskId() const = 0;
82  virtual ConstraintState getState() const = 0;
83  virtual Eigen::MatrixXd getTaskJacobian() const = 0;
84  virtual Eigen::VectorXd getTaskDerivatives() const = 0;
85 
86  virtual void update(const JointStates& joint_states, const KDL::JntArrayVel& joints_prediction, const Matrix6Xd_t& jacobian_data) = 0;
87  virtual void calculate() = 0;
88  virtual double getValue() const = 0;
89  virtual double getDerivativeValue() const = 0;
90  virtual Eigen::VectorXd getPartialValues() const = 0;
91  virtual double getPredictionValue() const = 0;
92 
93  virtual double getActivationGain() const = 0;
94  virtual double getSelfMotionMagnitude(const Eigen::MatrixXd& particular_solution,
95  const Eigen::MatrixXd& homogeneous_solution) const = 0;
96 
97  protected:
99 
100  virtual double getCriticalValue() const = 0;
101 };
102 
103 
109 template
110 <typename T_PARAMS, typename PRIO = uint32_t>
111 class ConstraintBase : public PriorityBase<PRIO>
112 {
113  public:
120  T_PARAMS params,
121  CallbackDataMediator& cbdm)
122  : PriorityBase<PRIO>(prio),
123  constraint_params_(params),
124  callback_data_mediator_(cbdm),
125  value_(0.0),
126  derivative_value_(0.0),
127  prediction_value_(std::numeric_limits<double>::max()),
128  last_value_(0.0),
129  last_time_(ros::Time::now()),
130  last_pred_time_(ros::Time::now())
131  {
132  this->member_inst_cnt_ = instance_ctr_++;
133  }
134 
135  virtual ~ConstraintBase()
136  {}
137 
138  virtual Task_t createTask()
139  {
140  Task_t task(this->getPriority(),
141  this->getTaskId(),
142  this->getTaskJacobian(),
143  this->getTaskDerivatives());
144  return task;
145  }
146 
147  virtual std::string getTaskId() const = 0;
148 
149  virtual ConstraintState getState() const
150  {
151  return this->state_;
152  }
153 
154  virtual Eigen::MatrixXd getTaskJacobian() const
155  {
156  return Eigen::MatrixXd::Zero(1, 1);
157  }
158 
159  virtual Eigen::VectorXd getTaskDerivatives() const
160  {
161  return Eigen::VectorXd::Zero(1, 1);
162  }
163 
164  virtual void update(const JointStates& joint_states, const KDL::JntArrayVel& joints_prediction, const Matrix6Xd_t& jacobian_data)
165  {
166  // ROS_INFO_STREAM("ConstraintBase::update: joint_states.current_q_.rows: " << joint_states.current_q_.rows());
167  // ROS_INFO_STREAM("ConstraintBase::update: joints_prediction.q.rows: " << joints_prediction.q.rows());
168  // ROS_INFO_STREAM("ConstraintBase::update: jacobian_data.cols: " << jacobian_data.cols());
169 
170  this->joint_states_ = joint_states;
171  this->jacobian_data_ = jacobian_data;
172  this->jnts_prediction_ = joints_prediction;
173  this->callback_data_mediator_.fill(this->constraint_params_);
174  this->calculate();
175  }
176 
177  virtual void calculate() = 0;
178 
179  virtual double getValue() const
180  {
181  return this->value_;
182  }
183 
184  virtual double getDerivativeValue() const
185  {
186  return this->derivative_value_;
187  }
188 
189  virtual Eigen::VectorXd getPartialValues() const
190  {
191  return this->partial_values_;
192  }
193 
194  virtual double getPredictionValue() const
195  {
196  return this->prediction_value_;
197  }
198 
199  virtual double getActivationGain() const = 0;
200  virtual double getSelfMotionMagnitude(const Eigen::MatrixXd& particular_solution,
201  const Eigen::MatrixXd& homogeneous_solution) const = 0;
202 
203  protected:
207 
211 
212  double value_;
214  Eigen::VectorXd partial_values_;
216  double last_value_;
219 
221  static uint32_t instance_ctr_;
222 
223  virtual double getCriticalValue() const
224  {
225  return 0.0;
226  }
227 };
228 
229 template <typename T_PARAMS, typename PRIO>
231 
233 
234 #endif // COB_TWIST_CONTROLLER_CONSTRAINTS_CONSTRAINT_BASE_H
PriorityBase(PRIO prio)
virtual Eigen::MatrixXd getTaskJacobian() const =0
double now()
virtual Eigen::VectorXd getTaskDerivatives() const
double derivative_value_
bool operator<(const PriorityBase &other) const
void setPriority(PRIO prio)
virtual Eigen::MatrixXd getTaskJacobian() const
CallbackDataMediator & callback_data_mediator_
JointStates joint_states_
bool operator==(const PriorityBase &other) const
double prediction_value_
virtual double getCriticalValue() const =0
ros::Time last_time_
static uint32_t instance_ctr_
Matrix6Xd_t jacobian_data_
ConstraintState state_
virtual double getCriticalValue() const
virtual double getPredictionValue() const
uint32_t member_inst_cnt_
virtual double getActivationGain() const =0
virtual Eigen::VectorXd getPartialValues() const =0
virtual Task_t createTask()
virtual double getValue() const
virtual Task_t createTask()=0
ConstraintBase(PRIO prio, T_PARAMS params, CallbackDataMediator &cbdm)
virtual double getValue() const =0
bool operator>(const PriorityBase &other) const
virtual double getDerivativeValue() const =0
T_PARAMS constraint_params_
virtual ~PriorityBase()
KDL::JntArrayVel jnts_prediction_
virtual std::string getTaskId() const =0
virtual ConstraintState getState() const
virtual double getSelfMotionMagnitude(const Eigen::MatrixXd &particular_solution, const Eigen::MatrixXd &homogeneous_solution) const =0
PRIO getPriority() const
ros::Time last_pred_time_
virtual double getPredictionValue() const =0
virtual void update(const JointStates &joint_states, const KDL::JntArrayVel &joints_prediction, const Matrix6Xd_t &jacobian_data)=0
Eigen::Matrix< double, 6, Eigen::Dynamic > Matrix6Xd_t
virtual ConstraintState getState() const =0
virtual void calculate()=0
virtual double getDerivativeValue() const
virtual Eigen::VectorXd getTaskDerivatives() const =0
virtual void update(const JointStates &joint_states, const KDL::JntArrayVel &joints_prediction, const Matrix6Xd_t &jacobian_data)
double max(double a, double b)
boost::shared_ptr< PriorityBase< uint32_t > > ConstraintBase_t
double getPriorityAsNum() const
Ensure priority class has overwritten double() operator.
Eigen::VectorXd partial_values_
Represents a data pool for distribution of collected data from ROS callback.
virtual ~ConstraintBase()
virtual Eigen::VectorXd getPartialValues() const


cob_twist_controller
Author(s): Felix Messmer , Marco Bezzon , Christoph Mark , Francisco Moreno
autogenerated on Thu Apr 8 2021 02:40:00