@@ -25,122 +25,126 @@ your EV3 or other ev3dev device as explained in the `ev3dev Getting Started guid
2525Make sure that you have a kernel version that includes ``-10-ev3dev `` or higher (a
2626larger number). You can check the kernel version by selecting "About" in Brickman
2727and scrolling down to the "kernel version". If you don't have a compatible version,
28- `upgrade the kernel before continuing `_. Also note that if the ev3dev image you downloaded
29- was created before September 2016, you probably don't have the most recent version of this
30- library installed: see `Upgrading this Library `_ to upgrade it.
28+ `upgrade the kernel before continuing `_.
3129
32- Once you have booted ev3dev and `connected to your EV3 (or Raspberry Pi / BeagleBone)
33- via SSH `_, you should be ready to start using ev3dev with Python: this library
34- is included out-of-the-box. If you want to go through some basic usage examples,
35- check out the `Usage Examples `_ section to try out motors, sensors and LEDs.
36- Then look at `Writing Python Programs for Ev3dev `_ to see how you can save
37- your Python code to a file.
30+ Usage
31+ -----
3832
39- Make sure that you look at the `User Resources `_ section as well for links
40- to documentation and larger examples.
33+ To start out, you'll need a way to work with Python. We recommend the
34+ `ev3dev Visual Studio Code extension `_. If you're interested in using that,
35+ check out our `Python + VSCode introduction tutorial `_ and then come back
36+ once you have that set up.
4137
42- Usage Examples
43- --------------
38+ Otherwise, you can can work with files `via an SSH connection `_ with an editor
39+ such as `nano `_, use the Python interactive REPL (type ``python3 ``), or roll
40+ your own solution. If you don't know how to do that, you are probably better off
41+ choosing the recommended option above.
4442
45- To run these minimal examples, run the Python3 interpreter from
46- the terminal using the `` python3 `` command:
43+ The template for a Python script
44+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4745
48- .. code-block :: bash
46+ Every Python program should have a few basic parts. Use this template
47+ to get started:
4948
50- $ python3
51- Python 3.4.2 (default, Oct 8 2014, 14:47:30)
52- [GCC 4.9.1] on linux
53- Type " help" , " copyright" , " credits" or " license" for more information.
54- >>>
49+ .. code-block :: python
5550
56- The ``>>> `` characters are the default prompt for Python. In the examples
57- below, we have removed these characters so it's easier to cut and
58- paste the code into your session.
51+ # !/usr/bin/env python3
52+ from ev3dev2.motor import LargeMotor, OUTPUT_A , SpeedPercent
53+ from ev3dev2.sensor.lego import TouchSensor
54+ from ev3dev2.led import Leds
5955
60- Required: Import the library
61- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
56+ # TODO : Add code here
6257
63- If you are using an EV3 brick (which is the case for most users), add the
64- following to the top of your file:
58+ The first line should be included in every Python program you write
59+ for ev3dev. It allows you to run this program from Brickman, the graphical
60+ menu that you see on the device screen. The other lines are import statements
61+ which give you access to the library functionality. You will need to add
62+ additional classes to the import list if you want to use other types of devices
63+ or additional utilities.
6564
66- .. code-block :: python
65+ You should use the `` .py `` extension for your file, e.g. `` my-file.py ``.
6766
68- import ev3dev.ev3 as ev3
67+ Important: Make your script executable (non-Visual Studio Code only)
68+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6969
70- If you are using a BrickPi, use this line:
70+ To be able to run your Python file, **your program must be executable **. If
71+ you are using the `ev3dev Visual Studio Code extension `_, you can skip this step,
72+ as it will be automatically performed when you download your code to the brick.
7173
72- .. code-block :: python
74+ **To mark a program as executable from the command line (often an SSH session),
75+ run ** ``chmod +x my-file.py ``.
7376
74- import ev3dev.brickpi as ev3
77+ You can now run ``my-file.py `` via the Brickman File Browser or you can run it
78+ from the command line by preceding the file name with ``./ ``: ``./my-file.py ``
7579
7680Controlling the LEDs with a touch sensor
7781~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7882
7983This code will turn the left LED red whenever the touch sensor is pressed, and
80- back to green when it's released. Plug a touch sensor into any sensor port and
81- then paste in this code - you'll need to hit ``Enter `` after pasting to complete
82- the loop and start the program. Hit ``Ctrl-C `` to exit the loop.
84+ back to green when it's released. Plug a touch sensor into any sensor port before
85+ trying this out.
8386
8487.. code-block :: python
8588
86- ts = ev3.TouchSensor()
89+ ts = TouchSensor()
90+ leds = Leds()
91+
8792 while True :
88- ev3.Leds.set_color(ev3.Leds.LEFT , (ev3.Leds.GREEN , ev3.Leds.RED )[ts.value()])
93+ if ts.is_pressed:
94+ leds.set_color(leds.led_groups.LEFT , leds.led_colors.GREEN )
95+ else :
96+ leds.set_color(leds.led_groups.LEFT , leds.led_colors.RED )
8997
9098 Running a motor
9199~~~~~~~~~~~~~~~
92100
93- Now plug a motor into the ``A `` port and paste this code into the Python prompt.
94- This little program will run the motor at 500 ticks per second, which on the EV3
95- "large" motors equates to around 1.4 rotations per second, for three seconds
96- (3000 milliseconds).
101+ This will run a LEGO Large Motor at 75% of maximum speed for 5 rotations.
97102
98103.. code-block :: python
99104
100- m = ev3. LargeMotor(' outA ' )
101- m.run_timed( time_sp = 3000 , speed_sp = 500 )
105+ m = LargeMotor(OUTPUT_A )
106+ m.on_for_rotations(SpeedPercent( 75 ), 5 )
102107
103- The units for `` speed_sp `` that you see above are in "tacho ticks" per second.
104- On the large EV3 motor, these equate to one tick per degree, so this is 500
105- degress per second.
108+ You can also run a motor for a number of degrees, an amount of time, or simply
109+ start it and let it run until you tell it to stop. Additionally, other units are
110+ also available. See the following pages for more information:
106111
112+ - http://python-ev3dev.readthedocs.io/en/stretch/motors.html#ev3dev.motor.Motor.on_for_degrees
113+ - http://python-ev3dev.readthedocs.io/en/stretch/motors.html#units
107114
115+ Driving with two motors
116+ ~~~~~~~~~~~~~~~~~~~~~~~
108117
109- Using text-to-speech
110- ~~~~~~~~~~~~~~~~~~~~
111-
112- If you want to make your robot speak, you can use the `Sound.speak ` method:
118+ The simplest drive control style is with the `MoveTank ` class:
113119
114120.. code-block :: python
115121
116- ev3.Sound.speak( ' Welcome to the E V 3 dev project! ' ).wait( )
122+ drive = MoveTank( OUTPUT_A , OUTPUT_B )
117123
118- **To quit the Python REPL, just type ** ``exit() `` **or press ** ``Ctrl-D `` **. **
124+ # drive in a turn for 5 rotations of the outer motor
125+ # the first two parameters are percentages; they can also be unit classes.
126+ drive.on_for_rotations(50 , 75 , 10 )
127+
128+ # drive in a different turn for 3 rotations of the outer motor
129+ drive.on_for_rotations(60 , 30 , 3 )
119130
120- Make sure to check out the ` User Resources `_ section for more detailed
121- information on these features and many others .
131+ There are also ` MoveSteering ` and ` MoveJoystick ` classes which provide different
132+ styles of control. Take a look at the corresponding documentation for more detail .
122133
123- Writing Python Programs for Ev3dev
124- ----------------------------------
134+ Using text-to-speech
135+ ~~~~~~~~~~~~~~~~~~~~
125136
126- Every Python program should have a few basic parts. Use this template
127- to get started:
137+ If you want to make your robot speak, you can use the ``Sound.speak `` method:
128138
129139.. code-block :: python
130140
131- # !/usr/bin/env python3
132- from ev3dev.ev3 import *
141+ from ev3dev2.sound import Sound
133142
134- # TODO : Add code here
143+ sound = Sound()
144+ sound.speak(' Welcome to the E V 3 dev project!' ).wait()
135145
136- The first two lines should be included in every Python program you write
137- for ev3dev. The first allows you to run this program from Brickman, while the
138- second imports this library.
139-
140- When saving Python files, it is best to use the ``.py `` extension, e.g. ``my-file.py ``.
141- To be able to run your Python code, **your program must be executable **. To mark a
142- program as executable run ``chmod +x my-file.py ``. You can then run ``my-file.py ``
143- via the Brickman File Browser or you can run it from the command line via ``$ ./my-file.py ``
146+ Make sure to check out the `User Resources `_ section for more detailed
147+ information on these features and many others.
144148
145149User Resources
146150--------------
@@ -150,6 +154,11 @@ Library Documentation
150154 You can always go there to get information on how you can use this
151155 library's functionality.
152156
157+ Demo Code
158+ There are several demo programs that you can run to get acquainted with
159+ this language binding. The programs are available at
160+ https://github.com/ev3dev/ev3dev-lang-python-demo
161+
153162ev3python.com
154163 One of our community members, @ndward, has put together a great website
155164 with detailed guides on using this library which are targeted at beginners.
@@ -171,11 +180,6 @@ Support
171180 what you are trying to do and what you have tried. The issue template
172181 is in place to guide you through this process.
173182
174- Demo Code
175- There are several demo programs that you can run to get acquainted with
176- this language binding. The programs are available at
177- https://github.com/ev3dev/ev3dev-lang-python-demo
178-
179183Upgrading this Library
180184----------------------
181185
@@ -196,16 +200,6 @@ Python Package Index
196200 libraries that others have written, including the `latest version of
197201 this package `_.
198202
199- The ev3dev Binding Specification
200- Like all of the language bindings for ev3dev _ supported hardware, the
201- Python binding follows the minimal API that must be provided per
202- `this document `_.
203-
204- The ev3dev-lang Project on GitHub
205- The `source repository for the generic API `_ and the scripts to automatically
206- generate the binding. Only developers of the ev3dev-lang-python _ binding
207- would normally need to access this information.
208-
209203Python 2.x and Python 3.x Compatibility
210204---------------------------------------
211205
@@ -222,17 +216,13 @@ Python 3 and this is the only version that will be supported from here forward.
222216.. _ev3dev-getting-started : http://www.ev3dev.org/docs/getting-started/
223217.. _upgrade the kernel before continuing : http://www.ev3dev.org/docs/tutorials/upgrading-ev3dev/
224218.. _detailed instructions for USB connections : ev3dev-usb-internet _
225- .. _ connected to your EV3 (or Raspberry Pi / BeagleBone) via SSH : http://www.ev3dev.org/docs/tutorials/connecting-to-ev3dev-with-ssh/
219+ .. _ via an SSH connection : http://www.ev3dev.org/docs/tutorials/connecting-to-ev3dev-with-ssh/
226220.. _ev3dev-usb-internet : http://www.ev3dev.org/docs/tutorials/connecting-to-the-internet-via-usb/
227221.. _our Read the Docs page : http://python-ev3dev.readthedocs.org/en/stable/
228- .. _source repository for the generic API : ev3dev-lang _
229222.. _ev3python.com : http://ev3python.com/
230223.. _FAQ : http://python-ev3dev.readthedocs.io/en/stable/faq.html
231- .. _ev3dev-lang : https://github.com/ev3dev/ev3dev-lang
232224.. _ev3dev-lang-python : https://github.com/rhempel/ev3dev-lang-python
233225.. _our Issues tracker : https://github.com/rhempel/ev3dev-lang-python/issues
234- .. _this document : wrapper-specification _
235- .. _wrapper-specification : https://github.com/ev3dev/ev3dev-lang/blob/develop/wrapper-specification.md
236226.. _EXPLOR3R : demo-robot _
237227.. _demo-robot : http://robotsquare.com/2015/10/06/explor3r-building-instructions/
238228.. _demo programs : demo-code _
@@ -246,3 +236,6 @@ Python 3 and this is the only version that will be supported from here forward.
246236.. _pypi : https://pypi.python.org/pypi
247237.. _latest version of this package : pypi-python-ev3dev _
248238.. _pypi-python-ev3dev : https://pypi.python.org/pypi/python-ev3dev
239+ .. _ev3dev Visual Studio Code extension : https://github.com/ev3dev/vscode-ev3dev-browser
240+ .. _Python + VSCode introduction tutorial : https://github.com/ev3dev/vscode-hello-python
241+ .. _nano : http://www.ev3dev.org/docs/tutorials/nano-cheat-sheet/
0 commit comments