aboutsummaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorThomas Gubler <thomasgubler@gmail.com>2013-10-20 15:03:11 +0200
committerThomas Gubler <thomasgubler@gmail.com>2013-10-24 18:08:23 +0200
commit146279b20fc65705e31e03298a1d3eea8911d0f8 (patch)
tree846eaf2859548eabc100a08393f9bad6e9480de5 /src/lib
parent3c14483df247fb842cabdbb02206912f7f4350cf (diff)
downloadpx4-firmware-146279b20fc65705e31e03298a1d3eea8911d0f8.tar.gz
px4-firmware-146279b20fc65705e31e03298a1d3eea8911d0f8.tar.bz2
px4-firmware-146279b20fc65705e31e03298a1d3eea8911d0f8.zip
wip fw ctrl, several small bugfixes, set limit to 1
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/ecl/attitude_fw/ecl_pitch_controller.cpp11
-rw-r--r--src/lib/ecl/attitude_fw/ecl_pitch_controller.h1
-rw-r--r--src/lib/ecl/attitude_fw/ecl_roll_controller.cpp15
-rw-r--r--src/lib/ecl/attitude_fw/ecl_roll_controller.h1
-rw-r--r--src/lib/ecl/attitude_fw/ecl_yaw_controller.cpp9
-rw-r--r--src/lib/ecl/attitude_fw/ecl_yaw_controller.h1
6 files changed, 17 insertions, 21 deletions
diff --git a/src/lib/ecl/attitude_fw/ecl_pitch_controller.cpp b/src/lib/ecl/attitude_fw/ecl_pitch_controller.cpp
index 8b9ba9c62..531512493 100644
--- a/src/lib/ecl/attitude_fw/ecl_pitch_controller.cpp
+++ b/src/lib/ecl/attitude_fw/ecl_pitch_controller.cpp
@@ -51,8 +51,7 @@ ECL_PitchController::ECL_PitchController() :
_last_output(0.0f),
_integrator(0.0f),
_rate_error(0.0f),
- _rate_setpoint(0.0f),
- _max_deflection_rad(math::radians(45.0f))
+ _rate_setpoint(0.0f)
{
}
@@ -148,10 +147,10 @@ float ECL_PitchController::control_bodyrate(float roll, float pitch,
/*
* anti-windup: do not allow integrator to increase if actuator is at limit
*/
- if (_last_output < -_max_deflection_rad) {
+ if (_last_output < -1.0f) {
/* only allow motion to center: increase value */
id = math::max(id, 0.0f);
- } else if (_last_output > _max_deflection_rad) {
+ } else if (_last_output > 1.0f) {
/* only allow motion to center: decrease value */
id = math::min(id, 0.0f);
}
@@ -163,9 +162,9 @@ float ECL_PitchController::control_bodyrate(float roll, float pitch,
_integrator = math::constrain(_integrator, -_integrator_max, _integrator_max);
/* Apply PI rate controller and store non-limited output */
- _last_output = (_rate_error * _k_p + _integrator * _k_i * _rate_setpoint * k_ff) * scaler * scaler; //scaler^2 is proportional to 1/airspeed^2
+ _last_output = (_rate_error * _k_p + _integrator * _k_i + _rate_setpoint * k_ff) * scaler * scaler; //scaler is proportional to 1/airspeed
- return math::constrain(_last_output, -_max_deflection_rad, _max_deflection_rad);
+ return math::constrain(_last_output, -1.0f, 1.0f);
}
void ECL_PitchController::reset_integrator()
diff --git a/src/lib/ecl/attitude_fw/ecl_pitch_controller.h b/src/lib/ecl/attitude_fw/ecl_pitch_controller.h
index ef6129d02..ba8ed3e6f 100644
--- a/src/lib/ecl/attitude_fw/ecl_pitch_controller.h
+++ b/src/lib/ecl/attitude_fw/ecl_pitch_controller.h
@@ -120,7 +120,6 @@ private:
float _rate_error;
float _rate_setpoint;
float _bodyrate_setpoint;
- float _max_deflection_rad;
};
#endif // ECL_PITCH_CONTROLLER_H
diff --git a/src/lib/ecl/attitude_fw/ecl_roll_controller.cpp b/src/lib/ecl/attitude_fw/ecl_roll_controller.cpp
index f3909593a..e5bd7b4f7 100644
--- a/src/lib/ecl/attitude_fw/ecl_roll_controller.cpp
+++ b/src/lib/ecl/attitude_fw/ecl_roll_controller.cpp
@@ -54,8 +54,7 @@ ECL_RollController::ECL_RollController() :
_integrator(0.0f),
_rate_error(0.0f),
_rate_setpoint(0.0f),
- _bodyrate_setpoint(0.0f),
- _max_deflection_rad(math::radians(45.0f))
+ _bodyrate_setpoint(0.0f)
{
}
@@ -96,6 +95,7 @@ float ECL_RollController::control_bodyrate(float pitch,
float k_ff = 0; //xxx: param
/* input conditioning */
+// warnx("airspeed pre %.4f", (double)airspeed);
if (!isfinite(airspeed)) {
/* airspeed is NaN, +- INF or not available, pick center of band */
airspeed = 0.5f * (airspeed_min + airspeed_max);
@@ -120,10 +120,10 @@ float ECL_RollController::control_bodyrate(float pitch,
/*
* anti-windup: do not allow integrator to increase if actuator is at limit
*/
- if (_last_output < -_max_deflection_rad) {
+ if (_last_output < -1.0f) {
/* only allow motion to center: increase value */
id = math::max(id, 0.0f);
- } else if (_last_output > _max_deflection_rad) {
+ } else if (_last_output > 1.0f) {
/* only allow motion to center: decrease value */
id = math::min(id, 0.0f);
}
@@ -133,12 +133,13 @@ float ECL_RollController::control_bodyrate(float pitch,
/* integrator limit */
_integrator = math::constrain(_integrator, -_integrator_max, _integrator_max);
- //warnx("roll: _integrator: %.4f, _integrator_max: %.4f", (double)_integrator, (double)_integrator_max);
+ warnx("roll: _integrator: %.4f, _integrator_max: %.4f, airspeed %.4f, _k_i %.4f", (double)_integrator, (double)_integrator_max, (double)airspeed, (double)_k_i);
/* Apply PI rate controller and store non-limited output */
- _last_output = (_rate_error * _k_p + _integrator * _k_i * _rate_setpoint * k_ff) * scaler * scaler; //scaler^2 is proportional to 1/airspeed^2
+ _last_output = (_rate_error * _k_p + _integrator * _k_i + _rate_setpoint * k_ff) * scaler * scaler; //scaler is proportional to 1/airspeed
+ warnx("roll: _last_output %.4f", (double)_last_output);
- return math::constrain(_last_output, -_max_deflection_rad, _max_deflection_rad);
+ return math::constrain(_last_output, -1.0f, 1.0f);
}
void ECL_RollController::reset_integrator()
diff --git a/src/lib/ecl/attitude_fw/ecl_roll_controller.h b/src/lib/ecl/attitude_fw/ecl_roll_controller.h
index f94db0dc7..dd7d1bf53 100644
--- a/src/lib/ecl/attitude_fw/ecl_roll_controller.h
+++ b/src/lib/ecl/attitude_fw/ecl_roll_controller.h
@@ -112,7 +112,6 @@ private:
float _rate_error;
float _rate_setpoint;
float _bodyrate_setpoint;
- float _max_deflection_rad;
};
#endif // ECL_ROLL_CONTROLLER_H
diff --git a/src/lib/ecl/attitude_fw/ecl_yaw_controller.cpp b/src/lib/ecl/attitude_fw/ecl_yaw_controller.cpp
index 84d9ebd88..bc036e082 100644
--- a/src/lib/ecl/attitude_fw/ecl_yaw_controller.cpp
+++ b/src/lib/ecl/attitude_fw/ecl_yaw_controller.cpp
@@ -54,7 +54,6 @@ ECL_YawController::ECL_YawController() :
_rate_error(0.0f),
_rate_setpoint(0.0f),
_bodyrate_setpoint(0.0f),
- _max_deflection_rad(math::radians(45.0f)),
_coordinated(1.0f)
{
@@ -135,10 +134,10 @@ float ECL_YawController::control_bodyrate(float roll, float pitch,
/*
* anti-windup: do not allow integrator to increase if actuator is at limit
*/
- if (_last_output < -_max_deflection_rad) {
+ if (_last_output < -1.0f) {
/* only allow motion to center: increase value */
id = math::max(id, 0.0f);
- } else if (_last_output > _max_deflection_rad) {
+ } else if (_last_output > 1.0f) {
/* only allow motion to center: decrease value */
id = math::min(id, 0.0f);
}
@@ -150,9 +149,9 @@ float ECL_YawController::control_bodyrate(float roll, float pitch,
_integrator = math::constrain(_integrator, -_integrator_max, _integrator_max);
/* Apply PI rate controller and store non-limited output */
- _last_output = (_rate_error * _k_p + _integrator * _k_i * _rate_setpoint * k_ff) * scaler * scaler; //scaler^2 is proportional to 1/airspeed^2
+ _last_output = (_rate_error * _k_p + _integrator * _k_i + _rate_setpoint * k_ff) * scaler * scaler; //scaler is proportional to 1/airspeed
- return math::constrain(_last_output, -_max_deflection_rad, _max_deflection_rad);
+ return math::constrain(_last_output, -1.0f, 1.0f);
}
void ECL_YawController::reset_integrator()
diff --git a/src/lib/ecl/attitude_fw/ecl_yaw_controller.h b/src/lib/ecl/attitude_fw/ecl_yaw_controller.h
index 0250fcb35..5c00fa873 100644
--- a/src/lib/ecl/attitude_fw/ecl_yaw_controller.h
+++ b/src/lib/ecl/attitude_fw/ecl_yaw_controller.h
@@ -117,7 +117,6 @@ private:
float _rate_error;
float _rate_setpoint;
float _bodyrate_setpoint;
- float _max_deflection_rad;
float _coordinated;
};