PX4 Firmware
PX4 Autopilot Software http://px4.io
ecl_controller.h
Go to the documentation of this file.
1
/****************************************************************************
2
*
3
* Copyright (c) 2013 Estimation and Control Library (ECL). All rights reserved.
4
*
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
7
* are met:
8
*
9
* 1. Redistributions of source code must retain the above copyright
10
* notice, this list of conditions and the following disclaimer.
11
* 2. Redistributions in binary form must reproduce the above copyright
12
* notice, this list of conditions and the following disclaimer in
13
* the documentation and/or other materials provided with the
14
* distribution.
15
* 3. Neither the name ECL nor the names of its contributors may be
16
* used to endorse or promote products derived from this software
17
* without specific prior written permission.
18
*
19
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
* POSSIBILITY OF SUCH DAMAGE.
31
*
32
****************************************************************************/
33
34
/**
35
* @file ecl_controller.h
36
* Definition of base class for other controllers
37
*
38
* @author Lorenz Meier <lm@inf.ethz.ch>
39
* @author Thomas Gubler <thomasgubler@gmail.com>
40
*
41
* Acknowledgements:
42
*
43
* The control design is based on a design
44
* by Paul Riseborough and Andrew Tridgell, 2013,
45
* which in turn is based on initial work of
46
* Jonathan Challinger, 2012.
47
*/
48
49
#pragma once
50
51
#include <
ecl.h
>
52
53
struct
ECL_ControlData
{
54
float
roll
;
55
float
pitch
;
56
float
yaw
;
57
float
body_x_rate
;
58
float
body_y_rate
;
59
float
body_z_rate
;
60
float
roll_setpoint
;
61
float
pitch_setpoint
;
62
float
yaw_setpoint
;
63
float
roll_rate_setpoint
;
64
float
pitch_rate_setpoint
;
65
float
yaw_rate_setpoint
;
66
float
airspeed_min
;
67
float
airspeed_max
;
68
float
airspeed
;
69
float
scaler
;
70
float
groundspeed
;
71
float
groundspeed_scaler
;
72
bool
lock_integrator
;
73
};
74
75
class
ECL_Controller
76
{
77
public
:
78
ECL_Controller
();
79
virtual
~
ECL_Controller
() =
default
;
80
81
virtual
float
control_attitude(
const
struct
ECL_ControlData
&ctl_data) = 0;
82
virtual
float
control_euler_rate(
const
struct
ECL_ControlData
&ctl_data) = 0;
83
virtual
float
control_bodyrate(
const
struct
ECL_ControlData
&ctl_data) = 0;
84
85
/* Setters */
86
void
set_time_constant(
float
time_constant);
87
void
set_k_p(
float
k_p);
88
void
set_k_i(
float
k_i);
89
void
set_k_ff(
float
k_ff);
90
void
set_integrator_max(
float
max
);
91
void
set_max_rate(
float
max_rate);
92
void
set_bodyrate_setpoint(
float
rate);
93
94
/* Getters */
95
float
get_rate_error();
96
float
get_desired_rate();
97
float
get_desired_bodyrate();
98
float
get_integrator();
99
100
void
reset_integrator();
101
102
protected
:
103
uint64_t
_last_run
;
104
float
_tc
;
105
float
_k_p
;
106
float
_k_i
;
107
float
_k_ff
;
108
float
_integrator_max
;
109
float
_max_rate
;
110
float
_last_output
;
111
float
_integrator
;
112
float
_rate_error
;
113
float
_rate_setpoint
;
114
float
_bodyrate_setpoint
;
115
float
constrain_airspeed(
float
airspeed
,
float
minspeed,
float
maxspeed);
116
};
ECL_ControlData::pitch_setpoint
float pitch_setpoint
Definition:
ecl_controller.h:61
ECL_ControlData::airspeed
float airspeed
Definition:
ecl_controller.h:68
ecl.h
Adapter / shim layer for system calls needed by ECL.
ECL_ControlData::body_y_rate
float body_y_rate
Definition:
ecl_controller.h:58
ECL_ControlData::yaw
float yaw
Definition:
ecl_controller.h:56
ECL_ControlData::pitch_rate_setpoint
float pitch_rate_setpoint
Definition:
ecl_controller.h:64
ECL_Controller::_integrator_max
float _integrator_max
Definition:
ecl_controller.h:108
ECL_ControlData::roll_setpoint
float roll_setpoint
Definition:
ecl_controller.h:60
ECL_Controller::_rate_error
float _rate_error
Definition:
ecl_controller.h:112
ECL_ControlData::scaler
float scaler
Definition:
ecl_controller.h:69
ECL_Controller::_rate_setpoint
float _rate_setpoint
Definition:
ecl_controller.h:113
ECL_Controller::_max_rate
float _max_rate
Definition:
ecl_controller.h:109
ECL_ControlData::airspeed_min
float airspeed_min
Definition:
ecl_controller.h:66
ECL_Controller
Definition:
ecl_controller.h:75
ECL_ControlData::yaw_setpoint
float yaw_setpoint
Definition:
ecl_controller.h:62
ECL_ControlData
Definition:
ecl_controller.h:53
ECL_ControlData::airspeed_max
float airspeed_max
Definition:
ecl_controller.h:67
ECL_ControlData::body_x_rate
float body_x_rate
Definition:
ecl_controller.h:57
ECL_ControlData::roll
float roll
Definition:
ecl_controller.h:54
ECL_Controller::_k_ff
float _k_ff
Definition:
ecl_controller.h:107
ECL_Controller::_integrator
float _integrator
Definition:
ecl_controller.h:111
ECL_Controller::_k_i
float _k_i
Definition:
ecl_controller.h:106
ECL_ControlData::yaw_rate_setpoint
float yaw_rate_setpoint
Definition:
ecl_controller.h:65
ECL_Controller::_bodyrate_setpoint
float _bodyrate_setpoint
Definition:
ecl_controller.h:114
ECL_Controller::_k_p
float _k_p
Definition:
ecl_controller.h:105
math::max
constexpr _Tp max(_Tp a, _Tp b)
Definition:
Limits.hpp:60
ECL_ControlData::lock_integrator
bool lock_integrator
Definition:
ecl_controller.h:72
ECL_ControlData::groundspeed
float groundspeed
Definition:
ecl_controller.h:70
ECL_ControlData::roll_rate_setpoint
float roll_rate_setpoint
Definition:
ecl_controller.h:63
ECL_ControlData::pitch
float pitch
Definition:
ecl_controller.h:55
ECL_ControlData::body_z_rate
float body_z_rate
Definition:
ecl_controller.h:59
ECL_Controller::_last_output
float _last_output
Definition:
ecl_controller.h:110
ECL_ControlData::groundspeed_scaler
float groundspeed_scaler
Definition:
ecl_controller.h:71
ECL_Controller::_last_run
uint64_t _last_run
Definition:
ecl_controller.h:103
ECL_Controller::_tc
float _tc
Definition:
ecl_controller.h:104
src
lib
ecl
attitude_fw
ecl_controller.h
Generated by
1.8.13