- 3.0.2 core module.
CustomController.h
Go to the documentation of this file.
1 /**********************************************************************************************************************
2 This file is part of the Control Toolbox (https://github.com/ethz-adrl/control-toolbox), copyright by ETH Zurich.
3 Licensed under the BSD-2 license (see LICENSE file in main directory)
4  **********************************************************************************************************************/
5 
6 #pragma once
7 
15 class CustomController : public ct::core::Controller<2, 1>
17 {
18 public:
19  static const size_t state_dim = 2; // two states
20  static const size_t control_dim = 1; // one control action
21 
23  CustomController(const ct::core::ControlVector<control_dim>& uff, // feedforward control
24  const double& kp, // P gain
25  const double& kd // D gain
26  )
27  : uff_(uff), kp_(kp), kd_(kd)
28  {
29  }
30 
34  CustomController(const CustomController& other) : uff_(other.uff_), kp_(other.kp_), kd_(other.kd_) {}
36  CustomController* clone() const override
37  {
38  return new CustomController(*this); // calls copy constructor
39  }
40 
43  const double& t,
44  ct::core::ControlVector<control_dim>& controlAction) override
45  {
46  controlAction = uff_; // apply feedforward control
47  controlAction(0) -= kp_ * state(0) + kd_ * state(1); // add feedback control
48  }
49 
50 private:
52  double kp_;
53  double kd_;
54 };
an example controller class that takes a 2-dimensional state and outputs a 1-dimensional control acti...
Definition: CustomController.h:16
static const size_t state_dim
Definition: CustomController.h:19
CustomController(const CustomController &other)
copy constructor
Definition: CustomController.h:34
static const size_t control_dim
Definition: CustomController.h:20
CustomController * clone() const override
clone method, needs to be implemented, overrides ct::core::Controller::clone()
Definition: CustomController.h:36
void computeControl(const ct::core::StateVector< state_dim > &state, const double &t, ct::core::ControlVector< control_dim > &controlAction) override
override the compute control method with a custom control law
Definition: CustomController.h:42
Definition: StateVector.h:12
~CustomController()
destructor
Definition: CustomController.h:32
CustomController(const ct::core::ControlVector< control_dim > &uff, const double &kp, const double &kd)
default constructor
Definition: CustomController.h:23
Interface class for all controllers.
Definition: Controller.h:26