6 Optional challenges

These challenges are more difficult, so we’ve made them optional. If you want more programming experience before tackling these challenges, then you can always come back to this section later in the block.

Check the module forums for additional challenges. Please feel free to share you own challenges with your fellow students (but please play nicely!).

6.1 Configuring the simulator

To download code to the simulator, use one of the simulator magics.

For example, prefix a code cell with the %%sim_magic_preloaded block magic as the first line to download the code in the cell to the simulator. Remember that you can use the %sim_magic_preloaded --preview command to show the code that is automatically imported and the %sim_magic --help command to show all available magic switches.

You may find the following specific switches useful when configuring the simulator via the magic:

  • -b BACKGROUND_NAME: load in a particular background file

  • -x X_COORD: specify the initial x-coordinate value for the simulated robot

  • -y Y_COORD: specify the initial y-coordinate value for the simulated robot

  • -a ANGLE: specify the initial rotation angle for the simulated robot

  • -p: specify pen-down mode

  • -C: clear the pen trace.

Load in the simulator in the usual way:

from nbev3devsim.load_nbev3devwidget import roboSim, eds

%load_ext nbev3devsim

6.1.2 Challenge – Fitness training take 3

Modify the program you developed for the Fitness training take 2 challenge so that the robot travels the same distance as the first traverse on the third and final traverse, and double the first distance on the second traverse.

Download your program to the simulator and run it to check that it performs as required.

Make any notes to help you complete the task here.

# Add your code here...
# Remember to start the cell with some appropriate magic to download code to the simulator

Make any notes/observations about how your program worked, or any issues associated with getting it to work, etc. to help you complete the task here.

6.1.3 Challenge – Fitness training take 4

Modify the program you developed for the Fitness training take 3 challenge so that the robot can easily be tasked with performing any number of traverses. On odd-numbered traverses it should travel a short distance; on even-numbered traverses it should travel twice that distance.

Download your program to the simulator and run it to check that it performs as required.

Make any notes to help you complete the task here.

# Add your code here...
# Remember to start the cell with some appropriate magic to download code to the simulator

Make any notes/observations about how your program worked, or any issues associated with getting it to work, etc. to help you complete the task here.