orwell 0.0.0
Controller.hpp
1/*
2 Copyright (c) Tobias Löw
3 Written by Tobias Löw <https://tobiloew.ch>
4
5 This file is part of orwell.
6
7 gafro is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License version 3 as
9 published by the Free Software Foundation.
10
11 gafro is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with gafro. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#pragma once
21
22#include <Eigen/Core>
23//
24#include <sackmesser/FactoryClass.hpp>
25#include <sackmesser/Interface.hpp>
26//
27#include <orwell/RobotModel.hpp>
28#include <orwell/RobotState.hpp>
29#include <orwell/StoppingCriterion.hpp>
30
31namespace orwell
32{
33
40 template <int dof>
41 class Controller : public std::enable_shared_from_this<Controller<dof>>
42 {
43 public:
51 Controller(const sackmesser::Interface::Ptr &interface, const std::string &name);
52
56 virtual ~Controller() = default;
57
66
73 void setRobotModel(const typename RobotModel<dof>::Ptr &robot_model);
74
81 void setStoppingCriterion(const std::shared_ptr<StoppingCriterion<dof>> &stopping_criterion);
82
90 bool isFinished(const RobotState<dof> &robot_state) const;
91
99 template <class Derived>
100 typename Derived::Ptr cast();
101
102 protected:
109
116
122 const RobotState<dof> &getRobotState() const;
123
124 private:
132 typename RobotState<dof>::Vector limitCommand(const typename RobotState<dof>::Vector &command);
133
134 private:
136 typename RobotModel<dof>::Ptr robot_model_;
137
139 RobotState<dof> robot_state_;
140
145 struct Configuration : public sackmesser::Configuration
146 {
151 bool load(const std::string &ns, const std::shared_ptr<sackmesser::Configurations> &server);
152
154 typename RobotState<dof>::Vector command_limits_;
155 } config_;
156
158 std::shared_ptr<StoppingCriterion<dof>> stopping_criterion_;
159
160 private:
161 // declare ParallelController as friend class such that it can access protected method computeCommand
162 template <int, template <int> class>
163 friend class ParallelController;
164 };
165
166} // namespace orwell
167
168#include <orwell/Controller.hxx>
base class for controller implementation
RobotState< dof >::Vector getControlCommand(const RobotState< dof > &robot_state)
general function to obtain control commands
bool isFinished(const RobotState< dof > &robot_state) const
check if the StoppingCriterion is fulfilled
const RobotState< dof > & getRobotState() const
proved access to the RobotState to derived classes
RobotModel< dof >::Ptr getRobotModel()
proved access to the RobotModel to derived classes
Derived::Ptr cast()
cast Controller to a derived class
void setRobotModel(const typename RobotModel< dof >::Ptr &robot_model)
set the RobotModel
virtual RobotState< dof >::Vector computeCommand()=0
will be invoked when calling getControlCommand
Controller(const sackmesser::Interface::Ptr &interface, const std::string &name)
loads configuration parameters
void setStoppingCriterion(const std::shared_ptr< StoppingCriterion< dof > > &stopping_criterion)
(optional) StoppingCriterion
invokes several controllers in parallel and combines their control command
std::shared_ptr< RobotModel > Ptr
typedef
describes the RobotState
Eigen::Vector< double, dof > Vector
typedef
base class for a stopping criterion for a Controller