EV3 Programming Resources
EV3 Sumo Robot Project
Step 1: Setup
In groups, choose one laptop to be used for coding and a second laptop for research. Close all other laptops.
Download and install Visual Studio Code and the LEGO MINDSTORMS EV3 MicroPython extension.
Connect to the local wifi:
- SSID: ROBOTS
- Password: 99999999
Step 2: Buld the Sumo Robot
The instructions are available here:
Connect the sensors and motors using the three cables:
- The color sensor is plugged into S1
- The motors are plugged into MA and MB
Step 3: Code the Sumo Robot
Start a new project. Open up main.py and use this code as a starting point:
#!/usr/bin/env pybricks-micropython from pybricks import ev3brick as brick from pybricks.ev3devices import (Motor, TouchSensor, ColorSensor, InfraredSensor, UltrasonicSensor, GyroSensor) from pybricks.parameters import (Port, Stop, Direction, Button, Color, SoundFile, ImageFile, Align) from pybricks.tools import print, wait, StopWatch from pybricks.robotics import DriveBase # Write your program here import time # Play a sound brick.sound.beep() # Initialize a motor at port A and B. rightMotor = Motor(Port.A) leftMotor = Motor(Port.B) # Initialize a colour sensor on port 1 color = ColorSensor(Port.S1) while True: print("Color "+str(color.color())) # If color is not black if color.color() != Color.BLACK: # Move forward rightMotor.run(300) leftMotor.run(300) # Wait one twentieth of a second time.sleep(0.05) # If color is black else: # Play a sound brick.sound.beep(200) # Backup rightMotor.run(-300) leftMotor.run(-300) # Waie one second time.sleep(1) # Spin rightMotor.run(-300) leftMotor.run(300) # Wait one second time.sleep(1)
Read the starting code line by line and all the comments. As a group strive to understand every line of code.
Your bin will have two names, the LEGO Brick will use the name on the red tape. Use Visual Studio Code to the LEGO Brick:
Push F5 on a PC or FN+F5 on a Mac to test your code.
The colour sensor will provide a number representing which color it is currenlty sensing:
You may use the provided electrical tape to make a sumo ring on your desk. For the competition we will use the wooden ring in the center of the classrooms:
Code your LEGO sumo robot to stay within the sumo ring and push the other robot out.
Step 4: Submitting
main.py files and a list of group members that were present in Blackboard.