MahatmaX / YADrone

Yet Another Drone Framework (for the AR.Drone 2)
39 stars 40 forks source link

Command scheduling after fixed time #14

Closed MahatmaX closed 10 years ago

MahatmaX commented 10 years ago

To program the drone, one needs to insert Thread.sleep statements between successive commands. For example, if you want to go forward for three seconds and then turn left, you need to write something like

drone.forward(); Thread.sleep(3000); drone.turnLeft();

The nodeCopter project has a nice API call for command sequences like these:

drone.forward(); drone.after(3000).turnLeft();

The behaviour is the same, but it looks much nicer.

One question remains: should the after()-method be executed synchronously (i.e. it blocks the command thread for 3 seconds) or should it be called asynchronously, return immediately and schedule the command in a TimerTask ?

MahatmaX commented 10 years ago

CommandManager now has 3 more methods: doFor(millis), waitFor(millis) and schedule(millis, runnable). First and second have same semantics and are blocking calls. Schedule is non-blocking.