Table of Contents

Use this guide to configure your Marty V2's infrared (IR) foot sensor and use its ground and obstacle readings in Blocks.

What is the IR sensor?

The IR foot sensor detects nearby objects in front of the foot and a surface underneath it. You can use these readings to make your program react to Marty's surroundings.

The infrared sensor mounted on Marty's foot

How do IR Sensors Work?

  1. An infrared LED emits light towards the surface or object.
  2. Some of that light reflects back towards a detector.
  3. The sensor uses the reflected light to decide whether an object or the ground is detected.

This is reflected-light sensing, not a physical contact switch or a precise distance measurement. The surface and lighting can affect the result, so check the readings on the surface where you will use Marty.

IR Sensor Set Up

Use the current Robotical app to check the sensor's name and connection:

  1. Turn on Marty and connect it to the app. If several devices are connected, select the Marty you want to configure.
  2. Open Robot settings, then choose Add-ons to open Manage Add-ons.
  3. Find the connected sensor with type IRFoot. Select its row or gear icon to expand its details.
  4. Check Add-on Type is IRFoot. A colour sensor may also appear in this list; it is a different sensor.
  5. If a name needs changing, edit Name this add-on and choose Update Name. Use RightIRFoot for an IR sensor on the right foot or LeftIRFoot for one on the left. If it is already named correctly, leave the name as it is.

The current Manage Add-ons screen with the connected RightIRFoot sensor expanded

The screenshot shows RightIRFoot expanded. The grey LeftColorSensor (Not Connected) row is a saved configuration for a sensor that is not currently detected; it does not mean that RightIRFoot is disconnected.

Restore Add-on Names is optional. It restores the standard names RightIRFoot and LeftColorSensor, and removes disconnected saved entries. If you use custom names or multiple sensors of the same type, name them individually with Update Name instead.

If the sensor is missing or marked Not Connected, check its cable and reconnect Marty before continuing. If you have removed the sensor, follow this video to fit it again. Turn Marty off before changing sensor wiring.

Using IR Sensing in Blocks

  1. Return to Home and open Blocks, or open Blocks in the web app. Keep Marty connected.
  2. Open your project and select the Marty sprite for the connected robot. If you have not added Marty to the project yet, follow the Blocks guide.
  3. In Marty's Sensing category, find Foot sensor on the ground.
  4. Use the block's sensor dropdown to select your IR sensor by its configured name, such as RightIRFoot.

With a connected sensor selected, Foot sensor on the ground reports true when a surface is detected beneath that sensor and false when it is not. Foot Obstacle Sensed is the separate block for detecting an object in front of the sensor.

The sensor dropdown can include both IR foot sensors and colour sensors because both support these readings. Choose the sensor whose reading you intend to use. A missing sensor or unavailable reading can also produce false, so check the connection before treating false as an edge.

Example: react to the ground reading

Build this stack, then select your IR sensor in the dropdown:

A Blocks program that repeats a ground-sensor check ten times and walks forwards or backwards

The screenshot uses coloursensor_0F. To try this example with the infrared sensor, change that dropdown to your IRFoot sensor's name, such as RightIRFoot.

The stack does the following:

  1. Get ready! puts Marty into its ready pose.
  2. Repeat 10 runs the decision ten times.
  3. If the chosen sensor detects the ground, Marty takes one forward step with a 5 mm step length, 1 second step time and 0° turn.
  4. Otherwise, Marty takes two steps backwards.

Click the stack to run it. It checks the sensor at the start of each repetition; it does not continuously recheck the ground during a walking command. The stack shown has no green-flag start block, so clicking the green flag alone will not start it.

Try the sensing block on a safe, flat surface before running the walking example. Test changes in the reading by supporting Marty and raising the sensor clear of the surface. Keep the walking example on the floor with room to move; it is not a guarantee that Marty will stop before a table edge.