varspeedservo response

Hi, I am using a Servo with a PID controller for a gyroscopic system; The output of the PID controller will dictate the speed of the Servo using a varspeedservo library. It all works fine, but of course, when the input value reaches the target (i.e the system is at its desired location), the output falls zero as expected, this causes the speed value to go to 0 too (setting the output to this parameter). However, zero on the varspeedservo library relates to a maximum speed as if there was no speed control. The way I've gotten around this currently is by saying, well if the output is between 1 and -1, (which all relates to a speed of 0), then then speed is held at 1, which is the minimum speed setting for the servo. Ideally, this would be OK, but my system is still sensitive to movement at speed 1, and as such responds.

Is there a way to simply tell the servo's to stop moving when the output is between 1 and -1. I know Servo's don't move until you tell them to, but the PID controller is telling them to move.

Thanks,

:)

Is there a way to simply tell the servo's to stop moving when the output is between 1 and -1.

We'd need to see a link to the library AND we'd need to know what kind of servo you are using. Is it REALLY a servo? That is, using the regular Servo library, can you make it go to a position and stay there?

If you are using PID to control the position of the servo, is it really necessary to control the speed, too?

PaulS: We'd need to see a link to the library AND we'd need to know what kind of servo you are using. Is it REALLY a servo? That is, using the regular Servo library, can you make it go to a position and stay there?

If you are using PID to control the position of the servo, is it really necessary to control the speed, too?

The library:

https://github.com/netlabtoolkit/VarSpeedServo

I am using a standard Servo, hi-tec hs-81 ... (looks and works like a Servo to me); little bit reluctant to share the full code I've written, its a Masters Project, but could share with you relevent snippets of it.

Controlling the speed is key, controlling the position via the PID won't really accomplish the gyroscopic motion properly. The servo will just get to a set position and stay there, regardless of how far off from the target it is. It will work, but I assume "accidentally" for small angles. The idea with controlling the speed is that the PID will provide a continuous torque with a magnitude relative to how far away the system is from the target (in an ideal situation, the servo's will just keep on rotating round until it gets to the desired position, I'm limited by 0 - 180 degrees, but the that should be enough room for my needs for the system).

Also, controlling the speed rather than the position will make nicer data :p

My first thought was that you could modify the library to change how the write(position, speed) method was implemented, so that a speed of 0 did what you wanted.

But, then, that doesn't really make sense. If the speed to move is 0, you would never get from the current position to the desired position.

Are you using PID to control the speed of the servo or the position of the servo? If it is speed, does changing the speed value really change the torque, when the distance to move is 0?

I'm using the PID to control the speed, every time the output changes polarity (i.e has overshot the target), I have told the servo's to move to the maximum, 180 or minimum, 0 value. The time it takes to move to the new position is what the PID controller is controlling (i.e the speed).

Yep, if the distance to move is 0, there will be no torque on the system, but AFAIK, there is no way to detect the current position of the servo, it only knows where it needs to g.

Actually, I could possibly recording the initial value of the servo, and every time it moves, keep a track of it's updated position at each interval. Therefore, when I need to stop the servo's, I can just write the servo's at the current position. Not sure if this is possible though to track the servo at each degree increment? Must be an easier way.

Actually, I could possibly recording the initial value of the servo

I think you need some feedback on your system. You need to be able to determine where the servo is, at any time.

I could tell the motors to slow down when it reaches the target, and tell the servos to go slowly (speed 1) to position 90 (halfway)... that would work possibly!

I think you're making a mistake of turning over the control of the servo to the varspeedservo library.

I have a bunch of servo projects and my strategy is to tell the servo which position it should be in with each pulse to the servo. This way you always know the position of the servo since you just told the servo where it should be.

As long as you don't give the servo a command to move to a position farther away than it can reach in 20ms, your position information should be correct.

I keep track of the servo's speed and position myself. I use an acceleration factor to determine how quickly the speed of the servo should change with each 20ms control cycle and move the servo's position based on the accelerating speed value. Part of the algorithm used to determine the servo's speed checks to see how far the servo is from the target position. I need to keep track of the distance to the target position so the servo will have enough time to stop using the desired acceleration.

By keeping track of the servos speed, position and distance to target, the servo can be controlled very smoothly.

I've posted code which uses this sort of constant acceleration algorithm here. I posted links to videos showing this code in action in reply #23 of the same thread. Just today I added code (untested) which moves the servos to their start positions when a button is pressed. By moving servos to their start position prior to removing power from the servos, the abrupt movement when the servos are powered on can be eliminated.

As I mentioned earlier, I've used lots of servos in several of my projects. In order control servo relatively precisely you need to control the position yourself with a 50Hz control loop. Here's a couple other examples of projects where I calculated the position of each servo at 50Hz. My 22 servo "Halloween Hex" doesn't use a constant acceleration algorithm but the program computes the IK position of the 18 leg servos each 20ms control interval. I used a bunch of different motion algorithms in this 32 servo demo. You can see how setting the position of each servo at a full 50Hz allows motion beyond the simple linear motion often seen in servo projects. These last couple projects weren't done on an Arduino but the same sort of motion is possible with an Arduino by setting the position of each servo at 50Hz. The "post #23" link given above leads to a couple Arduino servo projects showing this smooth motion.