Winter Olympics: Skiing Marty
Design and build a pair of robot skis then code Marty to become a cross country skiing robot
Introduction
You will design and build a suitable pair of robot skis for Marty then you will breakdown the individual movements needed to make Marty slide along a surface. Finally, you will use Scratch 3 to code Marty to become an Olympic gold medal winning cross country skiing robot!
Your mission is to create a cross country skiing robot using Marty. You will need to design and build skis and code Marty to ski by sliding forward to win gold at a robot Winter Olympics. You can even code Marty to have a go at a slalom ski move!
what you will need
- A Scratch 3 compatible device with Wifi - a laptop or tablet
- Marty the Robot
- Cardboard/paper/materials to make skis and poles
- Cello-tape/bluetac to attach skis to Marty
- Scissors
What will you learn about?
- Design and build skis for Marty that are functional and fit for purpose
- Evaluate ski designs to improve the prototype
- Code Marty to slide along the table by breaking down the individual movements
- Learn about control and event blocks
- How to use functions and parallel programming
extra information for educators
This activity covers and extends our Winter Olympics: Skiing Marty lesson.
building skis for marty
Start by designing and building a prototype pair of skis for Marty. You may then need to refine the design of your prototype skis several times based on how well Marty can move with skis before you are happy with your final version!
When you are designing Marty's skis, there are some things that you should keep in mind:
1. What do skis for humans typically look like?
2. Will your skis for Marty be a similar design? Why?
Think about the materials you can use to make your skis:
3. What material will slide enough on a table?
4. What material will be strong enough not to tear when Marty moves?
Think about the shape of the skis:
5. Does Marty move smoothly whilst wearing the skis?
6. Where is most of Marty's weight placed?
Let’s think about how we would cross country ski. You might want to pretend to ski to get a feel for how Marty should move.
We slide one leg forward a bit keeping it on the ground. Then the other leg does the same. But there’s something else happening too. We also lean to the side that is still connected to the ground.
Physics time! The centre of gravity of an object is an imaginary point in an object where the total weight of an object can be thought to be concentrated. As long as the centre of gravity stays above the base of the object, the object will be stable. But if the object starts to tilt to the side, the centre of gravity might not be above the base and the object will topple over.
So what happens to our centre of gravity when we’re standing on one leg and leaning to the side? The centre of gravity also shifts to that side. If the centre of gravity shifts too far because we lean too much, it will overhang our base (our feet) then we will fall over! We need to remember this when design the skis and we programme Marty...
Coding Marty to Slide with skis
Once you have made skis, it is time to code Marty to move. There are already built-in blocks that will program Marty to take steps forwards and backwards and if you have done the activity Teach Marty How to Walk you will have taught Marty to walk without these blocks! We want to teach Marty to ski so, just like teaching Marty to walk, we need to think about breaking down the skiing motion into smaller, individual movements whilst thinking about balance and the individual joints.
Create a new Scratch 3 project with the Marty the Robot extension added.
Tell Marty to get ready.
To stay balanced, Marty will need to lean in the opposite direction to the leg that moves forward. The blocks that move Marty's arms and legs can be found in the Marty the robot code drawer.
So if Marty's left leg is going to move forward, Marty will need to lean right then Marty's right leg will have to move backwards.
And if Marty's right leg is going to move forward, Marty will need to lean left then Marty's left leg will have to move backwards.
Putting these two sections of code together gives us one complete skiing movement.
We can use a forever loop from the Control blocks drawer to keep Marty skiing, well, forever....
Put the code for the skiing movement inside the forever loop and the complete code should look like this:
Hint: You can experiment with the time taken to lean and see how it affects the skiing motion!
Adding arm movements
Arms are also useful for stability and to help propel a skier forwards! We are going to add some arm movements in time with Marty's leg movements.
We are going to start simple by using the same event trigger to start both the arm and leg movements.
There will need to be a pause before Marty's arm movements start. This is while the get ready command is carried out in the leg movements code. We will use a wait block also found in the Control blocks drawer. Set the wait time to 1 second.
We want Marty's arms to swing backwards and forwards in time with the leg movements. We will need four blocks from the Marty the robot code drawer but this time we will need the blocks that allow us to set a time for how long each movement takes. We are going to move the right arm followed by the left arm. Positive values move the arm backwards and negative values move the arm forwards.
The first two blocks happen at the same time as Marty leans to the right and moves the left leg forward. The second two blocks code Marty's arms to do the opposite. These two blocks happens at the same time as Marty leans to the left and moves the right leg forwards. If you find this all a bit confusing, have a go at moving like Marty.
Put the code for the skiing movement inside another forever loop and the complete code should look like this:
To set Marty's arms and legs moving at the same time, all you need to do is click on the Green flag and when you think Marty has skied for long enough then click on the red Stop Sign:
Using Functions to slide Marty's legs
We can take a different approach to coding Marty to ski by using functions. This avoids lots of blocks of repeating code. Make sure that you have saved your basic Marty skiing project. You might find it helpful to start a new project screen for this section of our activity.
We are going to introduce functions here to represent Marty sliding with the right leg and Marty sliding with the left leg. This means that we can simply call the correct function when we want Marty to slide with that leg.
Select My Blocks from the code blocks drawer followed by Make a Block. You will get asked to name your new function; - remember to make it something meaningful so that you know what each function is responsible for doing.
Make a function to represent Marty's right leg sliding forward called slide right
Make a function to represent Marty's left leg sliding forward called slide left.
We can now use the slide left and slide right functions that we created inside a forever loop instead of the individual blocks from the Marty the robot code drawer that we used earlier. Our complete skiing code for Marty's legs now looks like this:
Using Parallel programming to add arm movements
We can use functions to code Marty's arm movements and then use parallel programming to make this code run at the same time as the code for Marty's leg movements.
Make a function to code for the arm movements that Marty needs to make when the slide left function runs. We have called this arm left.
Make another function to code for the arm movements that Marty needs to make when the slide right function runs. We have called this arm right.
We will use the broadcast block from the Event blocks. This block sends a broadcast across our Scratch program and any code that starts with the when I receive block set to that particular broadcast message will be kick-started to run. These blocks are shown below
Marty's skiing motion can be broken down into either a move to the left or a move to the right. We need run two different actions to move both the arms and the legs to each side! To do this we need to run our coding blocks in parallel - which means at the same time. Make a broadcast message called left and another broadcast message called right.
Just above where you found the broadcast block in the Events coding block drawer, you will see a when I receive message1 block. This block will run when we broadcast the message. All that is left to do is to have two of these events happening - one for a move to the left and another for a move to the right! Create the following code so that when the broadcast message left is received, the functions arm left and slide left will run at the same time.
We also want code for when the broadcast message right is received to make the functions arm right and slide right will run at the same time.
The complete code that we have just written for Marty's legs looked like this:
We need to replace the contents of the . Instead of the blocks slide left and slide right, put in the broadcast and wait blocks for broadcast left and broadcast right.
We can go one step further and make a block called ski. This means that we can make Marty do the whole skiing motion from left to right with arms and legs using just one block in our code!
Once we have our ski block, we can simply tell Marty to get ready and then ski.
EXTRA: Making marty more stable
At the start we thought about Marty's centre of gravity and how this affects whether Marty topples over or not. If we want to make Marty more stable, we can make Marty's base wider. We can do this by making Marty's skis point slightly outwards.
Turning Marty's legs out to make the skis point outwards increases area of Marty's base and decreases the chance of Marty topping over.
We can turn Marty's legs using these blocks from the Marty the robot code drawer. The blocks selects which part of Marty needs to move, the position that it needs to move to and how long the move should take. We want Marty's legs to turn outward in opposite directions so set the right twist to 15 and the left twist to -15. Set the time taken for this move to 1 second.
We could stop there...but it would be neat to have both twist moves happening at the same time again. We can use parallel programming again for this.
Make another broadcast block called skis out. Then make two when I receive skis out blocks - one for the right twist and the other for the left twist.
The code should now look like this:
Finally, we can make a block called skis out. This means that we can make Marty turn the skis outwards using just one block in our code!
Once we have our skis out block, we can simply tell Marty to get ready and then skis out. This would be a useful move at the very start of Marty's skiing code.
challenge? Making marty slalom
Now Marty has mastered the basic cross-country ski move, wouldn't it be fun to make Marty slalom?!
To make Marty slalom, we need Marty to slide sideways, move the hips so that Marty is leaning forwards and move the arms holding the ski poles out behind then quickly lean from side to side a few times. Marty can finish the move by standing up straight again and then slide sideways back to the starting point.
Create code for a slalom routine and then turn this into a function. You might want to think about the following,
- You will want to blocks from the Marty the robot coding drawer to tell Marty to lean right and left, to move the right and left hips, to move the right and left arms and to slide right and left.
- You will want to use a broadcast message to move the hips and arms at the same time.
- A repeat block will be useful here!
- You will want to make a block called slalom.
I need some help!
We are going to use parallel programming again to make Marty slalom.
Return to the Events coding drawer and make a broadcast message called slalom.
Above where you found the broadcast block in the Events coding block drawer, you will see a when I receive message1 block. This block will run when we broadcast the message. We want our code to run when the slalom broadcast is received.
Firstly, we want Marty's arms to move hold the ski poles out behind when the slalom message is received. We can do this using the block from the Marty the robot coding drawer that will move each arm to a set position in a certain time. We want to move the arms backwards so set the position to 100 and set the time taken for this to be 2 seconds. Do the same for both right and left arms!
We also want Marty's hips to move when the slalom message is received so that Marty is leaning forwards. We can use this by choosing the same block again but this time select hip . Set the position to 45 and the time taken to 2 seconds. Do the same for both right and left hips!
We now have 4 moves that will happen in parallel! So time to broadcast our slalom message and wait for the moves to be completed...
After moving Marty's hips and arms, we want Marty to lean from side to side a few times. We can do this by selecting a repeat loop from the Control coding drawer. We have set the number of repeats to 3. We can put blocks from the Marty the robot coding drawer inside this loop to tell Marty to lean right and then lean left. We have set the time taken for lean right and lean left to 0.5 seconds.
Our code now looks like this:
Next step is to make a function for the slalom routine so go to Make a block in My Blocks.
Make a block called slalom.
Now we are going to define the function that represents our slalom routine:
1. Marty slides to the right
2. The slalom broadcast message is sent to move both hips and both arms at the same time
3. Marty leans from side to side for 3 repeats
4. Marty stands up straight again
5. Marty slides to the left back to the starting position
Finally, we can use the slalom block in our code whenever we want Marty to carry out the slalom routine. We can tell Marty to get ready and then slalom!
Hint: You can experiment with the positions and times and see how that affects Marty's stability and motion!
Our complete code
We have three functions skis out which turns out Marty's skis to make Marty more stable, ski which makes Marty cross-country ski and slalom which makes Marty slalom ski from side to side. We can use the skis out, ski and slalom blocks to quickly code Marty's movements.
Time to put it all together and send Marty off on a skiing adventure...
What Next?
You started by designing and building a pair of skis for Marty. You have now just created and programmed Marty to ski using Scratch. If you want to continue to extend Marty's skiing movements, here are a few ideas!
- Got more than one Marty? You could stage your own cross country ski championships
- Experiment with the positions of Marty's arms and legs and see how this affects Marty's stability while skiing. How quickly can you make Marty ski without toppling over?
- Play around with Marty's arm movements. Maybe sometimes you want both arms swinging backwards and forwards together instead of opposite directions? Can you make a function for this?
- Introduce a variable to keep track of Marty's movements instead of needing to specify right or left every time Marty skis forwards. Use the instructions for Teach Marty to Walk to help you!
