Position Sensing

Every one of Marty's motors is a Smart Servo. That means it can report back its position (in degrees) and the amount of force on it.

We can get these readings in Scratch (and other programming languages), and they mean we can use Marty's motors as sensors.

In Scratch

You can find the joint position block in the sensing section of the Scratch blocks:

Click the check box next to the sensor block, and you'll be able to see the reading change as you move Marty's joint! You can select which joint from the dropdown list in the block.

Remember, the “Left” and “Right” joints are Marty's left and right, so if you're facing Marty they'll be the other way round for you!

Copying movements

This simple script will make Marty's left arm copy the movements you make on the right:

Recording and Playing back movements

This example is a little more complex, and uses lists and variables to build up a series of positions for Marty's arm to move through.

First off, we'll create a list of angles. Click the “Make a List” button in the Variables section:

Name your list armAngles. We'll build up the items in our list using this block:

Move Marty's left arm to a position you want, then click on the block. You'll see the angle be added to the list! Do this a number of times to add angles.

There is something to be careful of here. Marty's arms can be moved through a full rotation, but the position sensor can only sense through about 270 degrees. So there are parts of the movement that Marty can't measure - when their arms are bent back too far. Be careful to avoid these!

If you want to clear the list, you can use the delete all block

Once we've built up the list, we can get Marty to play it back! We'll need to us a variable to count through the list, so make one called index. We'll use another one to let us change the speed:

The code to cycle through the list will look a bit like this:

Next steps:

  • Can you tweak the code so it records a set of positions automatically over a few seconds, and then plays them back at the same speed?
  • Can you make that work with multiple joints?