LEARN.PARALLAX.COM
Published on LEARN.PARALLAX.COM (https://learn.parallax.com)
Home > Add Servos to the ELEV-8 v3

Add Servos to the ELEV-8 v3

The ELEV-8 v3 is a workhorse quadcopter – it’s sturdy, reliable, and most importantly, hackable!  Adding servos gives your ELEV-8 v3 the ability to do any number of tasks.  This tutorial contains beginner, intermediate, and advanced elements that will help you use additional servos to modify your ELEV-8 v3.  Although this tutorial will use specific hardware, many of the concepts will apply to other receivers, transmitters, and servos.

Hacking Cautions

It is possible to complete this tutorial by simply plugging in servos to the flight controller and making changes to the code.  If you choose to add servos more permanently to your ELEV-8 v3, you will need to take special care that:

  • The servos are firmly and safely fastened to the ELEV-8 v3’s chassis
  • Unless they are micro servos with no attached load, servos must have their own power supply
  • You thoroughly safety test your ELEV-8 v3 before fully flying it after it has been modified

Drive a Servo with the RC Receiver

A Beginner Hardware Hack

The easiest way to add a servo to your ELEV-8 v3 quadcopter is to drive it with a spare channel on the ELEV-8 v3’s receiver.

R/C receivers, such as the Spektrum AR610 6-Channel or the Spektrum AR8000 8-Channel receivers output a PWM (pulse-width modulated) signal that tell standard servos what position they should turn to and hold:

R/C servos are made to turn in a limited arc, no more than about 180°. You set the precise position of the output shaft of the servo motor by using the timing signal; this signal is provided by a microcontroller. Once the signal is applied, the motor moves to that position and stays there.

The control signal for a servo is a stream of pulses. The exact duration of these pulses, in fractions of a second, is what determines the position of the servo. Each pulse is nominally from 1000 to 2000 microseconds (μs) in duration — one microsecond is one millionth of a second. The pulses repeat about 50 times each second.

Your ELEV-8 v3 quadcopter needs 5 channels to fly: throttle, rudder, elevators, ailerons and gear/mode.  If your transmitter and receiver have additional channels available, you can use a spare channel to drive a servo.

Your Turn

  • Locate the receiver on your ELEV-8 v3 quadcopter.  If you are using a Spektrum Receiver, it sould look like this:

or this:

If a cable is already connecting the channel labeled Aux 1 on your receiver to your flight controller, it is safe to remove it – it is not critical for flight using the standard firmware.

  • Next, make sure that one of the switches or knobs on your transmitter is mapped to the Aux 1 channel.  You may need to read the user manual for your transmitter for specific instructions.  (Spektrum transmitter manuals can be found online here.)

STOP!
REMOVE THE PROPELLERS FROM YOUR QUADCOPTER BEFORE PROCEEDING!

  • Remove all of the propellers from your quadcopter.
  • Plug a servo into the Aux 1 channel on your receiver, as shown below. Be sure to align the black wire with ground:

 

  • Turn on your transmitter and connect the battery to power up your ELEV-8 v3.  Flip the switch or turn the knob on your transmitter that you mapped to the Aux 1 channel.  Your servo should move when you flip the switch or turn the knob

Although this works well if your transmitter has knob, not all transmitters do.  If you had to use a switch, you have noticed that you can only move the servo to 2 or 3 different positions.

By connecting that spare channel back up to the flight controller, you can modify the firmware on the flight controller to drive the servo in nearly any manner you choose.

Parts and Prep

Preparation – Safety First!

  • Make sure your ELEV-8 is OFF with the BATTERY DISCONNECTED AND REMOVED.
  • REMOVE THE PROPELLERS from the ELEV-8 v3 quadcopter’s motors. They are NOT needed for this tutorial.

What you will need:

A complete, tested, configured ELEV-8 v3 (Parallax Item #80300 or Item #80330) that has a receiver with at least 6 channels, such as:

  • A Spektrum AR610 6-Channel receiver (Parallax Item #80206 or comes with Item #80208), or
  • A Spektrum AR8000 8-Channel receiver (comes with Parallax Item #730-80300)
  • Any compatible transmitter/receiver pair with at least one spare (6 or more total) channel(s)

At least one R/C servo, such as:

  • A Parallax Standard Servo (Parallax Item #900-00005, below left) or
  • A Parallax (GWS) NARO Mini Servo (Parallax Item #900-00014, below right)

Optional Mounting Hardware:

If you wish to mount your servos to the bottom chassis plate of your ELEV-8 v3, you will need hardware and/or adhesive, such as:

  • #4-40 screws, locknuts, standoffs, and spacers (Available in hardware packs here or here)
  • Right angle (L-shaped) brackets (Parallax Item #720-00011)
  • Zip ties
  • Hot glue
  • Double-sided foam tape

Optional Separate Power Supply for Servos Under Load

Servos that are under load—lifting a weight or pulling against something—will need more current than if they are just moving freely.  If you are designing an ELEV-8 add-on that will put a load on the servos, they will need more current than the Flight Controller can supply. So, you would also need to build a separate power supply for your servos.

  • A 5V regulator, such as:
    • A low-dropout linear regulator (Parallax Item #601-00506), or
    • A switching regulator (Recommended) (Digikey Item #811-2196-5-ND)
  • A large electrolytic capacitor (Digikey Item #1189-1885-ND or similar)
  • (2) long 3-pin headers (Parallax Item #451-00303)
  • An 8″ 3-pin cable (Parallax Item #800-00080)
  • A soldering iron and solder (Available as a kit: Parallax Item #700-10011)
  • Short Female-to-Female jumper wires (Parallax Item #800-00045)
  • Tools for cutting and stripping wire (Available here, here, or here)
  • Electrical tape and/or heat shrink tubing

 

Edit the Firmware for Servos

An Intermediate Firmware & Hardware Hack

Connecting a servo to the Parallax Flight Controller on your ELEV-8 v3 quadcopter, and editing the firmware, gives you more control of the servo.  

The original Parallax Flight Controller firmware only generates servo pulses ranging from 1000 μs to 2000 μs (1.0 ms to 2.0 ms) wide.  Many servos operate over a wider range, ~700 μs to ~2300 μs.  So, the original Parallax Flight Controller firmware will only drive the servo through a portion of its full range:

This is important to note if the servo you are driving with the Parallax Flight Controller is part of a mechanism attached to your ELEV-8 v3.

  • Make sure that at least 6 channels from your receiver are connected to the Flight Controller and that you have successfully mapped one of the switches or knobs on your transmitter to the 6th channel (usually marked Aux 1).

Editing the Firmware to Support Additional Servos

If you haven’t done so already, follow the directions here (/courses/elev-8-v3-quadcopter-assembly-guide/step-22-install-software) to open the ELEV-8 v3 firmware using SimpleIDE.  Make sure you understand how to upload firmware to your ELEV-8 v3.  This project was tested with firmware version 1.0.2 and 1.0.3.

  • Follow the instructions in step 23 to find and open the Flight Controller Firmware.
  • With elev8-main.side open, click on the “Open Project Manager” icon in the lower left corner of the window:

A list of files will appear on the left side of the window.  

  • Click on elev8-main.cpp to make sure you are editing that file.
  • Scroll down until you find the following code (around line 135):
static long LEDModeColor;
  • After that line, add the following code:
static int servoPosition = 8000;    // create a variable to store the servos position, also tells servo where to start
  • Next, scroll down until you you find the following code (around line 385):
  Servo32_Init( 400 );
  for( int i=0; i<4; i++ ) {
    Servo32_AddFastPin( MotorPin[i] );
    Servo32_Set( MotorPin[i], Prefs.MinThrottle );
  }
  
  Servo32_Start();
  • On the line before Servo32_Start(); insert the following code:
Servo32_AddSlowPin( PIN_MOTOR_AUX1 );     // Add a standard servo on PIN_MOTOR_AUX1
Servo32_Set( PIN_MOTOR_AUX1, servoPosition );      // Set the starting position
  • Next, scroll down until you find the following code (around line 492):
S4_Define_Port(3, 115200, PIN_MOTOR_AUX2, TXBuf4, sizeof(TXBuf4), 32, RXBuf4, sizeof(RXBuf4));
  • Change the line to:
S4_Define_Port(3, 115200, 32, TXBuf4, sizeof(TXBuf4), 32, RXBuf4, sizeof(RXBuf4));
  • Next, scroll down until you find the line (around line 620):
UpdateFlightLEDColor();
  • After that line, add the following four lines of code:
if( Radio.Aux1 < -512 ) servoPosition = servoPosition - 12;  // if the switch/knob is low/down, turn counterclockwise
if( Radio.Aux1 >  512 ) servoPosition = servoPosition + 12;  // if the switch/knob is high/up, turn clockwise

servoPosition = clamp( servoPosition, 8000, 16000 );         // don't let the variable go outside of the 8000 to 16000 range!!
Servo32_Set( PIN_MOTOR_AUX1, servoPosition );                // set the servo position
  • Save your project.

DO NOT CONNECT YOUR ELEV-8’s Battery.  Make sure the propellers have been removed from your ELEV-8 quadcopter before continuing.

  • Plug your ELEV-8 v3 Flight Controller into your computer and select the corresponding port from the drop-down menu.
  • Click the Upload to EEPROM button.

 

Connect a Servo to the Flight Controller

Intermediate Hack, Continued

Once you have edited the firmware to support adding a servo to the Flight Controller, you are ready to plug in the servo.

MAKE SURE the propellers have been removed from your ELEV-8 v3 and the battery is unplugged before proceeding!

  • Connect the servo  the port on the flight controller shown below, making sure the white wire is on top:

  • Turn on your transmitter and plug in the quadcopter’s battery to turn it on.
  • Wait for the ELEV-8 v3 to start up completely.
  • Turn the knob or flip the switch you assigned to channel 6/Aux 1 – your servo should move accordingly.

To download the template file (AXD, DXF, and PDF) for the drop-rig mechanism, click here:

DropRig.zip

How the code works

The Parallax Flight Controller’s firmware contains a servo driver that generates the pulses necessary to drive the servo.  Although the driver has a high resolution and it supports high update rates, its range is limited.

You may have noticed the following code in the elev8-main.cpp file:

  Servo32_Init( 400 );
  for( int i=0; i<4; i++ ) {
    Servo32_AddFastPin( MotorPin[i] );
    Servo32_Set( MotorPin[i], Prefs.MinThrottle );
  }    
  Servo32_Start();

This code tells the servo drivers to create high-speed servo instances on each of the first 4 pins on the right side of the Flight Controller (labeled ESC/AUX).  This is where the ESCs that drive the motors for flight are attached.  They use the same signals as servos, except that their pulses are sent 400 times per second instead of 50 times per second for standard servos.  The drawing below shows the pin and how they are referenced in the firmware:

The code you added sets up a standard (“slow”) servo instance on the next pin header, where you plugged in your additional servo:

  Servo32_AddSlowPin( PIN_MOTOR_AUX1 );
  Servo32_Set( PIN_MOTOR_AUX1, servoPosition );

The next line you added tells the servo to start sending pulses that are exactly 1000 μs (1.0 ms) wide.  You may have noticed that the variable (servoPosition) that tells the servo driver to send 1000 μs pulses contains the number 8000 – this is because the servo driver has a resolution of ⅛th of a microsecond.  8 times 1000 = 8000.

Since the driver supports an output range from 1000 μs to 2000 μs, you can give it any value from 8000 to 16000.

The next lines of code read the value send by the receiver to the Flight Controller.  These values range from -1024 to +1024.  In fact, you can see these values next to the sticks at the bottom of the window when your Flight Controller is connected to the Parallax GroundStation software on your computer:

  if( Radio.Aux1 > 512  ) servoPosition = servoPosition + 12;
  if( Radio.Aux1 < -512 ) servoPosition = servoPosition - 12;

The next line of code ensures that you don’t send any number lower than 8000 or higher than 16000 to the servo driver.  In fact, sending a number outside of that range will cause the servo driver to lock up, and if that happens in flight, your ELEV-8 v3 will likely crash:

  servoPosition = clamp( servoPosition , 8000, 16000);

And finally, the servo is set to the position specified by servoPosition:

  Servo32_Set( PIN_MOTOR_AUX1, servoPosition);

Always use the clamp() function to make sure you do not send values outside of the 8000 to 16000 range to the servo driver!

 

To make the servo travel faster, you simply need to change how much is added or subtracted during each cycle.  If you use servoPosition = servoPosition + 24, the servo will move twice as fast.

Try This

Use a different channel to drive the servo.  

  • Change Radio.Aux1 shown the code above to Radio.Rudd or Radio.Thro (Rudder and Throttle, respectively).  

Radio.Elev, Radio.Aile and Radio.Aux2 are also available, and each has a range from -1024 to +1024.

Instead of using the transmitter to tell the servo to go clockwise or go counter clockwise, you can set it’s position directly.  

  • Change this code:
  if( Radio.Aux1 > 512  ) servoPosition = servoPosition + 12;
  if( Radio.Aux1 < -512 ) servoPosition = servoPosition - 12;
  • To this:
  servoPosition = 12000 + ( Radio.Aux1 * 4 );

The code above multiplies Radio.Aux by 4, so it’s range goes from -4096 to +4096.  It then adds it to 12000, meaning that the range goes from 7904 to 16096.  It is then run through the clamp() function to make sure that it stays between 8000 and 16000.

  • Once you have made changes, Click “Save” and then “Upload to EEPROM” to try them out.

DO NOT Fly your ELEV-8 v3 with modified firmware or hardware until you have read how to test it safely on the last page of this tutorial!

Build a Servo Power Supply

An Advanced Hardware Hack

If you plan to attach a servo to your ELEV-8 v3 and use it in flight, it is a good idea to give it its own power supply.  With a few components and a little soldering, it is easy to build a power supply for your additional servos.

DO NOT PROCEED unless the propellers and battery have been removed from your ELEV-8 v3!

  • Gather your materials.
  • Carefully study this diagram:

  • To begin building the power supply shown, cut a red and a black jumper wire in half.
  • Take one half of a red wire and one half of a black wire and cut them in half again – be sure to save all of the pieces.
  • Strip the cut ends of all of the wires so they can be soldered.
  • Solder the wires to the components as shown in the diagram above.
  • Use electrical tape or heat shrink tubing to wrap up exposed connections and keep them from touching each other and shorting out.
  • Connect the power supply you just built to a 3-pin header on the ELEV-8 Power Distribution Board. You may need to remove the flight stack from the ELEV-8 v3 to reach the connections:

  • Connect a white (signal) jumper wire to the top pin on the header your servo was originally plugged into on the ELEV-8 Flight Controller:

  • Connect the white (signal) wire and power supply to your servo as shown in the drawing above.
  • Turn on your transmitter.
  • Connect your ELEV-8 v3’s battery and veryify that everything is working correctly.

If you hear any popping or hissing, or smell something hot or smoke, immediately disconnect the battery!

DO NOT FLY Your ELEV-8 v3 after modifying the hardware or firmware until you have completed the safety testing on the last page of this tutorial!

 

Use Pitch and Roll from the IMU

An Advanced Firmware Hack

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.

Edit the Firmware to Compute Pitch and Roll

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.

  • With elev8-main.side open, click on the “Open Project Manager” icon in the lower left corner of the window:

A list of files will appear on the left side of the window.  

  • Click on quatIMU.h to edit that file
  • Scroll down to a blank line near line 50 and add the following code:
//Add containers for Pitch and Roll measurements
int QuatIMU_GetPitch(void);
int QuatIMU_GetRoll(void);
  • Go to the project tab on the left side of the window and click the quatIMU.cpp file to edit that file
  • Scroll down to a blank line near line 95 and add the following code:
    //Add variables for Pitch and Roll and associated scaling constants
    Pitch,
    Roll,
    const_outAngleScale,
    const_outNegAngleScale,
  • Scroll down to a blank line near line 230 and add the following code:
  //Define the scaling constants
  IMU_VARS[const_outAngleScale]     =    65536.0f / PI;
  IMU_VARS[const_outNegAngleScale]  =   -65536.0f / PI;
  • Scroll down to a blank line near line 300 and add the following code:
//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];
}
  • Scroll down to a blank line near line 745 and add the following code:
//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,

Edit the elev8-main.cpp file

  • Go to the project tab on the left side of the window and click the elev8-main.cpp file to edit that file.
  • Scroll down to line 388.
  • Delete you changes you made earlier in the tutorial and insert the following code before the line Servo32_Start(); :
  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)
  • Scroll down to line 620
  • Delete you changes you made earlier in the tutorial and insert the following code after the line UpdateFlightLED.Color(); :
  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 );
  • Save your project.

DO NOT CONNECT YOUR ELEV-8’s Battery yet!  Make sure the propellers have been removed from your ELEV-8 quadcopter before continuing!

  • Plug two servos into the ports shown in the photo below with the white (signal) wire upward:

  • Plug your ELEV-8 v3 Flight Controller into your computer and select the corresponding port from the drop-down menu.
  • Click the Upload to EEPROM button.
  • Once the edited firmware has uploaded, turn on your transmitter.
  • Plug the ELEV-8 v3’s battery in to turn it on.
  • Tilt and twist your ELEV-8 v3 to cause the Roll and Pitch driven servos to move.

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!

 

Safety Test after Hacking

Now that you have modified the hardware and/or firmware for the ELEV-8 v3, it is necessary to test its functionality to make sure it is safe to fly. Yes, do this every time you made hardware and/or firmware modifications!

DO NOT SKIP THIS PROCEDURE!  Flying with untested firmware is dangerous and can cause severe injury or property damage or loss.

If you have not done so already, REMOVE YOUR PROPELLERS before proceeding!

If your ELEV-8 v3 fails to pass any of the steps below, STOP – disconnect the ELEV-8 v3’s battery and return to prior steps to begin troubleshooting the problem.

  • The propeller blades should NOT be installed on the motors. If they are installed, remove them now.
  • Place your ELEV-8 v3 on a hard, flat surface.
  • Turn on your transmitter.
  • Open the Parallax GroundStation on your computer.
  • Connect your ELEV-8 v3 to your computer with its USB cable.

Pay close attention to the RGB LED on the Flight Controller.  During this process, it should continue to flash/alternate colors.  Except during power-up, arming and disarming, if the LED stops flashing, there is a problem with your code and it is not safe to fly.

  • Verify that the GroundStation software shows that the ELEV-8 v3 is connected.
  • Pick up your ELEV-8 v3 and make sure that the GroundStation is displaying it’s orientation correctly and smoothly.
  • Move the sticks around on your transmitter and make sure that the GroundStation is displaying them properly.
  • Disconnect your ELEV-8 v3 from your computer.
  • Connect your ELEV-8 v3’s battery.
  • Arm your ELEV-8 v3.
  • Make sure all 4 motors are spinning.
  • Move your transmitter sticks around.  Continue moving them around for at least 90 seconds (1.5 minutes).  Make sure that your motors are changing speeds appropriately.

The Propeller microcontroller on the Flight Controller has a system clock that takes approximately 53 seconds to roll back over to zero and start again.  Testing for 90 seconds ensures that the rollover will not cause a lock-up.

  • Check your Gear switch to make sure that your ELEV-8 v3 is changing modes appropriately.
  • Disarm your ELEV-8 v3.  Make sure the motors stop.

If your ELEV-8 v3 passed all of the above tests, it should be safe to re-install the propeller blades when you are ready to fly.  

For your first flight with modified firware and hardware, follow all safety precautions.  
Fly gently, close to the ground, and away from any people, objects, or structures until you are confident that your ELEV-8 v3 is performing normally.

 

DISCUSSION FORUMS | PARALLAX INC. STORE

About | Terms of Use | Feedback: learn@parallax.com | Copyright©Parallax Inc. 2024


Source URL:https://learn.parallax.com/courses/add-servos-to-the-elev-8-v3/
Links