Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions robots/EDUCATOR/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# EDUCATOR
These demonstration scripts are for the EDUCATOR robot that can be built using
the Education kit (45544). You can also build a close approximation using the
Home kit (31313) if you purchase some additional parts such as a gyro sensor and
ultrasonic sensor. You can substitute the ball and socket from the Education
kit with a single rear wheel.

**Building Instructions**: https://education.lego.com/en-au/support/mindstorms-ev3/building-instructions
15 changes: 15 additions & 0 deletions robots/EDUCATOR/color.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env python3
"""Make robot say whatever color it observes with the color sensor."""

from ev3dev.sensor.lego import ColorSensor
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you import from ev3dev.sensor here instead? Frankly, I think we should make the lego module "python private" and only advertise the ev3dev.sensor module. I don't see a reason that a user would want more detail.

from time import sleep
from ev3dev.sound import Sound

color_sensor = ColorSensor()
sound = Sound()

while True:
color = color_sensor.color
text = ColorSensor.COLORS[color]
sound.speak(text)
sleep(2)
28 changes: 28 additions & 0 deletions robots/EDUCATOR/square-gyro.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env python3
"""
Move robot in a square path using the Gyro sensor.

This script is a simple demonstration of turning using the Gyro sensor.
"""

from ev3dev.motor import MoveSteering, OUTPUT_B, OUTPUT_C
from ev3dev.sensor.lego import GyroSensor


motor_pair = MoveSteering(OUTPUT_B, OUTPUT_C)
gyro = GyroSensor()
gyro.mode = GyroSensor.MODE_GYRO_ANG

for i in range(4):

# Move robot forward for 3 seconds
motor_pair.on_for_seconds(steering=0, speed_pct=50, seconds=3)

# Spin robot to the left
motor_pair.on(steering=-100, speed_pct=5)

# Wait until angle changed by 90 degrees
gyro.wait_until_angle_changed_by(90)

# Stop motors
motor_pair.off()
18 changes: 18 additions & 0 deletions robots/EDUCATOR/square.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env python3
"""
Move robot in a square path without using the Gyro sensor.

This script is a simple demonstration of moving forward and turning.
"""

from ev3dev.motor import MoveSteering, OUTPUT_B, OUTPUT_C

motor_pair = MoveSteering(OUTPUT_B, OUTPUT_C)

for i in range(4):

# Move robot forward for 3 seconds
motor_pair.on_for_seconds(steering=0, speed_pct=50, seconds=3)

# Turn robot left 90 degrees (adjust rotations for your particular robot)
motor_pair.on_for_rotations(steering=-100, speed_pct=5, rotations=0.5)
24 changes: 24 additions & 0 deletions robots/EDUCATOR/touch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env python3
"""
Reverse robot if bumps into wall.

This script is a simple demonstration of the touch sensor.
"""

from ev3dev.motor import MoveSteering, OUTPUT_B, OUTPUT_C
from ev3dev.sensor.lego import TouchSensor

motor_pair = MoveSteering(OUTPUT_B, OUTPUT_C)
touch_sensor = TouchSensor()

# Start robot moving forward
motor_pair.on(steering=0, speed_pct=10)

# Wait until robot touches wall
touch_sensor.wait_for_pressed()

# Stop moving forward
motor_pair.off()

# Reverse away from wall
motor_pair.on_for_seconds(steering=0, speed_pct=-10, seconds=2)
37 changes: 37 additions & 0 deletions robots/EDUCATOR/ultrasonic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env python3
"""
Use robot to reposition cuboid.

This script is a simple demonstration of the ultrasonic sensor and medium
motor.
"""

from ev3dev.motor import MoveSteering, MediumMotor, OUTPUT_A, OUTPUT_B, OUTPUT_C
from ev3dev.sensor.lego import UltrasonicSensor
from time import sleep

motor_pair = MoveSteering(OUTPUT_B, OUTPUT_C)
medium_motor = MediumMotor(OUTPUT_A)
ultrasonic_sensor = UltrasonicSensor()

# Start robot moving forward
motor_pair.on(steering=0, speed_pct=10)

# Wait until robot less than 3.5cm from cuboid
while ultrasonic_sensor.distance_centimeters > 3.5:
sleep(0.01)

# Stop moving forward
motor_pair.off()

# Lower robot arm over cuboid
medium_motor.on_for_degrees(speed_pct=-10, degrees=90)

# Drag cuboid backwards for 2 seconds
motor_pair.on_for_seconds(steering=0, speed_pct=-20, seconds=2)

# Raise robot arm
medium_motor.on_for_degrees(speed_pct=10, degrees=90)

# Move robot away from cuboid
motor_pair.on_for_seconds(steering=0, speed_pct=-20, seconds=2)