Page 1 of 1

Question 3 (25 marks) This question tests your understanding of robot control programming. a. i.The program listed below

Posted: Mon May 02, 2022 12:23 pm
by answerhappygod
Question 3 (25 marks)
This question tests your understanding of robot control
programming.
a.
i.The program listed below is based around the Grey_bands
background.
The program is intended to make the simulated robot drive
forward over each grey band. When it drives into a new grey band,
the robot will say aloud how many bands it has entered.
You can download the code here.
Modify this program to:
1. Use the Coloured_bands background.
2. Continue to drive over all of the bands.
3. Count aloud how many bands it has entered whenever it enters
a non-white band.
4. Stop the robot after it drives forward over the black
band.
(10 marks)
1 %%sim_magic_preloaded --background Grey_bands -R
2 # Program to count the bands aloud
3
4 # Start the robot moving
5 tank_drive.on(SpeedPercent(15), SpeedPercent(15))
6
7 # Initial count value
8 count = 0
9
10 # Initial sensor reading
11 previous_value = colorLeft.reflected_light_intensity_pc
12
13 # Create a loop
14 while True:
15
16 # Check current sensor reading
17 current_value = colorLeft.reflected_light_intensity_pc
18
19 # Test when the robot has entered a band
20 if previous_value==100 and current_value < 100:
21 # When on a new band:
22 # - increase the count
23 count = count + 1
24 # - display the count in the output window
25 print(count)
26 # - say the count aloud
27 say(str(count))
28
29 # Update previous sensor reading
30 previous_value = current_value
ii.Try running the program you have written for part (i)
using the Rainbow_bands background.
If your program does not run correctly, outline what the issue
is, and what you would have to change to make your program run.
If your program does run correctly, outline how you have
achieved this. Discuss whether your program would work on any
banding of colours.
(6 marks)
This exact question is posted on here but I can't find a
correct answer and I'm really stuck!