Taking action after servo has completed move?

I'm trying to have a laser fire after a servo has pointed it at something. The only way I know how to do it (since I'm a noob), is to use the delay function to give the servo time to move. Is there a way that once the servo has completed it's move, it can take the next action, or do I just have to guesstimate with the delay() function how long the servo will take?

Most hobby servos do not provide for actual position feedback, although they can be modified to for reading the internal pot. As such, a short delay is the easiest way to allow the servo to get into position.

zoomkat: Most hobby servos do not provide for actual position feedback

Adafruit have one: http://www.adafruit.com/products/1404

From experience (I'm still a noob too!!!), the delay(); function will pause all functions, so this might conflict with your servo operation.

You can try to read the servo position, which I think would be something like...

servoPos = digitalRead(PINNUMBER);
if(servoPos == 160){
runFunction();
}

Hope this helps? If I got it wrong, very very sorry!!

You can try to read the servo position, which I think would be something like…

Alas, you can’t. The servo.write(pos) only sends a pulse which should result in a certain position, but a normal servo doesn’t report its position. You have to hope it got there, hence the delay(). But if there’s a huge load on it, it might never get there no matter how long you wait.

So if it’s crucial to know that the servo arrived, you need one like the Adafruit one which does report where it is.

If you can measure the angular speed of the servo and its behaviour is "linear enough" you can calculate the ETA of the new position.

suppose the angular speed is 60 degrees per second, then you know that for 1 degree takes approx 17 millis to move 1 degree. e.g. If abs( new -old) == 75 degrees ==> that will take 75 * 1/60 = 1,25 second.

Then it just boils down to setting a timer (micros/millis) and wait for the (estimated) end position

give it a thought

Marshiewoo: From experience (I'm still a noob too!!!), the delay(); function will pause all functions, so this might conflict with your servo operation.

You can try to read the servo position, which I think would be something like...

servoPos = digitalRead(PINNUMBER);
if(servoPos == 160){
runFunction();
}

Hope this helps? If I got it wrong, very very sorry!!

Sadly, this is wrong, for a number of reasons. A digitalRead will only ever return zero or one, so it would never equal 160. If you were to substitute a Servo.read(), all you'd get back would be the last value you wrote to the Servo object, whether or not the servo had actually reached that position.

JimboZA:

zoomkat: Most hobby servos do not provide for actual position feedback

Adafruit have one: http://www.adafruit.com/products/1404

DIY servo feedback project.

http://www.robotshop.com/forum/ssc-32-analog-input-servo-feedback-t2748