Go Down

Topic: Servo control (Read 1 time) previous topic - next topic

LinusRJ

Hey,

I am working on a project where I use servos to move different things. My project uses 6 servos and 12 buttons. The buttons are for making the servos rotate both CW and CCW. Each servo is connected to two buttons. Also I "hacked" the servos so that they can rotate endlessly.
What I want to do is send + or - "pulses" to the servos each time I press a button. The pulses are supposed to make the servo rotate 90 degrees in either direction depending on what button you press.

I know how to make the servo move to a specific angle, and I know how to connect it to a potentiometer. But for this project I want it to send pulses each time a button is pressed. Is this possible at all?
I am sort of new to Arduino coding so I would appreciate a little bit of help on this one.

Thanks in advance,
Linus

OldSteve

#1
Apr 17, 2016, 08:14 am Last Edit: Apr 17, 2016, 08:14 am by OldSteve
Also I "hacked" the servos so that they can rotate endlessly................The pulses are supposed to make the servo rotate 90 degrees in either direction depending on what button you press.
If you've converted them to continuous-rotation servos, then you no longer have the ability to move them a specific number of degrees. 'servo.write(90)' will stop the servo, 'servo.write(0)' will turn the servo at full speed in one direction and 'servo.write(180)' will turn the servo full speed in the other direction.

Quote
I know how to make the servo move to a specific angle,
If you really know how to do this with continuous-rotation servos, please share your method.
Please do not PM me for help. I am not a personal consultant.
And others will benefit as well if you post your question publicly on the forums.

bartolobot

Hi old Steve,

i have a very similar project but i have 4 servos which i made continuous rotation and five switches one for every servo and one more for all together.
i will be adding more servos and switches in the future .
But for now i need to figure out the code for what i got now.

any help i can get

i think would help both LinusRJ and me.
would be appreciated.

OldSteve

Hi old Steve,

i have a very similar project but i have 4 servos which i made continuous rotation and five switches one for every servo and one more for all together.
i will be adding more servos and switches in the future .
But for now i need to figure out the code for what i got now.

any help i can get

i think would help both LinusRJ and me.
would be appreciated.
You shouldn't really have posted your problem in someone else's thread. It just confuses things, especially if you're not trying to do exactly the same thing as him.

Having said that, if you are trying to do the same thing, I have the same answer - it's not possible to move servos a particular number of degrees after converting them to continuous-rotation. Instead of specifying a position like on unmodified servos, writing a value, (setting a pulse-width), sets the speed/direction on continuous-rotation ones.

If you're looking for help with another aspect of using your servos, you should really start your own thread, and post the code you've already written, then ask for help with any problems you're having.
Please do not PM me for help. I am not a personal consultant.
And others will benefit as well if you post your question publicly on the forums.

bartolobot

sorry about posting my issue on someone Else's thread ,
I have already started my own thread ( Humanoid robotic Arm With Servo Control) but not getting any help yet. Although they are very similar issues I understand what your saying.

I ll be patient and wait for some help. i would appreciate any help.

UKHeliBob

Quote
they are very similar issues
Are you using continuous rotation "servos" and if so is that clear in your other thread ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

LinusRJ

OldSteve, sorry about the misconception. I meant that I knew how to move unmodified servos to specific angles, sorry.
What you said about servo.write(180) and servo.write(0) where they will just keep on spinning. Would it be possible to write for example servo.write(180, how many ms you want it to turn?)
Then I might have the solution for my project.

OldSteve

#7
Apr 17, 2016, 01:17 pm Last Edit: Apr 17, 2016, 01:23 pm by OldSteve
What you said about servo.write(180) and servo.write(0) where they will just keep on spinning. Would it be possible to write for example servo.write(180, how many ms you want it to turn?)
Then I might have the solution for my project.
You can't do it exactly how you've written it without modifying the servo library. No such ready-made function exists. (The servo library was written for standard, unmodified servos.)

It's possible to do the same thing, but you'll never get quite the results you want by using timing. The servo(s) won't necessarily always move at exactly the same speed, so positioning would be very inaccurate.

If you don't need more than a total of just under 180 degrees travel, you're best off using unmodified servos.

If you really need more than 180 degrees travel, take a look here. (Sail winch servos might be the answer, or maybe you could use limit switches for position feedback.)

For doing what you suggested, (timing-based movements), you could do this:-
Code: [Select]
servo.write(180);
delay(250);
and it would turn at full speed in one direction, CCW I think, for 250ms. You'd need to work out the exact delay to suit your purpose.
As I say, though, I don't think you'll find that method suitable. And if you want it non-blocking, you'd also need to use millis()-based timing instead of 'delay()'. (I didn't bother for the example, especially since it won't work properly as mentioned.)
Please do not PM me for help. I am not a personal consultant.
And others will benefit as well if you post your question publicly on the forums.

LinusRJ

#8
Apr 17, 2016, 02:12 pm Last Edit: Apr 17, 2016, 02:17 pm by LinusRJ
OldSteve, thanks for the help. I might need to buy some sail winch servos then.
A question that I did not get an answer to yet is, can you send pulses to servos?
Each time you press the button, the servo will rotate 90 degrees from its' previous position. My idea is something like; servo.write(+90); or servo.write(-90) to make it spin 90 degrees either direction.

OldSteve

OldSteve, thanks for the help. I might need to buy some sail winch servos then.
A question that I did not get an answer to yet is, can you send pulses to servos?
Each time you press the button, the servo will rotate 90 degrees from its' previous position. My idea is something like; servo.write(+90); or servo.write(-90) to make it spin 90 degrees either direction.
You didn't make that question very clear originally, so I missed it.

No, it's not possible. Continuous rotation servos cannot rotate a given number of degrees, period. I made that part very clear.

Even with standard servos it's not possible to have the library handle that. You'd need to do the calculation in your firmware, based on the last position you wrote to the servo.
For example:-
Code: [Select]
byte currentPos = 120;  // This would be the last position that you wrote to the servo.
servo.write(currentPos);  // Like so.
.
.
.
servo.write(currentPos-90);  // This will position the servo relative to the last known position.
(Standard servo only, not C-R types)
Please do not PM me for help. I am not a personal consultant.
And others will benefit as well if you post your question publicly on the forums.

LinusRJ

OldSteve, so if I were to buy a sail winch servo and wire it up to a button. Would it be possible to do what I asked for above? How would the code look?

OldSteve

OldSteve, so if I were to buy a sail winch servo and wire it up to a button. Would it be possible to do what I asked for above? How would the code look?
The "Servo" library does not support this type of thing:-
Code: [Select]
servo.write(-35);

I already said that. Again:-
Quote
Even with standard servos it's not possible to have the library handle that. You'd need to do the calculation in your firmware, based on the last position you wrote to the servo.
It would need to be done in a similar fashion to what I just wrote in my last reply. ie. Your program would need to store the current position then work out the new position and write it to the servo.

There are only two functions in the "Servo" library for setting a servo's position, and neither is written for relative positioning, only absolute.
Here are the declarations for both functions:-
Code: [Select]
  void write(int value);             // if value is < 200 its treated as an angle, otherwise as pulse width in microseconds
  void writeMicroseconds(int value); // Write pulse width in microseconds
Please do not PM me for help. I am not a personal consultant.
And others will benefit as well if you post your question publicly on the forums.

LinusRJ

OldSteve, okay, thank you for all the help! I really appreciate it! :)
I only have one more question before we leave this thread.
Are there any components that you know of that can do something similar to this?
I know that you can use rotary encoders with servos to rotate the servos "manually". I am actually considering to go with that. Although, rotary encoders use alot of pins of the arduinoboard each. And I need six of them, plus servos. That's why I was wondering if I could make this with buttons instead. I have also heard of port extenders, but don't know how they work.
What is the best solution for my project in your opinion?
Thanks

LinusRJ

Anyone else that knows a good solution?

UKHeliBob

Consider using a Mega.
54 digital pins
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Go Up