Hack your servo v3.00 - Get full PID position and speed control from your hobby servo
Yes we like servo mods!
As promished this is the third servo hack. This builts upon the second hack - 'add 10-bit abolute/incremental feedback encoder to your hobby servo' - node/18470. Source code is open and links provided at the end of the post. Schematics are also provided. In terms of the board files... well dont be lazy! After all all three boards are two-sided and fairly easy to design once you have a look at the schematics (and the main pic:). A somewhat similar post is also found in the Components page, but here I explain more or less how you would make it yourself, the components needed, some well-thought tips and how to install it inside your servo.
So lets make a start, shall we?
To do this you need 3 basic components:
- Magnetic encoder IC and a circumferential field distribution magnet. The AS5040 gives you 10-bit resolution, the AS5145 12-bit resolution (4096 positions / 360 degrees) and an SPI interface which always comes handy. The two ICs are pin-to-pin compatible. Get these directly from Austrian Microsystems - ask for a sample, they normally ship the next day.
- An ATMega 328P (MFL package) an on-board regulator and a 20MHz crystal (to get the control loop closing at 1KHz)
- A Freescale motor driver IC (MC33887) which can deliver up to 5 Amps continuous. If you need something smaller try the MCP17511 (1 Amp cont.)
Each of these should go into a separate board and all three should stack together using low profile pin headers/sockets. The target board outline is 15.5x15.5mm - a good design exercise :) This will make it fit inside any standard size servo. If you cannot get it that small try the 1/4 scale instead. The target board outline for this is 25x32mm with plenty of height space.
When designing the magnetic encoder board bear in mind that the centre of the servo's output shaft for standard servos should be located 10mm from servo casing (15mm for 1/4-scale servos). The magnetic encoder ICs have an allignment tolerance of +/- 0.5 mm so they are pretty forgiving in terms of misallignment.
The ATMega328P board should stack directly under the magnetic encoder. It is the same processor Arduino uses. Remember to keep the programming pins near the board edge for easy access. The pins needed to get feedback from the encoder and control the motor driver should come out on the sides of the board such that all three boards can be stacked together. The remaining pins should be exposed using pads so you can solder wires and use them if your application needs them. You should have 4 digital IOs and 4 analog inputs available for other stuff. If you go for an RS485 transciever this should go at the bottom of the board. Basically you get full Arduino functionality but 4MHz faster clock and half the footprint of Arduino nano :))
The motor driver board should be on the bottom of the board assembly. Keep the bottom layer free of components with a large copper plane and use thermal vias to direct heat away from the board. Keep it free of components so you can add heatsinking if so required. Normally you should ok without, but if you go for high-performance coreless servos heatsinking becomes a must.
When everything is ready (.....) you can install the boards inside your servo. To do that first you have to connect the magnet to the servo's output shaft. I will repeat the necessary part of the procedure of my previous post (node/18470) just to avoid any confusion.
- Start by accessing the servo’s bottom compartment and by removing the control / power electronics from the servo. Unsolder the motor’s leads and proceed by removing the feedback potentiometer.
- If continuous rotation is required, access the servo’s top compartment where the gearbox is located and remove the mechanical stop from the output gear. Take extra care not to damage the gear’s teeth as well as, keeping any foreign particles from entering the gearbox assembly. Particles residing on any of the gears’ teeth will cause undesirable noise during operation and may also affect the performance of your servo.
- Next disassemble the potentiometer keeping the rotation shaft. Remove the potentiometer slider from the shaft. What remains is going to be used as a support shaft for the encoder’s disk magnet. The magnet is going to be glued onto it.
- Carefully flatten the potentiometer’s base using sandpaper or an abrasive disk.
- Roughen the side of the disk magnet to be glued onto the potentiometer’s shaft by using sandpaper. This step is essential and will ensure a strong assembly.
- Take a small piece of wood, 10mm thick and drill a blind 3.5mm diameter hole approximately 5mm deep. This is going to hold the potentiometer’s shaft and the disk magnet vertically while the epoxy settles.
- Prepare a small epoxy mix, insert the pot’s shaft to the hole and place the disk magnet on the pot’s shaft with a small drop of epoxy between them. Remove any excess epoxy. Ideally you should aim to leave a small ring of epoxy around the circumference of your magnet for lateral support. Remember that your servo has an output speed of about 60 rpm but the system that the servo is going to be installed will most likely be subjected to other sources of vibration. Accurately centre the magnet on the shaft and leave to settle for at least 6 hours (for a 5min epoxy). I know that by now you cannot wait to start using the servo on your project but you must show patience if you do not want to repeat this step in the near future.
- Insert the pot’s shaft back into the servo’s output gear. Make sure the flatten area of the shaft goes fully into the corresponding ‘pocket’ of the servo’s output gear like it did before the modification.
Next you need to flash the Atmel. Check Google Code page(s) below for the source code and programming guide for AVRStudio, MS Visual Studio Xpress and Eclipse. The AVR library page is a must. Currently supporting only ATMega MCUs but soon to be expanded.
Following the procedure above you need to make a hard decision: I2C, RS232 or RS485?? With I2C and RS485 you can daisy chain many controllers together. Solder the appropriate cables in place together with the motor-leads' cables and the power-cables.
At this point you should be able to drop the boards assembly inside, locate it in place using heat-glue or thermal foam and start playing :))
For the Eagle schematics go to:
http://www.01mech.com/supermodified > scroll down the page & right click on the link > Save as...
I am still waiting on my boards to arrive. Will update the post accordingly then.