-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-your-first-project.html
More file actions
320 lines (302 loc) · 11.4 KB
/
create-your-first-project.html
File metadata and controls
320 lines (302 loc) · 11.4 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=edge"><![endif]-->
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="Asciidoctor 1.5.5">
<title>docs</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:300,300italic,400,400italic,600,600italic%7CNoto+Serif:400,400italic,700,700italic%7CDroid+Sans+Mono:400,700">
<link rel="stylesheet" href="./asciidoctor.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css">
</head>
<body class="article toc2 toc-left">
<div id="header">
<h1>Create your first Project</h1>
<div class="details">
<span id="revnumber">version 2.4.16</span>
</div>
<div id="toc" class="toc2">
<div id="toctitle">Table of Contents</div>
<ul class="sectlevel1">
<li><a href="#introduction">1. Introduction</a></li>
<li><a href="#create-your-first-project-using-the-gradle-template-project">2. Create your first project using the Gradle template project</a>
<ul class="sectlevel2">
<li><a href="#clone-download-the-project-in-your-computer">2.1. Clone/Download the project in your computer</a></li>
<li><a href="#configure-the-brick-ip">2.2. Configure the Brick IP</a></li>
<li><a href="#deploy-the-default-program">2.3. Deploy the default program</a></li>
<li><a href="#add-a-new-java-program">2.4. Add a new Java program</a></li>
</ul>
</li>
<li><a href="#create-your-first-project-from-scratch">3. Create your first project from scratch</a></li>
<li><a href="#playing-with-more-examples">4. Playing with more examples</a></li>
<li><a href="#the-next-step">5. The Next Step</a></li>
</ul>
</div>
</div>
<div id="content">
<div class="sect1">
<h2 id="introduction">1. Introduction</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Create your first project is not complicated but the process requires time and this is the reason to
develop a <code>Template project</code> using <code>Gradle</code>.</p>
</div>
<div class="paragraph">
<p>The advantages of the usage of the Template project are:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>Build System configured</p>
</li>
<li>
<p>Dependencies defined</p>
</li>
<li>
<p>Tasks defined to interact with the Brick</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>Further information about <code>Template project</code> <a href="https://github.com/ev3dev-lang-java/template-project-gradle">here</a></p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="create-your-first-project-using-the-gradle-template-project">2. Create your first project using the Gradle template project</h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="clone-download-the-project-in-your-computer">2.1. Clone/Download the project in your computer</h3>
<div class="paragraph">
<p>The project <code>Template project</code> is hosted on Github and it possible to download the content of a Git branch or
execute the following statement to clone the project in local.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code>git clone https://github.com/ev3dev-lang-java/template_project_gradle.git</code></pre>
</div>
</div>
<div class="paragraph">
<p>Now you have you have in local the project.
Open the project with your favourite Java IDE.</p>
</div>
</div>
<div class="sect2">
<h3 id="configure-the-brick-ip">2.2. Configure the Brick IP</h3>
<div class="paragraph">
<p>In the project opened, open the file: <code>config.gradle</code>: to update IP of you Brick connected to the network
where your computer is connected:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code>remotes {
ev3dev {
host = '10.0.1.3'
user = 'robot'
password = 'maker'
}
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>to check that the Java IDE connects with the Brick, execute the following Gradle task:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code>./gradlew testConnection</code></pre>
</div>
</div>
<div class="paragraph">
<p>If the execution of the task was successfully then your computer has a direct connection with your Brick.</p>
</div>
</div>
<div class="sect2">
<h3 id="deploy-the-default-program">2.3. Deploy the default program</h3>
<div class="paragraph">
<p>The template project includes a Default program named <code>MyFirstRobot.java</code>.
The example was designed to move a Mobile Robot with 2 motors connected to Port A & Port B.
If you need inspiration to create your Physical robot, <code>LEGO Education</code> provides some excellent
<a href="https://education.lego.com/en-us/support/mindstorms-ev3/building-instructions">Building Instructions Guides</a></p>
</div>
<div class="paragraph">
<p><span class="image"><img src="baseRobot.png" alt="Base Robot"></span></p>
</div>
<div class="paragraph">
<p>Follow the <a href="https://le-www-live-s.legocdn.com/sc/media/lessons/mindstorms-ev3/building-instructions/ev3-rem-driving-base-79bebfc16bd491186ea9c9069842155e.pdf">link</a> to build the Base Robot.</p>
</div>
<div class="paragraph">
<p><strong>MyFirstRobot.java</strong></p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-java" data-lang="java">package examples;
import ev3dev.actuators.lego.motors.EV3LargeRegulatedMotor;
import ev3dev.sensors.Battery;
import lejos.hardware.port.MotorPort;
import lejos.utility.Delay;
public class MyFirstRobot {
public static void main(final String[] args){
System.out.println("Creating Motor A & B");
final EV3LargeRegulatedMotor motorLeft = new EV3LargeRegulatedMotor(MotorPort.A);
final EV3LargeRegulatedMotor motorRight = new EV3LargeRegulatedMotor(MotorPort.B);
//To Stop the motor in case of pkill java for example
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
public void run() {
System.out.println("Emergency Stop");
motorLeft.stop();
motorRight.stop();
}
}));
System.out.println("Defining the Stop mode");
motorLeft.brake();
motorRight.brake();
System.out.println("Defining motor speed");
final int motorSpeed = 200;
motorLeft.setSpeed(motorSpeed);
motorRight.setSpeed(motorSpeed);
System.out.println("Go Forward with the motors");
motorLeft.forward();
motorRight.forward();
Delay.msDelay(2000);
System.out.println("Stop motors");
motorLeft.stop();
motorRight.stop();
System.out.println("Go Backward with the motors");
motorLeft.backward();
motorRight.backward();
Delay.msDelay(2000);
System.out.println("Stop motors");
motorLeft.stop();
motorRight.stop();
System.out.println("Checking Battery");
System.out.println("Votage: " + Battery.getInstance().getVoltage());
System.exit(0);
}
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>To deploy the example on your brick, open a <code>terminal</code> and type:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code>./gradlew deployAndBrickRun</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="add-a-new-java-program">2.4. Add a new Java program</h3>
<div class="paragraph">
<p>Once you feel comfortable with the Template project and the Gradle Tasks, you could feel the need to add your
own program. In this case, add in the project the new Java file like this one:</p>
</div>
<div class="paragraph">
<p><strong>HelloWorld.java</strong></p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-java" data-lang="java">public class HelloWorld {
public static void main(String[] args) {
// Prints "Hello World" to the terminal window.
System.out.println("Hello World");
}
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>In order to run the new program, you will have to open the file MANIFEST.MF and update the field about <code>Main-Class</code>
indicating the new class, in this case <code>HelloWorld</code></p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-java" data-lang="java">Manifest-Version: 1.0
Implementation-Title: EV3Dev-lang-java // Template project
Implementation-Version: 0.3.0
Implementation-Vendor: YOUR NAME
Main-Class: HelloWorld</code></pre>
</div>
</div>
<div class="paragraph">
<p>To deploy the new example on your brick, open a <code>terminal</code> and type:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code>./gradlew deployAndBrickRun</code></pre>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="create-your-first-project-from-scratch">3. Create your first project from scratch</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Another alternative is the creation of a project from Scratch using Maven/Gradle.</p>
</div>
<div class="paragraph">
<p>To start a new project with this library, add the following repository and dependency.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-xml" data-lang="xml"><repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories></code></pre>
</div>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-xml" data-lang="xml"><dependency>
<groupId>com.github.ev3dev-lang-java</groupId>
<artifactId>ev3dev-lang-java</artifactId>
<version>2.4.16</version>
</dependency></code></pre>
</div>
</div>
<div class="paragraph">
<p>Further information about <a href="https://jitpack.io/#ev3dev-lang-java/ev3dev-lang-java/2.4.16">the dependency</a></p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="playing-with-more-examples">4. Playing with more examples</h2>
<div class="sectionbody">
<div class="paragraph">
<p>The project has a repository with several examples about the usage of the different libraries.</p>
</div>
<div class="paragraph">
<p>Visit the <a href="https://github.com/ev3dev-lang-java/examples">repository about examples</a> to download and test more examples.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="the-next-step">5. The Next Step</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Continue with the next section about: <a href="../#fundamentals-of-robotics">Fundamentals of Robotics</a></p>
</div>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-343143-18', 'auto');
ga('send', 'pageview');
</script>
</div>
</div>
</div>
<div id="footer">
<div id="footer-text">
Version 2.4.16<br>
Last updated 2021-01-09 15:56:33 CET
</div>
</div>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prettify/r298/prettify.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/prettify/r298/prettify.min.js"></script>
<script>prettyPrint()</script>
</body>
</html>