Hide last authors
aas2 3.1 1 = Program LEGO Mindstorms with leJOS and SCCharts =
2
3
4
5 {{toc minLevel="2"/}}
6
7 ----
8
9 == Overview ==
10
aas2 21.1 11 Mindstorms is a product family from Lego, with sensors, motors and a programmable brick. The newest iteration of the product family is the EV3 programmable brick. Its predecessors are NXT and RCX. In the following we will see how to develop applications for the NXT brick.
aas2 1.1 12
aas2 7.1 13 Several open-source, third-party replacements for the offical Lego firmware have been developed. These support many well known programming languages, such as Java, C/C++, Python, Lua, etc. In the following we will use KIELER SCCharts to program Mindstorms running the Lego Java Operating System ([[leJOS>>url:http://www.lejos.org/||shape="rect"]]). Therefore we will first install leJOS NXJ and flash its firmware. Afterwards we will create a simple SCCharts project in KIELER that we will compile and deploy to the NXT brick.
aas2 5.1 14
aas2 35.1 15 If you want to learn the SCCharts langugage first, you can follow these links:
16
aas2 42.1 17 * [[Introduction to SCCharts>>doc:SCCharts (pre 1\.0)]]
Soeren Domroes 44.1 18 * [[The Textual SCCharts Language SCT>>doc:Textual SCCharts Language SCT]]
aas2 35.1 19 * [[SCCharts Examples>>doc:Examples]]
20
aas2 3.1 21 ----
22
23 == Download and install leJOS ==
24
cmot 22.1 25 Download and extract the newest archives for your Operating System from [[Sourceforce>>url:http://sourceforge.net/projects/nxt.lejos.p/files/||shape="rect"]] (Linux/Mac) or use the Setup.exe (Windows).
aas2 3.1 26
aas2 7.1 27 The further installation is explained in detail at [[http:~~/~~/www.lejos.org/nxt/nxj/tutorial/Preliminaries/GettingStarted.htm>>url:http://www.lejos.org/nxt/nxj/tutorial/Preliminaries/GettingStarted.htm||shape="rect"]].
aas2 3.1 28
aas2 31.1 29 Do not forget to flash the download leJOS firmware to the Mindstorms brick as explained in the tutorial!
30
aas2 7.1 31 === Known issues ===
aas2 3.1 32
aas2 27.1 33 ==== Linux ====
aas2 17.1 34
aas2 7.1 35 On Linux there is an issue when uploading the firmware because of a kernel module ([[http:~~/~~/ubuntuforums.org/showthread.php?t=1123633>>url:http://ubuntuforums.org/showthread.php?t=1123633||shape="rect"]]). If you can't upload the firmware with your Linux OS, add **blacklist cdc_acm**{{code language="none"}}{{/code}} at the very end of the file **{{code language="none"}}/etc/modprobe.d/blacklist.conf{{/code}}**. Afterwards execute **{{code language="none"}}sudo rmmod cdc_acm{{/code}}**. This will remove the cdc_acm module from the kernel and prevent its restart. Now try to flash the firmware again.
aas2 3.1 36
aas2 17.1 37 Another issue is that the development package of **libusb** has to be installed. On Ubuntu you can do this by using **{{code language="none"}}sudo apt-get install libusb-dev{{/code}}**.
38
aas2 30.1 39 Furthermore, to use USB connection, a java library has to be compiled via **ant**. To do this perform **cd /path/to/leJOS/build** and start **ant**. If the ant build tool is not installed on your system, you can do so via **sudo apt-get install ant**.
aas2 17.1 40
aas2 27.1 41 ==== Windows ====
42
43 The setup.exe of the current LEGO Fantom driver for Windows (1.2.0) has an awkward issue. If you get an error message (Developer Error) because an .msi file could not be found, don't panic. The file is part of the downladed archive (in the Products folder) but you have to start it manually.
44
aas2 30.1 45 ==== Mac OS X ====
46
47 The **leJOS NXJ** tools require a **32 Bit** version of Java. However, newer 32 Bit versions of Java are not longer available for Mac. Thus to use leJOS the installation of **Java 1.6 is required**, which is the last one that supports a 32 Bit mode. You can download the installer for Java 1.6 from [[https:~~/~~/support.apple.com/kb/dl1572?locale=en_US>>url:https://support.apple.com/kb/dl1572?locale=en_US||shape="rect"]]. It will install Java 1.6 to ///System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home// so that the environment variable //LEJOS_NXT_JAVA_HOME//, which is set in the installation instructions, points to the correct path.
48
aas2 33.1 49 The environment variable LEJOS_NXT_JAVA_HOME is set in the installation tutorial by editing ~~/.profile. However, on a Mac the environment variables defined in this file are not visible for GUI Applications, only for apps started from terminal. Thus to use leJOS together with KIELER, one either has to start KIELER from terminal or set the environment variable so that all GUI applications can access it. However, this does not seem to be trivial on Mac (see also [[http:~~/~~/stackoverflow.com/questions/135688/setting-environment-variables-in-os-x>>url:http://stackoverflow.com/questions/135688/setting-environment-variables-in-os-x||shape="rect"]]).
aas2 30.1 50
aas2 3.1 51 ----
52
aas2 7.1 53 == Test the Mindstorm ==
aas2 3.1 54
aas2 7.1 55 A simple Hello World application for the Mindstorms is developed as part of the leJOS tutorial [[http:~~/~~/www.lejos.org/nxt/nxj/tutorial/Preliminaries/FirstProgram.htm>>url:http://www.lejos.org/nxt/nxj/tutorial/Preliminaries/FirstProgram.htm||shape="rect"]]
aas2 3.1 56
aas2 27.1 57 If this works with your device, you are able to start using KIELER to develop applications for the NXT brick.
aas2 3.1 58
59 ----
60
aas2 28.1 61 == Download and Configure KIELER
62 ==
aas2 27.1 63
64 Download and unpack the nightly build of KIELER for your OS. It is available at the [[doc:Downloads]] page.\\
65
aas2 33.1 66 **Note:** Java 1.8 is needed on all operating systems. With Java 1.7 not all plugins of KIELER will be loaded. **Furthermore on Windows**, you will need to download the **32 Bit version of KIELER** – even if you have a 64 bit operating system! Otherwise flashing the brick and uploading to the brick will fail.
aas2 27.1 67
aas2 28.1 68 === The Eclipse plugin for leJOS ===
aas2 27.1 69
cmot 24.1 70 There is an Eclipse plugin for leJOS which adds a project creation wizard and launch configuration to the platform.
aas2 3.1 71
cmot 24.1 72 1. You have to install it via the Eclipse Marketplace (//Help > Eclipse Marketplace...//).
73 OR
cmot 25.1 74 1. Install the plugin manually (Help > Install new Software...). Use the following update site\\
75 11. for NXT: [[http:~~/~~/www.lejos.org/tools/eclipse/plugin/nxj/>>url:http://www.lejos.org/tools/eclipse/plugin/nxj/||shape="rect"]]
76 11. for EV3: [[http:~~/~~/www.lejos.org/tools/eclipse/plugin/ev3/>>url:http://www.lejos.org/tools/eclipse/plugin/ev3/||shape="rect"]]
cmot 24.1 77
cmot 25.1 78 If you have an **NXT** **brick**, install the **leJOS NXJ** Plug-in. If you have an **EV3 brick**, install the **leJOS EV3** plugin.
79
aas2 40.1 80 [[image:attach:Screenshot_20171016_130805.png]]
81
aas2 37.1 82 **Tip:** To speed up the installation, uncheck the option "Contact all update sites during install to find required software". This will reduce the installation time from drastically (around 30 seconds instead 10 minutes).
83
aas2 40.1 84 \\
aas2 8.1 85
aas2 28.1 86 After the installation, the plugin requires a **little configuration**. Go to //Window > Preferences > leJOS NXJ// (//Window > Preferences > leJOS EV3 //respectively) and enter the base directory of your **leJOS** **installation** in the **NXJ_HOME field**.
aas2 19.1 87
aas2 33.1 88 For EV3, the plugin requires the IP address to connect to the brick (it may work without, but its safer to directly set the name. Reduces headache ). Check **Connect to named brick** and enter the **IP adress** of the brick (displayed on the brick at startup).
aas2 3.1 89
90 ----
91
aas2 14.1 92 == Creating an Example Project ==
93
aas2 33.1 94 The following shows how to create a project, which will turn on a light if a button is pressed.
aas2 14.1 95
aas2 15.1 96 === Create a new project: ===
aas2 14.1 97
aas2 18.1 98 1. Choose //File > New > Project > KIELER SCCharts > SCCharts Project//
aas2 21.1 99 1. In the project creation wizard that opens, select //Mindstorms NXJ// or// Mindstorms EV3// (depending on your brick) as environment and hit //finish//
aas2 14.1 100 1. The project wizard from the leJOS plugin opens. Set the project name to //Flashlight// and click //finish//.
101 1. The project is created and the model file is opened in an editor (This might take a few seconds).
102
aas2 40.1 103 === Edit the Model: ===
aas2 14.1 104
105 Change the contents of the model file to the following code and save it.
106
aas2 32.1 107 {{code language="sct" theme="Eclipse" title="Floodlight.sct"}}
aas2 14.1 108 scchart Flashlight {
109
110 @Wrapper TouchSensor, S4
111 input bool button;
112
113 @Wrapper Floodlight, S1
114 output bool light;
115
116 initial state lightOff
117 --> lightOn with button / light = true;
118
119 state lightOn
120 --> lightOff with !button / light = false;
121 }
122 {{/code}}
123
124 This model will start in the state lightOff. If the button is pressed, it will turn on the light and change to the corresponding state, where the light is turned off, as soon as the button is not pressed anymore.
125
aas2 21.1 126 The annotations on the input and output variable are used to define which wrapper code is used to set / read them. **@Wrapper TouchSensor, S4** will set the input variable to true iff the touch sensor on the port S4 is pressed. **@Wrapper Floodlight, S1** on the output variable will turn on the red led of the light sensor that is attatched to port S1 iff the variable is true.
127
aas2 40.1 128 The available wrapper code snippets are defined in the directory //assets/snippets// in ftl files (FreeMarker template files). The table below gives an overview of the available wrapper code snippets.
aas2 21.1 129
aas2 26.1 130 **Note:** The Floodlight of the EV3 has a pretty high latency when switching between on and off.
131
aas2 39.1 132 **Note: **To view ftl files with highlighting, you may want to install the //FreeMarker IDE// feature from the JBoss Tools. However, this is not necessary to work with KIELER. JBoss Tools is available in the Eclipse Market Place and via update site. The update site for stable releases is [[http:~~/~~/download.jboss.org/jbosstools/neon/stable/updates/ >>url:http://download.jboss.org/jbosstools/neon/stable/updates/||shape="rect"]]. Note that only the //FreeMarker IDE// feature is required (Abridged JBoss Tools > FreeMarker IDE).**
aas2 14.1 133 **
134
aas2 40.1 135 === Build the Project: ===
aas2 14.1 136
aas2 40.1 137 The model is now ready to be compiled. Compilation is done in the background when the project is built. There are two ways to build a project: manually using //Project > Build Project//, or automatically via //Project > Build Automatically//. If the automatic build is enabled, resources are built when they are saved.
aas2 14.1 138
aas2 40.1 139 Building the project will create a new folder //kieler-gen// in which all results are saved. This includes the compiled code from the model, an executable simulation for the model and wrapper code that is ready to be deployed to the Mindstorms Brick.
aas2 18.1 140
aas2 40.1 141 The simulation is saved as JAR file in //kieler-gen/sim/bin// and can be started via //Right Click > Run as > KIELER Simulation//. Models and variables of a running simulation are displayed in the Data Pool View.
aas2 19.1 142
aas2 40.1 143 [[image:attach:Screenshot_20171016_110005.png]]
144
145 Besides the simulation, the finished wrapper code that can be uploaded to the Mindstorms brick is created as part of the project build. It is saved in //kieler-gen/model//. To upload it to the Mindstorms brick, use //Right Click > Run as > leJOS NXT Program//.
146
147 [[image:attach:Screenshot_20171016_120554.png]]
148
149 ==== Excluding the Simulation from the NXT Build ====
150
151 It is necessary to exclude the simulation directory and org.json directory inside kieler-gen from the NXT project specific build via //Right Click > Build Path > Exclude//. Afterwards the project has to be build again to remove all error markers in these directories.
152
153 [[image:attach:Screenshot_20171016_105821.png]]
154
155 Normally the NXT project attempts to compile all Java files in the kieler-gen directory for the platform. However, the simulation that is generated is not targeted at the Mindstorms brick and has compilation errors. It is compiled separately by KIELER.
156
aas2 33.1 157 === Available Wrapper Code Snippets ===
158
aas2 40.1 159 There are several wrapper code snippets that can be used as annotations on input and output variables in the model file. These snippets are inserted in the main file template as part of the project build. The available snippets are listed below.
aas2 33.1 160
161 For sensors, the port has to be on of S1, S2, S3, S4.
162
aas2 34.1 163 For motors / actuators the port has to be one of A, B, C, D.
aas2 33.1 164
aas2 35.1 165 (% class="wrapped" %)
aas2 33.1 166 |=(((
167 Snippet Name and Parameters
168 )))|=(((
169 Description
170 )))|=(((
171 Use on
172 )))|=(% colspan="1" %)(% colspan="1" %)
173 (((
174 Variable type
175 )))|=(((
176 Remark
aas2 34.1 177 )))|=(% colspan="1" %)(% colspan="1" %)
178 (((
179 Defined in File
aas2 33.1 180 )))
181 |(% colspan="1" %)(% colspan="1" %)
182 (((
183 **Clock,** milliseconds
184 )))|(% colspan="1" %)(% colspan="1" %)
185 (((
Reinhard von Hanxleden 36.1 186 Sets a variable to true for one tick if the time in milliseconds passed since the last time it was set to true.
aas2 33.1 187 )))|(% colspan="1" %)(% colspan="1" %)
188 (((
189 input
190 )))|(% colspan="1" %)(% colspan="1" %)
191 (((
192 bool
193 )))|(% colspan="1" %)(% colspan="1" %)
194 (((
195 See also ResetClock.
aas2 34.1 196 )))|(% colspan="1" %)(% colspan="1" %)
197 (((
198 timing.ftl
aas2 33.1 199 )))
200 |(% colspan="1" %)(% colspan="1" %)
201 (((
202 **ResetClock,** clockVariableName, autoFalse
203 )))|(% colspan="1" %)(% colspan="1" %)
204 (((
205 Resets a clock, such that the full time intervall of the clock has to elapse, before the clock will be set to true again.
206
207 If autoFalse is true, the reset variable will be set to false automatically.
208 )))|(% colspan="1" %)(% colspan="1" %)
209 (((
210 output
211 )))|(% colspan="1" %)(% colspan="1" %)
212 (((
213 bool
214 )))|(% colspan="1" %)(% colspan="1" %)
215 (((
216 autoFalse is true per default.
aas2 34.1 217 )))|(% colspan="1" %)(% colspan="1" %)
218 (((
219 timing.ftl
aas2 33.1 220 )))
221 |(% colspan="1" %)(% colspan="1" %)
222 (((
223 **Time**
224 )))|(% colspan="1" %)(% colspan="1" %)
225 (((
aas2 41.1 226 Reads the elapsed time since program start (milliseconds)
aas2 33.1 227 )))|(% colspan="1" %)(% colspan="1" %)
228 (((
229 input
230 )))|(% colspan="1" %)(% colspan="1" %)
231 (((
232 int
233 )))|(% colspan="1" %)(% colspan="1" %)
234 (((
aas2 39.1 235 \\
aas2 34.1 236 )))|(% colspan="1" %)(% colspan="1" %)
237 (((
238 timing.ftl
aas2 33.1 239 )))
240 |(% colspan="1" %)(% colspan="1" %)
241 (((
aas2 38.1 242 **TickLoopDuration,** targetInMilliseconds
aas2 33.1 243 )))|(% colspan="1" %)(% colspan="1" %)
244 (((
245 Delays the execution until the tick loop takes at least as long as the given target duration.
246
247 The input variable is set to the actual tick loop duration.
248 )))|(% colspan="1" %)(% colspan="1" %)
249 (((
250 input
251 )))|(% colspan="1" %)(% colspan="1" %)
252 (((
253 int
254 )))|(% colspan="1" %)(% colspan="1" %)
255 (((
256 Should be used on the very first input variable in the model, such that waiting is the last action in the tick loop.
aas2 41.1 257
258 In case the actual tick loop duration is longer than the target duration, the modeler can provide some error handling.
aas2 34.1 259 )))|(% colspan="1" %)(% colspan="1" %)
260 (((
261 timing.ftl
aas2 33.1 262 )))
263 |(% colspan="1" %)(% colspan="1" %)
264 (((
aas2 38.1 265 **TickWakeUp**
266 )))|(% colspan="1" %)(% colspan="1" %)
267 (((
aas2 41.1 268 (% class="content-wrapper" %)
269 (((
270 Sets the input variable to the current system time (milliseconds). The model can add to this variable to get a new value. This is the next system time the tick function will be called.
aas2 38.1 271
aas2 41.1 272 In other words, the next tick function call is delayed until the wake up time has been reached.
273
274 For instance the statement **nextTickWakeUp += 500** could be used to call the tick function again in 500 milliseconds, if nextTickWakeUp is an input with the corresponding annotation.
275 )))
aas2 38.1 276 )))|(% colspan="1" %)(% colspan="1" %)
277 (((
278 input
279 )))|(% colspan="1" %)(% colspan="1" %)
280 (((
281 int
282 )))|(% colspan="1" %)(% colspan="1" %)
283 (((
284 Should be used on the very last input variable in the model, such that waiting and settings the system time is the last action done, before the tick function call.
285 )))|(% colspan="1" %)(% colspan="1" %)
286 (((
287 timing.ftl
288 )))
289 |(% colspan="1" %)(% colspan="1" %)
290 (((
aas2 42.1 291 **TickCount**
292 )))|(% colspan="1" %)(% colspan="1" %)
293 (((
294 Counts the ticks. First tick is 0, the following are 1, 2, 3, ...
295 )))|(% colspan="1" %)(% colspan="1" %)
296 (((
297 input
298 )))|(% colspan="1" %)(% colspan="1" %)
299 (((
300 int
301 )))|(% colspan="1" %)(% colspan="1" %)
302 (((
303 \\
304 )))|(% colspan="1" %)(% colspan="1" %)
305 (((
306 timing.ftl
307 )))
308 |(% colspan="1" %)(% colspan="1" %)
309 (((
aas2 33.1 310 **Sleep**
311 )))|(% colspan="1" %)(% colspan="1" %)
312 (((
313 Lets the current thread sleep the time in milliseconds of the variable value.
314 )))|(% colspan="1" %)(% colspan="1" %)
315 (((
316 output
317 )))|(% colspan="1" %)(% colspan="1" %)
318 (((
319 int
320 )))|(% colspan="1" %)(% colspan="1" %)
321 (((
aas2 39.1 322 \\
aas2 34.1 323 )))|(% colspan="1" %)(% colspan="1" %)
324 (((
325 timing.ftl
aas2 33.1 326 )))
327 |(% colspan="1" %)(% colspan="1" %)
328 (((
329 **Print,** autoReset
330 )))|(% colspan="1" %)(% colspan="1" %)
331 (((
332 Prints a string variable if the string is not empty. If autoReset is true then the string variable is set to the empty string after it has been printed
333 )))|(% colspan="1" %)(% colspan="1" %)
334 (((
335 output
336 )))|(% colspan="1" %)(% colspan="1" %)
337 (((
338 string
339 )))|(% colspan="1" %)(% colspan="1" %)
340 (((
341 autoReset is true per default.
aas2 34.1 342 )))|(% colspan="1" %)(% colspan="1" %)
343 (((
344 print.ftl
aas2 33.1 345 )))
346 |(% colspan="1" %)(% colspan="1" %)
347 (((
348 **DrawString,** x, y
349 )))|(% colspan="1" %)(% colspan="1" %)
350 (((
351 Prints a string to the given x and y coordinate on the LCD.
352 )))|(% colspan="1" %)(% colspan="1" %)
353 (((
354 output
355 )))|(% colspan="1" %)(% colspan="1" %)
356 (((
357 string
358 )))|(% colspan="1" %)(% colspan="1" %)
359 (((
aas2 39.1 360 \\
aas2 34.1 361 )))|(% colspan="1" %)(% colspan="1" %)
362 (((
363 print.ftl
aas2 33.1 364 )))
365 |(% colspan="1" %)(% colspan="1" %)
366 (((
367 **Button, **buttonId
368 )))|(% colspan="1" %)(% colspan="1" %)
369 (((
370 Sets a variable to true iff the button on the Mindstorms device is pressed.
371 )))|(% colspan="1" %)(% colspan="1" %)
372 (((
373 input
374 )))|(% colspan="1" %)(% colspan="1" %)
375 (((
376 bool
377 )))|(% colspan="1" %)(% colspan="1" %)
378 (((
379 The buttonId has to be one of ENTER, LEFT, RIGHT
aas2 34.1 380 )))|(% colspan="1" %)(% colspan="1" %)
381 (((
382 touch_and_buttons.ftl
aas2 33.1 383 )))
384 |(% colspan="1" %)(% colspan="1" %)
385 (((
386 **TouchSensor**, port
387 )))|(% colspan="1" %)(% colspan="1" %)
388 (((
389 Sets a variable to true iff the touch sensor on the given port is pressed.
390 )))|(% colspan="1" %)(% colspan="1" %)
391 (((
392 input
393 )))|(% colspan="1" %)(% colspan="1" %)
394 (((
395 bool
396 )))|(% colspan="1" %)(% colspan="1" %)
397 (((
aas2 39.1 398 \\
aas2 34.1 399 )))|(% colspan="1" %)(% colspan="1" %)
400 (((
401 touch_and_buttons.ftl
aas2 33.1 402 )))
403 |(% colspan="1" %)(% colspan="1" %)
404 (((
405 **LightSensor,** port, percentValue
406 )))|(% colspan="1" %)(% colspan="1" %)
407 (((
408 Reads  the value of a light sensor.
409
410 If percentValue is true, the a percent value is retured, based on the light sensor calibration.
411 )))|(% colspan="1" %)(% colspan="1" %)
412 (((
413 input
414 )))|(% colspan="1" %)(% colspan="1" %)
415 (((
416 int
417 )))|(% colspan="1" %)(% colspan="1" %)
418 (((
419 percentValue is not available on EV3
aas2 34.1 420 )))|(% colspan="1" %)(% colspan="1" %)
421 (((
422 light.ftl
aas2 33.1 423 )))
424 |(% colspan="1" %)(% colspan="1" %)
425 (((
426 **CalibrateLightSensor,** port, signal
427 )))|(% colspan="1" %)(% colspan="1" %)
428 (((
429 Calibrates a light sensors high or low values. This means if the variable is true, the current value of the light sensor is taken as its reference high / low value.
430 )))|(% colspan="1" %)(% colspan="1" %)
431 (((
432 output
433 )))|(% colspan="1" %)(% colspan="1" %)
434 (((
435 bool
436 )))|(% colspan="1" %)(% colspan="1" %)
437 (((
438 signal has to be one of High, Low
aas2 34.1 439 )))|(% colspan="1" %)(% colspan="1" %)
440 (((
441 light.ftl
aas2 33.1 442 )))
443 |(% colspan="1" %)(% colspan="1" %)
444 (((
445 **Floodlight,** port
446 )))|(% colspan="1" %)(% colspan="1" %)
447 (((
448 Reads / Sets the state of the red lamp of the light sensor.
449 )))|(% colspan="1" %)(% colspan="1" %)
450 (((
451 input
452
453 output
454 )))|(% colspan="1" %)(% colspan="1" %)
455 (((
456 bool
457 )))|(% colspan="1" %)(% colspan="1" %)
458 (((
aas2 39.1 459 \\
aas2 34.1 460 )))|(% colspan="1" %)(% colspan="1" %)
461 (((
462 light.ftl
aas2 33.1 463 )))
464 |(% colspan="1" %)(% colspan="1" %)
465 (((
466 **RCXLamp,** port
467 )))|(% colspan="1" %)(% colspan="1" %)
468 (((
469 Turns an RCX lamp on (variable is true) or off (variable is false)
470 )))|(% colspan="1" %)(% colspan="1" %)
471 (((
472 output
473 )))|(% colspan="1" %)(% colspan="1" %)
474 (((
475 bool
476 )))|(% colspan="1" %)(% colspan="1" %)
477 (((
aas2 39.1 478 \\
aas2 34.1 479 )))|(% colspan="1" %)(% colspan="1" %)
480 (((
481 light.ftl
aas2 33.1 482 )))
483 |(% colspan="1" %)(% colspan="1" %)
484 (((
485 **MotorSpeed,** port, brake
486 )))|(% colspan="1" %)(% colspan="1" %)
487 (((
488 Reads / Sets the speed of the motor in degrees per minute. If the speed value is negative, the motor will drive backwards. If the speed is zero, the motor will actively brake until it stops (brake is true) or remove all power and rollout (brake is false).
489 )))|(% colspan="1" %)(% colspan="1" %)
490 (((
491 input
492
493 output
494 )))|(% colspan="1" %)(% colspan="1" %)
495 (((
496 int
497 )))|(% colspan="1" %)(% colspan="1" %)
498 (((
499 brake is true per default.
aas2 34.1 500 )))|(% colspan="1" %)(% colspan="1" %)
501 (((
502 motor.ftl
aas2 33.1 503 )))
504 |(% colspan="1" %)(% colspan="1" %)
505 (((
506 **MotorIsMoving,** port
507 )))|(% colspan="1" %)(% colspan="1" %)
508 (((
509 Sets a variable to true iff the motor on the given port is moving.
510 )))|(% colspan="1" %)(% colspan="1" %)
511 (((
512 input
513 )))|(% colspan="1" %)(% colspan="1" %)
514 (((
515 bool
516 )))|(% colspan="1" %)(% colspan="1" %)
517 (((
aas2 39.1 518 \\
aas2 34.1 519 )))|(% colspan="1" %)(% colspan="1" %)
520 (((
521 motor.ftl
aas2 33.1 522 )))
523 |(% colspan="1" %)(% colspan="1" %)
524 (((
525 **MotorRotation,** port
526 )))|(% colspan="1" %)(% colspan="1" %)
527 (((
528 Lets a motor rotate the variable value in degrees. This is only done if the value is unequal zero. If the value is negative, the motor rotates backwards. The variable is set to zero afterwards, such that setting the variable once to a value //X//, will let the motor rotate //X// degrees.
529 )))|(% colspan="1" %)(% colspan="1" %)
530 (((
531 output
532 )))|(% colspan="1" %)(% colspan="1" %)
533 (((
534 int
535 )))|(% colspan="1" %)(% colspan="1" %)
536 (((
aas2 39.1 537 \\
aas2 34.1 538 )))|(% colspan="1" %)(% colspan="1" %)
539 (((
540 motor.ftl
aas2 33.1 541 )))
542 |(% colspan="1" %)(% colspan="1" %)
543 (((
544 **Beep,** volume
545 )))|(% colspan="1" %)(% colspan="1" %)
546 (((
547 Plays a beep sound as long as the variable is true.
548 )))|(% colspan="1" %)(% colspan="1" %)
549 (((
550 output
551 )))|(% colspan="1" %)(% colspan="1" %)
552 (((
553 bool
554 )))|(% colspan="1" %)(% colspan="1" %)
555 (((
556 default volume is 10
aas2 34.1 557 )))|(% colspan="1" %)(% colspan="1" %)
558 (((
559 sound.ftl
aas2 33.1 560 )))
561 |(% colspan="1" %)(% colspan="1" %)
562 (((
563 **Buzz,** volume
564 )))|(% colspan="1" %)(% colspan="1" %)
565 (((
566 Plays a buzz sound as long as the variable is true.
567 )))|(% colspan="1" %)(% colspan="1" %)
568 (((
569 output
570 )))|(% colspan="1" %)(% colspan="1" %)
571 (((
572 bool
573 )))|(% colspan="1" %)(% colspan="1" %)
574 (((
575 default volume is 10
aas2 34.1 576 )))|(% colspan="1" %)(% colspan="1" %)
577 (((
578 sound.ftl
aas2 33.1 579 )))
580 |(% colspan="1" %)(% colspan="1" %)
581 (((
582 **BeepSequence,** direction, volume
583 )))|(% colspan="1" %)(% colspan="1" %)
584 (((
585 Plays a sequence of tones in either ascending or descending tone frequency if the variable is true.
586
587 The variable is set to false automatically.
588 )))|(% colspan="1" %)(% colspan="1" %)
589 (((
590 output
591 )))|(% colspan="1" %)(% colspan="1" %)
592 (((
593 bool
594 )))|(% colspan="1" %)(% colspan="1" %)
595 (((
596 direction has to be one of Up, Down
597
598 default volume is 10
aas2 34.1 599 )))|(% colspan="1" %)(% colspan="1" %)
600 (((
601 sound.ftl
aas2 33.1 602 )))
603 |(% colspan="1" %)(% colspan="1" %)
604 (((
605 **UltrasonicSensor,** port
606 )))|(% colspan="1" %)(% colspan="1" %)
607 (((
608 Reads the distance that an ultrasonic sensor measures.
609 )))|(% colspan="1" %)(% colspan="1" %)
610 (((
611 input
612 )))|(% colspan="1" %)(% colspan="1" %)
613 (((
614 int
615 )))|(% colspan="1" %)(% colspan="1" %)
616 (((
aas2 39.1 617 \\
aas2 34.1 618 )))|(% colspan="1" %)(% colspan="1" %)
619 (((
620 ultrasonic.ftl
aas2 33.1 621 )))
622 |(% colspan="1" %)(% colspan="1" %)
623 (((
624 **Gyro,** port, mode
625 )))|(% colspan="1" %)(% colspan="1" %)
626 (((
627 Reads the value of a gyroscope.
628 )))|(% colspan="1" %)(% colspan="1" %)
629 (((
630 input
631 )))|(% colspan="1" %)(% colspan="1" %)
632 (((
633 int
634 )))|(% colspan="1" %)(% colspan="1" %)
635 (((
636 Not available on NXT
637
638 mode hat to be one of Angle, Rate
aas2 34.1 639 )))|(% colspan="1" %)(% colspan="1" %)
640 (((
641 gyro.ftl
aas2 33.1 642 )))
643 |(% colspan="1" %)(% colspan="1" %)
644 (((
645 **CalibrateGyro,** port, autoReset
646 )))|(% colspan="1" %)(% colspan="1" %)
647 (((
648 Resets a gyroscope if the variable is true.
649
650 If autoReset is true, the variable is set to false automatically.
651 )))|(% colspan="1" %)(% colspan="1" %)
652 (((
653 output
654 )))|(% colspan="1" %)(% colspan="1" %)
655 (((
656 bool
657 )))|(% colspan="1" %)(% colspan="1" %)
658 (((
659 autoReset is true per default
aas2 34.1 660 )))|(% colspan="1" %)(% colspan="1" %)
661 (((
662 gyro.ftl
aas2 33.1 663 )))
664
aas2 39.1 665 \\
aas2 33.1 666
aas2 19.1 667 ----
668
669 == Using the Remote Console (RConsole) ==
670
aas2 21.1 671 The display of the **NXT brick** is rather small compared to a Monitor. To ease debugging, one can print to a Remote Console (RConsole), if the USB cable is connected. This enables easier collection for example of sensor data.
aas2 19.1 672
aas2 21.1 673 To use the RConsole, **uncomment** the **RConsole** lines in the wrapper code template **Main.ftl**. Start the **nxjconsoleviewer** tool in the bin directory of your **leJOS installation**. Now, when **starting the application**, the brick tries to connect with the nxjconsoleviewer. **Press the //Connect//** button. If connected succesfully, RConsole.println(...) commands will be written to this window.
aas2 19.1 674
aas2 21.1 675 The **EV3 brick** has a similar feature. However it does not require any code changes. Just run the ev3console program in the bin directory of your leJOS installation from command line. The output of the brick will be printed to this command line.
aas2 23.1 676
677 ----
678
679 == Problem Solving ==
680
681 The following presents typical issues and how to solve them.
682
aas2 35.1 683 (% class="wrapped" %)
aas2 23.1 684 |=(((
685 Issue
686 )))|=(((
687 Typical Error Messages
688 )))|=(((
689 Description
690 )))|=(((
691 Solution
692 )))
693 |(((
694 leJOS EV3 does not support Java 8
695 )))|(((
696 "java.lang.UnsupportedClassVersionError"
697
698 "unsupported major.minor version"
699 )))|(((
700 You compile the sources in your project with Java 8 and upload them to the brick. However the lejos EV3 does not support Java 8
701 )))|(((
702 Go to the project properties and switch to Java 7 (Right Click on project > Properties > Java Compiler > Compiler compliance level)
703 )))
aas2 31.1 704 |(% colspan="1" %)(% colspan="1" %)
705 (((
706 Uploading to the brick does not respond
707 )))|(% colspan="1" %)(% colspan="1" %)
708 (((
aas2 39.1 709 \\
aas2 31.1 710 )))|(% colspan="1" %)(% colspan="1" %)
711 (((
712 You compile a file successfully and when uploading the result, the connected brick is found. Anyway the upload does not terminate and does not react.
713 )))|(% colspan="1" %)(% colspan="1" %)
714 (((
715 Flash the brick with the current leJOS firmware. If the brick is recognized correctly and the attempt to upload a compiled file fails then the firmware on the brick might be outdated.
716 )))
717 |(% colspan="1" %)(% colspan="1" %)
718 (((
719 Compilation and uploading works from command line but not when using KIELER
720 )))|(% colspan="1" %)(% colspan="1" %)
721 (((
722 This Java instance does not support a 32-bit JVM. Please install the desired version.
723 )))|(% colspan="1" %)(% colspan="1" %)
724 (((
725 You can compile and upload code to the brick using the command line tools but when using KIELER an error message apprears because Java does not support 32-bit JVM.
726 )))|(% colspan="1" %)(% colspan="1" %)
727 (((
728 Set the LEJOS_NXT_JAVA_HOME environment variable, such that it points to an 32-bit JDK and is visible for GUI applications (or at least KIELER). The process to do so differs on every OS. As alternative, execute KIELER from terminal.
729 )))
aas2 32.1 730 |(% colspan="1" %)(% colspan="1" %)
731 (((
732 Brick does nothing after program finished and prints "Program exit"
733 )))|(% colspan="1" %)(% colspan="1" %)
734 (((
aas2 39.1 735 \\
aas2 32.1 736 )))|(% colspan="1" %)(% colspan="1" %)
737 (((
738 A program was uploaded and finished without errors. Afterwards the brick prints "Program exit" but does not open the main menu.
739 )))|(% colspan="1" %)(% colspan="1" %)
740 (((
741 This is normal behaviour if uploading a program in debug mode instead run mode (//Debug As// instead //Run As// in Eclipse). To get back to the main menu, press the ENTER and ESCAPE button of the brick at the same time.
742 )))
aas2 23.1 743
aas2 39.1 744 \\
aas2 23.1 745
aas2 39.1 746 \\