Asked — Edited
Resolved Resolved by DJ Sures!

How To Stop A Moving Servo

I'm learning how to use EZB scripts. I'm doing a very simple exercise. I make a servo move , and want it to stop it as soon as a sensor makes a digital input high. I'd want to see how long it takes to actually stop. I use "release" to stop it (it's a digital servo, it will keep its position even with no signal). I see no other script statement to stop a servo movement. I wrote this script:

servospeed(d3,5) servo(d3,180) (the servo travel, from 130 to 180, lasts about 3 sec.) sleep(200) if (getdigital(d11)=1) release(d3) endif

The sensor is activated during servo travel, (3 sec.) but the servo reaches its target, ignoring the "if" statement . What's going on ? stress stress


ARC Pro

Upgrade to ARC Pro

ARC Pro is your passport to a world of endless possibilities in robot programming, waiting for you to explore.

PRO
USA
#1  

@Leonardo,

Release you already know does not stop the servo.

When you setup a speed and you send a position to the EZB controller, the firmware keeps moving the servo until it reaches the position.

ASFAIK there is no stop command implemented in the EZB controller.

The only way is to send the servo to a specific position without a delay (Speed 0).

PRO
Synthiam
#2  

Please post code using the [ code ] [ /code ] tags for readability

It's a real good idea to first learn how a servo works to understand limitations, here's an important tutorial: https://synthiam.com/Tutorials/Lesson/48?courseId=6

That tutorial will explain that a servo simply moves into position based on a PWM signal.

Secondly, the code you posted does not have a loop or logic that resembles the goal.

Try this, which will move the servo and test the position with each step...


repeat($pos, 130, 180, 5)

servo(d3, $pos)

sleep(100)

if (getdigital(d11)=1)

  halt()

endif

endrepeat

PRO
USA
#3  

@DJ, my bad, slower even better, you can stop. When doing slower moves i prefer your approach, that way i can know the position.

@Leonardo, what kind of sensor you have on d11 ? Are you sure is not floating ?

#4  

I saw two options, by DJ, to try, one using "release", the other step by step , capable to inform about the position where the servo was stopped. I don't see any more the first one. Dj has deleted it ? I tried the second . It works, but the servo stops with a large delay (1-1.5 seconds !) Is it a limit of the ezb system (that's not a real-time system ) ? Should I use an embedded MCU for that ? @PTP. I plan to use a digital I.R. sensor. Now I'm trying with a simple micro-switch. I checked it working correctly , non floating. there's a resistor pull-down at the pin. It works well.

PRO
Synthiam
#5  

It stops with a delay because you mostly likely have the servo speed still set to 5. You will need to reset the servo speed to use default values and follow my code, otherwise it will not work.

If your project requires a slower servo speed, you will need to increase the sleep() delay to compensate for it.

PRO
Synthiam
#6  

Also, adding the sleep() after the servo() before the condition will work better by accommodating the physical real world movements.


repeat($pos, 130, 180, 5)

servo(d3, $pos)

sleep(100)

if (getdigital(d11)=1)

  halt()

endif

endrepeat

#7  

Ok,DJ, now it works faster. Can you explain the logic of the repeat statement? it's not very clear in the scrips description. It seems like the "for-next" statement in basic. repeat ($pos,130,180,5) means execute 5 times the code , but which value is assigned to the variable $pos each time ? 140,150,160,170,180 ?

PRO
Synthiam
#8  

5 is the increment. It's like a for statement.

130, 135, 140, 145, 150, 155 ... 180