Member-only story

How to Write your own Flight Controller Software — Part 9

ESC Arming and an Introduction to BLDC Motors

Well that didn’t work! Following Part 8 we added a standard Arduino PID library, wrote the motor mixer, and stuck the drone on our Gyro test stand (Figure 1). The quadcopter was receiving the SBUS signals, but the propellers didn’t rotate.

In this part we will work out where the problem is and describe how we control the ESC and brushless motors to get the desired drone orientation. We will also cover a lot of other motor related information.

Figure 1. Magpie Drone mounted in Gyro Test Rig

Basic Motor Control

Whenever something doesn’t work the way we expect, we go back to basics. Let’s just get the throttle working before adding all the fancy PID stuff. Our high level flight loop looks like this:

This is simplified but shows the major moving parts. We want this loop to execute as fast as possible in order to maximise the responsiveness of our drone.

At this stage we are using the Arduino Servo library to drive our ESC. As an input it is expecting a pulse width in microseconds between 1000 and 2000. For our purposes this equates to a throttle value between 0 and 100%.

The throttle value that we receive from our remote control receiver, using SBUS is between 172 and 1811. We need to convert from an SBUS value to what is expected by the Servo library. The map function does this for us.

rxThrottle = map(channels[0], MIN_SBUS, MAX_SBUS, MIN_PULSEWIDTH, MAX_PULSEWIDTH);

The array channels contains the values for each remote control channel (e.g., throttle, pitch, roll, yaw, etc.). Although throttle is on channel 1, arrays in C start at 0, hence we use channels[0].

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

David Such
David Such

Written by David Such

Reefwing Software · Embedded Systems Engineer · iOS & AI Development · Robotics · Drones · Arduino · Raspberry Pi · Flight Control

No responses yet

Write a response