mirror of
https://github.com/pybricks/pybricks-api.git
synced 2026-09-12 01:24:17 +00:00
doc: doc8
This commit is contained in:
+50
-21
@@ -1,7 +1,8 @@
|
||||
Signals and Units
|
||||
=================
|
||||
|
||||
Many commands allow you to specify arguments in terms of well-known physical quantities. This page gives an overview of each quantity and its unit.
|
||||
Many commands allow you to specify arguments in terms of well-known physical
|
||||
quantities. This page gives an overview of each quantity and its unit.
|
||||
|
||||
.. _time:
|
||||
|
||||
@@ -9,26 +10,36 @@ time: ms
|
||||
---------
|
||||
All time and duration values are measured in milliseconds (ms).
|
||||
|
||||
For example, the duration of motion with :meth:`run_time <.ev3devices.Motor.run_time>`, the duration of :func:`wait <.tools.wait>`, or the time values returned by the :class:`StopWatch <.tools.StopWatch>` are specified in milliseconds.
|
||||
For example, the duration of motion with :meth:`run_time
|
||||
<.ev3devices.Motor.run_time>`, the duration of :func:`wait <.tools.wait>`, or
|
||||
the time values returned by the :class:`StopWatch <.tools.StopWatch>` are
|
||||
specified in milliseconds.
|
||||
|
||||
.. _angle:
|
||||
|
||||
angle: deg
|
||||
-----------
|
||||
All angles are measured in degrees (deg). One full rotation corresponds to 360 degrees.
|
||||
|
||||
For example, the angle values of a :meth:`Motor <.ev3devices.Motor.angle>` or the :meth:`GyroSensor <.ev3devices.GyroSensor.angle>` are expressed in degrees.
|
||||
All angles are measured in degrees (deg). One full rotation corresponds to 360
|
||||
degrees.
|
||||
|
||||
For example, the angle values of a :meth:`Motor <.ev3devices.Motor.angle>` or
|
||||
the :meth:`GyroSensor <.ev3devices.GyroSensor.angle>` are expressed in degrees.
|
||||
|
||||
.. _speed:
|
||||
|
||||
rotational speed: deg/s
|
||||
-----------------------
|
||||
|
||||
Rotational speed, or *angular velocity* describes how fast something rotates, expressed as the number of degrees per second (deg/s).
|
||||
Rotational speed, or *angular velocity* describes how fast something rotates,
|
||||
expressed as the number of degrees per second (deg/s).
|
||||
|
||||
For example, the rotational speed values of a :meth:`Motor <.ev3devices.Motor.speed>` or the :meth:`GyroSensor <.ev3devices.GyroSensor.speed>` are expressed in degrees per second.
|
||||
For example, the rotational speed values of a :meth:`Motor
|
||||
<.ev3devices.Motor.speed>` or the :meth:`GyroSensor
|
||||
<.ev3devices.GyroSensor.speed>` are expressed in degrees per second.
|
||||
|
||||
While we recommend working with degrees per second in your programs, you can use the following table to convert between commonly used units.
|
||||
While we recommend working with degrees per second in your programs, you can
|
||||
use the following table to convert between commonly used units.
|
||||
|
||||
+-----------+-------+-----------+
|
||||
| | deg/s | rpm |
|
||||
@@ -44,9 +55,11 @@ distance: mm
|
||||
-------------
|
||||
Distances are expressed in millimeters (mm) whenever possible.
|
||||
|
||||
For example, the distance value of the :meth:`UltrasonicSensor <.ev3devices.UltrasonicSensor.distance>` is measured in millimeters.
|
||||
For example, the distance value of the :meth:`UltrasonicSensor
|
||||
<.ev3devices.UltrasonicSensor.distance>` is measured in millimeters.
|
||||
|
||||
While we recommend working with millimeters in your programs, you can use the following table to convert between commonly used units.
|
||||
While we recommend working with millimeters in your programs, you can use the
|
||||
following table to convert between commonly used units.
|
||||
|
||||
+---------+------+-----+--------+
|
||||
| | mm | cm | inch |
|
||||
@@ -62,7 +75,9 @@ While we recommend working with millimeters in your programs, you can use the fo
|
||||
|
||||
dimension: mm
|
||||
-------------
|
||||
Dimensions are expressed in millimeters (mm) whenever possible, just like distances.
|
||||
|
||||
Dimensions are expressed in millimeters (mm) whenever possible, just like
|
||||
distances.
|
||||
|
||||
For example, the diameter of a wheel is measured in millimeters.
|
||||
|
||||
@@ -72,9 +87,12 @@ For example, the diameter of a wheel is measured in millimeters.
|
||||
relative distance: %
|
||||
---------------------
|
||||
|
||||
Some distance measurements do not provide an accurate value with a specific unit, but they range from very close (0%) to very far (100%). These are referred to as relative distances.
|
||||
Some distance measurements do not provide an accurate value with a specific
|
||||
unit, but they range from very close (0%) to very far (100%). These are
|
||||
referred to as relative distances.
|
||||
|
||||
For example, the distance value of the :meth:`InfraredSensor <.ev3devices.InfraredSensor.distance>` is a relative distance.
|
||||
For example, the distance value of the :meth:`InfraredSensor
|
||||
<.ev3devices.InfraredSensor.distance>` is a relative distance.
|
||||
|
||||
|
||||
|
||||
@@ -89,20 +107,27 @@ For example, the speed of a robotic vehicle is expressed in mm/s.
|
||||
|
||||
.. _acceleration:
|
||||
|
||||
rotational acceleration: deg/s/s
|
||||
--------------------------------
|
||||
Rotational acceleration, or *angular acceleration* describes how fast the rotational speed changes. This is expressed as the change of the number of degrees per second, during one second (deg/s/s). This is also commonly written as :math:`deg/s^2`.
|
||||
rotational acceleration: deg/s/s -------------------------------- Rotational
|
||||
acceleration, or *angular acceleration* describes how fast the rotational speed
|
||||
changes. This is expressed as the change of the number of degrees per second,
|
||||
during one second (deg/s/s). This is also commonly written as :math:`deg/s^2`.
|
||||
|
||||
For example, you can adjust the rotational acceleration setting of a :meth:`Motor <.ev3devices.Motor.set_run_settings>` to change how smoothly or how quickly it reaches the constant speed set point.
|
||||
For example, you can adjust the rotational acceleration setting of a
|
||||
:meth:`Motor <.ev3devices.Motor.set_run_settings>` to change how smoothly or
|
||||
how quickly it reaches the constant speed set point.
|
||||
|
||||
|
||||
.. _percentage:
|
||||
|
||||
percentage: %
|
||||
--------------
|
||||
Some signals do not have specific units but range from a minimum (0%) to a maximum (100%). A specific type of percentages are :ref:`relative distances <relativedistance>`.
|
||||
|
||||
For example, the sound :meth:`volume <.ev3brick.sound.beep>` ranges from 0% to 100%.
|
||||
Some signals do not have specific units but range from a minimum (0%) to a
|
||||
maximum (100%). A specific type of percentages are :ref:`relative distances
|
||||
<relativedistance>`.
|
||||
|
||||
For example, the sound :meth:`volume <.ev3brick.sound.beep>` ranges from 0% to
|
||||
100%.
|
||||
|
||||
.. _frequency:
|
||||
|
||||
@@ -110,7 +135,8 @@ frequency: Hz
|
||||
--------------
|
||||
Sound frequencies are expressed in Hertz (Hz).
|
||||
|
||||
For example, you can choose the frequency of a :meth:`beep <.ev3brick.sound.beep>` to change the pitch.
|
||||
For example, you can choose the frequency of a :meth:`beep
|
||||
<.ev3brick.sound.beep>` to change the pitch.
|
||||
|
||||
.. _voltage:
|
||||
|
||||
@@ -118,12 +144,15 @@ voltage: mV
|
||||
--------------
|
||||
Voltages are expressed in millivolt (mV).
|
||||
|
||||
For example, you can check the voltage of the :meth:`battery <.ev3brick.battery.voltage>`.
|
||||
For example, you can check the voltage of the :meth:`battery
|
||||
<.ev3brick.battery.voltage>`.
|
||||
|
||||
.. _current:
|
||||
|
||||
current: mA
|
||||
--------------
|
||||
|
||||
Electrical currents are expressed in milliampere (mA).
|
||||
|
||||
For example, you can check the current supplied by the :meth:`battery <.ev3brick.battery.current>`.
|
||||
For example, you can check the current supplied by the :meth:`battery
|
||||
<.ev3brick.battery.current>`.
|
||||
|
||||
@@ -122,8 +122,8 @@ Display
|
||||
# Display a custom image from your project folder
|
||||
brick.display.image('pybricks.png')
|
||||
|
||||
# Display a custom image at the top right of the screen, without clearing
|
||||
# the screen first
|
||||
# Display a custom image at the top right of the screen,
|
||||
# without clearing the screen first
|
||||
brick.display.image('arrow.png', Align.TOP_RIGHT, clear=False)
|
||||
|
||||
Battery
|
||||
|
||||
@@ -12,10 +12,10 @@ Motors
|
||||
|
||||
Example::
|
||||
|
||||
# Initialize a motor (by default this means clockwise, without any gears).
|
||||
# Initialize a motor (by default this means is, without any gears).
|
||||
example_motor = Motor(Port.A)
|
||||
|
||||
# Initialize a motor where positive speed values should go counterclockwise
|
||||
# Initialize a motor with positive speed as counterclockwise
|
||||
right_motor = Motor(Port.B, Direction.COUNTERCLOCKWISE)
|
||||
|
||||
# Initialize a motor with a gear train
|
||||
@@ -82,11 +82,13 @@ Motors
|
||||
|
||||
Example::
|
||||
|
||||
# Set the maximum speed to 200 deg/s and acceleration to 400 deg/s/s.
|
||||
# Set the maximum speed to 200 deg/s and
|
||||
# acceleration to 400 deg/s/s.
|
||||
example_motor.set_run_settings(200, 400)
|
||||
|
||||
# Make the motor run for 5 seconds. Even though the speed argument is 300
|
||||
# deg/s in this example, the motor will move at only 200 deg/s because of
|
||||
# Make the motor run for 5 seconds. Even though the
|
||||
# speed argument is 300 deg/s in this example, the
|
||||
# motor will move at only 200 deg/s because of
|
||||
# the settings above.
|
||||
example_motor.run_time(300, 5000)
|
||||
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
Color Sorter
|
||||
=====================
|
||||
|
||||
This example program for the color sorter (:numref:`fig_color_sorter`) lets you scan colored Technic beams using the Color Sensor.
|
||||
This example program for the color sorter (:numref:`fig_color_sorter`) lets you
|
||||
scan colored Technic beams using the Color Sensor.
|
||||
|
||||
Scan the colored beams one by one and add them to the tray. A beep confirms that it has registered the color. When the tray is full or when you press the center button, the robot will start distributing the Technic bricks by color.
|
||||
Scan the colored beams one by one and add them to the tray. A beep confirms
|
||||
that it has registered the color. When the tray is full or when you press the
|
||||
center button, the robot will start distributing the Technic bricks by color.
|
||||
|
||||
You can find building instructions for the color sorter on the `LEGO Education website <https://le-www-live-s.legocdn.com/sc/media/lessons/mindstorms-ev3/building-instructions/ev3-model-core-set-color-sorter-c778563f88c986841453574495cb5ff1.pdf>`_.
|
||||
You can find building instructions for the color sorter on the `LEGO Education
|
||||
website
|
||||
<https://le-www-live-s.legocdn.com/sc/media/lessons/mindstorms-ev3/building-instructions/ev3-model-core-set-color-sorter-c778563f88c986841453574495cb5ff1.pdf>`_.
|
||||
|
||||
.. _fig_color_sorter:
|
||||
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
Robot Arm H25
|
||||
=====================
|
||||
|
||||
This example program makes the robot (:numref:`fig_robot_arm`) move the black wheel hub stacks around forever. The robot arm will first initialize and then start moving the hubs around.
|
||||
This example program makes the robot (:numref:`fig_robot_arm`) move the black
|
||||
wheel hub stacks around forever. The robot arm will first initialize and then
|
||||
start moving the hubs around.
|
||||
|
||||
You can find building instructions for the robot on the `LEGO Education website <https://le-www-live-s.legocdn.com/sc/media/lessons/mindstorms-ev3/building-instructions/ev3-model-core-set-robot-arm-h25-56cdb22c1e3a02f1770bda72862ce2bd.pdf>`_.
|
||||
You can find building instructions for the robot on the `LEGO Education website
|
||||
<https://le-www-live-s.legocdn.com/sc/media/lessons/mindstorms-ev3/building-instructions/ev3-model-core-set-robot-arm-h25-56cdb22c1e3a02f1770bda72862ce2bd.pdf>`_.
|
||||
|
||||
Tip: When building the robot, reverse the orientation of the EV3 Brick such that the microSD card is easily accessible.
|
||||
Tip: When building the robot, reverse the orientation of the EV3 Brick such
|
||||
that the microSD card is easily accessible.
|
||||
|
||||
.. _fig_robot_arm:
|
||||
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
Robot Educator
|
||||
=====================
|
||||
|
||||
This example makes the Robot Educator (:numref:`fig_robot_educator`) drive until it sees an obstacle. It then backs up, turns around, and starts driving again.
|
||||
This example makes the Robot Educator (:numref:`fig_robot_educator`) drive
|
||||
until it sees an obstacle. It then backs up, turns around, and starts driving
|
||||
again.
|
||||
|
||||
You can find building instructions for the Robot Educator on the `LEGO Education website <https://education.lego.com/en-us/support/mindstorms-ev3/building-instructions#robot>`_.
|
||||
You can find building instructions for the Robot Educator on the `LEGO
|
||||
Education website
|
||||
<https://education.lego.com/en-us/support/mindstorms-ev3/building-instructions#robot>`_.
|
||||
|
||||
.. _fig_robot_educator:
|
||||
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
Using MicroPython with LEGO\ :sup:`®` MINDSTORMS\ :sup:`®` EV3
|
||||
==============================================================
|
||||
==================================================================
|
||||
|
||||
This guide shows you how to get started writing MicroPython programs for your
|
||||
LEGO® MINDSTORMS® EV3 robots. You'll learn to do so in two steps:
|
||||
|
||||
- :doc:`Installation <startinstall>`: First you'll prepare your computer and
|
||||
your EV3 Brick by collecting and installing the required tools. You'll also learn
|
||||
how to turn the EV3 Brick on and off and to navigate the menu on the screen.
|
||||
your EV3 Brick by collecting and installing the required tools. You'll also
|
||||
learn how to turn the EV3 Brick on and off and to navigate the menu on the
|
||||
screen.
|
||||
|
||||
- :doc:`Creating and running programs <startrun>`: Next, you'll learn how to
|
||||
create a program and download it to the EV3 Brick. You'll also learn how to
|
||||
|
||||
+61
-25
@@ -1,7 +1,8 @@
|
||||
Installation
|
||||
===================
|
||||
|
||||
This page guides you through the steps to collect and install everything you need to start programming.
|
||||
This page guides you through the steps to collect and install everything you
|
||||
need to start programming.
|
||||
|
||||
What do you need?
|
||||
-----------------------------------------------------------
|
||||
@@ -11,19 +12,24 @@ To get started, you'll need:
|
||||
- A Windows 10 or Mac OS computer
|
||||
- Internet access and administrator access
|
||||
|
||||
This is required during the installation only. You will not need special access to write and run programs later on.
|
||||
This is required during the installation only. You will not need special
|
||||
access to write and run programs later on.
|
||||
|
||||
- A microSD card
|
||||
|
||||
You'll need a card with a minimum capacity of 4GB and a maximum capacity of 32GB. This type of microSD cards is also known as microSDHC. We recommend cards with Application Performance Class A1.
|
||||
You'll need a card with a minimum capacity of 4GB and a maximum capacity of
|
||||
32GB. This type of microSD cards is also known as microSDHC. We recommend
|
||||
cards with Application Performance Class A1.
|
||||
|
||||
- A microSD card slot or card reader in your computer
|
||||
|
||||
If your computer does not have a (micro)SD card slot, you can use an external USB (micro)SD card reader.
|
||||
If your computer does not have a (micro)SD card slot, you can use an
|
||||
external USB (micro)SD card reader.
|
||||
|
||||
- A mini-USB cable, like the one included with your EV3 set
|
||||
|
||||
The typical configuration of this equipment is summarized in :numref:`fig_overview`.
|
||||
The typical configuration of this equipment is summarized in
|
||||
:numref:`fig_overview`.
|
||||
|
||||
.. _fig_overview:
|
||||
|
||||
@@ -37,7 +43,8 @@ The typical configuration of this equipment is summarized in :numref:`fig_overvi
|
||||
Preparing your computer
|
||||
-----------------------------------------------------------
|
||||
|
||||
You'll write your MicroPython programs using Visual Studio Code. Follow the steps below to download, install, and configure this application:
|
||||
You'll write your MicroPython programs using Visual Studio Code. Follow the
|
||||
steps below to download, install, and configure this application:
|
||||
|
||||
1. Download `Visual Studio Code <https://code.visualstudio.com/Download>`_.
|
||||
2. Follow the on-screen instructions to install the application.
|
||||
@@ -50,7 +57,7 @@ You'll write your MicroPython programs using Visual Studio Code. Follow the step
|
||||
.. figure:: images/store.png
|
||||
:alt: store
|
||||
:align: center
|
||||
|
||||
|
||||
Installing the extension from the Visual Studio Code marketplace
|
||||
|
||||
.. _prepsdcard:
|
||||
@@ -58,24 +65,42 @@ You'll write your MicroPython programs using Visual Studio Code. Follow the step
|
||||
Preparing the microSD card
|
||||
-----------------------------------------------------------
|
||||
|
||||
To make it possible to run MicroPython programs on your EV3 Brick, you'll now learn how to install the required tools on your microSD card.
|
||||
To make it possible to run MicroPython programs on your EV3 Brick, you'll now
|
||||
learn how to install the required tools on your microSD card.
|
||||
|
||||
If the microSD card contains files you want to keep, make sure to create a backup of its contents first. See :ref:`managing files on the EV3 <managefiles>` to learn how to backup your previous MicroPython programs if necessary.
|
||||
If the microSD card contains files you want to keep, make sure to create a
|
||||
backup of its contents first. See :ref:`managing files on the EV3
|
||||
<managefiles>` to learn how to backup your previous MicroPython programs if
|
||||
necessary.
|
||||
|
||||
*This process erases everything on your microSD card, including any previous MicroPython programs on it.*
|
||||
*This process erases everything on your microSD card, including any previous
|
||||
MicroPython programs on it.*
|
||||
|
||||
|
||||
To install the MicroPython tools on your microSD card:
|
||||
|
||||
|
||||
1. Download the `EV3 MicroPython microSD card image <.>`_ and save it in a convenient location. This file is approximately 360 MB. Do **not** open or unzip the file.
|
||||
2. Download and install a microSD card flashing tool such as `Etcher <https://www.balena.io/etcher/>`_.
|
||||
3. Insert the microSD card into your computer or card reader.
|
||||
4. Launch the flashing tool and follow the steps on your screen to install the file you have just downloaded. If you use Etcher, you can follow the instructions below, as shown in :numref:`fig_etcher`.
|
||||
1. Download the `EV3 MicroPython microSD card image <.>`_ and save it in a
|
||||
convenient location. This file is approximately 360 MB. Do **not** open or
|
||||
unzip the file.
|
||||
|
||||
a. Select the EV3 MicroPython microSD card image file you have just downloaded.
|
||||
b. Select your microSD card. Make sure that the device and size correspond to your microSD card.
|
||||
c. Start the flashing process. This may take several minutes. Do not remove the card until the flashing process is complete.
|
||||
2. Download and install a microSD card flashing tool such as `Etcher
|
||||
<https://www.balena.io/etcher/>`_.
|
||||
|
||||
3. Insert the microSD card into your computer or card reader.
|
||||
|
||||
4. Launch the flashing tool and follow the steps on your screen to install the
|
||||
file you have just downloaded. If you use Etcher, you can follow the
|
||||
instructions below, as shown in :numref:`fig_etcher`.
|
||||
|
||||
a. Select the EV3 MicroPython microSD card image file you have just
|
||||
downloaded.
|
||||
|
||||
b. Select your microSD card. Make sure that the device and size correspond
|
||||
to your microSD card.
|
||||
|
||||
c. Start the flashing process. This may take several minutes. Do not remove
|
||||
the card until the flashing process is complete.
|
||||
|
||||
.. _fig_etcher:
|
||||
|
||||
@@ -89,14 +114,18 @@ To install the MicroPython tools on your microSD card:
|
||||
Updating the microSD card
|
||||
-----------------------------------------------------------
|
||||
|
||||
To update the microSD card, download a new image file using the link above and flash it to the microSD card as described above. Be sure to :ref:`back up any MicroPython programs you want to save <managefiles>`.
|
||||
To update the microSD card, download a new image file using the link above and
|
||||
flash it to the microSD card as described above. Be sure to :ref:`back up any
|
||||
MicroPython programs you want to save <managefiles>`.
|
||||
|
||||
You do not need to erase the contents of the microSD card first. This is done automatically when you flash the new image file.
|
||||
You do not need to erase the contents of the microSD card first. This is done
|
||||
automatically when you flash the new image file.
|
||||
|
||||
Using the EV3 Brick
|
||||
-----------------------------------------------------------
|
||||
|
||||
Make sure the EV3 Brick is turned off. Insert the microSD card you prepared into the microSD card slot on the EV3 Brick, as shown in :numref:`fig_sd`.
|
||||
Make sure the EV3 Brick is turned off. Insert the microSD card you prepared
|
||||
into the microSD card slot on the EV3 Brick, as shown in :numref:`fig_sd`.
|
||||
|
||||
.. _fig_sd:
|
||||
|
||||
@@ -113,9 +142,14 @@ Turning the EV3 Brick on and off
|
||||
|
||||
Turn on the EV3 Brick by pressing the dark gray center button.
|
||||
|
||||
The boot process may take several minutes. While booting, the EV3 Brick status light turns orange and blinks intermittently, and you'll see a lot of text on the EV3 screen. The EV3 Brick is ready for use when the status light turns green.
|
||||
The boot process may take several minutes. While booting, the EV3 Brick status
|
||||
light turns orange and blinks intermittently, and you'll see a lot of text on
|
||||
the EV3 screen. The EV3 Brick is ready for use when the status light turns
|
||||
green.
|
||||
|
||||
To turn the EV3 Brick off, open the shutdown menu with the back button, and then select *Power Off* using the center button, as shown in :numref:`fig_onoff`.
|
||||
To turn the EV3 Brick off, open the shutdown menu with the back button, and
|
||||
then select *Power Off* using the center button, as shown in
|
||||
:numref:`fig_onoff`.
|
||||
|
||||
.. _fig_onoff:
|
||||
|
||||
@@ -129,7 +163,8 @@ To turn the EV3 Brick off, open the shutdown menu with the back button, and then
|
||||
Viewing motor and sensor values
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
When you're not running a program, you can view motor and sensor values using the device browser, as shown in :numref:`fig_devicebrowser`.
|
||||
When you're not running a program, you can view motor and sensor values using
|
||||
the device browser, as shown in :numref:`fig_devicebrowser`.
|
||||
|
||||
.. _fig_devicebrowser:
|
||||
|
||||
@@ -141,9 +176,10 @@ When you're not running a program, you can view motor and sensor values using th
|
||||
Viewing motor and sensor values
|
||||
|
||||
Going back to the original firmware
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
You can go back to the LEGO® firmware and your LEGO programs at any time. To do so:
|
||||
You can go back to the LEGO® firmware and your LEGO programs at any time.
|
||||
To do so:
|
||||
|
||||
1. Turn the EV3 Brick off as shown above.
|
||||
2. Wait for the screen and brick status light to turn off.
|
||||
|
||||
+51
-18
@@ -1,13 +1,21 @@
|
||||
Creating and running programs
|
||||
=============================
|
||||
|
||||
Now that you've set up your computer and EV3 Brick, you're ready to start writing programs.
|
||||
Now that you've set up your computer and EV3 Brick, you're ready to start
|
||||
writing programs.
|
||||
|
||||
To make it easier to create and manage your programs, let's first have a quick look at how MicroPython projects and programs for your EV3 robots are organized.
|
||||
To make it easier to create and manage your programs, let's first have a quick
|
||||
look at how MicroPython projects and programs for your EV3 robots are
|
||||
organized.
|
||||
|
||||
Programs are organized into *project folders*, as shown in :numref:`fig_projectstructure`. A project folder is a directory on your computer that contains the main program (**main.py**) and other optional scripts or files. This project folder and all of its contents will be copied to the EV3 Brick, where the main program will be run.
|
||||
Programs are organized into *project folders*, as shown in
|
||||
:numref:`fig_projectstructure`. A project folder is a directory on your
|
||||
computer that contains the main program (**main.py**) and other optional
|
||||
scripts or files. This project folder and all of its contents will be copied to
|
||||
the EV3 Brick, where the main program will be run.
|
||||
|
||||
This page shows you how to create such a project and how to transfer it to the EV3 Brick.
|
||||
This page shows you how to create such a project and how to transfer it to the
|
||||
EV3 Brick.
|
||||
|
||||
|
||||
.. _fig_projectstructure:
|
||||
@@ -17,13 +25,17 @@ This page shows you how to create such a project and how to transfer it to the E
|
||||
:alt: projectstructure
|
||||
:align: center
|
||||
|
||||
A project contains a program called **main.py** and optional resources like sounds or MicroPython modules.
|
||||
A project contains a program called **main.py** and optional resources like
|
||||
sounds or MicroPython modules.
|
||||
|
||||
|
||||
Creating a new project
|
||||
-----------------------------------------------------------
|
||||
|
||||
To create a new project, open the Pybricks tab and click *create a new project*, as shown in :numref:`fig_newproject`. Enter a project name in the text field that appears and press *Enter*. When prompted, choose a location for this program and confirm by clicking *choose folder*.
|
||||
To create a new project, open the Pybricks tab and click *create a new
|
||||
project*, as shown in :numref:`fig_newproject`. Enter a project name in the
|
||||
text field that appears and press *Enter*. When prompted, choose a location for
|
||||
this program and confirm by clicking *choose folder*.
|
||||
|
||||
.. _fig_newproject:
|
||||
|
||||
@@ -32,11 +44,15 @@ To create a new project, open the Pybricks tab and click *create a new project*,
|
||||
:alt: newproject
|
||||
:align: center
|
||||
|
||||
Creating a new project. This example is called *getting_started*, but you can choose any name.
|
||||
Creating a new project. This example is called *getting_started*, but you
|
||||
can choose any name.
|
||||
|
||||
When you create a new project, it already includes a file called *main.py*. To see its contents and to modify it, open it from the file browser as shown in :numref:`fig_projectoverview`. This is where you'll write your programs.
|
||||
When you create a new project, it already includes a file called *main.py*. To
|
||||
see its contents and to modify it, open it from the file browser as shown in
|
||||
:numref:`fig_projectoverview`. This is where you'll write your programs.
|
||||
|
||||
If you are new to MicroPython programming, we recommend that you keep the existing code in place and add your code to it.
|
||||
If you are new to MicroPython programming, we recommend that you keep the
|
||||
existing code in place and add your code to it.
|
||||
|
||||
.. _fig_projectoverview:
|
||||
|
||||
@@ -50,7 +66,10 @@ If you are new to MicroPython programming, we recommend that you keep the existi
|
||||
Opening an existing project
|
||||
-----------------------------------------------------------
|
||||
|
||||
To open a project you created previously, click *File* and click *Open Folder*, as shown in :numref:`fig_existingproject`. Next, navigate to your previously created project folder and click *OK*. You can also open your recently used projects using the *Open Recent* menu option.
|
||||
To open a project you created previously, click *File* and click *Open Folder*,
|
||||
as shown in :numref:`fig_existingproject`. Next, navigate to your previously
|
||||
created project folder and click *OK*. You can also open your recently used
|
||||
projects using the *Open Recent* menu option.
|
||||
|
||||
.. _fig_existingproject:
|
||||
|
||||
@@ -64,7 +83,9 @@ To open a project you created previously, click *File* and click *Open Folder*,
|
||||
Connecting to the EV3 Brick with Visual Studio Code
|
||||
-----------------------------------------------------------
|
||||
|
||||
To be able to transfer your code to the EV3 Brick, you'll first need to connect the EV3 Brick to your computer with the mini-USB cable and configure the connection with Visual Studio Code. To do so:
|
||||
To be able to transfer your code to the EV3 Brick, you'll first need to connect
|
||||
the EV3 Brick to your computer with the mini-USB cable and configure the
|
||||
connection with Visual Studio Code. To do so:
|
||||
|
||||
- Turn the EV3 Brick on
|
||||
- Connect the EV3 Brick to your computer with the mini-USB cable
|
||||
@@ -82,11 +103,16 @@ To be able to transfer your code to the EV3 Brick, you'll first need to connect
|
||||
Downloading and running a program
|
||||
-----------------------------------------------------------
|
||||
|
||||
You can press the F5 key to run the program. Alternatively, you can start it manually by going to the *debug* tab and clicking the green start arrow, as shown in :numref:`fig_running`.
|
||||
You can press the F5 key to run the program. Alternatively, you can start it
|
||||
manually by going to the *debug* tab and clicking the green start arrow, as
|
||||
shown in :numref:`fig_running`.
|
||||
|
||||
When the program starts, a pop-up toolbar allows you to stop the program if necessary. You can also stop the program at any time using the back button on the EV3 Brick.
|
||||
When the program starts, a pop-up toolbar allows you to stop the program if
|
||||
necessary. You can also stop the program at any time using the back button on
|
||||
the EV3 Brick.
|
||||
|
||||
If your program produces any output with the :mod:`print <.tools>` command, this is shown in the output window.
|
||||
If your program produces any output with the :mod:`print <.tools>` command,
|
||||
this is shown in the output window.
|
||||
|
||||
.. _fig_running:
|
||||
|
||||
@@ -100,7 +126,9 @@ If your program produces any output with the :mod:`print <.tools>` command, this
|
||||
Expanding the example program
|
||||
-----------------------------------------------------------
|
||||
|
||||
Now that you've run the basic code template, you can expand the program to make a motor move. First, attach a Large Motor to Port B on the EV3 Brick, as shown in :numref:`fig_firstprogram`.
|
||||
Now that you've run the basic code template, you can expand the program to make
|
||||
a motor move. First, attach a Large Motor to Port B on the EV3 Brick, as shown
|
||||
in :numref:`fig_firstprogram`.
|
||||
|
||||
.. _fig_firstprogram:
|
||||
|
||||
@@ -115,14 +143,17 @@ Next, edit *main.py* to make it look like this:
|
||||
|
||||
.. literalinclude:: ../../examples/ev3/getting_started/main.py
|
||||
|
||||
This program makes your robot beep, rotate the motor, and beep again with a higher pitched tone. Run the program to make sure that it works as expected.
|
||||
This program makes your robot beep, rotate the motor, and beep again with a
|
||||
higher pitched tone. Run the program to make sure that it works as expected.
|
||||
|
||||
.. _managefiles:
|
||||
|
||||
Managing files on the EV3 Brick
|
||||
-----------------------------------------------------------
|
||||
|
||||
After you've downloaded a project to the EV3 Brick, you can run, delete, or back up programs stored on it using the device browser as shown in in :numref:`fig_files`.
|
||||
After you've downloaded a project to the EV3 Brick, you can run, delete, or
|
||||
back up programs stored on it using the device browser as shown in in
|
||||
:numref:`fig_files`.
|
||||
|
||||
.. _fig_files:
|
||||
|
||||
@@ -139,7 +170,9 @@ Running a program without a computer
|
||||
|
||||
You can run previously downloaded programs directly from the EV3 Brick.
|
||||
|
||||
To do so, find the program using the *file browser* on the EV3 screen and press the center button key to start the program as shown in in :numref:`fig_manualrun`.
|
||||
To do so, find the program using the *file browser* on the EV3 screen and press
|
||||
the center button key to start the program as shown in in
|
||||
:numref:`fig_manualrun`.
|
||||
|
||||
.. _fig_manualrun:
|
||||
|
||||
|
||||
@@ -12,10 +12,10 @@ Motors
|
||||
|
||||
Example::
|
||||
|
||||
# Initialize a motor (by default this means clockwise, without any gears).
|
||||
# Initialize a motor (by default this means is, without any gears).
|
||||
example_motor = Motor(Port.A)
|
||||
|
||||
# Initialize a motor where positive speed values should go counterclockwise
|
||||
# Initialize a motor with positive speed as counterclockwise
|
||||
right_motor = Motor(Port.B, Direction.COUNTERCLOCKWISE)
|
||||
|
||||
# Initialize a motor with a gear train
|
||||
@@ -82,11 +82,13 @@ Motors
|
||||
|
||||
Example::
|
||||
|
||||
# Set the maximum speed to 200 deg/s and acceleration to 400 deg/s/s.
|
||||
# Set the maximum speed to 200 deg/s and
|
||||
# acceleration to 400 deg/s/s.
|
||||
example_motor.set_run_settings(200, 400)
|
||||
|
||||
# Make the motor run for 5 seconds. Even though the speed argument is 300
|
||||
# deg/s in this example, the motor will move at only 200 deg/s because of
|
||||
# Make the motor run for 5 seconds. Even though the
|
||||
# speed argument is 300 deg/s in this example, the
|
||||
# motor will move at only 200 deg/s because of
|
||||
# the settings above.
|
||||
example_motor.run_time(300, 5000)
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
:mod:`movehub` -- LEGO® Power Functions 2.0 Move Hub
|
||||
====================================================
|
||||
======================================================
|
||||
|
||||
.. automodule:: movehub
|
||||
:no-members:
|
||||
|
||||
Reference in New Issue
Block a user