Tuesday, June 4, 2013

Much Needed Feedback from a Hobby Servo

[caption id="attachment_128" align="aligncenter" width="242"]Hobby Servo Figure 1. Hobby Servo[/caption]

Background Information


Hobby servos do not give you position feedback. They are selfish. The only feedback they have is internal and the manufactures do not give you access. This internal feedback tells the servo if its current position does not match the desired position (desired position is set by you).

What does this mean?? It means that the only way you can know a servo's location is by sending it somewhere then remembering where it is you sent it. Well of course, you could just look at the output shaft (figure 1) and eyeball its position, but an end-user shouldn't have to nor can you utilize this visual reading in code real time.

Configuring hobby servos in a system (this happens usually when the system is powered on) means there's going to be a potential moment of chaos as the servos are first sent to a known position (from an unknown position.... hence potential chaos). Imagine you wake up in the middle of the night and you need to use the bathroom. First step is to get out of bed, but assume you don't know where you are until you get out of bed... you kinda flail around to achieve your desired position in a fit of insult to your intelligence. That's what it could look like depending how far away the servos are from the configuration setting. Let's avoid this by modifying the servo.

In a Nutshell


By soldering a wire to the wiper of the potentiometer you now have position! There are four wires seen in figure 2: black (ground), red (to power servo), yellow (pwm signal), and now white (voltage reading from pot). The white wire that I attached to the servo is an output lead that can be connected to a device that takes voltage readings. The voltage reading will vary as the output shaft (connected to the pot) rotates which results in you knowing the position of the output shaft.

 

[caption id="attachment_129" align="aligncenter" width="192"]Tap to the Wiper Figure 2. Tap to the Wiper[/caption]

Implications


1) Knowing the position from the servo at start up can allow you to configure the servos so that they never behave erratic. 

2) Implement a 'record mode' which will remember servo positions over time. In other words, you can actually drag the robot around and the chip/computer will remember what you did.

3) I'm not convinced yet, but having voltage measurements on the output-shaft position, velocity can be set/controlled since angular velocity is radians/second. Without feedback you can only adjust velocity through software increment control (which really isn't controlling velocity).

I'm sure there's more but those are the top three I will experiment with.

Technical Aspect


To assess the accuracy and ability of converting the wiper reading to position, I set up an data gathering experiment:

1) A PIC micro-controller sent the servo through 1800 different PWM signals (600 to 2400 increment by 1 each iteration).




[caption id="attachment_132" align="aligncenter" width="300"]Setup for experiment Figure 3. Setup for experiment[/caption]

2) Through each iteration, the wiper data (hooked up to an ADC) was sampled and sent 10 times to a laptop through serial communication. Each serial packet's data consisted of the 10 ADC wiper readings along with the PWM signal value.




[caption id="attachment_131" align="aligncenter" width="300"]Data being sent from controller to laptop Figure 4. Data being sent from controller to laptop[/caption]

3) Using Linux, the data was received and organized into a file stored on the hard drive. Each packet received was broken down by averaging the samples into one data point and stored with its corresponding PWM signal. Click image for a closer look.




[caption id="attachment_130" align="aligncenter" width="113"]File created from data collecting Figure 5. File created from data collecting[/caption]

4) The file's data was imported into Matlab where the information was analyzed (figure 3). The blue plot shows the actual data and the red line under it is the linear curve that was fit. The blue line looks overall linear which means the ADC value will be a good indication of where the servo is. The reason for the data not being more smooth is because the servo itself has an 8-bit chip which is only capable of 256 positions (0.705 degrees per step), where I put it through 1800 positions (0.1 degrees per step). The equation listed is the linear equation for the fit. This equation can be used to determine the PWM signal needed to address a certain position.




[caption id="attachment_133" align="aligncenter" width="530"]ADCvPWM Figure 6. Data plotted with curve fit[/caption]

 Conclusion


The experiment was successful and determined that this technique of modifying hobby servos can be used to gain some of the advantages more expensive servos offer. Despite the data showing promising results, the real tests will come with application.

This experiment already encompassed the first implication, knowing where the servo is when power is turned on. The next experiment to conduct (done partially already) is with the second implication which is recording data from me turning the servo shaft with my hand then having the servo repeat the movements on its own.

No comments:

Post a Comment