20160309编程工具新特性

20160309编程工具新特性

张北一 -
回帖数:0

原帖http://ftcforum.usfirst.org/showthread.php?6675-Can-you-block-in-the-newest-beta&highlight=hardware+read%2Fwrite+thread

Tom对新的线程级别特性说明如下

Hi Varun,

With the new beta (1.7) software, coding in the LinearOpMode class is very similar to coding in RobotC. For instance, you can block (for example, sleep()) in your LinearOpMode and also not have to worry about using the waitOneFullHardwareCycle method. 

You can also reset the encoders and not have to wait an arbitrary amount of time to wait for the change to take effect. Once the control is returned to your op mode, the task should be already complete.

Also, when the command statements in the OpMode are done running, the Op Mode should auto stop. The driver does not have to push the stop button to stop the op mode if all of its commands have been executed.

One key difference for the LinearOpMode class that is different from RobotC, is that you should still only do interruptible loops. For example, you should use the opModeIsActive() method as the test condition for a while loop:

while (opModeIsActive()) {

...

}

You want to use an interruptible method rather than do something like "while (true)" so that the op mode will stop properly when the user pushes the stop button on the driver station. If you have an uninterruptible thread running in your op mode, if the user pushes the stop button, but the thread is not interruptible, the app will eventually log an error (indicating a potential runaway process) and then crash the Robot Controller app to stop the thread. This is not ideal because once the Robot Controller app has crashed, you lose communication with the robot (unless someone restarts the app or power cycles the robot).

Tom