- Getting started
- Motion control blocks
- Single servo blocks
- Multi servo blocks
- Sensor blocks
- Speech blocks
- General blocks
Scratch 2.0 is a visual programming language developed by the MIT Media Lab. It can be used for a range of educational purposes from maths and science projects to animated stories with art and music. It provides a stepping stone to the more advanced world of computer programming. Scratch 2.0 is available as an offline program. You can download a version for Windows & macOS from the MIT Web site. It is also available for the Raspberry Pi.
The Edbot Software enables your Scratch 2.0 project to control your Edbots by providing extra Scratch blocks in a Scratch 2.0 extension.
Make sure the Edbot Software is running locally on your device. Your Edbots should be available in the Robots pane. It doesn't matter if they are configured locally or remotely.
Generate the sample projects by selecting Scratch → Generate Sample Projects in the Edbot Software. This will embed the Scratch 2.0 extension with your Edbot names into each project. You can open any of the generated Scratch 2.0 projects but for now open the edbot_blank.sb2 project. You'll find the new blocks in the Scratch 'More Blocks' section. Use them like any other Scratch blocks to build your program. Note all Scratch 2.0 project files have an .sb2 suffix.
You can use the Scratch → Project updater in the Edbot Software to rename robots in existing Scratch projects and update the Scratch blocks if the project was generated by an older version.
The Edbot Scratch blocks are described below in a fair amount of detail. Please take the time to read through the rest of this document to familiarise yourself, there's a lot going on! We've called our Edbot 'Bob', but you'll have given yours its own cool name of course…
Some of the Edbot Scratch blocks require you to enter a value. If you enter an invalid value, Scratch has no way of letting you know. You can check for errors by opening the Log Viewer window in the Edbot Software under Tools → Log viewer.
Motion control blocks
A motion is a set of movements. For example the 'walk forwards' motion instructs your Edbot to walk a few steps forwards. As each servo moves, it will light up in a specific colour to add a stunning visual effect to the motion. Your Edbot comes pre-loaded with lots of motions which are arranged in six categories to make things easier to find:
basic, dance, fight, greet, gym & sport
Your Scratch script will wait until the motion has completed before moving on.
You can also run a motion by number, starting from 1. This is useful if you want to cycle through the available motions, for example.
Set motion lights
Normally your Edbot will automatically light up in an aurora of colours when it is performing a motion. This is great to look at, but you may want to set the motion colours yourself. You can turn off the automatic motion lights using this block. You can then use the servo colour block (described below) to set the servo colours before you run a motion. Remember to turn them off when the motion has completed. For example, try setting all servos to green when walking forwards and red when reversing.
Get motion name
Give this Scratch reporter block a motion number and it will give you the motion name in return. If the motion number is unknown, empty text (zero length) will be returned.
Single servo blocks
These blocks let you control individual servos. You can turn a servo on or off, set the colour, speed and position of a servo and get its current position. All of the blocks, with the exception of servo position, offer an "all" option to address all the servos at the same time. If you need to control a set of servos simultaneously, use the multi servo blocks described below.
Set servo on/off
With all servos turned off, your Edbot will be all floppy. Use this block to turn a servo on or off. Note that when you run a motion the servos will be automatically turned on and left on for subsequent instructions.
Set servo colour
Use this block to set the colour of a servo to your chosen colour. Use the same block to turn the servo light off. You can use a number in place of a colour name here, see the list below.
Set servo speed
Set the servo speed for the next servo position block. This can be applied to a specific servo or all servos at the same time. The speed is a number from 1 to 100 inclusive. Setting this to 100 will effectively set the maximum servo speed which can be quite snappy, so mind those fingers!
Set servo position
Move an individual servo to the position specified between 0 and 300
degrees. See the diagram below.
You need to be a little careful here. It's a good idea to check the current position of the servo before moving it to a new position in case you end up tying your Edbot up in knots. Get the servo position from the current position block described below. If you're unsure you can do something seriously cool like this, to move servo 1 by 10 degrees:
Get servo position
This is a Scratch reporter block which gives you the current position of a servo. The position is an angle between 0 and 300 degrees. See the diagram above.
Get servo load
This Scratch reporter block returns the current load on a servo expressed as a percentage. When a servo is switched on you can gently apply a force to try and move it. The more force you apply, the greater the load. Check out the Scratch handshake project in the sample folder for a cool example.
The load is directional and ranges from -100 to +100.
Multi servo blocks
These blocks allow you to control a set of servos simultaneously.
Set servos on/off
Turn a set of servos on or off. Specify the servo by number followed by "/" followed by 0 or 1 to turn the servo off or on respectively. Specify multiple servos by repeating the sequence, for example "1/0/2/0/3/1/4/1". Servo number 0 means all servos, so "0/0" will turn all servos off.
Set servo colours
Set the colours of a set of servos. Specify the servo number followed by "/" followed by the servo colour index as defined in the colour table. Specify multiple servos by repeating the sequence, for example "1/3/2/3/3/3/4/3". Servo number 0 means all servos, so "0/3" will set all servos to colour index 3.
Set servo speeds
Set the speed of a set of servos. Specify the servo number followed by "/" followed by the speed expressed as a percentage greater than zero. Specify multiple servos by repeating the sequence, for example "1/50/2/50/3/50/4/50". Servo number 0 means all servos, so "0/12.5" will set all servos to one eighth speed.
Set servo positions
Set the position of a set of servos. Specify the servo number followed by "/" followed by the position which is an angle from 0 to 300 degrees, see the servo diagram. Specify multiple servos by repeating the sequence, for example "1/250/2/50".
Get servo positions
This is a Scratch reporter block which gives you the current position of each servo. Useful for more advanced scripting.
Set head IR sensor
Your Edbot continuously sends servo and sensor data to the Edbot Software. However you may need to get the servo data as quickly as possible, for example if you're doing motion capture. Use this block to turn off the head IR sensor so your Edbot only sends servo data. It's on by default.
Get head IR sensor
This reporter block returns the current value of the head IR sensor. The IR sensor is mounted on the Edbot's head and measures the distance to an object in front of the Edbot. The sensor was calibrated using the distance between the front edge of the feet and a vertical white A4 card. Note the sensor may give different measurements for different coloured objects placed the same distance away. The reading should be interpreted as an approximate distance in centimetres. The measuring range is 3cm to 30cm rounded to 1 decimal place. A value of 100.0cm means "out of range". In addition you can use the raw value returned from the sensor.
The following blocks instruct your Edbot to speak! The voice, language, volume, pitch and speed will have been set up during configuration.
|Try configuring your Edbot with a different language, if you have the voices available. You can then type text in your chosen language in the speech blocks!|
Say the words! This block won't wait for the speech to finish before continuing to the next block.
Say and wait
Say the words! This block will wait for the speech to finish before continuing to the next block.
This reporter block gives you the current word as it is being spoken. It returns empty text (zero length) if your Edbot isn't speaking. Use it to add visual emphasis during speech, such as flashing your Edbot's servo lights on and off. The example below displays the current word in a speech bubble.
This will stop the current command, turn all the servo lights off, set the motion lights / sensor to defaults and halt any speech on a word boundary. It won't turn the servos off however, just in in case your Edbot is in the middle of an amazing acrobatic routine.
This reporter block can be used to check if your Edbot is connected to the Edbot Software and whether it is enabled or not. The block returns 1 if connected or enabled and 0 if not.