Setup of a CleanFlight flight controller for an Omni-Directional robot.
In previous pages I described the motors, wheels and electronics I chose for the prototype omni-directional robot I am making. Now I will explain how I am setting up the flight controller to control a three wheel omni-directional robot.
At first I tried to use stock CleanFlight firmware to control the robot but this is almost impossible. CleanFlight was never intended for a ground vehicle but for aircraft. Model aircraft require all sorts of safety measures to both prevent injury and also to stop them from randomly falling out of the sky. A combat robot doesn’t need either of these.
Well maybe a little.
The first issue is the arming procedure. When you first turn on a quadcopter you don’t want the propellers to spin up immediately and chop your fingers off. So when a quadcopter is turned on it needs to placed on a level surface and then armed by the transmitter before the motors can be turned on. This is done by either moving the throttle to zero and moving the yaw to the right for 1 second or by a dedicated switch on the transmitter.
Since I am restricted to a 4 channel receiver at the moment the dedicated switch is out. This means I need to use the stick arming procedure. The problem is the stick arming is designed for quadcopters with non-reversing motors. When armed the throttle outputs at approximately 5% which will cause the quadcopters motors to spin slowly. However this causes my reversible motors to run full speed in reverse until I bring the throttle up to 50%. This means when I first arm the robot it will spin rapidly until I can stop it.
CleanFlight does have the option to configured for 3D flight that allows a quadcopters motors to be reversed. This would allow a quadcopter to fly upside down and perform “3D” stunts. The problem when using 3D motors is that stick arming is not an option for the same reason I am having issues. when armed using the stick the throttle is at 0% and the quadcopter would run with full negative thrust. So the quadcopter must be armed with a switch on an Aux channel while the throttle is at 50%.
But I don’t have any Aux channels available on my 4ch receiver. So I set Aux 1 to failsafe to 80% in CleanFlight and for the controller to arm at 80%. The theory was that if no Aux channels are connected then Aux1 would failsafe to a set level and that this level would arm the controller. But I could only get it to arm with CleanFlight V2.1 and only if the throttle was at 50% and the board level when powering on. But the 3D quadcopter settings didn’t work anyway.
3D Quadcopter Settings and why they suck.
A 3D quadcopter is a quadcopter that tries to mimic a Collective Cyclic Pitch model helicopters ability to fly upside down. A CCP helicopter does this by changing the pitch of the rotor blades while keeping the rotor head spinning at a constant RPM.
There have not been many variable pitch quadcopters but the first example the comes to mind is the Assault Reaper 500.
The Reaper 500 has a single motor driving all four rotors which are kept at a constant RPM. To change the amount of thrust produced by the rotors the pitch is changed by a servo. To produce zero thrust the blades are at 0 degrees and then the angle increased to produce positive thrust. If a negative angle is applied then a negative thrust is produced and the quadcopter can hover upside down. This way the rotors can switch very quickly from positive to negative thrust without changing the motor speed.
But the thing that makes quadcopters so popular is their simplicity. They only have 4 moving parts, the propellers / motors. All the control is done by changing the power to the motors. So get a fixed pitch quadcopter to produce negative thrust the motor has to be reversed.
I have only seen this in smaller quadcopters due to the smaller inertia of the motors and propellers. To fly inverted the throttle stick on the controller is pulled bellow 50%, the motors braked until stopped and then spun up again in reverse. This can take a few milliseconds so they are not capable of rapid 3D maneuvers like the variable pitch quadcopters.
So the problem with the 3D settings in CleanFlight?
It is due to the delay in braking and restarting of the motors when changing to negative thrust. CleanFlight limits how often this is done to only when the throttle stick crosses the 50% mark. For example, If the throttle stick is at 55% and a hard roll was implemented that caused a motor to drop bellow 50% then that motor would stop and reverse. After the roll it would stop and reverse again. If this happens too often then the motors would spend too much time Braking, stopped, accelerating and the quadcopter would just fall out of the sky.
For my omni-directional robot I have the throttle pinned to 50%. With 3D mode enabled CleanFlight limits the motor outputs to a positive direction only. It is doing this to prevent my robot from falling out of the sky but it doesn’t realise that the robot should never be off the ground.
So 3D mode sucks for robot use.
Aside from arming issue the other useful feature of 3D mode is ESC dead-band compensation.
Reversing Electronic Speed Controllers stop the motor when the throttle signal is at 50%. They do not start the motor immediately when the the throttle is moved above or bellow the centre but you need to move a set value above or bellow. This is to account for noise on the throttle line. CleanFlights 3D setting compensated for this dead-band by skipping over it. Otherwise fine adjustments around 50% throttle would have no effect.
There are many websites that have some complicated looking maths and diagrams explaining how to calculate motor speeds to get the robot to travel in a set direction. Here is my answer without the math:
- Motor 1 = Roll * 0.5 + Yaw * -1.0
- Motor 2 = Roll * -1.0 + Pitch * 1.0 + Yaw * -1.0
- Motor 3 = Roll * -1.0 + Pitch * -1.0 + Yaw * -1.0
Where Roll is left/right and Pitch is forward/back.
I added this as a custom mix through the Command Line Interface like this:
mmix 0 1.0 0.5 0.0 -1.0 mmix 1 1.0 -1.0 1.0 1.0 mmix 2 1.0 -1.0 -1.0 -1.0
This mix does cause the robot to drive faster forwards/reverse than it can left/right but I don’t want to restrict the top speed.
The bigger problem is that this mixes not only the output of the Yaw gyro into the output but also the Pitch and Roll gyros. This made the robot very jittery when driving over rough ground.
The only way I have to fix this is to crack open the CleanFlight source code and make some changes. That will be on the next page.