1

Do you know how to stop continuous servo in desired position?

I tried to code like this (which I found on many forums):

myservo.write(10); //moves forward
delay (1000); //waits 1s
myservo.write(90); //stops

My servo indeed moves forward for 1s then stops in the position I wanted then immediately goes back to its one position (the same position every time). I would like it to stay in the desired position. For example, I counted that in 150ms it moves for angle of 60 degrees and there it should stop and wait for next info.

I also tried to use trick to detach servo like this:

myservo.write(10);
delay(120);
myservo.detach();
delay(2000);

It works, but it is not as precise as I want it to be and I can't reach smaller angles than 100 degrees.

I'm using Servo TowerPro MG996R Robot 360 which is continuous servo.

I'm sorry if there is already the answer for my question but I promise I went through countless topics and forums! Thank you for any advices!!!

Nithin P
  • 513
  • 3
  • 16
Aśka
  • 11
  • 1
  • 4
  • It is all true what you wrote but still it dosen't help me. Values from 49 to 97 stops the motor in one certain position. But still the range of positions is very tiny. Maybe I will tell you about my project to make it clear. It is sorting machine: 1st servo should move 90degrees right and wait in this position for next info. After getting this info it should move again next 90 degrees without going back. 2nd servo should move 60, 120, 180... and so one and stop waiting for next move. All I want is to stop motor after certain time in the position it is in. Is this possible? – Aśka Jan 04 '17 at 11:37
  • Nevermind, I misunderstood the question. I thought the problem was the fact that the *servo* keeps going back to the initial position, while it looks like that your problem is stopping it at the desired position. I think you would need to implement some kind of sensor-based feedback system, if you want to have any kind of precision. – Patrick Trentin Jan 04 '17 at 11:48
  • Yeah, it is one of the problems. I would like my servo to behave like this (code in sources): [link](https://www.youtube.com/watch?v=15y1ImY_XEQ) function myservo.write(90) in the video means "stop and stay where you are". In my servo the same function does "stop and go back to initial position". – Aśka Jan 04 '17 at 12:27
  • But according to the amazon description *stop* was value `0`.. that ain't working? – Patrick Trentin Jan 04 '17 at 12:30
  • 1
    I don't know how this servo works and so you probably have to check its datasheet, but according to my experience what you are trying to do is NOT done with a servo, but a stepper. A servo is fine for 180° rotations (back and forth) or, removing the feedback, for continuous rotation (without positioning). If you want to make a continuous rotation motor and set its position steadily and precisely go with a stepper – frarugi87 Jan 04 '17 at 12:58
  • what happens after the myservo.write(90)? provide more of your code – Piglet Jan 04 '17 at 18:48
  • My code: `#include Servo myservo; void setup(){ myservo.attach (9); } void loop (){ myservo.write(90); //goes to initial position delay (2000); myservo.write(37); // minimum speed clockwise I can enter, for 38 servo stops near initial postition delay(15); // minimum delay I can enter, for 14 and less it doesn't move myservo.write(0); //it stops the servo, the same way like command myservo.detach() delay(2000); //waits in this position servo_dolne.write(90); //goes back to the same point every time ` – Aśka Jan 05 '17 at 09:44
  • @PatrickTrentin thanks for idea about write(0)! It works but still I can't stop my servo at once. After some dealay it is far away from position I desired. It would work but I still can't reach the position around 90 degrees which is essential to my project. – Aśka Jan 05 '17 at 10:01
  • @Aśka one thing at a time, it's still some progress. The next step is to reduce the rotation speed as much as possible and, if necessary, build a feedback mechanism that is capable of sensing the current *angle*. As suggested by frarugi87, your life would be much easier with a *stepper*, since it implements exactly the *feedback* mechanism and *speed reduction* system that you would need to create yourself. – Patrick Trentin Jan 05 '17 at 10:05

0 Answers0