Although it is useful to use a spare channel on your transmitter to drive a servo, you can drive a servo using other variables in the Flight Controller's firmware instead. For instance, a useful application for servos is a sensor gimbal. You may have a sensor that needs to stay level or that always points straight down. Since the Flight Controller always knows its orientation, you can use its computed pitch and roll to drive servos in use as a gimbal.
The latest version of the Firmware available on GitHib includes code for computing Pitch and Roll - if you download your firmware from GitHub after April 5, 2016, you can skip to the section titled "Edit the elev8-main.cpp file" below.
A list of files will appear on the left side of the window.
//Add containers for Pitch and Roll measurements int QuatIMU_GetPitch(void); int QuatIMU_GetRoll(void);
//Add variables for Pitch and Roll and associated scaling constants Pitch, Roll, const_outAngleScale, const_outNegAngleScale,
//Define the scaling constants IMU_VARS[const_outAngleScale] = 65536.0f / PI; IMU_VARS[const_outNegAngleScale] = -65536.0f / PI;
//Create functions to retrieve the calculated Pitch and Roll Measurements int QuatIMU_GetPitch(void) { return INT_VARS[Pitch]; } int QuatIMU_GetRoll(void) { return INT_VARS[Roll]; }
//Calculate the Pitch and Roll F32_opASinCos, m12, const_1, temp, F32_opMul, temp, const_outAngleScale, temp, F32_opTruncRound, temp, const_0, Pitch, F32_opASinCos, m10, const_1, temp, F32_opMul, temp, const_outNegAngleScale, temp, F32_opTruncRound, temp, const_0, Roll,
Servo32_AddSlowPin( PIN_MOTOR_AUX1 ); // Add a servo to this pin for Pitch Servo32_AddSlowPin( PIN_MOTOR_AUX2 ); // Add a servo to this pin for Roll Servo32_Set( PIN_MOTOR_AUX1, 12000 ); // Set this servo to center (1.5 ms) Servo32_Set( PIN_MOTOR_AUX2, 12000 ); // Set this servo to center (1.5 ms)
int servoRoll = QuatIMU_GetRoll() / 5; // divide by 5 to match the servo's movement to the actual roll, may need to adjust int servoPitch = QuatIMU_GetPitch() / 5; // divide by 5 to match the servo's movement to the actual pitch, may need to adjust; servoPitch = servoPitch + ( Radio.Aux1 << 1); // Add the Aux1 channel to the pitch to control the gimbal's tilt. // You can delete this line if you don't want to do this servoRoll = clamp( (12000 - servoRoll), 8000, 16000 ); // Make sure the Roll and Pitch don't go out of range servoPitch = clamp( (12000 - servoPitch), 8000, 16000 ); Servo32_Set( PIN_MOTOR_AUX1, servoRoll ); // Send the values to the servos Servo32_Set( PIN_MOTOR_AUX2, servoPitch );
DO NOT CONNECT YOUR ELEV-8's Battery yet! Make sure the propellers have been removed from your ELEV-8 quadcopter before continuing!
DO NOT Fly your ELEV-8 v3 with attached servos unless they are connected through a separate power supply!
DO NOT Fly your ELEV-8 v3 with modified firmware or hardware until you have followed the procedure to test it safely on the last page of this tutorial!