Getting the most out of your hobby servo

Overview

ServoProject

by Adam Bäckström

Getting the most out of your hobby servo

Robot

Theory

The control system of a regular hobby servo looks something like this:

loop1

This control scheme is good at holding and moving fast between position, but not so good at following a smooth predefined motion. Which is what you want when you build a robot.

Industrial servo controllers use a cascade based control scheme instead, which looks something like this:

loop2

This is the control scheme used in this project.

The main benefit of this approach is that it also takes the velocity and torque into account. This allows for a much tighter motion tracking.

Backlash control

When dealing with cheap gearboxes, backlash is always a problem. The hacked servos in this project uses two encoders to compensate for backlash. One AS5048a magnetic encoder or a potentiometer on the output shaft and one custom optical encoder inside the DC-motor. The benefit of having the extra encoder inside the motor is getting higher resolution and a main control loop which is backlash free. If one would only use the AS5048a for controlling, the backlash would enter the control loop as a time delay. This limits the control loop performance.

The backlash compensation is done by moving the main control loops reference-position so that the output encoder reaches the correct position.

Project structure

ArduinoSketch

This folder contains the Arduino project for the Adafruit ItsyBitsy M0 Express boards.

When compiling, the active configuration is selected by modifying the #include "*.h" line in the config/config.h file to include the desired config file. The configSelector.py and the configurationWizard.py scripts can be used to to simplify the config selecting process by giving a drop-down list with all configs in the config folder.

The folder also holds a Makefile which can be used to compile and transfer the project. One benefit of using the Makefile is that the configSelector script always is executed prior to compiling. To be able to use the Makefile you must first install arduino-cli.

Setup

setupStep1

  1. Create the base configuration

setupStep2

  1. Make the new configuration the active configuration by selecting it in the drop-down and transfer the project to the microcontroller. Either with the Arduino IDE or the make script.

setupStep3

  1. Calibrate the optical encoder

setupStep4

  1. Calibrate the pwm nonlinearity compensation

setupStep5

  1. Generate the system model (auto tune control loops)

setupStep6

  1. Calibrate the output encoder nonlinearity compensation

MasterCommunication

Holds the example master project.

To compile run make. This creates the program ./executable with the following options.

Allowed options:
  --playPath            play the path defined in createPath()
  --output arg          data output file
  --simulate            simulate servos

Obsolete options:
  --servoNr arg         servo nr
  --recOpticalEncoder   record optical encoder data of given servo
  --recSystemIdentData  record system ident data of given servo
  --recMomentOfInertia  record moment of inertia data of given servo
  --amp                 amplitude for recMomentOfInertia
  --frq                 frequency for recMomentOfInertia
  --pwmAmp              pwm amplitude for recOpticalEncoder and recSystemIdentData
  --fricPwmAmp          pwm amplitude to overcome friction for recSystemIdentData

MasterCommunication/view.kst

Kst2 project file which can be used to view the recorder data in test.txt from --playPath option. Run

./executable --playPath --output test.txt

to start robot movement and update plots.

USB_To_Serial

Basic Arduino project to turn an arm based Arduino into a fast usb-to-serial-converter. The resulting communication delay becomes much lower than FTDI based converters. This is important since the master has to be able to send and receive from all six servos every 18 ms.

CadFiles

Holds all .stl and the original Freecad files

PcbDesignes

Holds all KiCad projects for the electronics

Dependencies

ArduinoSketch

ArduinoSketch/configSelector.py

  • Python >= 3.8.2
  • python3-gi

ArduinoSketch/configurationWizard.py

  • Python >= 3.8.2
  • matplotlib >= 3.2.1
  • numba
  • numpy >= 1.18.5
  • python3-gi
  • scipy >= 1.5.0
  • serial

ArduinoSketch/Makefile

  • GNU Make >= 4.2.1
  • arduino-cli

MasterCommunication/Makefile

  • GNU Make >= 4.2.1
  • gcc >= 9.3.0
  • boost >= 1.71.0
  • Eigen >= 3.4.0

Hardware

Parts list

Modified normal size servo

Cad and stl files for 3D printing:

CadFiles/Servo

Electrical schematic:

PcbDesignes/Servo

Modified micro servo

Cad and stl files for 3D printing:

CadFiles/MicroServo

Electrical schematic:

PcbDesignes/MicroServo

Gripper

  • 1 x SG90 servo

".stl" files for 3D printing:

CadFiles/Robot/stl/GripperBase.stl
CadFiles/Robot/stl/GripperClip.stl
CadFiles/Robot/stl/GripperFinger1.stl
CadFiles/Robot/stl/GripperFinger2.stl
CadFiles/Robot/stl/GripperMount.stl

Robot

Cad and stl files for 3D printing:

CadFiles/Robot

Normal size servo modification (Turnigy MG959)

Build MainPcb and AS5048aEncoderBoard

A video on how to build the MainPcb and AS5048aEncoderBoard can be found at https://youtu.be/YQpAAr5RPSE?t=60. This video is for an older version but the building instructions are the same.

Servo gearbox with 3D printed parts

PCB Assemblies

How to mount the PCBs to servo

Build the Optical Encoder

  1. Take the motor, use pliers to bend out the four indents in the metal housing and bend up the motor lid.
  1. Remove the two steel brushes from the lid carefully by cutting the lid into pieces. Take the 3D printed motor lid and insert the two steel brushes and two ITR8307 into the new lid. Solder the ITR8307 according to:
PcbDesignes/Servo/OpticalEncoder/OpticalEncoder.sch
  1. Take the motor with the lid removed. Paint the rotor with black nail polish and glue in the optical encoder wheel on top as shown in the middle image. The dimensions of the encoder wheel can be found in:
CadFiles/Servo/OpticalEncoderWheelDimensions.png

Then carefully put the new lid on the motor without bending the steel brushes.

  1. Solder the four leads from the optical encoder on top of ItsyBitsy board as shown in this image.

Micro servo modification (MG90S or SG90)

  1. Open the servo, desolder the motor and the potentiometer
  1. Bend down the motor terminals and remove the plastic back axis cover so the motor looks like the one in the last image
  1. Place one of the holes on a servo horn over the axis. Then use a screw and a vice to push out the motor axis about 1 mm so it looks like the motor in the last image.
  1. Then solder two wires to the motor terminals. Use super glue to mount the optical encoder wheel to the back axis and mount the 3D printed "OpticalEncoderSensorMount" part over the back of the motor.
  1. Place the two IR sensors next to each other on a piece of tape and put some hot glue over them. Fold pin 4 of the lower sensor like the middle picture shows. Then fold in the rest of the ground pins, cut them to length and solder them together.
  1. Place the four resistors next to each other on a piece of tape, in the order 6.8k, 120, 1.5k and 120 ohm from right to left. Put some hot glue over them to hold them together and remove the tape. Fold the top leg of the 6.8k resistor like the middle picture shows. Then fold in the rest of the 3.3V pins and solder them together.
  1. Connect the two 120 ohm resistors to pin 1 on the IR sensors and the 6.8k and 1.5k ohm resistors to pin 3.
  1. Solder three wires to the potentiometer.
  1. Connect the potentiometers 3.3V and ground to the optical encoder sensors while soldering on a 5 wire flat cable to the assembly. Then connect the third wire of the flat cable to the potentiometer sens wire and connect the fourth and fifth wires to the IR sensors third pin. This wires up the flat cable so that from right to left we have: 3.3V, GND, output shaft potentiometer, optical encoder channel A and lastly channel B.
  1. Glue the optical encoder sensors to the "OpticalEncoderSensorMount". Cut the screws to a length so that they fit with the servo lid removed.
  1. Put back the motor and the potentiometer into the servo. See "PcbDesignes/MicroServo/MainPcb/MainPcb.sch" for info on how to connect the microcontroller and motor driver.

License

Open Source License

ServoProject is free software. You can redistribute it and/or modify it under the terms of Creative Commons Attribution 3.0 United States License.

To view a copy of this license, visit http://creativecommons.org/licenses/by/3.0/us/

Comments
  • Accuracy achievable

    Accuracy achievable

    Hi Adam, An awesome project. I was looking greater accuracy in servos for my automatic turret. Can you please tell me how accurate are the modified servos in degrees ?

    opened by vkumarsinghnoida 9
  • No current sensor?

    No current sensor?

    What a great project! I noticed that previous versions had current sensors and corresponding control codes。 However, in the latest version, there is no current sensor on the circuit diagram. However, there is still a current sampling part in the code. Is that right?

    opened by pzh11001 6
  • Alternative boards and code

    Alternative boards and code

    Hi My questions are regarding how to make the servo without custom pcb as given in coreless servo build. How many boards are required to control 2 servos? How exactly do we connect the board and use which software ? And can we use the original potentiometer instead of the magnetic encoder ?

    opened by vkumarsinghnoida 5
  • Compatibility with DS3218 servos

    Compatibility with DS3218 servos

    Hi adam,

    First congratulations for your work, your results with theses cheap servos are really impressive

    i'm verry interested in building five of them but before checkout on JLCPB, i would like to have your opinion about the PCB compatibility with DS3218 servos.

    i think its ok because the only difference with 3225 servos seems to be height , and obviously the final torque.

    what do you think ?

    Regards,

    opened by PJfixer 2
  • Brushed servos

    Brushed servos

    For building the robot you mention to use 3x coreless modified servos + 3x micro modified servos. Brushed servos are not required? Finding ATSAMD21G18A-A at a reasonable price for a custom PCB is very difficult this days. So, can we build the robot just with off the shelf boards?

    opened by Telepresent 1
Releases(v3.1)
WIP SAT benchmarking tooling, written with only my personal use in mind.

SAT Benchmarking Some early work in progress tooling for running benchmarks and keeping track of the results when working on SAT solvers and related t

Jannis Harder 1 Dec 26, 2021
Parameterized testing with any Python test framework

Parameterized testing with any Python test framework Parameterized testing in Python sucks. parameterized fixes that. For everything. Parameterized te

David Wolever 714 Dec 21, 2022
Fidelipy - Semi-automated trading on fidelity.com

fidelipy fidelipy is a simple Python 3.7+ library for semi-automated trading on fidelity.com. The scope is limited to the Trade Stocks/ETFs simplified

Darik Harter 8 May 10, 2022
Mypy static type checker plugin for Pytest

pytest-mypy Mypy static type checker plugin for pytest Features Runs the mypy static type checker on your source files as part of your pytest test run

Dan Bader 218 Jan 03, 2023
A folder automation made using Watch-dog, it only works in linux for now but I assume, it will be adaptable to mac and PC as well

folder-automation A folder automation made using Watch-dog, it only works in linux for now but I assume, it will be adaptable to mac and PC as well Th

Parag Jyoti Paul 31 May 28, 2021
Ab testing - basically a statistical test in which two or more variants

Ab testing - basically a statistical test in which two or more variants

Buse Yıldırım 5 Mar 13, 2022
Percy visual testing for Python Selenium

percy-selenium-python Percy visual testing for Python Selenium. Installation npm install @percy/cli: $ npm install --save-dev @percy/cli pip install P

Percy 9 Mar 24, 2022
Main purpose of this project is to provide the service to automate the API testing process

PPTester project Main purpose of this project is to provide the service to automate the API testing process. In order to deploy this service use you s

4 Dec 16, 2021
Flexible test automation for Python

Nox - Flexible test automation for Python nox is a command-line tool that automates testing in multiple Python environments, similar to tox. Unlike to

Stargirl Flowers 941 Jan 03, 2023
No longer maintained, please migrate to model_bakery

Model Mommy: Smart fixtures for better tests IMPORTANT: Model Mommy is no longer maintained and was replaced by Model Bakery. Please, consider migrati

Bernardo Fontes 917 Oct 04, 2022
a socket mock framework - for all kinds of socket animals, web-clients included

mocket /mɔˈkɛt/ A socket mock framework for all kinds of socket animals, web-clients included - with gevent/asyncio/SSL support ...and then MicroPytho

Giorgio Salluzzo 249 Dec 14, 2022
The async ready version of the AniManga library created by centipede000.

Async-Animanga An Async/Aiohttp compatible library. Async-Animanga is an async ready web scraping library that returns Manga information from animepla

3 Sep 22, 2022
Docker-based integration tests

Docker-based integration tests Description Simple pytest fixtures that help you write integration tests with Docker and docker-compose. Specify all ne

Avast 326 Dec 27, 2022
Silky smooth profiling for Django

Silk Silk is a live profiling and inspection tool for the Django framework. Silk intercepts and stores HTTP requests and database queries before prese

Jazzband 3.7k Jan 04, 2023
Python program that uses pynput to simulate key presses. Probably only works on Windows.

AutoKey Python program that uses pynput to simulate key presses. Probably only works on Windows. Can be used for pretty much whatever you want except

2 Oct 28, 2022
✅ Python web automation and testing. 🚀 Fast, easy, reliable. 💠

Build fast, reliable, end-to-end tests. SeleniumBase is a Python framework for web automation, end-to-end testing, and more. Tests are run with "pytes

SeleniumBase 3k Jan 04, 2023
Simple frontend TypeScript testing utility

TSFTest Simple frontend TypeScript testing utility. Installation Install webpack in your project directory: npm install --save-dev webpack webpack-cli

2 Nov 09, 2021
模仿 USTC CAS 的程序,用于开发校内网站应用的本地调试。

ustc-cas-mock 模仿 USTC CAS 的程序,用于开发校内网站应用阶段调试。 请勿在生产环境部署! 只测试了最常用的三个 CAS route: /login /serviceValidate(验证 CAS ticket) /logout 没有测试过 proxy ticket。(因为我

taoky 4 Jan 27, 2022
How to Create a YouTube Bot that Increases Views using Python Programming Language

YouTube-Bot-in-Python-Selenium How to Create a YouTube Bot that Increases Views using Python Programming Language. The app is for educational purpose

Edna 14 Jan 03, 2023
Python dilinin Selenium kütüphanesini kullanarak; Amazon, LinkedIn ve ÇiçekSepeti üzerinde test işlemleri yaptığımız bir case study reposudur.

Python dilinin Selenium kütüphanesini kullanarak; Amazon, LinkedIn ve ÇiçekSepeti üzerinde test işlemleri yaptığımız bir case study reposudur. LinkedI

Furkan Gulsen 8 Nov 01, 2022