bitsim
Model, simulate, estimate and control robots in C++
Loading...
Searching...
No Matches
Flying a quadrotor with an LQR

Flying a simulated quadrotor from the laptop flies a quadrotor with an angle mode flight controller: the pilot tilts it, and the controller holds the tilt. To fly it along a path, most drones put a position loop around such a controller, which works out the tilt and the thrust it needs from where the drone is: a cascade of loops, each designed on its own. A linear quadratic regulator (LQR) does it in one go instead: it looks at all twelve states of the drone at once, and works out the thrust and the three torques from all of them. This example flies both along the same path, and pushes both off it.

The LQR, blue, and the cascade, orange, follow the red targets along a square, 2.5 m apart, and are pushed east at 22 s. Twice the real speed

What you need

Nothing beyond bitsim itself to run it. To see it, or to make the pictures of the GIF, bitsim built with Chrono and Irrlicht. See Installing bitsim.

The drone

It is the quadrotor of The dynamics of a quadrotor and Flying a simulated quadrotor from the laptop, QuadrotorDynamics, with some air drag. Its state has twelve values: the position in the world (NED, z down), the velocity and the angular velocity in the body's axes, and the Euler angles. Both controllers run at 100 Hz, and the model steps every 1 ms.

The LQR

The inputs of the LQR are the total thrust and the torques about the three axes, which quadrotor_mixer turns into the four rotor speeds. The example linearises one control period of the model, 10 steps with the inputs held, at hover: level, still, with the thrust carrying the weight. It does it by central differences of the model itself, so the linear model is that of the simulation, \(x_{k+1} = A x_k + B u_k\) for the deviations from hover.

The weights follow Bryson's rule: each is one over the square of how much of it is acceptable, 0.5 m of position, 1 m/s, 2 rad/s, 0.3 rad of tilt, 2 N of thrust and 0.05 N m of torque. dlqr() gives the gain, a 4 x 12 matrix, and the controller is

\[u = u_{hover} - K (x - x_{ref}) , \]

with \(x_{ref}\) the hover at the point of the path where the drone should be, moving at the path's velocity. The slowest mode of the closed loop halves in 0.29 s.

The cascade

The other drone flies with QuadrotorFlightController, whose sticks a PD position loop moves. From the error of the position and of the velocity, it works out the acceleration it wants: \(a = k_p e - k_d \dot e\), with \(k_p = 1\,s^{-2}\) and \(k_d = 1.6\,s^{-1}\) along the ground, a damping of 0.8, and twice that up. The tilt that gives that acceleration sets the pitch and the roll sticks, and the throttle carries the weight plus the climb. The flight controller then holds the tilt.

The mission

Both drones start at hover 2 m up and follow a reference that waits 2 s and then moves at 1 m/s along a square of 4 m, climbing to 3 m and coming back down; the cascade's is the same, 2.5 m to the west. At 22 s, hovering at the end, both are pushed: their velocity changes by 2 m/s to the east.

Running the example

./quadrotor_lqr # print the errors
./quadrotor_lqr --render # and show both, in real time
./quadrotor_lqr --record frames # and write the window to frames/, ten pictures a second

The GIF above is made from the pictures, at twice the speed, with

ffmpeg -framerate 20 -i frames/frame_%05d.png \
-vf "scale=640:-1:flags=lanczos,split[a][b];[a]palettegen=max_colors=64[p];[b][p]paletteuse" \
quadrotor_lqr.gif

The example exits with an error if the LQR does not follow the path or does not recover from the push, so it runs as a test too.

Output

LQR designed at hover: the slowest closed loop mode decays by 0.9765 a step, 0.29 s to halve
time [s] reference LQR error [m] cascade error [m]
0.0 ( 0.0 0.0 2.0) 0.000 0.000
4.0 ( 2.0 0.0 2.0) 0.224 0.578
...
18.0 ( 0.0 0.2 2.1) 0.202 0.549
20.0 ( 0.0 0.0 2.0) 0.037 0.035
24.0 ( 0.0 0.0 2.0) 0.064 0.493
28.0 ( 0.0 0.0 2.0) 0.000 0.035
RMS error along the path [m] largest error after the push [m] back within 0.1 m after [s]
LQR 0.236 0.634 1.81
cascade 0.464 0.767 4.46

Along the path, the LQR stays about 0.2 m from its reference, the cascade about 0.55 m. Neither gets to zero while it moves, because of the drag: at 1 m/s the drone has to lean to hold its speed, and its reference is level. The cascade lags more: with the gains chosen here its position loop is slower than the LQR. After the push, the LQR is off by at most 0.63 m and back within 0.1 m of its target in 1.8 s; the cascade by 0.77 m, and in 4.5 s.

That is a comparison of two designs, not of the two kinds of controller. The cascade's gains were chosen by hand, and faster gains would close part of the gap. What the LQR gives is a systematic way to get gains for all twelve states at once from what matters, the weights, and the tilt, the speeds and the position are balanced against one another by the same cost.

Things to try

  • Make the LQR's weight on the position 10 times larger. How much closer does it follow the path, and how much more does it tilt to do it?
  • Give the reference the tilt that holds the drag at 1 m/s, as feedforward, so that \(x_{ref}\) is the state the drone is really in when it flies along the path. How much of the error along the path is left?
  • Tune the cascade's gains until it recovers from the push as fast as the LQR. What happens to its error along the path?
  • Push harder, at 5 m/s. The LQR was designed at hover and assumes small angles; how far from hover does it still work?

The library

Class or function What it does
dlqr the gain of a discrete LQR, from the discrete Riccati equation
quadrotor_mixer the rotor speeds for a thrust and three torques
QuadrotorFlightController the angle mode flight controller of the cascade
QuadrotorView the window, with the drones, their trails and the targets

The code

// A quadrotor flown along a path and pushed off it, by an LQR and by the flight controller of
// quadrotor_rc_simulation with a position loop around it.
//
// Usage: quadrotor_lqr [--render] [--record DIR]
//
// The LQR is designed on the model linearised at hover. The other drone flies with the angle mode
// flight controller, whose sticks a PD position loop moves: a cascade of the kind most drones
// fly with. Both follow the same reference along a square, 2.5 m apart, and get the same push
// sideways. --render shows them in a window, in real time; --record DIR also writes the window to
// DIR, ten pictures a second, which needs bitsim built with Chrono and Irrlicht.
#include "bitsim/bitsim_config.h"
#if defined(BITSIM_IRRLICHT) && defined(BITSIM_CHRONO)
#endif
#include <algorithm>
#include <array>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <optional>
#include <string>
#include <thread>
#include <vector>
namespace quadrotor_lqr
{
const real_t STEP_SIZE = 0.001; // [s] of the dynamics
const real_t CONTROL_PERIOD = 0.01; // [s] both controllers run at 100 Hz
const uint_t SUB_STEPS = 10; // dynamics steps per control period
const real_t SPEED = 1.0; // of the reference along the path [m/s]
const real_t START = 2.0; // when the reference starts to move [s]
const real_t PUSH_AT = 22.0; // [s]
const real_t PUSH = 2.0; // the push, sideways to the east [m/s]
const real_t DURATION = 28.0; // [s]
const real_t SEPARATION = 2.5; // the cascade flies 2.5 m west of the LQR [m]
const real_t PRINT_PERIOD = 2.0; // [s]
const real_t RENDER_RATE = 30.0; // [frames/s]
const real_t RECORD_RATE = 10.0; // [frames/s]
// The names of the state of QuadrotorDynamics, in the order of the LQR's state vector
const std::array<const char *, 12> NAMES{"x", "y", "z", "u", "v", "w",
"p", "q", "r", "phi", "theta", "psi"};
// The quadrotor of quadrotor_rc_simulation
QuadrotorDynamicsConfig quadrotor_config()
{
QuadrotorDynamicsConfig config;
config.dt = STEP_SIZE;
config.mass = 0.468;
config.l = 0.225;
config.k_1 = 2.980e-6;
config.k_2 = 1.140e-7;
config.Jx = 4.856e-3;
config.Jy = 4.856e-3;
config.Jz = 8.801e-3;
config.drag = 0.25;
return config;
}
{
std::array<std::pair<std::string, real_t>, 12> values;
for (uint_t i = 0; i < 12; ++i)
{
values[i] = {NAMES[i], x[static_cast<index_t>(i)]};
}
return SysState<12>(std::move(values));
}
{
Vector x(12);
for (uint_t i = 0; i < 12; ++i)
{
x[static_cast<index_t>(i)] = state.get(NAMES[i]);
}
return x;
}
// The rotor speeds for a thrust and the torques, u = [T, tau_phi, tau_theta, tau_psi]
RealVec mix(const QuadrotorDynamicsConfig &config, const Vector &u, real_t max_rotor_speed)
{
return bitsim::control::quadrotor_mixer(config, u[0], RealColVec3d(u[1], u[2], u[3]),
max_rotor_speed);
}
// The state one control period on, from x with u held
Vector step(const QuadrotorDynamicsConfig &config, const Vector &x, const Vector &u,
real_t max_rotor_speed)
{
QuadrotorDynamics dynamics(config, state);
const RealVec rotors = mix(config, u, max_rotor_speed);
for (uint_t k = 0; k < SUB_STEPS; ++k)
{
dynamics.integrate(rotors);
}
return to_vector(dynamics.get_state());
}
// The map of one control period linearised about hover, by central differences: the discrete
// model x_{k+1} = A x_k + B u_k of the deviations from hover
bitsim::control::DiscreteLinearModel linearise(const QuadrotorDynamicsConfig &config,
const Vector &hover, const Vector &u_hover,
real_t max_rotor_speed)
{
bitsim::control::DiscreteLinearModel model{Matrix(12, 12), Matrix(12, 4)};
const real_t h = 1.0e-5;
for (index_t j = 0; j < 12; ++j)
{
Vector plus = hover;
Vector minus = hover;
plus[j] += h;
minus[j] -= h;
model.A.col(j) = (step(config, plus, u_hover, max_rotor_speed) -
step(config, minus, u_hover, max_rotor_speed)) /
(2.0 * h);
}
for (index_t j = 0; j < 4; ++j)
{
Vector plus = u_hover;
Vector minus = u_hover;
const real_t hu = h * std::max(1.0, std::abs(u_hover[j]));
plus[j] += hu;
minus[j] -= hu;
model.B.col(j) = (step(config, hover, plus, max_rotor_speed) -
step(config, hover, minus, max_rotor_speed)) /
(2.0 * hu);
}
return model;
}
// The reference: it waits at the start, then moves along a square at SPEED, and stops at the end
struct Path
{
std::vector<RealColVec3d> corners{{0, 0, -2}, {4, 0, -2}, {4, 4, -3}, {0, 4, -3}, {0, 0, -2}};
RealColVec3d at(real_t time) const
{
real_t s = std::max(0.0, time - START) * SPEED;
for (uint_t i = 0; i + 1 < corners.size(); ++i)
{
const RealColVec3d leg = corners[i + 1] - corners[i];
if (s <= leg.norm())
{
return corners[i] + leg * (s / leg.norm());
}
s -= leg.norm();
}
return corners.back();
}
// The velocity of the reference, by a central difference
{
const real_t h = 1.0e-3;
return (at(time + h) - at(std::max(0.0, time - h))) / (time + h - std::max(0.0, time - h));
}
};
// The rotation from the body to the world, Rz(yaw) Ry(pitch) Rx(roll), the same one the
// quadrotor's dynamics use
{
const real_t cy = std::cos(yaw), sy = std::sin(yaw);
const real_t cp = std::cos(pitch), sp = std::sin(pitch);
const real_t cr = std::cos(roll), sr = std::sin(roll);
R << cy * cp, cy * sp * sr - sy * cr, cy * sp * cr + sy * sr, //
sy * cp, sy * sp * sr + cy * cr, sy * sp * cr - cy * sr, //
-sp, cp * sr, cp * cr;
return R;
}
// A drone and what happened to it
struct Drone
{
std::string name;
RealColVec3d offset; // its path is the reference moved by this
SysState<12> state;
QuadrotorDynamics dynamics;
Drone(const std::string &n, const RealColVec3d &o, const QuadrotorDynamicsConfig &config,
const Vector &x0)
: name(n), offset(o), state(to_state(x0)), dynamics(config, state)
{
}
RealColVec3d position() const { return dynamics.get_position(); }
// The velocity in the world, NED
{
const auto R = body_to_world(dynamics.psi(), dynamics.theta(), dynamics.phi());
return R * dynamics.get_velocity();
}
// A push: a change of the velocity in the world, east
void push(real_t east)
{
const auto R = body_to_world(dynamics.psi(), dynamics.theta(), dynamics.phi());
const RealColVec3d v = dynamics.get_velocity() + R.transpose() * RealColVec3d(0, east, 0);
dynamics.get_state().set("u", v[0]);
dynamics.get_state().set("v", v[1]);
dynamics.get_state().set("w", v[2]);
}
void record_error(const RealColVec3d &reference, real_t time)
{
const real_t e = (position() - reference).norm();
if (time < PUSH_AT)
{
sum_sq_error += e * e;
}
else
{
if (e > 0.1)
{
}
else if (back_within_10cm < 0.0)
{
}
}
}
};
// The position loop of the cascade: from where the drone is and where it should be, the sticks
// of the angle mode flight controller. A PD loop sets the acceleration it wants, and the tilt and
// the thrust that give it
RCCommand position_loop(const Drone &drone, const RealColVec3d &target,
const RealColVec3d &target_velocity,
const QuadrotorFlightController &controller)
{
const real_t kp = 1.0; // [1/s^2]
const real_t kd = 1.6; // [1/s]
const real_t kp_z = 2.0;
const real_t kd_z = 2.4;
const RealColVec3d e = target - drone.position();
const RealColVec3d v = drone.world_velocity() - target_velocity;
// the horizontal acceleration it wants, north and east, and the climb, up
const real_t a_north = kp * e[0] - kd * v[0];
const real_t a_east = kp * e[1] - kd * v[1];
const real_t a_up = -kp_z * e[2] + kd_z * v[2];
const real_t max_tilt = controller.parameters().max_tilt;
const auto &d = drone.dynamics;
command.armed = true;
// tilting forward by theta gives g tan(theta) forward; pitch forward is nose down
command.pitch = std::atan(a_north / G) / max_tilt;
command.roll = std::atan(a_east / G) / max_tilt;
command.throttle =
controller.hover_throttle() * (1.0 + a_up / G) / (std::cos(d.phi()) * std::cos(d.theta()));
return command.clamped();
}
struct Options
{
bool render{false};
std::string record;
};
int run(const Options &options)
{
const QuadrotorFlightController flight_controller(config);
const real_t max_rotor_speed = flight_controller.max_rotor_speed();
// Hover: level, still, the thrust carrying the weight
const Path path;
Vector hover = Vector::Zero(12);
hover.head(3) = path.at(0.0);
Vector u_hover = Vector::Zero(4);
u_hover[0] = config.mass * G;
const auto model = linearise(config, hover, u_hover, max_rotor_speed);
// Bryson's rule: each weight is one over the square of how much is acceptable: 0.5 m of
// position, 1 m/s, 2 rad/s, 0.3 rad of tilt; 2 N of thrust and 0.05 N m of torque
Vector q(12);
q << 4, 4, 4, 1, 1, 1, 0.25, 0.25, 0.25, 11, 11, 11;
Vector r(4);
r << 0.25, 400, 400, 400;
const auto lqr = bitsim::control::dlqr(model.A, model.B, q.asDiagonal().toDenseMatrix(),
r.asDiagonal().toDenseMatrix());
const Matrix A_closed = model.A - model.B * lqr.K;
std::printf("LQR designed at hover: the slowest closed loop mode decays by %.4f a step, %.2f "
"s to halve\n",
A_closed.eigenvalues().cwiseAbs().maxCoeff(),
std::log(0.5) / std::log(A_closed.eigenvalues().cwiseAbs().maxCoeff()) *
Drone lqr_drone("LQR", RealColVec3d::Zero(), config, hover);
Vector cascade_start = hover;
cascade_start[1] -= SEPARATION;
Drone cascade_drone("cascade", RealColVec3d(0, -SEPARATION, 0), config, cascade_start);
#if defined(BITSIM_IRRLICHT) && defined(BITSIM_CHRONO)
using bitsim::utils::render::QuadrotorView;
std::optional<QuadrotorView> view;
if (options.render || !options.record.empty())
{
QuadrotorView::Style lqr_style;
lqr_style.body = chrono::ChColor(0.25f, 0.45f, 0.8f);
lqr_style.trail = chrono::ChColor(0.3f, 0.6f, 1.0f);
QuadrotorView::Style cascade_style;
cascade_style.body = chrono::ChColor(0.85f, 0.45f, 0.1f);
cascade_style.trail = chrono::ChColor(1.0f, 0.8f, 0.2f);
view.emplace("A quadrotor flown by an LQR, and by a cascade of PD loops",
std::vector<QuadrotorView::Style>{lqr_style, cascade_style}, options.record,
view->fix_camera(RealColVec3d(-2.5, -5.5, -5.0), RealColVec3d(2.0, 0.8, -1.2));
}
#else
if (options.render || !options.record.empty())
{
std::cerr << "--render and --record need bitsim built with Chrono and Irrlicht\n";
return 1;
}
#endif
std::printf("\n time [s] reference LQR error [m] cascade error [m]\n");
const auto steps = static_cast<uint_t>(std::lround(DURATION / CONTROL_PERIOD));
real_t next_print = 0.0;
real_t next_render = 0.0;
const auto wall_start = std::chrono::steady_clock::now();
for (uint_t k = 0; k <= steps; ++k)
{
const real_t time = k * CONTROL_PERIOD;
if (std::abs(time - PUSH_AT) < 0.5 * CONTROL_PERIOD)
{
lqr_drone.push(PUSH);
cascade_drone.push(PUSH);
}
const RealColVec3d reference = path.at(time);
lqr_drone.record_error(reference, time);
cascade_drone.record_error(reference + cascade_drone.offset, time);
if (time >= next_print - 1e-9)
{
std::printf("%9.1f (%4.1f %4.1f %4.1f) %13.3f %17.3f\n", time, reference[0],
reference[1], -reference[2], (lqr_drone.position() - reference).norm(),
(cascade_drone.position() - reference - cascade_drone.offset).norm());
next_print += PRINT_PERIOD;
}
#if defined(BITSIM_IRRLICHT) && defined(BITSIM_CHRONO)
if (view && time >= next_render - 1e-9)
{
view->set_targets({reference, reference + cascade_drone.offset});
char status[160];
std::snprintf(status, sizeof(status),
"t %5.1f s blue LQR: off by %.2f m orange cascade: off by %.2f m%s",
time, (lqr_drone.position() - reference).norm(),
(cascade_drone.position() - reference - cascade_drone.offset).norm(),
(time >= PUSH_AT && time < PUSH_AT + 1.5) ? " PUSH" : "");
if (!view->show({&lqr_drone.dynamics, &cascade_drone.dynamics}, time, status))
{
break;
}
next_render += 1.0 / RENDER_RATE;
if (options.render)
{
// in real time
const real_t ahead = time - std::chrono::duration<real_t>(
std::chrono::steady_clock::now() - wall_start)
.count();
if (ahead > 0.0)
{
std::this_thread::sleep_for(std::chrono::duration<real_t>(ahead));
}
}
}
#endif
// the LQR: u = u_hover - K (x - x_ref), with x_ref hover at the reference, moving with
// it: level and at the reference's velocity, which in the body frame of a level drone
// facing north is the same
const RealColVec3d reference_velocity = path.velocity(time);
Vector x_ref = hover;
x_ref.head(3) = reference;
x_ref.segment(3, 3) = reference_velocity;
const Vector x = to_vector(lqr_drone.dynamics.get_state());
const Vector u = u_hover - lqr.K * (x - x_ref);
const RealVec lqr_rotors = mix(config, u, max_rotor_speed);
// the cascade: the position loop sets the sticks, the flight controller the rotors
const RCCommand command = position_loop(cascade_drone, reference + cascade_drone.offset,
reference_velocity, flight_controller);
for (uint_t s = 0; s < SUB_STEPS; ++s)
{
lqr_drone.dynamics.integrate(lqr_rotors);
cascade_drone.dynamics.integrate(
flight_controller.rotor_speeds(command, cascade_drone.dynamics));
}
}
std::printf("\n%-8s RMS error along the path [m] largest error after the push [m] back "
"within 0.1 m after [s]\n",
"");
for (const Drone *d : {&lqr_drone, &cascade_drone})
{
std::printf("%-8s %28.3f %32.3f %26.2f\n", d->name.c_str(),
std::sqrt(d->sum_sq_error / std::max<uint_t>(1, d->n_errors)),
d->max_error_after_push, d->back_within_10cm);
}
// what the example shows: the LQR follows the path and recovers from the push
const bool ok = lqr_drone.back_within_10cm > 0.0 &&
std::sqrt(lqr_drone.sum_sq_error / lqr_drone.n_errors) < 0.5;
return ok ? 0 : 1;
}
} // namespace quadrotor_lqr
int main(int argc, char **argv)
{
for (int i = 1; i < argc; ++i)
{
const std::string arg = argv[i];
if (arg == "--render")
{
options.render = true;
}
else if (arg == "--record" && i + 1 < argc)
{
options.record = argv[++i];
}
else
{
std::cerr << "Usage: quadrotor_lqr [--render] [--record DIR]\n";
return 1;
}
}
return quadrotor_lqr::run(options);
}
The basic types of bitsim. Code outside this file names Eigen's matrix and vector types only through ...
The flight controller of a toy quadrotor in angle mode: it turns the sticks of an RCCommand into roto...
Definition quadrotor_flight_controller.h:52
The QuadrotorDynamics class. Implements quadrotor dynamics The implementation of this class follows t...
Definition quadrotor_dynamics.h:134
SysState utility class describing the state of a system.
Definition system_state.h:25
int main()
Definition discounted_returns.cpp:19
RealVec quadrotor_mixer(const dynamics::QuadrotorDynamicsConfig &config, real_t thrust, const RealColVec3d &tau, real_t max_rotor_speed)
The rotor speeds [rad/s] of a plus quadrotor (see dynamics::QuadrotorDynamics) that give the thrust T...
Definition quadrotor_flight_controller.cpp:13
Linear quadratic regulators: the Riccati equations, the discretisation of a linear model,...
const real_t G
Acceleration due to gravity m/secs.
Definition bitsim_consts.h:68
LQRSolution dlqr(const Matrix &A, const Matrix &B, const Matrix &Q, const Matrix &R)
The LQR of : with P from solve_dare().
Definition lqr.cpp:154
RealMat Matrix
The matrices of the linear models and the controllers.
Definition lqr.h:20
LQRSolution lqr(const Matrix &A, const Matrix &B, const Matrix &Q, const Matrix &R)
The LQR of : with P from solve_care().
Definition lqr.cpp:161
RealColVec Vector
The vectors of the linear models and the controllers: states, inputs.
Definition lqr.h:23
@ R
Definition fixed_wing_dynamics.h:39
std::size_t uint_t
uint_t
Definition bitsim_types.h:40
Eigen::Index index_t
The type Eigen indexes and sizes matrices and vectors with.
Definition bitsim_types.h:45
DynVec< real_t > RealVec
double precision floating point vector
Definition bitsim_types.h:111
Eigen::Matrix3< real_t > RealMat3d
3×3 matrix of type double.
Definition bitsim_types.h:86
double real_t
real_t
Definition bitsim_types.h:20
Eigen::Vector3d RealColVec3d
3D column vector
Definition bitsim_types.h:137
std::map< std::string, std::any > command(real_t v, real_t w)
Definition diff_drive_kinematics.cpp:29
Controller controller(const MultiRobotNavigation &env, uint_t robot)
Definition distributed_robot_navigation.cpp:113
real_t h(real_t x)
Definition importance_sampling.cpp:39
state
Definition play.py:39
list values
Definition plot_losses.py:13
Definition quadrotor_lqr.cpp:36
const real_t SEPARATION
Definition quadrotor_lqr.cpp:61
const real_t DURATION
Definition quadrotor_lqr.cpp:60
const real_t PRINT_PERIOD
Definition quadrotor_lqr.cpp:62
const real_t START
Definition quadrotor_lqr.cpp:57
QuadrotorDynamicsConfig quadrotor_config()
Definition quadrotor_lqr.cpp:71
const real_t G
Definition quadrotor_lqr.cpp:52
RCCommand position_loop(const Drone &drone, const RealColVec3d &target, const RealColVec3d &target_velocity, const QuadrotorFlightController &controller)
Definition quadrotor_lqr.cpp:264
SysState< 12 > to_state(const Vector &x)
Definition quadrotor_lqr.cpp:86
int run(const Options &options)
Definition quadrotor_lqr.cpp:298
Vector to_vector(const SysState< 12 > &state)
Definition quadrotor_lqr.cpp:96
const real_t PUSH_AT
Definition quadrotor_lqr.cpp:58
RealMat3d body_to_world(real_t yaw, real_t pitch, real_t roll)
Definition quadrotor_lqr.cpp:189
const real_t SPEED
Definition quadrotor_lqr.cpp:56
const real_t PUSH
Definition quadrotor_lqr.cpp:59
const real_t CONTROL_PERIOD
Definition quadrotor_lqr.cpp:54
RealVec mix(const QuadrotorDynamicsConfig &config, const Vector &u, real_t max_rotor_speed)
Definition quadrotor_lqr.cpp:107
const uint_t SUB_STEPS
Definition quadrotor_lqr.cpp:55
const real_t RENDER_RATE
Definition quadrotor_lqr.cpp:63
const real_t STEP_SIZE
Definition quadrotor_lqr.cpp:53
Vector step(const QuadrotorDynamicsConfig &config, const Vector &x, const Vector &u, real_t max_rotor_speed)
Definition quadrotor_lqr.cpp:114
bitsim::control::DiscreteLinearModel linearise(const QuadrotorDynamicsConfig &config, const Vector &hover, const Vector &u_hover, real_t max_rotor_speed)
Definition quadrotor_lqr.cpp:129
const std::array< const char *, 12 > NAMES
Definition quadrotor_lqr.cpp:67
const real_t RECORD_RATE
Definition quadrotor_lqr.cpp:64
An Irrlicht window that shows quadrotors flying over a tiled floor. Needs bitsim built with Chrono an...
Matrix A
Definition lqr.h:30
Matrix B
Definition lqr.h:31
Matrix K
Definition lqr.h:75
What the sticks of a radio transmitter for a quadrotor say, as a toy drone's transmitter sends them: ...
Definition rc_command.h:20
Definition quadrotor_dynamics.h:13
real_t dt
The time step to use.
Definition quadrotor_dynamics.h:56
Definition quadrotor_lqr.cpp:203
void push(real_t east)
Definition quadrotor_lqr.cpp:229
RealColVec3d position() const
Definition quadrotor_lqr.cpp:219
real_t max_error_after_push
Definition quadrotor_lqr.cpp:210
void record_error(const RealColVec3d &reference, real_t time)
Definition quadrotor_lqr.cpp:238
real_t back_within_10cm
Definition quadrotor_lqr.cpp:211
Drone(const std::string &n, const RealColVec3d &o, const QuadrotorDynamicsConfig &config, const Vector &x0)
Definition quadrotor_lqr.cpp:213
real_t sum_sq_error
Definition quadrotor_lqr.cpp:208
std::string name
Definition quadrotor_lqr.cpp:204
QuadrotorDynamics dynamics
Definition quadrotor_lqr.cpp:207
SysState< 12 > state
Definition quadrotor_lqr.cpp:206
RealColVec3d world_velocity() const
Definition quadrotor_lqr.cpp:222
uint_t n_errors
Definition quadrotor_lqr.cpp:209
RealColVec3d offset
Definition quadrotor_lqr.cpp:205
Definition quadrotor_lqr.cpp:293
std::string record
Definition quadrotor_lqr.cpp:295
bool render
Definition quadrotor_lqr.cpp:294
Definition quadrotor_lqr.cpp:161
RealColVec3d velocity(real_t time) const
Definition quadrotor_lqr.cpp:180
std::vector< RealColVec3d > corners
Definition quadrotor_lqr.cpp:162
RealColVec3d at(real_t time) const
Definition quadrotor_lqr.cpp:164