<
From version < 18.1 >
edited by aas2
on 2015/11/11 13:35
To version < 32.1 >
edited by aas2
on 2016/01/19 15:23
>
Change comment: There is no comment for this version

Summary

Details

Page properties
Content
... ... @@ -8,7 +8,7 @@
8 8  
9 9  == Overview ==
10 10  
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, thus //Mindstorms// will be used exchangeable with //NXT brick//.
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.
12 12  
13 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.
14 14  
... ... @@ -16,60 +16,67 @@
16 16  
17 17  == Download and install leJOS ==
18 18  
19 -Download and extract the newest archives for your Operating System from [[Sourceforce>>url:http://sourceforge.net/projects/nxt.lejos.p/files/||shape="rect"]].
19 +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).
20 20  
21 21  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"]].
22 22  
23 +Do not forget to flash the download leJOS firmware to the Mindstorms brick as explained in the tutorial!
24 +
23 23  === Known issues ===
24 24  
25 -== Linux ==
27 +==== Linux ====
26 26  
27 27  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.
28 28  
29 29  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}}**.
30 30  
31 -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**.
33 +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**.
32 32  
33 -----
35 +==== Windows ====
34 34  
35 -== Test the Mindstorm ==
37 +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.
36 36  
37 -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"]]
39 +==== Mac OS X ====
38 38  
39 -If this works with your device, you are able to start using KIELER to develop applications for the NXT brick.\\
41 +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.
40 40  
43 +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, which seems to be not 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"]]).
44 +
41 41  ----
42 42  
43 -== The Eclipse plugin for leJOS ==
47 +== Test the Mindstorm ==
44 44  
45 -There is an Eclipse plugin for leJOS which adds a project creation wizard and launch configuration to the platform. You can install it via the Eclipse Marketplace (//Help > Eclipse Marketplace...//)
49 +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"]]
46 46  
47 -[[image:attach:lejos_eclipse_plugin.png]]
51 +If this works with your device, you are able to start using KIELER to develop applications for the NXT brick.
48 48  
49 49  ----
50 50  
51 -== Configure KIELER ==
55 +== Download and Configure KIELER
56 + ==
52 52  
53 -With the Eclipse plugin for leJOS installed, you can now use KIELER SCCharts for an model-based approach of programming.
58 +Download and unpack the nightly build of KIELER for your OS. It is available at the [[doc:Downloads]] page.\\
54 54  
55 -First check the environment settings for NXJ of the KIELER tool (//Window > Preferences > KIELER > Environments//). On the **Execute** tab, ensure that only the commands for your operating system are checked.
60 +**Note:** Java 1.8 is needed on all operating systems, with Java 1.7 not all plugins of KIELER will be loaded. **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.
56 56  
57 -Hit the //Variables// button and search for **nxj.home**. If the variable exists, your good. If it does not exist, create a new variable (//Edit Variables... > New//) with that name and point it to the base folder of your leJOS installation. The variable is referenced by the shell commands of the environment.
62 +=== The Eclipse plugin for leJOS ===
58 58  
59 -[[image:attach:environments_preferences.png]]
64 +There is an Eclipse plugin for leJOS which adds a project creation wizard and launch configuration to the platform.
60 60  
61 -**Note:** If you already created and launched a project, the settings of the environment are copied to the launch configuration. It is thus may be necessary to alter settings on the launch configuration as well as the environment.
66 +1. You have to install it via the Eclipse Marketplace (//Help > Eclipse Marketplace...//).
67 +OR
68 +1. Install the plugin manually (Help > Install new Software...). Use the following update site\\
69 +11. for NXT: [[http:~~/~~/www.lejos.org/tools/eclipse/plugin/nxj/>>url:http://www.lejos.org/tools/eclipse/plugin/nxj/||shape="rect"]]
70 +11. for EV3: [[http:~~/~~/www.lejos.org/tools/eclipse/plugin/ev3/>>url:http://www.lejos.org/tools/eclipse/plugin/ev3/||shape="rect"]]
62 62  
63 -----
72 +If you have an **NXT** **brick**, install the **leJOS NXJ** Plug-in. If you have an **EV3 brick**, install the **leJOS EV3** plugin.
64 64  
65 -== Using the Remote Console (RConsole) ==
74 +[[image:attach:lejos_eclipse_plugin.png]]
66 66  
67 -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.
76 +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**.
68 68  
69 -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**.
78 +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).
70 70  
71 -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.
72 -
73 73  ----
74 74  
75 75  == Creating an Example Project ==
... ... @@ -79,7 +79,7 @@
79 79  === Create a new project: ===
80 80  
81 81  1. Choose //File > New > Project > KIELER SCCharts > SCCharts Project//
82 -1. In the project creation wizard that opens, select //Mindstorms NXJ// as environment and hit //finish//
89 +1. In the project creation wizard that opens, select //Mindstorms NXJ// or// Mindstorms EV3// (depending on your brick) as environment and hit //finish//
83 83  1. The project wizard from the leJOS plugin opens. Set the project name to //Flashlight// and click //finish//.
84 84  1. The project is created and the model file is opened in an editor (This might take a few seconds).
85 85  
... ... @@ -87,7 +87,7 @@
87 87  
88 88  Change the contents of the model file to the following code and save it.
89 89  
90 -{{code title="Floodlight.sct" theme="Eclipse" language="sct"}}
97 +{{code language="sct" theme="Eclipse" title="Floodlight.sct"}}
91 91  scchart Flashlight {
92 92  
93 93   @Wrapper TouchSensor, S4
... ... @@ -106,7 +106,13 @@
106 106  
107 107  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.
108 108  
109 -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.**
116 +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.
117 +
118 +The available wrapper code snippets are defined in the //snippets// directory of the project in ftl files (FreeMarker template files).
119 +
120 +**Note:** The Floodlight of the EV3 has a pretty high latency when switching between on and off.
121 +
122 +**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 Eclipse Luna is [[http:~~/~~/download.jboss.org/jbosstools/updates/stable/luna/>>url:http://download.jboss.org/jbosstools/updates/stable/luna/||shape="rect"]] . Note that only the //FreeMarker IDE// feature is required (Abridged JBoss Tools > FreeMarker IDE).**
110 110  **
111 111  
112 112  === Launch the project: ===
... ... @@ -113,6 +113,86 @@
113 113  
114 114  With the mouse over the SCT file in the project explorer, perform //Right Click > Run As > KiCo Compilation.//
115 115  
116 -A launch config is created, which compiles the model to Java code and creates wrapper code from the annotations in the model file. Afterwards this output is compiled and deployed to the Mindstorms brick, by using the shell commands that are defined in the Mindstorms NXJ environment.
129 +A launch config is created, which compiles the model to Java code and creates wrapper code from the annotations in the model file. Afterwards this output is compiled and deployed to the Mindstorms brick, by using the launch shortcut from the leJOS plugin. If any errors occur, you can see them in the Console View.
117 117  
118 118  For a deeper understanding of the project launch and initialization, take a look at the [[wiki page for Prom>>url:http://rtsys.informatik.uni-kiel.de/confluence/pages/viewpage.action?pageId=13762626||shape="rect"]].
132 +
133 +----
134 +
135 +== Using the Remote Console (RConsole) ==
136 +
137 +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.
138 +
139 +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.
140 +
141 +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.
142 +
143 +----
144 +
145 +== Problem Solving ==
146 +
147 +The following presents typical issues and how to solve them.
148 +
149 +|=(((
150 +Issue
151 +)))|=(((
152 +Typical Error Messages
153 +)))|=(((
154 +Description
155 +)))|=(((
156 +Solution
157 +)))
158 +|(((
159 +leJOS EV3 does not support Java 8
160 +)))|(((
161 +"java.lang.UnsupportedClassVersionError"
162 +
163 +"unsupported major.minor version"
164 +)))|(((
165 +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
166 +)))|(((
167 +Go to the project properties and switch to Java 7 (Right Click on project > Properties > Java Compiler > Compiler compliance level)
168 +)))
169 +|(% colspan="1" %)(% colspan="1" %)
170 +(((
171 +Uploading to the brick does not respond
172 +)))|(% colspan="1" %)(% colspan="1" %)
173 +(((
174 +
175 +)))|(% colspan="1" %)(% colspan="1" %)
176 +(((
177 +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.
178 +)))|(% colspan="1" %)(% colspan="1" %)
179 +(((
180 +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.
181 +)))
182 +|(% colspan="1" %)(% colspan="1" %)
183 +(((
184 +Compilation and uploading works from command line but not when using KIELER
185 +)))|(% colspan="1" %)(% colspan="1" %)
186 +(((
187 +This Java instance does not support a 32-bit JVM. Please install the desired version.
188 +)))|(% colspan="1" %)(% colspan="1" %)
189 +(((
190 +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.
191 +)))|(% colspan="1" %)(% colspan="1" %)
192 +(((
193 +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.
194 +)))
195 +|(% colspan="1" %)(% colspan="1" %)
196 +(((
197 +Brick does nothing after program finished and prints "Program exit"
198 +)))|(% colspan="1" %)(% colspan="1" %)
199 +(((
200 +
201 +)))|(% colspan="1" %)(% colspan="1" %)
202 +(((
203 +A program was uploaded and finished without errors. Afterwards the brick prints "Program exit" but does not open the main menu.
204 +)))|(% colspan="1" %)(% colspan="1" %)
205 +(((
206 +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.
207 +)))
208 +
209 +
210 +
211 +
Confluence.Code.ConfluencePageClass[0]
Id
... ... @@ -1,1 +1,1 @@
1 -13763595
1 +15532230
URL
... ... @@ -1,1 +1,1 @@
1 -https://rtsys.informatik.uni-kiel.de/confluence//wiki/spaces/KIELER/pages/13763595/LEGO Mindstorms with leJOS and SCCharts
1 +https://rtsys.informatik.uni-kiel.de/confluence//wiki/spaces/KIELER/pages/15532230/LEGO Mindstorms with leJOS and SCCharts