Session 08 nxc(1) - Session8 MultipleTasks Objective...

This preview shows page 1 - 3 out of 3 pages.

Session 8 Multiple Tasks Objective:  Explain how programs with multiple tasks operate  Preparation Read Section VI Parallel Tasks Activity 8.1  Mini Lecture:  Parallel Tasks Activity 8.2 A Hunting Bot that Avoids Obstacles In the lecture we created the program for a bot with a modicum of intelligence. It hunts for food until it  hits an obstacle, then it backs away from the  obstacle turns and continues its search. //huntbot.nxc task hunt() { while (true) { OnFwd(OUT_AC, 75); Wait(Random(2000)); OnRev(OUT_C, 75); Wait(Random(1000)); } } task detect_bump() { while (true) {
Image of page 1

Subscribe to view the full document.

if (SENSOR_1 == 1) { StopTask(hunt); OnRev(OUT_AC, 75); Wait(500); OnFwd(OUT_A, 75); Wait(850); StartTask(hunt); } } } task main() { SetSensorTouch(IN_1); StartTask(detect_bump); StartTask (hunt); }  Download this program and perform the following  experiments: 1.How does the bot perform when it hits the wall at different angles? 2.What effect does changing the range of the two random number generators have on the
Image of page 2
Image of page 3

Unformatted text preview: ability of the bot to hunt? Huntbot Report (due midnight, Tue 10/2/2014). Your report should have the following structure: Goal Statement Write a simple one or two sentence goal statement describing this bot. Program Listing Include the listing of the program, and add comments Experiments Describe the results of the two sets of experiments in Activity 8.2 General Questions 1. Answer the following general questions: 2. When StopTask (hunt); is executed, does the task complete the set of instructions to the final } in the task definition? 3. If hunt is interrupted and then started within task detect_bump() where does it begin execution of the code in hunt()? 4. What would happen if you wrote SetSensor(SENSOR_1, sensor_touch); in task main() ? 5. What happens if you put a semicolon after while (true); ?...
View Full Document

  • Fall '09
  • random number generators, multiple tasks, parallel tasks, task hunt, task detect_bump

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern