-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstartrun.html
402 lines (279 loc) · 20 KB
/
startrun.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Creating and running programs — ev3-micropython 2.0.0 documentation</title>
<script type="text/javascript" src="_static/js/modernizr.min.js"></script>
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT:'./',
VERSION:'2.0.0',
LANGUAGE:'None',
COLLAPSE_INDEX:false,
FILE_SUFFIX:'.html',
HAS_SOURCE: true,
SOURCELINK_SUFFIX: '.txt'
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script type="text/javascript" src="_static/contentui.js"></script>
<script type="text/javascript" src="_static/js/theme.js"></script>
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="_static/contentui.css" type="text/css" />
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Accessing advanced EV3 features" href="startlinux.html" />
<link rel="prev" title="Using the EV3 Brick" href="startbrick.html" />
<link rel="stylesheet" href="_static/css/theme_overrides.css" type="text/css">
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="index.html">
<img src="_static/lego-education-logo-small.png" class="logo" alt="Logo"/>
</a>
<div class="version">
2.0.0
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<p class="caption"><span class="caption-text">Getting Started</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="startinstall.html">Installation</a></li>
<li class="toctree-l1"><a class="reference internal" href="startbrick.html">Using the EV3 Brick</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">Creating and running programs</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#creating-a-new-project">Creating a new project</a></li>
<li class="toctree-l2"><a class="reference internal" href="#opening-an-existing-project">Opening an existing project</a></li>
<li class="toctree-l2"><a class="reference internal" href="#connecting-to-the-ev3-brick-with-visual-studio-code">Connecting to the EV3 Brick with Visual Studio Code</a></li>
<li class="toctree-l2"><a class="reference internal" href="#downloading-and-running-a-program">Downloading and running a program</a></li>
<li class="toctree-l2"><a class="reference internal" href="#expanding-the-example-program">Expanding the example program</a></li>
<li class="toctree-l2"><a class="reference internal" href="#managing-files-on-the-ev3-brick">Managing files on the EV3 Brick</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="startlinux.html">Accessing advanced EV3 features</a></li>
<li class="toctree-l1"><a class="reference internal" href="startupgrade.html">Upgrading from v1.0 to v2.0</a></li>
</ul>
<p class="caption"><span class="caption-text">Pybricks Modules</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="hubs.html"><code class="docutils literal notranslate"><span class="pre">hubs</span></code> – Programmable Hubs</a></li>
<li class="toctree-l1"><a class="reference internal" href="ev3devices.html"><code class="docutils literal notranslate"><span class="pre">ev3devices</span></code> – EV3 Devices</a></li>
<li class="toctree-l1"><a class="reference internal" href="nxtdevices.html"><code class="docutils literal notranslate"><span class="pre">nxtdevices</span></code> – NXT Devices</a></li>
<li class="toctree-l1"><a class="reference internal" href="iodevices.html"><code class="docutils literal notranslate"><span class="pre">iodevices</span></code> – Generic I/O Devices</a></li>
<li class="toctree-l1"><a class="reference internal" href="parameters.html"><code class="docutils literal notranslate"><span class="pre">parameters</span></code> – Parameters and Constants</a></li>
<li class="toctree-l1"><a class="reference internal" href="tools.html"><code class="docutils literal notranslate"><span class="pre">tools</span></code> – Timing and Data logging</a></li>
<li class="toctree-l1"><a class="reference internal" href="robotics.html"><code class="docutils literal notranslate"><span class="pre">robotics</span></code> – Robotics</a></li>
<li class="toctree-l1"><a class="reference internal" href="media.html"><code class="docutils literal notranslate"><span class="pre">media</span></code> – Sounds and Images</a></li>
<li class="toctree-l1"><a class="reference internal" href="messaging.html"><code class="docutils literal notranslate"><span class="pre">messaging</span></code> – Messaging</a></li>
</ul>
<p class="caption"><span class="caption-text">Engineering Extras</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="signaltypes.html">Signals and Units</a></li>
<li class="toctree-l1"><a class="reference internal" href="motors.html">More about Motors</a></li>
</ul>
<p class="caption"><span class="caption-text">Robot Educator Programs</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="examples/robot_educator_basic.html">Basic Movement</a></li>
<li class="toctree-l1"><a class="reference internal" href="examples/robot_educator_ultrasonic.html">Obstacle Avoidance</a></li>
<li class="toctree-l1"><a class="reference internal" href="examples/robot_educator_line.html">Line Following</a></li>
</ul>
<p class="caption"><span class="caption-text">Core Set Programs</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="examples/color_sorter.html">Color Sorter</a></li>
<li class="toctree-l1"><a class="reference internal" href="examples/robot_arm.html">Robot Arm H25</a></li>
<li class="toctree-l1"><a class="reference internal" href="examples/puppy.html">Puppy</a></li>
<li class="toctree-l1"><a class="reference internal" href="examples/gyro_boy.html">Gyro Boy</a></li>
</ul>
<p class="caption"><span class="caption-text">Expansion Set Programs</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="examples/elephant.html">Elephant</a></li>
<li class="toctree-l1"><a class="reference internal" href="examples/stair_climber.html">Stair Climber</a></li>
<li class="toctree-l1"><a class="reference internal" href="examples/tank_bot.html">Tank Bot</a></li>
<li class="toctree-l1"><a class="reference internal" href="examples/znap.html">Znap</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="index.html">ev3-micropython</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content style-external-links">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="index.html">Docs</a> »</li>
<li>Creating and running programs</li>
<li class="wy-breadcrumbs-aside">
<a href="_sources/startrun.rst.txt" rel="nofollow"> View page source</a>
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<div class="section" id="creating-and-running-programs">
<h1>Creating and running programs<a class="headerlink" href="#creating-and-running-programs" title="Permalink to this headline">¶</a></h1>
<p>Now that you’ve set up your computer and EV3 Brick, you’re ready to start
writing programs.</p>
<p>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.</p>
<p>Programs are organized into <em>project folders</em>, as shown in
<a class="reference internal" href="#fig-projectstructure"><span class="std std-numref">Figure 8</span></a>. A project folder is a directory on your
computer that contains the main program (<strong>main.py</strong>) 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.</p>
<p>This page shows you how to create such a project and how to transfer it to the
EV3 Brick.</p>
<div class="figure align-center" id="id1">
<span id="fig-projectstructure"></span><img alt="projectstructure" src="_images/projectstructure_label.png" style="width: 100%;" />
<p class="caption"><span class="caption-number">Figure 8 </span><span class="caption-text">A project contains a program called <strong>main.py</strong> and optional resources like
sounds or MicroPython modules.</span></p>
</div>
<div class="section" id="creating-a-new-project">
<h2>Creating a new project<a class="headerlink" href="#creating-a-new-project" title="Permalink to this headline">¶</a></h2>
<p>To create a new project, open the EV3 MicroPython tab and
click <em>create a new project</em>, as shown in <a class="reference internal" href="#fig-newproject"><span class="std std-numref">Figure 9</span></a>. Enter a
project name in the text field that appears and press <em>Enter</em>. When prompted,
choose a location for this program and confirm by clicking <em>choose folder</em>.</p>
<div class="figure align-center" id="id2">
<span id="fig-newproject"></span><img alt="newproject" src="_images/newproject_label.png" style="width: 100%;" />
<p class="caption"><span class="caption-number">Figure 9 </span><span class="caption-text">Creating a new project. This example is called <em>getting_started</em>, but you
can choose any name.</span></p>
</div>
<p>When you create a new project, it already includes a file called <em>main.py</em>. To
see its contents and to modify it, open it from the file browser as shown in
<a class="reference internal" href="#fig-projectoverview"><span class="std std-numref">Figure 10</span></a>. This is where you’ll write your programs.</p>
<p>If you are new to MicroPython programming, we recommend that you keep the
existing code in place and add your code to it.</p>
<div class="figure align-center" id="id3">
<span id="fig-projectoverview"></span><img alt="projectoverview" src="_images/projectoverview_label.png" style="width: 100%;" />
<p class="caption"><span class="caption-number">Figure 10 </span><span class="caption-text">Opening the default <em>main.py</em> program.</span></p>
</div>
</div>
<div class="section" id="opening-an-existing-project">
<h2>Opening an existing project<a class="headerlink" href="#opening-an-existing-project" title="Permalink to this headline">¶</a></h2>
<p>To open a project you created previously, click <em>File</em> and click
<em>Open Folder</em>, as shown in <a class="reference internal" href="#fig-existingproject"><span class="std std-numref">Figure 11</span></a>. Next, navigate to
your previously created project folder and click <em>OK</em>. You can also open your
recently used projects using the <em>Open Recent</em> menu option.</p>
<div class="figure align-center" id="id4">
<span id="fig-existingproject"></span><img alt="existingproject" src="_images/existingproject_label.png" style="width: 75%;" />
<p class="caption"><span class="caption-number">Figure 11 </span><span class="caption-text">Opening a previously created project.</span></p>
</div>
</div>
<div class="section" id="connecting-to-the-ev3-brick-with-visual-studio-code">
<h2>Connecting to the EV3 Brick with Visual Studio Code<a class="headerlink" href="#connecting-to-the-ev3-brick-with-visual-studio-code" title="Permalink to this headline">¶</a></h2>
<p>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:</p>
<ul class="simple">
<li>Turn the EV3 Brick on</li>
<li>Connect the EV3 Brick to your computer with the mini-USB cable</li>
<li>Configure the USB connection as shown in <a class="reference internal" href="#fig-connecting"><span class="std std-numref">Figure 12</span></a>.</li>
</ul>
<div class="figure align-center" id="id5">
<span id="fig-connecting"></span><img alt="connecting" src="_images/connecting_label.png" style="width: 100%;" />
<p class="caption"><span class="caption-number">Figure 12 </span><span class="caption-text">Configuring the USB connection between the computer and the EV3 Brick</span></p>
</div>
</div>
<div class="section" id="downloading-and-running-a-program">
<h2>Downloading and running a program<a class="headerlink" href="#downloading-and-running-a-program" title="Permalink to this headline">¶</a></h2>
<p>You can press the F5 key to run the program. Alternatively, you can start it
manually by going to the <em>debug</em> tab and clicking the green start arrow, as
shown in <a class="reference internal" href="#fig-running"><span class="std std-numref">Figure 13</span></a>.</p>
<p>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.</p>
<p>If your program produces any output with the <code class="docutils literal notranslate"><span class="pre">print</span></code> command, this is shown
in the output window.</p>
<div class="figure align-center" id="id6">
<span id="fig-running"></span><img alt="running" src="_images/running_label.png" style="width: 100%;" />
<p class="caption"><span class="caption-number">Figure 13 </span><span class="caption-text">Running a program</span></p>
</div>
</div>
<div class="section" id="expanding-the-example-program">
<h2>Expanding the example program<a class="headerlink" href="#expanding-the-example-program" title="Permalink to this headline">¶</a></h2>
<p>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 <a class="reference internal" href="#fig-firstprogram"><span class="std std-numref">Figure 14</span></a>.</p>
<div class="figure align-center" id="id7">
<span id="fig-firstprogram"></span><img alt="firstprogram" src="_images/firstprogram_label.png" style="width: 100%;" />
<p class="caption"><span class="caption-number">Figure 14 </span><span class="caption-text">The EV3 Brick with a Large Motor attached to port B.</span></p>
</div>
<p>Next, edit <em>main.py</em> to make it look like this:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="ch">#!/usr/bin/env pybricks-micropython</span>
<span class="kn">from</span> <span class="nn">pybricks.hubs</span> <span class="kn">import</span> <span class="n">EV3Brick</span>
<span class="kn">from</span> <span class="nn">pybricks.ev3devices</span> <span class="kn">import</span> <span class="n">Motor</span>
<span class="kn">from</span> <span class="nn">pybricks.parameters</span> <span class="kn">import</span> <span class="n">Port</span>
<span class="c1"># Create your objects here</span>
<span class="c1"># Initialize the EV3 Brick.</span>
<span class="n">ev3</span> <span class="o">=</span> <span class="n">EV3Brick</span><span class="p">()</span>
<span class="c1"># Initialize a motor at port B.</span>
<span class="n">test_motor</span> <span class="o">=</span> <span class="n">Motor</span><span class="p">(</span><span class="n">Port</span><span class="o">.</span><span class="n">B</span><span class="p">)</span>
<span class="c1"># Write your program here</span>
<span class="c1"># Play a sound.</span>
<span class="n">ev3</span><span class="o">.</span><span class="n">speaker</span><span class="o">.</span><span class="n">beep</span><span class="p">()</span>
<span class="c1"># Run the motor up to 500 degrees per second. To a target angle of 90 degrees.</span>
<span class="n">test_motor</span><span class="o">.</span><span class="n">run_target</span><span class="p">(</span><span class="mi">500</span><span class="p">,</span> <span class="mi">90</span><span class="p">)</span>
<span class="c1"># Play another beep sound.</span>
<span class="n">ev3</span><span class="o">.</span><span class="n">speaker</span><span class="o">.</span><span class="n">beep</span><span class="p">(</span><span class="n">frequency</span><span class="o">=</span><span class="mi">1000</span><span class="p">,</span> <span class="n">duration</span><span class="o">=</span><span class="mi">500</span><span class="p">)</span>
</pre></div>
</div>
<p>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.</p>
</div>
<div class="section" id="managing-files-on-the-ev3-brick">
<span id="managefiles"></span><h2>Managing files on the EV3 Brick<a class="headerlink" href="#managing-files-on-the-ev3-brick" title="Permalink to this headline">¶</a></h2>
<p>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
<a class="reference internal" href="#fig-files"><span class="std std-numref">Figure 15</span></a>.</p>
<div class="figure align-center" id="id8">
<span id="fig-files"></span><img alt="files" src="_images/files_label.png" style="width: 100%;" />
<p class="caption"><span class="caption-number">Figure 15 </span><span class="caption-text">Using the EV3 device browser to manage files on your EV3 Brick</span></p>
</div>
</div>
</div>
</div>
</div>
<footer>
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
<a href="startlinux.html" class="btn btn-neutral float-right" title="Accessing advanced EV3 features" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
<a href="startbrick.html" class="btn btn-neutral float-left" title="Using the EV3 Brick" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
</div>
<hr/>
<div role="contentinfo">
<p>
© Copyright 2019-2020 The LEGO Group. All rights reserved.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
<div class="disclaimer">LEGO, the LEGO logo, MINDSTORMS and the MINDSTORMS EV3 logo are trademarks and/or copyrights of the LEGO Group.</div>
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>