14Tasks - Must make the task run forever. Otherwise It only...

Multitasking in NQC COMP 106 Sensors • In the graphical environment, we are able to use multiple sensors using the “Sensors” blocks. • Whenever we use a new sensor block, a new “line” is created, in addition to the main line.

This preview
has intentionally blurred sections.
Sign up to view the full version.

Tasks (threads) • Previously, we said that each sensor line runs at the same time as the main line • Each line is called a thread • Note: each sensor line runs forever! Problem • Have the robot patrol in a square forever. • During the patrol, if the right sensor is touched, play a song.

Solution With Events Better Solution (Graphical)

This preview
has intentionally blurred sections.
Sign up to view the full version.

This is the end of the preview. Sign up
to
access the rest of the document.

Unformatted text preview: Must make the task run forever. Otherwise It only run once! Tasks You can have up to 10 tasks in NQC Must have a task named Main All other tasks must be explicitly start/stop Tasks run simultaneously Remote Control Roverbot Two controls (4 possibilities): Sensor 1 is released -&gt; moves forward Sensor 1 is pressed -&gt; moves backward Sensor 3 is pressed -&gt; spin Both Sensors are pressed -&gt; turn off 1 1 1 1 Sensor 3 Sensor 1 Test for all four possibilities Make sure you stop all the other tasks to avoid conflicts...
View Full
Document