Drones don’t always fly in a perfectly straight line, especially if there’s an air current, the battery is running low, or the drone has crashed one too many times. If you notice your drone drifting, you can use the
set_trim() function at the beginning of your program (underneath pairing and before takeoff) to fix its roll, its sideway movement, or pitch, its forward and backward movement. For example, if your CoDrone Mini is drifting to the right, you can set the roll, or its sideways movement, to a negative number. This is what it would look like:
This trim value will remain saved, even after powering off, until you’ve changed the trim either in the program or reset with the remote. NOTE: If you’re setting the trim right before a takeoff, make sure to add a
time.sleep(1) before the
takeoff() . Otherwise, the take off might be skipped.
This is what your program would look like with the trim function:
drone = CoDrone_mini.CoDrone()
drone.set_trim(-1, 0). # example: drone is drifting right, so trim to roll left a little bit
time.sleep(1) # Add a time.sleep(1) before takeoff if you're planning to set the trim before takeoff
Trim refers to modifying the controller inputs to counter any aerodynamic flaws in the drone itself. Since it is nearly impossible to have a drone completely balanced perfectly in its center, they will often have to be trimmed in order to hover properly. A correctly trimmed drone should hover in one place without input from the user.
In essence, what is happening is we are compensating for the imbalance in the drone by modifying the power values of the motors. For example, if the drone is floating to the right, you can trim down the left motor values so they don’t “push” the drone to the right. Ideally, all values would be exactly the same for motor power settings, but this is rarely the case. When drones crash, it can cause slight imperfections in their aerodynamics that are not visible to the human eye but can cause drift. This makes the drone difficult to control, which is why it is important to trim the drone before flying.