I encountered a problem with following code
- Code: Select all
Pilot pilot = new Pilot(5.6f, 15.5f, Motor.C, Motor.A, true);
which causes the robot to move forward for a while and to rotate but without stopping rotating. (BTW: notify() has been called in an EventListener)
I thought it was a problem with the Pilot class and started creating my own class until I run in the same error. But then I recognized that it seems to be a problem with the usage of Thread.yield(). Therefore, I replaced all Thread.yield() with Thread.sleep(80) in the Pilot class. Now it works as expected, but I'm not sure why and if there is a better way to deal with.
My second problem is the usage of waitForPressAndRelease(). I thought this method would wait until the button is pressed and released, but it seems press and release events are queued and the method will not wait if the button has already been pressed and released before. Is there a way to empty this queue before calling waitForPressAndRelease()?
Thanks and regards.