Activity: Driving Shapes 2
Program the rover to request a number from the user and drive in a shape with that many sides. For more advanced maths make the rover draw the shape with uneven length sides.
Relevant Coding Skills
Relevant Rover Concepts
Setup
All you need is a flat, uniform surface to drive on. Different surfaces have different friction properties. This means the tracks will slip differently dependent on where the rover is driving. Some movement blocks such as turn by degrees are calibrated for an average friction. When driving on other surfaces you may need to turn more or less to get the desired angle.
Here’s Our Approach
Stage 1
First we need to ask for a number of sides. We can use the request input block. This block returns this a text string. We need to convert it to an integer so that it can be used as a number. Once we have converted it we store the number in a variable called ‘sides’.
Stage 2
Once we have a number of sides we can create the code to draw our shape. We will need a repeat for number loop block to repeat the movement blocks for each side. This loop needs to run as many times as we have sides, so we put our sides variable block in the number of times it will repeat.
Stage 3
In each iteration of the loop we need to draw a side with movement blocks. We need to move forward and then turn by degrees. We can calculate how many degrees we need to turn each time a simple math operation. Divide 360 by our number of sides using a math operation block.