Control Libraries 7.4.0
Loading...
Searching...
No Matches
ControllerFactory.cpp
1#include "controllers/ControllerFactory.hpp"
2
3#include "controllers/exceptions/InvalidControllerException.hpp"
4#include "controllers/impedance/Impedance.hpp"
5#include "controllers/impedance/VelocityImpedance.hpp"
6#include "controllers/impedance/Dissipative.hpp"
7#include "controllers/impedance/CompliantTwist.hpp"
8
9using namespace state_representation;
10
11namespace controllers {
12
13template<>
14std::shared_ptr<IController<CartesianState>> ControllerFactory<CartesianState>::create_controller(
15 CONTROLLER_TYPE type, const std::list<std::shared_ptr<ParameterInterface>>& parameters, unsigned int
16) {
17 switch (type) {
18 case CONTROLLER_TYPE::IMPEDANCE:
19 return std::make_shared<impedance::Impedance<CartesianState>>(parameters);
20 case CONTROLLER_TYPE::VELOCITY_IMPEDANCE:
21 return std::make_shared<impedance::VelocityImpedance<CartesianState>>(parameters);
22 case CONTROLLER_TYPE::DISSIPATIVE:
23 return std::make_shared<impedance::Dissipative<CartesianState>>(
24 parameters, impedance::ComputationalSpaceType::FULL);
25 case CONTROLLER_TYPE::DISSIPATIVE_LINEAR:
26 return std::make_shared<impedance::Dissipative<CartesianState>>(
27 parameters, impedance::ComputationalSpaceType::LINEAR);
28 case CONTROLLER_TYPE::DISSIPATIVE_ANGULAR:
29 return std::make_shared<impedance::Dissipative<CartesianState>>(
30 parameters, impedance::ComputationalSpaceType::ANGULAR);
31 case CONTROLLER_TYPE::DISSIPATIVE_DECOUPLED:
32 return std::make_shared<impedance::Dissipative<CartesianState>>(
33 parameters, impedance::ComputationalSpaceType::DECOUPLED_TWIST);
34 case CONTROLLER_TYPE::COMPLIANT_TWIST:
35 return std::make_shared<impedance::CompliantTwist>(parameters);
36 default:
37 case CONTROLLER_TYPE::NONE:
38 return nullptr;
39 }
40}
41
42template<>
43std::shared_ptr<IController<JointState>> ControllerFactory<JointState>::create_controller(
44 CONTROLLER_TYPE type, const std::list<std::shared_ptr<ParameterInterface>>& parameters, unsigned int dimensions
45) {
46 switch (type) {
47 case CONTROLLER_TYPE::IMPEDANCE:
48 return std::make_shared<impedance::Impedance<JointState>>(parameters, dimensions);
49 case CONTROLLER_TYPE::VELOCITY_IMPEDANCE:
50 return std::make_shared<impedance::VelocityImpedance<JointState>>(parameters, dimensions);
51 case CONTROLLER_TYPE::DISSIPATIVE:
52 return std::make_shared<impedance::Dissipative<JointState>>(
53 parameters, impedance::ComputationalSpaceType::FULL, dimensions);
54 case CONTROLLER_TYPE::DISSIPATIVE_LINEAR:
55 case CONTROLLER_TYPE::DISSIPATIVE_ANGULAR:
56 case CONTROLLER_TYPE::DISSIPATIVE_DECOUPLED:
57 throw exceptions::InvalidControllerException(
58 "The JointState dissipative controller cannot be decoupled into linear and angular terms");
59 case CONTROLLER_TYPE::COMPLIANT_TWIST:
60 throw exceptions::InvalidControllerException(
61 "The compliant twist controller only works in Cartesian space");
62 default:
63 case CONTROLLER_TYPE::NONE:
64 return nullptr;
65 }
66}
67
68template<>
69std::shared_ptr<IController<CartesianState>> ControllerFactory<CartesianState>::create_controller(
70 CONTROLLER_TYPE type, const std::list<std::shared_ptr<ParameterInterface>>& parameters,
72) {
73 auto ctrl = ControllerFactory<CartesianState>::create_controller(type, parameters);
74 if (ctrl == nullptr) {
75 throw exceptions::InvalidControllerException("Cannot assign robot model to this controller!");
76 }
77 ctrl->set_robot_model(robot_model);
78 return ctrl;
79}
80
81template<>
82std::shared_ptr<IController<JointState>> ControllerFactory<JointState>::create_controller(
83 CONTROLLER_TYPE type, const std::list<std::shared_ptr<ParameterInterface>>& parameters,
85) {
86 auto ctrl = ControllerFactory<JointState>::create_controller(type, parameters, robot_model.get_number_of_joints());
87 if (ctrl == nullptr) {
88 throw exceptions::InvalidControllerException("Cannot assign robot model to this controller!");
89 }
90 ctrl->set_robot_model(robot_model);
91 return ctrl;
92}
93
94}// namespace controllers
static std::shared_ptr< IController< S > > create_controller(CONTROLLER_TYPE type, unsigned int dimensions=6)
Create a controller of the desired type.
The Model class is a wrapper around pinocchio dynamic computation library with state_representation e...
Definition Model.hpp:62
Systems to determine a command output from measured and desired inputs.
CONTROLLER_TYPE
Enumeration of the implemented controllers.
Robot kinematics and dynamics.
Core state variables and objects.