Hardware in the loop/real time physics simulation: Feasible idea?

Official Python bindings with a focus on reinforcement learning and robotics.
Post Reply
Posts: 1
Joined: Fri Feb 09, 2018 9:30 pm

Hardware in the loop/real time physics simulation: Feasible idea?

Post by barafael » Fri Feb 09, 2018 9:42 pm

I am building a drone flight controller from scratch. It runs on a fairly small microcontroller. Like many projects involving hardware, it is somewhat difficult to test. While thinking about it, I had this idea and I need some input on feasibility.

Bear with me, the setup is a little complex. First, some context about what the flight controller does:

The flight controller gets some input from the operator (think game controller). It also measures the current attitude and angular velocities using some Inertial Measurement Unit. Using control mechanisms (cascaded PID, it figures out a needed response that is sent to the motors, which then affect attitude and angular velocity. If the system works correctly, the craft stabilizes in the air, reacts to the inputs by the operator, and is stable against disturbance by wind gusts or collisions or differences in motor power.

It is a closed loop: the sensor measures the environment, then then takes some steps to influence it, observes the effect, and keeps adjusting.

It is hard to test the controller without actually flying on a drone. Here is the funny idea: why not mock the input/output to the flight controller?

The motor commands from the controller are continuously sent to a physics simulation, which simulates the effect of the commands on some vehicle in real time and displays a (crude) render of it. I can connect the board in a way that makes it look like a game controller for the computer. During operation, the simulation outputs readings about angular velocity and attitude, adds some noise and drift, and sends them back to the flight controller. There is another board between PC and flight controller that acts as the middleman (I can figure that part out as long as the simulation offers some kind of interface for external programs to read the attitude and angular rate).

The flight controller should ideally not notice that anything is different from normal operation. The loop rate (400Hz to maybe 1.2kHz, rough estimation) should not be affected, but I do not know if simulations on a computer and the serial communication might be a bottleneck for this.

Now, one thing I know nothing about is physics simulation. Is it possible to use an existing game/physics engine? I found Bullet because it is embedded in blender and must be quite scriptable... in the following, will just blurt out some ideas, please tell me if any of this is not at all possible or if you have thoughts and ideas on it.

It would be great to be able to simulate wildly different configurations. Not Kerbal Space Program level, but I want to change the airframe, change weights and motor power, possibly even propeller type. It would be great to attach motors to other configurations like blimps or boats (which the controller can stabilize as well) and simulate those. In my book, it would be ok to have to edit a 3d model for this.

The engine should be capable to do a good approximation of moderately accurate flight physics.

In any case, it should be possible to do some IPC with another program or read the serial port directly (pyserial?) in order to interface with the mock board. The simulation needs to read the values from that board, simulate, measure, send data back in 'real time'.

I hope I described it clear enough, but here is a nice image/schematic: https://raw.githubusercontent.com/baraf ... st_rig.png

Is the simulation part feasible at all in bullet? I have some linear algebra and diffEq background, but I do hope I won't have to use it too much in this project!

Thanks for reading this wall of text. Looking forward to read your ideas.

tl;dr: I need to run a pretty accurate physics simulation of a vehicle (think multicopter) that can react to input from the serial port (or IPC) and send data about the vehicle (attitude, angular velocity) back over the same channel.

Post Reply