parallelism day 12
DESCRIPTION
Parallelism Day 12. Computer Programming through Robotics CPST 410 Summer 2009. Course organization. Course home page (http://robolab.tulane.edu/CPST410/) Lab (Newcomb 442) will be open for practice with 3-4 Macs, but you can bring your own laptop and all robots. Parallelism. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Parallelism Day 12](https://reader036.vdocuments.us/reader036/viewer/2022062422/56812f43550346895d94d524/html5/thumbnails/1.jpg)
ParallelismDay 12
Computer Programming through Robotics
CPST 410
Summer 2009
![Page 2: Parallelism Day 12](https://reader036.vdocuments.us/reader036/viewer/2022062422/56812f43550346895d94d524/html5/thumbnails/2.jpg)
7/1/09 Harry Howard, CPST 410, Tulane University
2
Course organization
Course home page (http://robolab.tulane.edu/CPST410/)
Lab (Newcomb 442) will be open for practice with 3-4 Macs, but you can bring your own laptop and all robots.
![Page 3: Parallelism Day 12](https://reader036.vdocuments.us/reader036/viewer/2022062422/56812f43550346895d94d524/html5/thumbnails/3.jpg)
Parallelism
Beams vs. tasks
![Page 4: Parallelism Day 12](https://reader036.vdocuments.us/reader036/viewer/2022062422/56812f43550346895d94d524/html5/thumbnails/4.jpg)
Multiple beams in NXT-G
Open the Mindstorms app.
![Page 5: Parallelism Day 12](https://reader036.vdocuments.us/reader036/viewer/2022062422/56812f43550346895d94d524/html5/thumbnails/5.jpg)
7/1/09 Harry Howard, CPST 410, Tulane University
5
Parking
Tribot, drive straight forward for 1 rotations, then drive forward turning to the right for 1 rotations, then back up for 2 seconds. When you are finished, display a locked lock for 3
seconds and reset the screen.
While you are backing up, play a warning sound (! hydraulic 03).
![Page 6: Parallelism Day 12](https://reader036.vdocuments.us/reader036/viewer/2022062422/56812f43550346895d94d524/html5/thumbnails/6.jpg)
ParkBot.rbt, part 1
![Page 7: Parallelism Day 12](https://reader036.vdocuments.us/reader036/viewer/2022062422/56812f43550346895d94d524/html5/thumbnails/7.jpg)
The second part
How do you make Tribot play a sound while it backs up?
You need to pull out a new sequence beam.Hold down shift key to pull out new beam.
Also, Tribot must play the sound continuously.
The next program is a good first try.
![Page 8: Parallelism Day 12](https://reader036.vdocuments.us/reader036/viewer/2022062422/56812f43550346895d94d524/html5/thumbnails/8.jpg)
7/1/09 Harry Howard, CPST 410, Tulane University
8
ParkBot.rbt, Part 2, first try
![Page 9: Parallelism Day 12](https://reader036.vdocuments.us/reader036/viewer/2022062422/56812f43550346895d94d524/html5/thumbnails/9.jpg)
A problem
The problem is that the sound does not necessarily stop when Tribot stops backing up.
To do so, you have to ensure that the loop breaks when the backup motion has finished.
This can only be done with a logical variable.
![Page 10: Parallelism Day 12](https://reader036.vdocuments.us/reader036/viewer/2022062422/56812f43550346895d94d524/html5/thumbnails/10.jpg)
ParkBot.rbt, Part 2, final try
![Page 11: Parallelism Day 12](https://reader036.vdocuments.us/reader036/viewer/2022062422/56812f43550346895d94d524/html5/thumbnails/11.jpg)
Parallel beams = tasks in NXC
Close the Mindstorms app,
and open BricxCC.
![Page 12: Parallelism Day 12](https://reader036.vdocuments.us/reader036/viewer/2022062422/56812f43550346895d94d524/html5/thumbnails/12.jpg)
7/1/09 Harry Howard, CPST 410, Tulane University
12
Task overview
An NXC program consists of at most 256 tasks, each of which must have a unique name.
There must always be a task named main, since this is the first task to be executed.
Another task will be executed when a running task tells it to be executed;if it is explicitly scheduled in main.
Tasks run simultaneously unless otherwise specified by scheduling statements.
![Page 13: Parallelism Day 12](https://reader036.vdocuments.us/reader036/viewer/2022062422/56812f43550346895d94d524/html5/thumbnails/13.jpg)
7/1/09 Harry Howard, CPST 410, Tulane University
13
Task syntax and usage
task name(){
“statements”
}Start a task by means of the function:
StartTask(task)Example
StartTask(sound); // start the sound task
![Page 14: Parallelism Day 12](https://reader036.vdocuments.us/reader036/viewer/2022062422/56812f43550346895d94d524/html5/thumbnails/14.jpg)
7/1/09 Harry Howard, CPST 410, Tulane University
14
Parallelism
Even though tasks run simultaneously, the action performed by the task has to be programmed to run continuously.So always put the action within an endless while loop:
my_task(){
while(true){// do something}
}
![Page 15: Parallelism Day 12](https://reader036.vdocuments.us/reader036/viewer/2022062422/56812f43550346895d94d524/html5/thumbnails/15.jpg)
7/1/09 Harry Howard, CPST 410, Tulane University
15
Now translate the parking program to NXC
![Page 16: Parallelism Day 12](https://reader036.vdocuments.us/reader036/viewer/2022062422/56812f43550346895d94d524/html5/thumbnails/16.jpg)
7/1/09 Harry Howard, CPST 410, Tulane University
16
Scheduling tasksp. 159
Since tasks execute simultaneously, it takes special functions to schedule them:Precedes(task1, task2, …, taskN);Follows(task1, task2, …, taskN);ExitTo(task);
UsagePrecedes and Follows should only be used once within
a task, preferably at its beginning.If multiple tasks declare that they precede or follow the
same task, then they execute simultaneously.
![Page 17: Parallelism Day 12](https://reader036.vdocuments.us/reader036/viewer/2022062422/56812f43550346895d94d524/html5/thumbnails/17.jpg)
7/1/09 Harry Howard, CPST 410, Tulane University
17
Halting the programp. 159
Halt the program by stopping all tasks:Stop(condition);StopAllTasks;
UsageThe program halts after either command, so
everything following them is ignored.
![Page 18: Parallelism Day 12](https://reader036.vdocuments.us/reader036/viewer/2022062422/56812f43550346895d94d524/html5/thumbnails/18.jpg)
7/1/09 Harry Howard, CPST 410, Tulane University
18
Next time
E-mail me your final project ideally, by the end of class on Monday;or by Tuesday evening.
Drop off your robot at Newcomb 302, between 9am and 5 pm, ore-mail me to make an appointment for some
other time.