Servo Deadband Correction

5.9K1326

Intro: Servo Deadband Correction

a.articles { font-size: 110.0%; font-weight: bold; font-style: italic; text-decoration: none; background-color: red; } a.articles:hover { background-color: black; }

Analog servos require the pulse-width to change by up to 10 microseconds before they start to move. This represents an error of almost 2 degrees. [1]

This instructable explains how to significantly reduce the deadband errors in the servo plotter described in https://www.instructables.com/Servo-Plotter/

Images

  • Photo 1 shows the orginal servo plotter
  • The lower trace in photo2 shows two overlaid squares. One square is plotted clockwise (CW) ... the other is plotted counter-clockwise (CCW). Deadband is distorting the squares and causing the diagonals to separate.
  • The upper trace in photo2 shows the improvement when deadband compensation is applied.
  • The video shows servo plotter 2 in action ... note the deadband improvement

The cost of the push-switches for this project is less than $5.00

Notes

[1]

For a standard servo:

  • 500uS produces 0 degrees
  • 1000uS produces 90 degrees
  • 1500uS produces 180 degrees
  • 1 degree equates to (1500-500)/180uS = 5.5uS
  • 10uS equates to 10/5.5 = 1.8 degrees

STEP 1: Reducing Mechanical Errors

Photo 1 shows the penlift in instructable https://www.instructables.com/Servo-Plotter/.

This simple penlift has a serious problem ... the servo horn tends to displace plotter arm 2 sideways when it is raised and lowered.

Rotating the SG90 servo 90 degrees doesn’t fix the problem as the servo horn is now off-center causing arm2 to twist.

Arm 2 is replaced in Photos 2, 3, 4 with a length of 3mm aluminium extrusion to which an alternate design penlift is attached.

Only the pen touches the paper under its own weight ... the servo arms are no longer displaced.

Now that the mechanical errors have been minimised (there is still a tiny backlash in the gears) lets modify the circuit.

STEP 2: Circuit Diagram

The circuit and parts are the same as for the plotter described in https://www.instructables.com/Servo-Plotter/ with the addition of two push-switches.

These push-switches allow you to increase/decrease the servo pulse widths under menu control.

The cost of the push-switches for this project is less than $5.00

STEP 3: Installing the Software

Method:

  • Copy the attached file “servo_plotter_10.ino” into an Arduino sketch and save it to a folder using the same name but without the .ino extension.
  • Copy myServo.h into the folder you have just created. [1]
  • Copy myServo.cpp into the folder you have just created. [1]
  • Compile and upload “servo_plotter_10” to your Arduino.
  • Set your Arduino “Serial Monitor” to 9600 bauds.
  • The menu in photo should appear.

Caution:

[1]

The above files, myServo.h and myServo.cpp, are different from those of the same name in https://www.instructables.com/Servo-Plotter/


15 January 2022

Alternate software using a PCA9685 servo shield has been posted here https://www.instructables.com/ArduinoServo-Shield/

STEP 4: Calibrating the Servos

Servo Arm 1

  • Draw radials at 10 degree intervals as shown in photo 1
  • Select menu option T4 ... numbers should start scolling on your monitor.
  • Press the “decrease” button until the servo is fully left (0 degrees)
  • Now press the “increase” button and record the microseconds every 10 degrees.
  • If you overshoot press the decrease button and approach the overshot point in a CW direction.
  • You should now have 19 measurements.
  • Repeat the process, this time recording the pulsewidths every 10 degrees in a CCW direction.
  • Enter these values into spreadsheet as shown in photo 2
  • Subtract the readings at each 10 degrees interval
  • Sum these readings and divide by 19 ... this your servo deadband.
  • Record this reading as “deadband1” in the “servo_plotter_10.ino” file header.
  • Record the CCW reading for 90 degrees in the “servo1_90” header variable.
  • Record the CCW reading for 45 degree in the “servo1_45” header variable
  • Press both buttons to return to the menu.
  • Recompile the Arduino sketch.

Servo Arm 2

  • Repeat Method 1 for servo arm two using menu item T5. [1]
  • Since servo 2 is inverted 0 degrees is in the CW direction.
  • Stop rotating before the arms collide ... just divide by a lesser number.
  • Record the average deadband as “deadband2”
  • Record the 90 degree CCW reading in the “servo2_90” header variable
  • Record the 45 degree CCW reading in the “servo2_45” header variable
  • Press both buttons to return to the menu.
  • Recompile the Arduino sketch.

Penlift

  • The values for the SG90 servo in the header are near enough
  • Press menu item T2 (Pen Up) before attaching the servo horn vertically.
  • Photo 3 shows a graph of the CW and CCW readings for servo 1.

Notes

[1]

You may need to position servo arm 1 and reposition the radials first.

STEP 5: Theory

Analog servos convert the incoming pulse-width to a DC voltage. A linear potentiometer is attached to the output shaft. This potentiometer acts as a voltage divider. When the DC voltage equals the potentiometer voltage the servo stops.

Deadband is introduced to reduce the the stationary servo current and to stop the servo "hunting".

In order to move to the next position we need to increase/decrease the pulsewidth until the motor moves.

With this in mind my software converts the target angle to a pulse-width. If the target angle is less than the last_angle I subtract the deadband for that motor. If the target angle is equal or greater than the last_angle I add the deadband for that motor.

This has the effect of reducing the deadband.

So how does it work?

Assumptions:

  • each target location is surrounded by a circle of deadband radius
  • hobby servos stop whenever they enter a deadband circle

Let’s assume that the plotter (servo) is currently sitting at coordinate “Point1”.

Start = Point1 ............... (1)

Let’s get the servo moving by increasing the pulsewidth to “Point2+deadband”.

Target = Point2+deadband .................(2)

But a circle of radius “deadband” about the Target lies on Point2

Finish = (Point2 + deadband) – (deadband radius) = Point2 ..................(3)

(which is exactly what we want ... the deadband has been cancelled.)

You can verify this as follows:

  • the plots improve if you add the deadband pulse-width to the target pulse-width
  • subtracting rather than adding the deadband pulse-width degrades the plots
  • doubling the amount of deadband causes the plots to “wiggle/oscillate” due to overshoot.

STEP 6: Sample Plots

Images

  • Photo1 shows overlaid squares with and without deadband compensation
  • Photo 2 shows a “Hello World!” plot
  • A “Sobel” outline was obtained from photo 3 using my instructable https://www.instructables.com/CNC-Edge-Detection-...
  • Photo 4 shows a partial plot of photo 3 in progress
  • Photo 5 shows the finished outline.

The wiggles are possibly due to slight mechanical backlash in the servo gears.

STEP 7: ​Summary

This instructables explains how to reduce the effects of servo deadband.

Improvements have been made to the plotter described in my instructable https://www.instructables.com/Servo-Plotter/. Specifically:

  • Self supporting arms
  • An improved penlift
  • Deadband correction

Acceptable watercolor outlines can be produced using this servo plotter. [1]

The additional cost of parts for this plotter is less than $5.00

Note

[1]

Consider my CoreXY Plotter described in https://www.instructables.com/CoreXY-CNC-Plotter/... if you require high resolution plots.

  Click here   to view my other instructables.

24 Comments

it works thank you so much my friend you have been a real help i started fowling you thnak you so much much apericated
so i got everything correct and i am just fixing up a problem whith it saying error compilibng with arduino dont worry i can do this one thanks for the help my friend ill let you know if it works
so update i switched to an arduino uno r3 microcontroller and its still says the same message servo not declared or other stuff verifying always has an error pop up and nothing else works i dont know what to do anymore
it just all goes to notepad and not the arduino app like the servo h and cpp go to notepad and the servo plotter 10 ino goes to the arduino app how do i exsacly get them all into one app
You shouldn't be getting error messages like that.

The problem is not with the code ... as I will show below ...
it has to be something you are doing or some thing in your Arduino environment.

Check that your Arduino environment looks like mine (screenshot attached) ... I've highllighted the key points. Later releases of the Arduino should be fine.

Let's try a different way of compiling my code.

Left- click each of the following files in Step 3 of this instructable:
- myServo.cpp
- myServo.h
- servo_plotter_10.ino

You should now see these three files in your download folder (screenshot attached)
DO NOT OPEN THEM ... your editor may be corrupting the files.

Right-click your mouse and select new|folder. Name this folder servo_plotter_10 (screen shot attached)

Drag each of the files you have downloaded into this new folder. Double click the folder and you should see each of the files (screenshot attached)

Now open your Arduino IDE, select File |Open, and navigate your way to the .../downloads/servo_plotter_10 folder that you have just created and select the file servo_plotter_10.ino. Your Arduino IDE should look like the attached screen shot.

Finally compile and upload the code by left-clicking the right-arrow button. (screenshot attached)

If this doesn't work then I'm fresh out of ideas.





so i did everything and the only problem is that when i click on the ino file there is only one file that pops up on the ide
Thanks for being patent my friend I really aperciate it:)
Thank you for your interest in my project :)

My code does work ... watch the diagonals in the video overlap when deadband correction is applied.

For the code to work the following three files must all reside in a folder called "servo_plotter_10" (without the quotes)
- "servo_plotter_10.ino"
- "myServo.h"
- "myServo.cpp"

Without more information I cannot help.



i put them as one folder and it still doesent work though
I need to know what doesn't work ... for instance:
- Does the code compile?
- Are you using an Arduino UNO R3?
- What servos are you using?
- Have you calibrated your servos as outlined in Step 4?

Contact me via the Instructables message sytem and I will help sort the problem.





plz respond as soon as possible and i am using an arduino mega2560 and i am using the smaller servos it does compile it just pulls up problem after problem with the code
My code was written for an Arduino UNO R3 microcontroller and compiles without errors using the standard Arduino IDE ... screen shot attached.

Note there are three tabs ... one for each of the following files
- servo_plotter_10.ino
- myServo.h
- myservo.cpp

These tabs automatically appear when the ino file is opened in the Arduino IDE providing each of the above three files has been placed in a folder named servo_plotter_10.

While most Arduino code will run on an Arduino Mega my code may not as I am not using standard functions such a delay() and delayMicroseconds() ... instead I am writing directly to the Timer1 registers.

From what I've read, the pinouts for the Arduino Mega Timer1 are different to the pinouts for the Arduino Uno R3. There are probably other differences.

If you choose to stay with an Arduino Mega you will have to adapt my code to suit.



it wont even let me upload withoute there being an error with the servos it always says servo not declared plz help i swithed to the arduino uno r3 microcontroller and nothing still doesent work same message keeps popping up servo not declared
Listen I know your trying to help if you can is there a way for you to make a v3 for this project or an update to the code that would be very appreciated idk if it is my board that is the problem or something else I switched to an arduino uno r3 microcontroller no luck the code is weird it is not working an update or a fix to the code would be apercated thanks for everything
it always says like servo was not declared and i switched to an arduino uno r3 microcontroller and it still doesent work
See my reply further down.
it also keeps saying that servo was not declared in this scope or somthing like that
See my reply further down
More Comments