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 gateway to a community of like-minded robot enthusiasts and professionals, all united by a passion for advanced robot programming.

#17  

That's why DJ is the Master around here. He is the keeper of the knowledge. :D

I'm glad you found a way.

PRO
Synthiam
#18  

Leonard, i did not say that you could not use Release - that was not me.

Release with a servo while it is moving slowly from ServoSpeed() will work, it's just not the way i would do it. You can do it anyway you wish that works.

Rather than speculating, a simple experiment will provide the answer. For example, try this code. Which will initialize a servo on D0 to a position, then begin moving it slowly with slow servospeed() to a new position, and 2 seconds later will release it, which stops from moving. You can simply do this test on your own. The code posted in the first message, as i had previously stated, was incomplete and did not have a loop or reflect any form of logic related to the goal - incomplete or incorrect user code does not reflect the capabilities of the EZ-B or ARC.


servospeed(d0, 0)

servo(d0, 10)

sleep(500)

servospeed(d0, 5)

servo(d0, 180)

sleep(2000)

release(d0)

If you were to use your original idea, it could be done like this...


# Open the gripper quickly
servospeed(d3, 0)
servo(d3, 150)

# Wait a bit for the servo to be open
sleep(1000)

# begin closing gripper
servospeed(d3, 5)
servo(d3, 180)

# loop 50 times or until the digital port has detected object
REPEAT ($cnt, 0, 50, 1)

  IF (getdigital(d11) = 1)

    release(d3)

    halt()

  ENDIF

  sleep(100)

ENDREPEAT

If you wish to for some reason know the position of a servo by reading it, you can purchase dynamixel servos, which are a lot more money but have more features than standard servos. However, there is no reason to know the position of a servo by reading it - ever. Because you're the one telling the servo what position to be in. Unless you expect some external force to move the servo so you can use the servo as a POT or input device, there's no reason. It's simple logic - your code tells the servo where to move, that's it. There's no mystery around it.:)

PRO
USA
#19  

Related to the release... I was the bad influence:)

#20  

Ok, DJ, I had well understood what you had said in your #3 post. I had tried some code, but not working, being a newcomer. You had said "release is worth trying, but I'd use another option, with a loop, etc, so I can know the position". I tried the loop option, and it worked, and I gave you a credit for having solved my question. You provided, in that post , the code for the release option. For some unknown reason (?), I found the post modified and the release option had disappeared. Now you are sending once again the code for the release option. I can test it for my experience, though the other option is working well. I agree with you that reading the servo position from the servo itself is not necessary. It might be useful only in very sophisticated projects.