-
Notifications
You must be signed in to change notification settings - Fork 30
Create example scripts for the EDUCATOR robot #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| 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) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.sensorhere instead? Frankly, I think we should make thelegomodule "python private" and only advertise theev3dev.sensormodule. I don't see a reason that a user would want more detail.