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. Which means we can use Marty's motors as sensors.
We can get these readings in Blocks and in the Sensor Dashboard, where we can view and graph readings from each of Marty's motors in real time!
In Blocks
You can find the joint position block in the sensing section of 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 the list armAngles. We'll use it to store a list of joint positions we want Marty to reproduce.
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 several angles.
If you want to clear items from the list, you can use the delete block to remove a specific entry or the delete all block to wipe the list.
Once we've built up the list, we can get Marty to play it back! We'll need to use a variable to count through the list, so make one called index.
Example code:
Next steps:
- Can you tweak the code so it records a set of positions automatically over a few seconds, and then plays them back?
- Can you get Marty to use different speeds of moving his arm?
- Can you make the code work with multiple joints?