7. Position with Distance sensor

Luly, small LEGO Education SPIKE Prime competition robot with 3D building instructions

Luly is a new STEAM competition robot from LEGO Education SPIKE Prime. We would use in some of the courses. It's simple, it requires a really small number of parts and we can demonstrate most of the attachments and programs with it. Check out the courses below and see how Luly is used to complete in a competition.

Distance sensor attachment from LEGO Education SPIKE Prime, with 3D building instructions

This is a distance sensor attachment for Luly, small LEGO Education SPIKE Prime competition robot with 3D building instructions. This attachment is place on the robot whenever we want to work with the LEGO Education SPIKE Prime Distance Sensor.

Scratch (Word Blocks) program to stop at distance from the border, with LEGO Education SPIKE Prime

This program is developed with LEGO Education SPIKE App Word Blocks and is used to make the Luly, small LEGO Education SPIKE Prime competition robot with 3D building instructions stop at a distance from the border field.

Python program to stop at distance from the border, with LEGO Education SPIKE Prime

This program is developed with LEGO Education SPIKE App Python and is used to make the Luly, small LEGO Education SPIKE Prime competition robot with 3D building instructions stop at a distance from the border field.

from spike import PrimeHub, LightMatrix, Button, StatusLight, ForceSensor, MotionSensor, Speaker, ColorSensor, App, DistanceSensor, Motor, MotorPair
from spike.control import wait_for_seconds, wait_until, Timer
from math import *

hub = PrimeHub() 
distance_sensor = DistanceSensor('C')

motor_pair = MotorPair('A', 'B') # Set the motor ports in the motor_pair.
motor_pair.set_default_speed(50) # Set the default speed of the motor_pair.
motor_pair.set_motor_rotation(17.6, 'cm') # Set the distance that the robot travels for one rotation of its wheels. The value 17.6 comes from
                                        # the diameter of the wheel (5.6cm) multiplied by "π" (3.14).
motor_pair.set_stop_action('brake') # Activate the brakes when the robot stops. The other conditions are 'hold' and 'coast'.
distance_sensor.light_up_all() # Turn on the distance sensor lights.

motor_pair.start() # Move forward.

distance_sensor.wait_for_distance_closer_than(20, 'cm') # Wait until distance is closer than 20 centimeters.

motor_pair.stop() # Stop moving.
distance_sensor.light_up_all(0) # Turn off the distance sensor lights.

raise SystemExit # Close the program.