Skip to content

add a servo.stop() function #127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
macMikey opened this issue May 3, 2024 · 6 comments
Open

add a servo.stop() function #127

macMikey opened this issue May 3, 2024 · 6 comments
Labels
topic: code Related to content of the project itself type: enhancement Proposed improvement

Comments

@macMikey
Copy link

macMikey commented May 3, 2024

think of this as something akin to an e-stop.
i have run into a situation, with the crunchlabs iturret. at power on, the turret attempts to pitch home. unfortunately, the force of that move can cause the turret to "spike" the magazine (because we don't know the power-on position of the servo, and we can't read it, either).
there are two ways to solve that problem (using this library):

  1. implement feature request: Servo class: servo.write(int angle, float rotationspeed) #71
  2. add servo.stop(). this command would act like an e-stop, cutting the signal to the servo, regardless of the .write() it is currently executing.
    i suppose my code for homing the servo would then look something like this:
for ( int i = 0 , i < 5 , i++ ) {
   servo.write (90);
   delay (5);
   servo.stop();
   delay (10);
}
servo.write(90); // just to ensure that we finally make it to 90, if the previous five moves didn't do it

in this way, the move to 90 would be broken into five moves (depending on the starting position), reducing the change in angular momentum, and still not requiring us to know the position of the servo.

@per1234 per1234 added type: enhancement Proposed improvement topic: code Related to content of the project itself labels May 3, 2024
@HeavyFalcon678
Copy link

@macMikey to have full stop control, you could connect the 5V pin to a digital pin and set it to high. Whenever you want to stop the servo you could just set that pin low and it would cut power to the servo.

@edgar-bonet
Copy link
Contributor

A couple of remarks:

  1. The servo is controlled by a PWM signal, with pulses sent every 20 ms. I would then suggest waiting for 20 ms between Servo.write() and Servo.stop().
  2. Thus functionality can be implemented by issuing Servo.detach(), then Servo.attach() right before the next Servo.write().

@macMikey
Copy link
Author

i'm pretty sure i tried to detach the servo, but that didn't solve the problem. it seems that once the servo receives the instruction, it's moving to the instructed position, no matter what.
i also rewrote the servo driver, to see if i could get to it, that way, too. that was also unsuccessful.
i think the only reasonable solution is going to be to switch power to an output pin. i have not tried that, because i got bored, after rewriting the servo driver didn't solve the problem.

@edgar-bonet
Copy link
Contributor

@macMikey wrote:

i'm pretty sure i tried to detach the servo, but that didn't solve the problem. it seems that once the servo receives the instruction, it's moving to the instructed position, no matter what.

This is pretty weird. What Arduino are you using? What type of servo?

The file Servo.h says, about detach(): “Stops an attached servos from pulsing its I/O pin”. At least the AVR version (the only one I looked at) seems to do exactly that. Traditional analog servos stop doing anything when their data line is not pulsed.

@macMikey
Copy link
Author

macMikey commented Apr 21, 2025

it may be that the controller is just not fast enough.this issue is with one of the hackpacks, specifically the ir turret. when the unit powers on, it attempts to crash-home the pitch servo. unfortunately, the turret's center of mass is far enough away from the magnetic mount that it can detach from the base, either at the start, or at the end of the move.
it appears that once the pulse is sent, the motor won't stop. again, it might be that the detach is not executed until it's already too late.
it looks like they updated the turret in a later version, by adding more magnets to the turret, so only those of us with the 1.0 version will experience this issue (but, TBH, now that i'm so deep in the weeds, it would be cool to be able to solve a problem that i have been told is unfixable).

@HeavyFalcon678
Copy link

I have looked at this before with my turret, and it looks like the problem is when you use attach, not the write. There is no way to smoothly attach the servo, because it doesn't know its position before it gets there. When the attach method is called, it moves the servo straight to home, and then you can move it as slowly as you like because you know where it is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: enhancement Proposed improvement
Projects
None yet
Development

No branches or pull requests

4 participants