View unanswered posts | View active topics It is currently Sat Aug 30, 2014 2:58 pm






Reply to topic  [ 8 posts ] 
some control issues with servos 
Author Message
Rookie

Joined: Tue Jan 13, 2009 12:24 pm
Posts: 10
Post some control issues with servos
at the moment im having a problem controlling my servos for example

servo[servoA] = joystick.joy1_x1;

but the servo only turns half of the lenth it should im not sure how to fix this problem

ive also tried just making it jump to position i want but i cant turn the servo to a different spot if needed and its making it much harder

does anyone know why that isnt working?


Thu Jan 15, 2009 4:51 pm
Profile
Rookie

Joined: Fri Jan 02, 2009 9:13 pm
Posts: 10
Post Re: some control issues with servos
Unlike the motors, the Servos have a range of 0-255. Since the highest joystick value is 127, it only can go half way.

There are a few ways to make it use the whole range, I'm guessing the best for you would be to multiply your joystick value by 2, like this:

servoTarget[servoA] = (joystick.joy1_x1)*2;


Thu Jan 15, 2009 10:09 pm
Profile
Novice

Joined: Thu Oct 09, 2008 7:58 pm
Posts: 79
Post Re: some control issues with servos
Well Dooey, that might be a good idea, but what happens when the joystick value is negative? You are now going below the value the servos can operate at.

Try adding 128 to the joystick value. So zero lines up in the middle and 127 becomes 255.


Thu Jan 15, 2009 10:56 pm
Profile
Rookie

Joined: Tue Jan 13, 2009 12:24 pm
Posts: 10
Post Re: some control issues with servos
so it should look like this?

servo[servoA] = joystick.joy1_x1 +127;

or did i understand that wrong?


Thu Jan 15, 2009 11:01 pm
Profile
Rookie

Joined: Fri Jan 02, 2009 9:13 pm
Posts: 10
Post Re: some control issues with servos
That will also work, but when the joystick is in its neutral position, the servo will be halfway turned. If that is what you want, great. :)


Fri Jan 16, 2009 2:03 am
Profile
Novice

Joined: Thu Oct 09, 2008 7:58 pm
Posts: 79
Post Re: some control issues with servos
That is correct. If you want the servos to *mimic* the position of the joystick, ie, when the joystick is up, the servos move up, but when the joysticks center, the servos move to the center, then the above code is correct. :D.


Fri Jan 16, 2009 6:58 pm
Profile
Rookie

Joined: Tue Jan 13, 2009 12:24 pm
Posts: 10
Post Re: some control issues with servos
oh i want the servo to stop were i stop it what would the code look like for that
servo[servoA] = ??


Tue Jan 20, 2009 9:30 am
Profile
Rookie

Joined: Sun Nov 16, 2008 3:07 pm
Posts: 45
Post Re: some control issues with servos
shooting from the hip here, so you get what you pay for, but if you want is the servo to go "up more" when you push the joystick up, and "down more" when you push the joystick down, then something like this should do it:

servoTarget[servoA] = servoTarget[servoA] + joystick.joy1_x1;

(which i would write as servoTarget[servoA] += joystick.joy1_x1;)

That would mean:
if the joystick value is positive, add some to the servo position.
if the joystick value is negative, subtract some from the servo position.
if the joystick value is 0, hold still.

if the Joystick value is a LOT positive, add a LOT to the servo position.
etc.

This is going to be hard to control, and will minimally need to be in some sort of loop with some time regulation so that you don't spin around a thousand times in a second adding 42 to the servo position, which means it will go full stroke .006 seconds.

Something like this might be a good first stab:

while (true)
{
get joystick values...

servoTarget[servoA] += joystick.joy1_x1/8; // divide by 8 to try to slow down to a reasonable rate
// in here you ought to make sure the value isn't bigger than 255 nor less than 0 (really before you assign it to servoTarget)
wait10Msec(1);

}

That will still go full stroke really fast. max joystick would be 127, divided by 8 is about 16, so you are adding 16 every 10 ms, servo range is 255, so 255/16*10==160 ms.

Fool around with the wait and the divide - maybe you can come up with something that works.


Tue Jan 20, 2009 12:29 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 8 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.