Learning Portal

Our hands-on, comprehensive lesson plans span a range of levels. Browse our free STEM and coding learning resources.

Marty Image

Workout with Marty!

Introduction

Have you been doing PE with Joe Wicks to keep you fit during lockdown? In this activity, we’ll program Marty to do some workout moves that you can join in with! But can you outlast Marty?!

Check out Marty Wicks doing squats in the video above!

What you will need

What will you learn about?

  • Making your own blocks of code (or functions)
  • The "blocking mode" block and parallel programming

a basic workout

The easiest way to workout with Marty is to use a series of the movement blocks in the Marty extension.

For example, you could make a workout program like the one we did below. Be sure to use the repeat blocks to get Marty to perform the same move several times and build up stamina!

Tip: Use the wait block to give you a chance to get into position after running the code!

making custom workout moves: lunges, squats...

Marty can do quite a few moves, but what if we want to tone a different set of muscles? This next section will show you how to make your own blocks of code in Scratch that contain a sequence of movements to allowing Marty to perform other workout exercises such as lunges and squats!

Some of the exercises we program Marty to perform are quite complex. In order to make our code easier to read we can store the new moves we make in 'blocks'. Then when we want Marty to perform one of our custom movements, instead of writing out all the steps again we can simply insert the block into our sequence! In other programming languages, these blocks of code are often called functions.

Don't worry if this seems confusing - it will make more sense as we work through the activity.

To make your own block of code, click on the 'My Blocks' button in the Scratch menu. Then click on the 'make a block' button.

The pop-up below will appear. Type the name of your new block into the 'block name' section - we called ours 'lunges'

After you have done this, you'll find a new block with the name you just entered appears in the 'My Blocks' section.

You'll also see a 'define' block appear in the coding area.

coding your own marty exercises: lunges

Now we are ready to code the new movements we want Marty to perform. You can be as creative as you like here, but here are a couple of ideas we had to get you started!

Our first idea for a new move was lunges (or Marty's version of lunges). To do these we need to move both Marty's arms and legs at the same time... but how?!

Well, there is a block called 'set blocking mode' at the very bottom of the Marty extension blocks. This block is set to 'enabled' by default, meaning Marty will finish every action he does before performing the next one. However, if we set it to 'disabled' Marty will perform any actions that don't use the same motor at the same time! Awesome!

Place the 'set blocking mode' block below the 'define lunges' block you created using the previous steps. Make sure 'disabled' is selected from the drop down menu. Your code should look like this:

When we write programs that run multiple blocks of code at the same time we say we are parallel programming. Parallel programming is becoming hugely important these days as it reduces the time programs take to run and allows them to be run using multiple computers.

Now we need to program the movements Marty uses to perform the lunges. Think about how a human moves when they do lunges. What joints do you use? Can you break it down into steps?

First up we want Marty to move his left leg forward and his right leg backwards at the same time. Since we have disabled the 'blocking mode' we can do this using two 'move leg' blocks as shown below. It doesn't matter which block you put first as Marty moves both legs at the same time!

Now, we also want Marty's arms to move in time with Marty's legs. To do this use the 'move ... to ... in ... seconds' blocks. You might have to experiment with the values you use for the arm movements. We used -90 for both the right and left arms, but if your arm motors are callibrated differently you may want to use different values. In order for Marty's arms and legs to move in time with each other, the time for the arm movement should be set to 0.5 seconds.Since the arm and leg movements use different motors they will all run at the same time... phew!

We have now done half a lunge! For the second part we must swap over which leg Marty has moved forward and which leg has been moved backwards. Since this uses the same leg motors as the previous leg movements, Marty will not perform them until the first part of the lunge is finished.

Finally we want Marty's arms to move at the same time like they did before.

Congratualtions! You've just programmed a lunge! Your finished block of code should look like this:

Here's a video of our Marty performing some lunges!

more exercises: squats!

Squats can be hard work, but Marty knows you have to work hard to get fit!

We won't go into as much detail on how to program Marty to perform squats, but here are some questions to think about:

  • Will Marty need to move multiple joints at once?
  • Will you need blocking mode 'disabled' like before?
  • Can you break a squat down into a sequence of individual joint movements?
  • What joint's do you need to move and when?

Remember to make a new block to store yoursquat movement in, like we did with the lunges! Your 'My Blocks' section should now contain both a 'lunges' block and a 'squats' block.

If you're stuck, our squats block turned out like this. Don't worry if yours looks slightly different! If you're happy with how your Marty moves that's all that matters!

putting it all together!

Now let's make our workout routine using a sequence of the exercises we just created!

This final step is made much easier because we wrote our own custom blocks of code! Instead of having to write out all the instructions every time we want Marty to perform a squat, we just need to add one of our 'squats' blocks into the program! Remember that as always Marty needs to warm up with a 'Get Ready' block.

You'll probably want Marty to perform more than one rep of each exercise, so make good use of repeat blocks!

You can make Marty's workout as long as you like and mix up your own blocks with moves such as side steps and circle dances which you'll already find in the Marty extension! Be sure to work out with Marty if you want to get fit too!

What Next?

You have now learned about the 'blocking mode' block, parallel programming and how to define your own movement block! Experiment with making more movements for Marty to perform... maybe your Marty could balance on one leg or jog on the spot?!