Fixed event race condition

If this is anything like the Bebop, then taking off immediately fires the "flying" event, but these events aren't buffered so attaching an event handler afterwards achieves nothing. When I ran the same code for the Bebop (as suggested on the site) it never landed, prompting an emergency connect-with-phone-hammer-buttons scramble. Swapping the event registration with the takeoff method call fixed the problem immediately.
This commit is contained in:
Cathal Garvey 2015-11-06 20:32:00 -08:00
parent afd2e81911
commit 051f54c7a0
1 changed files with 1 additions and 1 deletions

View File

@ -14,12 +14,12 @@ func main() {
drone := ardrone.NewArdroneDriver(ardroneAdaptor, "Drone")
work := func() {
drone.TakeOff()
gobot.On(drone.Event("flying"), func(data interface{}) {
gobot.After(3*time.Second, func() {
drone.Land()
})
})
drone.TakeOff()
}
robot := gobot.NewRobot("drone",