ev3 micropython lesson 1...lesson 1 by stempowering girls stempoweringgirls.org downloading...

24
EV3 Micropython Lesson 1 By STEMPowering Girls stempoweringgirls.org

Upload: others

Post on 27-May-2020

14 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: EV3 Micropython Lesson 1...Lesson 1 By STEMPowering Girls stempoweringgirls.org Downloading MicroPython 1. Download Visual Studio Code 2. Follow the directions it gives you to install

EV3 MicropythonLesson 1

By STEMPowering Girlsstempoweringgirls.org

Page 2: EV3 Micropython Lesson 1...Lesson 1 By STEMPowering Girls stempoweringgirls.org Downloading MicroPython 1. Download Visual Studio Code 2. Follow the directions it gives you to install

Downloading MicroPython1. Download Visual Studio Code

2. Follow the directions it gives you to install VS Code

3. Start the application

4. Open the extensions tab

5. In the extensions tab search for EV3 MicroPython

6. Download the first extension that shows up

a. should have the Ev3 Logo

STEMPowering Girlshttps://stempoweringgirls.org

Page 3: EV3 Micropython Lesson 1...Lesson 1 By STEMPowering Girls stempoweringgirls.org Downloading MicroPython 1. Download Visual Studio Code 2. Follow the directions it gives you to install

Variables

STEMPowering Girlshttps://stempoweringgirls.org

Page 4: EV3 Micropython Lesson 1...Lesson 1 By STEMPowering Girls stempoweringgirls.org Downloading MicroPython 1. Download Visual Studio Code 2. Follow the directions it gives you to install

Variables

Variables are used to store things.

In python, they can be used to store anything from numbers

to pieces of code

STEMPowering Girlshttps://stempoweringgirls.org

Page 5: EV3 Micropython Lesson 1...Lesson 1 By STEMPowering Girls stempoweringgirls.org Downloading MicroPython 1. Download Visual Studio Code 2. Follow the directions it gives you to install

VariablesIn MicroPython, most people use variables to store the ports of motors and sensors.

If you wanted to initialize a motor at port B:

MotorB = Motor(Port.B)

Now, anytime you need to use that motor you can call on it using the variable you just made.

STEMPowering Girlshttps://stempoweringgirls.org

Page 6: EV3 Micropython Lesson 1...Lesson 1 By STEMPowering Girls stempoweringgirls.org Downloading MicroPython 1. Download Visual Studio Code 2. Follow the directions it gives you to install

run_target()

STEMPowering Girlshttps://stempoweringgirls.org

Page 7: EV3 Micropython Lesson 1...Lesson 1 By STEMPowering Girls stempoweringgirls.org Downloading MicroPython 1. Download Visual Studio Code 2. Follow the directions it gives you to install

run_TargetThe run_target function is used to make to robot go forward for at a certain speed for a certain number of degrees.

1 Rotation = 360 degrees

motorB.run_target(500, 90)

STEMPowering Girlshttps://stempoweringgirls.org

180 Degrees

Page 8: EV3 Micropython Lesson 1...Lesson 1 By STEMPowering Girls stempoweringgirls.org Downloading MicroPython 1. Download Visual Studio Code 2. Follow the directions it gives you to install

Run_Target

This part of run_target tells the robot to run motor B at a speed of 500 degrees per second.

The speed range of micro python is 0 - 1000 degrees per second.

motorB.run_target(500, 90)

STEMPowering Girlshttps://stempoweringgirls.org

Page 9: EV3 Micropython Lesson 1...Lesson 1 By STEMPowering Girls stempoweringgirls.org Downloading MicroPython 1. Download Visual Studio Code 2. Follow the directions it gives you to install

Run_Target

This part of run_target specifies the amount of degrees. In this case, it tells to robot to go for a distance of 90 degrees or ¼ of a rotation.

motorB.run_target(500, 90)

STEMPowering Girlshttps://stempoweringgirls.org

Page 10: EV3 Micropython Lesson 1...Lesson 1 By STEMPowering Girls stempoweringgirls.org Downloading MicroPython 1. Download Visual Studio Code 2. Follow the directions it gives you to install

Now Try it Yourself!Intalize Motors in Port B and C and Make them Travel 1

Rotation at speed of 300

STEMPowering Girlshttps://stempoweringgirls.org

Page 11: EV3 Micropython Lesson 1...Lesson 1 By STEMPowering Girls stempoweringgirls.org Downloading MicroPython 1. Download Visual Studio Code 2. Follow the directions it gives you to install

Direction

STEMPowering Girlshttps://stempoweringgirls.org

Page 12: EV3 Micropython Lesson 1...Lesson 1 By STEMPowering Girls stempoweringgirls.org Downloading MicroPython 1. Download Visual Studio Code 2. Follow the directions it gives you to install

DirectionThe direction of the wheel rotation is by

default Clockwise. To change the direction, you need to specify it when you initialize the motor. You can also make the speed negative.

motorB = Motor(Port.B, Direction.COUNTERCLOCKWISE)

STEMPowering Girlshttps://stempoweringgirls.org

Page 13: EV3 Micropython Lesson 1...Lesson 1 By STEMPowering Girls stempoweringgirls.org Downloading MicroPython 1. Download Visual Studio Code 2. Follow the directions it gives you to install

NOW Try it Yourself!Make the Robot Go backwards for 2 Rotations

STEMPowering Girlshttps://stempoweringgirls.org

Page 14: EV3 Micropython Lesson 1...Lesson 1 By STEMPowering Girls stempoweringgirls.org Downloading MicroPython 1. Download Visual Studio Code 2. Follow the directions it gives you to install

Run

STEMPowering Girlshttps://stempoweringgirls.org

Page 15: EV3 Micropython Lesson 1...Lesson 1 By STEMPowering Girls stempoweringgirls.org Downloading MicroPython 1. Download Visual Studio Code 2. Follow the directions it gives you to install

RUNThe run Function is almost exactly like run_target. It uses the speed parameter but will go on forever.

To stop, use the function .stop().

If you want to wait between starting and stop (you normally do), use the wait function.

motorB.run(500)

wait(2000)

motorB.stop()

Stop.COAST lets the robot slow to a stop

Stop.BRAKE makes the robot stop immediately

STEMPowering Girlshttps://stempoweringgirls.org

Page 16: EV3 Micropython Lesson 1...Lesson 1 By STEMPowering Girls stempoweringgirls.org Downloading MicroPython 1. Download Visual Studio Code 2. Follow the directions it gives you to install

Run_TIME()

STEMPowering Girlshttps://stempoweringgirls.org

Page 17: EV3 Micropython Lesson 1...Lesson 1 By STEMPowering Girls stempoweringgirls.org Downloading MicroPython 1. Download Visual Studio Code 2. Follow the directions it gives you to install

RUN_Time

The run_time Function is exactly like run_target but instead of using degrees in uses time as the stop parameter.

motorB.run_time(500,1000)

STEMPowering Girlshttps://stempoweringgirls.org

Page 18: EV3 Micropython Lesson 1...Lesson 1 By STEMPowering Girls stempoweringgirls.org Downloading MicroPython 1. Download Visual Studio Code 2. Follow the directions it gives you to install

Wait

Page 19: EV3 Micropython Lesson 1...Lesson 1 By STEMPowering Girls stempoweringgirls.org Downloading MicroPython 1. Download Visual Studio Code 2. Follow the directions it gives you to install

Wait FunctionThe waits function tells the program whether or not complete the block before running the next block after.

By default it’s set to True.

motorB.run_target(500,90,wait = False)

motorB.run_target(500,90,wait = True)

Page 20: EV3 Micropython Lesson 1...Lesson 1 By STEMPowering Girls stempoweringgirls.org Downloading MicroPython 1. Download Visual Studio Code 2. Follow the directions it gives you to install

TURNING

STEMPowering Girlshttps://stempoweringgirls.org

Page 21: EV3 Micropython Lesson 1...Lesson 1 By STEMPowering Girls stempoweringgirls.org Downloading MicroPython 1. Download Visual Studio Code 2. Follow the directions it gives you to install

PInpoint Turns

A pinpoint turn is when one motor goes forward while the other motor goes backwards. It causes the robot to spin in its center of gravity.

STEMPowering Girlshttps://stempoweringgirls.org

Page 22: EV3 Micropython Lesson 1...Lesson 1 By STEMPowering Girls stempoweringgirls.org Downloading MicroPython 1. Download Visual Studio Code 2. Follow the directions it gives you to install

Pivot Turn

A pivot turn is when one motor it stop while the other goes forward. It causes the robot to pivot around the stopped wheel.

STEMPowering Girlshttps://stempoweringgirls.org

Page 23: EV3 Micropython Lesson 1...Lesson 1 By STEMPowering Girls stempoweringgirls.org Downloading MicroPython 1. Download Visual Studio Code 2. Follow the directions it gives you to install

Swing Turn

A swing turn is when both motors are driving forward but one is moving faster than the other.

STEMPowering Girlshttps://stempoweringgirls.org

Page 24: EV3 Micropython Lesson 1...Lesson 1 By STEMPowering Girls stempoweringgirls.org Downloading MicroPython 1. Download Visual Studio Code 2. Follow the directions it gives you to install

NOW Try it Yourself!Choose Your Favorite Turn and then have the robot turn 180 Degrees

STEMPowering Girlshttps://stempoweringgirls.org