Camera servo control off of the Joystick axes

I have been trying to figure this out for some time, but so far I have failed in being able to use the joystick axes to move the camera mount instead of the normal method of using the buttons. I am interested in using the analogue on the joystick as to have the ability to dynamically change the rate of servo movement.

What would I need to do to get a set up like this to work seeing as servos work by moving to a designated position? I would assume that I would want to set it somehow to move towards either 0 or 170 when the joystick is moved, but have the rate at which the servo changes position be varied by the value sent by the joystick.

Any assistance that you might be able to give would be much appreciated.

I’m going to be slightly pedantic here, but I’m hoping you’ll benefit from seeing the thought process exposed. I’m also hoping someone doesn’t swoop in in the next 5 minutes with the answer all gift wrapped for you. Here’s my sort of thought process on something like this:

What exactly are we trying to do? We have a servo and a joystick. We want to move the servo with the joystick. Specifically, we want to control the speed of the servo by the position of the joystick. Alas, the joystick outputs position, and the servo inputs position, not speed.

Mathematically speaking, what’s the difference between the position input the servo has, and the speed input we want it to have? The mathematical definition of speed is change-in-position per unit of time. So, we need to change a command of change-in-position per unit of time into an actual command of position. We know that speed times time is the change in position over that chunk of time. So if we started at 0", and we moved at 1"/sec for 1 sec, then we’d be at 1". If we moved for another sec, we’d be at 1"+1", or 2". If we sped up to 3"/s for the next second, we’d be at 2"+3", or 5". And we could keep on adding the speed times time to our last position to find out where we are now.

The big question, of course, is what on earth this has to do with controlling the servo. The answer is pretty simple. With my ridiculous example just above, we could determine our position based on our last position, our speed, and how long we moved. You can do the same thing to tell your servo where you want it to be.

Your program has a nice sort-of timed loop in it where it waits for data from the driver’s station. This gives us our chunks of time to work with. Your joystick is telling us how fast we’re moving. The only other thing we need is to know where we were the last time through the loop. So here’s what you do:

  1. Save the position of the servo from one loop to the next. It’s important that this is a floating point number, not an integer.
  2. Add your joystick position (times some scaling factor) to the old servo position from the last time through the loop.
  3. Check that this new position command fits inside the bounds of a good servo command. In your case, check if it’s between 0 to 170. If it’s not, make it fit. That is, if the new position is 172, make it equal 170.
  4. Send this new position command to the servo, and save the command to use is as the OLD position in your next run of the loop.
  5. Repeat for 2 minutes.

Actual implementation depends on if you’re using Labview or WindRiver. But it’s important that you only use a floating point number. Your loops are going to be running fairly quickly, so you’ll probably be wanting to add small amounts to the position in each loop. If you’re using an integer and try to add 0.25 to your old position in every loop, it will be rounded down and your servo won’t move. You’d be stuck adding 1, 2, 3, etc. every loop, and that’s pretty likely to be too fast to really be useful.

So, for a more detailed explanation, I’d need to know what programming language you’re using. But the basic idea is to just add your joystick’s value to the position of your servo every time you make a loop.

I am running labview for the code. I think I know how to do the majority of the codework, but how would I save the floating point number?

If anyone can help, I know exactly how to do this now. I just need to know how to make it so the joystick axes have a value of 0-179 instead of a value of -1 to 1. I would be most greatful if anyone were to help me with this.

Also, reading the servo position into the current value of a pid and having the modified joystick on the input would allow me to run the servos as such, correct? (I cant explain this too well so I can give a screenshot if anyone wants it.)

It’s a simple linear equation. Multiply by 89.5 then add 89.5, and you’ve got what you need. Alternatively, add 1 then multiply by 89.5 and you get the same thing.

Also, reading the servo position into the current value of a pid and having the modified joystick on the input would allow me to run the servos as such, correct? (I cant explain this too well so I can give a screenshot if anyone wants it.)

I suppose you could do this, but why would you want to? The servo itself does its own closed-loop feedback control of position.

Thank you, I will try this out tomorrow. Also the pid is mainly so I can modify the rate of change.