Skip to content

Commit 70988d7

Browse files
gregcowelldwalton76
authored andcommitted
Create example scripts for the EDUCATOR robot (#13)
1 parent 0368c54 commit 70988d7

6 files changed

Lines changed: 130 additions & 0 deletions

File tree

robots/EDUCATOR/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# EDUCATOR
2+
These demonstration scripts are for the EDUCATOR robot that can be built using
3+
the Education kit (45544). You can also build a close approximation using the
4+
Home kit (31313) if you purchase some additional parts such as a gyro sensor and
5+
ultrasonic sensor. You can substitute the ball and socket from the Education
6+
kit with a single rear wheel.
7+
8+
**Building Instructions**: https://education.lego.com/en-au/support/mindstorms-ev3/building-instructions

robots/EDUCATOR/color.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env python3
2+
"""Make robot say whatever color it observes with the color sensor."""
3+
4+
from ev3dev.sensor.lego import ColorSensor
5+
from time import sleep
6+
from ev3dev.sound import Sound
7+
8+
color_sensor = ColorSensor()
9+
sound = Sound()
10+
11+
while True:
12+
color = color_sensor.color
13+
text = ColorSensor.COLORS[color]
14+
sound.speak(text)
15+
sleep(2)

robots/EDUCATOR/square-gyro.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Move robot in a square path using the Gyro sensor.
4+
5+
This script is a simple demonstration of turning using the Gyro sensor.
6+
"""
7+
8+
from ev3dev.motor import MoveSteering, OUTPUT_B, OUTPUT_C
9+
from ev3dev.sensor.lego import GyroSensor
10+
11+
12+
motor_pair = MoveSteering(OUTPUT_B, OUTPUT_C)
13+
gyro = GyroSensor()
14+
gyro.mode = GyroSensor.MODE_GYRO_ANG
15+
16+
for i in range(4):
17+
18+
# Move robot forward for 3 seconds
19+
motor_pair.on_for_seconds(steering=0, speed_pct=50, seconds=3)
20+
21+
# Spin robot to the left
22+
motor_pair.on(steering=-100, speed_pct=5)
23+
24+
# Wait until angle changed by 90 degrees
25+
gyro.wait_until_angle_changed_by(90)
26+
27+
# Stop motors
28+
motor_pair.off()

robots/EDUCATOR/square.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Move robot in a square path without using the Gyro sensor.
4+
5+
This script is a simple demonstration of moving forward and turning.
6+
"""
7+
8+
from ev3dev.motor import MoveSteering, OUTPUT_B, OUTPUT_C
9+
10+
motor_pair = MoveSteering(OUTPUT_B, OUTPUT_C)
11+
12+
for i in range(4):
13+
14+
# Move robot forward for 3 seconds
15+
motor_pair.on_for_seconds(steering=0, speed_pct=50, seconds=3)
16+
17+
# Turn robot left 90 degrees (adjust rotations for your particular robot)
18+
motor_pair.on_for_rotations(steering=-100, speed_pct=5, rotations=0.5)

robots/EDUCATOR/touch.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Reverse robot if bumps into wall.
4+
5+
This script is a simple demonstration of the touch sensor.
6+
"""
7+
8+
from ev3dev.motor import MoveSteering, OUTPUT_B, OUTPUT_C
9+
from ev3dev.sensor.lego import TouchSensor
10+
11+
motor_pair = MoveSteering(OUTPUT_B, OUTPUT_C)
12+
touch_sensor = TouchSensor()
13+
14+
# Start robot moving forward
15+
motor_pair.on(steering=0, speed_pct=10)
16+
17+
# Wait until robot touches wall
18+
touch_sensor.wait_for_pressed()
19+
20+
# Stop moving forward
21+
motor_pair.off()
22+
23+
# Reverse away from wall
24+
motor_pair.on_for_seconds(steering=0, speed_pct=-10, seconds=2)

robots/EDUCATOR/ultrasonic.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Use robot to reposition cuboid.
4+
5+
This script is a simple demonstration of the ultrasonic sensor and medium
6+
motor.
7+
"""
8+
9+
from ev3dev.motor import MoveSteering, MediumMotor, OUTPUT_A, OUTPUT_B, OUTPUT_C
10+
from ev3dev.sensor.lego import UltrasonicSensor
11+
from time import sleep
12+
13+
motor_pair = MoveSteering(OUTPUT_B, OUTPUT_C)
14+
medium_motor = MediumMotor(OUTPUT_A)
15+
ultrasonic_sensor = UltrasonicSensor()
16+
17+
# Start robot moving forward
18+
motor_pair.on(steering=0, speed_pct=10)
19+
20+
# Wait until robot less than 3.5cm from cuboid
21+
while ultrasonic_sensor.distance_centimeters > 3.5:
22+
sleep(0.01)
23+
24+
# Stop moving forward
25+
motor_pair.off()
26+
27+
# Lower robot arm over cuboid
28+
medium_motor.on_for_degrees(speed_pct=-10, degrees=90)
29+
30+
# Drag cuboid backwards for 2 seconds
31+
motor_pair.on_for_seconds(steering=0, speed_pct=-20, seconds=2)
32+
33+
# Raise robot arm
34+
medium_motor.on_for_degrees(speed_pct=10, degrees=90)
35+
36+
# Move robot away from cuboid
37+
motor_pair.on_for_seconds(steering=0, speed_pct=-20, seconds=2)

0 commit comments

Comments
 (0)