Controlling Non-Continous Rotation Servo with Accelerometer
Dan Toborowski
Posts: 7
I'm currently working on a project that requires a pair of servos match the orientation of a 2-axis·accelerometer in real time. Most of my experience with servos is continuous rotation which only requires a PULSEOUT specifying a duration value for speed and direction. I understand that when I want to specify a rotation angle for a non-continuous rotation servo, I need to use a PULSEOUT command inside a FOR loop·with a counter variable to specify number of pulses. I understand how to implement this code for sending a servo to a specified orientation in a desired amount of time but I need the servo position to continuously update to match the changing accelerometer measurements in real time.
At the moment I'm using a method like this:
FOR counter PulseXOld TO PulseX STEP 80
·· PULSEOUT 12, counter
·· PAUSE 20
This code moves the servo to the desired orientation "PulseX" which is calculated by adding or subtracting the adjusted accelerometer readings from 750 (servo center) and the adjustment moves from the previous orientation "PulseXOld". I had to use a very large step size "80" to provide a fast enough response but the system occasionally overshoots and as a result does not operate very smoothly.
Essentially all I need is to move the servo to a position which is defined by a direct relationship to accelerometer readings without any need for ramping or smoothing. The movement will ideally happen instantaneously matching the accelerometer exactly. What is the best way to accomplish this? Thanks!
·
At the moment I'm using a method like this:
FOR counter PulseXOld TO PulseX STEP 80
·· PULSEOUT 12, counter
·· PAUSE 20
This code moves the servo to the desired orientation "PulseX" which is calculated by adding or subtracting the adjusted accelerometer readings from 750 (servo center) and the adjustment moves from the previous orientation "PulseXOld". I had to use a very large step size "80" to provide a fast enough response but the system occasionally overshoots and as a result does not operate very smoothly.
Essentially all I need is to move the servo to a position which is defined by a direct relationship to accelerometer readings without any need for ramping or smoothing. The movement will ideally happen instantaneously matching the accelerometer exactly. What is the best way to accomplish this? Thanks!
·
Comments
GOSUB ReadAccel ' read accelerometer data - store servo positions in value1 and value2
PULSEOUT 12, value1
PULSEOUT 13, value2
Pause 5 ' if ReadAccel takes 15 mS then this pause should only be 5 - adjust accordingly
LOOP
Rich H