Changes for page LEGO Mindstorms with leJOS and SCCharts
Last modified by Alexander Schulz-Rosengarten on 2023/09/11 16:17
Summary
-
Page properties (1 modified, 0 added, 0 removed)
-
Objects (1 modified, 0 added, 0 removed)
Details
- Page properties
-
- Content
-
... ... @@ -12,6 +12,12 @@ 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 15 +If you want to learn the SCCharts langugage first, you can follow these links: 16 + 17 +* [[Introduction to SCCharts>>doc:SCCharts]] 18 +* [[The Textual SCCharts Language SCT>>doc:Textual SCCharts Language SCT]] 19 +* [[SCCharts Examples>>doc:Examples]] 20 + 15 15 ---- 16 16 17 17 == Download and install leJOS == ... ... @@ -71,8 +71,12 @@ 71 71 72 72 If you have an **NXT** **brick**, install the **leJOS NXJ** Plug-in. If you have an **EV3 brick**, install the **leJOS EV3** plugin. 73 73 74 -[[image:attach: lejos_eclipse_plugin.png]]80 +[[image:attach:Screenshot_20171016_130805.png]] 75 75 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 + 84 +\\ 85 + 76 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**. 77 77 78 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). ... ... @@ -90,7 +90,7 @@ 90 90 1. The project wizard from the leJOS plugin opens. Set the project name to //Flashlight// and click //finish//. 91 91 1. The project is created and the model file is opened in an editor (This might take a few seconds). 92 92 93 -=== Edit the model: ===103 +=== Edit the Model: === 94 94 95 95 Change the contents of the model file to the following code and save it. 96 96 ... ... @@ -115,29 +115,44 @@ 115 115 116 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 117 118 -The available wrapper code snippets are defined in the //snippets//directoryof theroject in ftl files (FreeMarker template files). The table below gives an overview of the available wrapper code snippets.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. 119 119 120 120 **Note:** The Floodlight of the EV3 has a pretty high latency when switching between on and off. 121 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 EclipseLuna isupdates/stable/luna/>>url:http://download.jboss.org/jbosstools/updates/stable/luna/||shape="rect"]]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).** 123 123 ** 124 124 125 -=== Launchtheproject: ===135 +=== Build the Project: === 126 126 127 - Withthe mouse over theSCTfile in the projectexplorer,perform//RightClick>RunAs>KiCoCompilation.//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. 128 128 129 - A launchconfigiscreated,whichcompilesthemodel toJava code and createswrappercode from the annotationsinthe modelfile.Afterwardsthis outputiscompiledand deployed to the Mindstormsbrick, by using the launch shortcut from the leJOS plugin.If any errors occur, you can see them in the Console View.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. 130 130 131 - For a deeperunderstandingoftheprojectlaunchandinitialization,take alook atthe [[wikipageforProm>>url:http://rtsys.informatik.uni-kiel.de/confluence/pages/viewpage.action?pageId=13762626||shape="rect"]].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. 132 132 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 + 133 133 === Available Wrapper Code Snippets === 134 134 135 -There are several wrapper code snippets that can be used on input and output variables in the model file. These snippets are inserted in the main file template as part of the project launch. The available snippets are listed below.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. 136 136 137 137 For sensors, the port has to be on of S1, S2, S3, S4. 138 138 139 -For motors the port has to be one of A, B, C, D. 163 +For motors / actuators the port has to be one of A, B, C, D. 140 140 165 +(% class="wrapped" %) 141 141 |=((( 142 142 Snippet Name and Parameters 143 143 )))|=((( ... ... @@ -149,6 +149,9 @@ 149 149 Variable type 150 150 )))|=((( 151 151 Remark 177 +)))|=(% colspan="1" %)(% colspan="1" %) 178 +((( 179 +Defined in File 152 152 ))) 153 153 |(% colspan="1" %)(% colspan="1" %) 154 154 ((( ... ... @@ -155,7 +155,7 @@ 155 155 **Clock,** milliseconds 156 156 )))|(% colspan="1" %)(% colspan="1" %) 157 157 ((( 158 -Sets a variable to true if the time in milliseconds passed 186 +Sets a variable to true for one tick if the time in milliseconds passed since the last time it was set to true. 159 159 )))|(% colspan="1" %)(% colspan="1" %) 160 160 ((( 161 161 input ... ... @@ -165,6 +165,9 @@ 165 165 )))|(% colspan="1" %)(% colspan="1" %) 166 166 ((( 167 167 See also ResetClock. 196 +)))|(% colspan="1" %)(% colspan="1" %) 197 +((( 198 +timing.ftl 168 168 ))) 169 169 |(% colspan="1" %)(% colspan="1" %) 170 170 ((( ... ... @@ -183,6 +183,9 @@ 183 183 )))|(% colspan="1" %)(% colspan="1" %) 184 184 ((( 185 185 autoFalse is true per default. 217 +)))|(% colspan="1" %)(% colspan="1" %) 218 +((( 219 +timing.ftl 186 186 ))) 187 187 |(% colspan="1" %)(% colspan="1" %) 188 188 ((( ... ... @@ -189,7 +189,7 @@ 189 189 **Time** 190 190 )))|(% colspan="1" %)(% colspan="1" %) 191 191 ((( 192 -Reads the elapsed time since program start 226 +Reads the elapsed time since program start (milliseconds) 193 193 )))|(% colspan="1" %)(% colspan="1" %) 194 194 ((( 195 195 input ... ... @@ -198,11 +198,14 @@ 198 198 int 199 199 )))|(% colspan="1" %)(% colspan="1" %) 200 200 ((( 201 - 235 +\\ 236 +)))|(% colspan="1" %)(% colspan="1" %) 237 +((( 238 +timing.ftl 202 202 ))) 203 203 |(% colspan="1" %)(% colspan="1" %) 204 204 ((( 205 -**TickDuration,** targetInMilliseconds 242 +**TickLoopDuration,** targetInMilliseconds 206 206 )))|(% colspan="1" %)(% colspan="1" %) 207 207 ((( 208 208 Delays the execution until the tick loop takes at least as long as the given target duration. ... ... @@ -217,9 +217,40 @@ 217 217 )))|(% colspan="1" %)(% colspan="1" %) 218 218 ((( 219 219 Should be used on the very first input variable in the model, such that waiting is the last action in the tick loop. 257 + 258 +In case the actual tick loop duration is longer than the target duration, the modeler can provide some error handling. 259 +)))|(% colspan="1" %)(% colspan="1" %) 260 +((( 261 +timing.ftl 220 220 ))) 221 221 |(% colspan="1" %)(% colspan="1" %) 222 222 ((( 265 +**TickWakeUp** 266 +)))|(% colspan="1" %)(% colspan="1" %) 267 +((( 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. 271 + 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 +))) 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 +((( 223 223 **Sleep** 224 224 )))|(% colspan="1" %)(% colspan="1" %) 225 225 ((( ... ... @@ -232,7 +232,10 @@ 232 232 int 233 233 )))|(% colspan="1" %)(% colspan="1" %) 234 234 ((( 235 - 303 +\\ 304 +)))|(% colspan="1" %)(% colspan="1" %) 305 +((( 306 +timing.ftl 236 236 ))) 237 237 |(% colspan="1" %)(% colspan="1" %) 238 238 ((( ... ... @@ -249,6 +249,9 @@ 249 249 )))|(% colspan="1" %)(% colspan="1" %) 250 250 ((( 251 251 autoReset is true per default. 323 +)))|(% colspan="1" %)(% colspan="1" %) 324 +((( 325 +print.ftl 252 252 ))) 253 253 |(% colspan="1" %)(% colspan="1" %) 254 254 ((( ... ... @@ -264,7 +264,10 @@ 264 264 string 265 265 )))|(% colspan="1" %)(% colspan="1" %) 266 266 ((( 267 - 341 +\\ 342 +)))|(% colspan="1" %)(% colspan="1" %) 343 +((( 344 +print.ftl 268 268 ))) 269 269 |(% colspan="1" %)(% colspan="1" %) 270 270 ((( ... ... @@ -281,6 +281,9 @@ 281 281 )))|(% colspan="1" %)(% colspan="1" %) 282 282 ((( 283 283 The buttonId has to be one of ENTER, LEFT, RIGHT 361 +)))|(% colspan="1" %)(% colspan="1" %) 362 +((( 363 +touch_and_buttons.ftl 284 284 ))) 285 285 |(% colspan="1" %)(% colspan="1" %) 286 286 ((( ... ... @@ -296,7 +296,10 @@ 296 296 bool 297 297 )))|(% colspan="1" %)(% colspan="1" %) 298 298 ((( 299 - 379 +\\ 380 +)))|(% colspan="1" %)(% colspan="1" %) 381 +((( 382 +touch_and_buttons.ftl 300 300 ))) 301 301 |(% colspan="1" %)(% colspan="1" %) 302 302 ((( ... ... @@ -315,6 +315,9 @@ 315 315 )))|(% colspan="1" %)(% colspan="1" %) 316 316 ((( 317 317 percentValue is not available on EV3 401 +)))|(% colspan="1" %)(% colspan="1" %) 402 +((( 403 +light.ftl 318 318 ))) 319 319 |(% colspan="1" %)(% colspan="1" %) 320 320 ((( ... ... @@ -331,6 +331,9 @@ 331 331 )))|(% colspan="1" %)(% colspan="1" %) 332 332 ((( 333 333 signal has to be one of High, Low 420 +)))|(% colspan="1" %)(% colspan="1" %) 421 +((( 422 +light.ftl 334 334 ))) 335 335 |(% colspan="1" %)(% colspan="1" %) 336 336 ((( ... ... @@ -348,7 +348,10 @@ 348 348 bool 349 349 )))|(% colspan="1" %)(% colspan="1" %) 350 350 ((( 351 - 440 +\\ 441 +)))|(% colspan="1" %)(% colspan="1" %) 442 +((( 443 +light.ftl 352 352 ))) 353 353 |(% colspan="1" %)(% colspan="1" %) 354 354 ((( ... ... @@ -364,7 +364,10 @@ 364 364 bool 365 365 )))|(% colspan="1" %)(% colspan="1" %) 366 366 ((( 367 - 459 +\\ 460 +)))|(% colspan="1" %)(% colspan="1" %) 461 +((( 462 +light.ftl 368 368 ))) 369 369 |(% colspan="1" %)(% colspan="1" %) 370 370 ((( ... ... @@ -383,6 +383,9 @@ 383 383 )))|(% colspan="1" %)(% colspan="1" %) 384 384 ((( 385 385 brake is true per default. 481 +)))|(% colspan="1" %)(% colspan="1" %) 482 +((( 483 +motor.ftl 386 386 ))) 387 387 |(% colspan="1" %)(% colspan="1" %) 388 388 ((( ... ... @@ -398,7 +398,10 @@ 398 398 bool 399 399 )))|(% colspan="1" %)(% colspan="1" %) 400 400 ((( 401 - 499 +\\ 500 +)))|(% colspan="1" %)(% colspan="1" %) 501 +((( 502 +motor.ftl 402 402 ))) 403 403 |(% colspan="1" %)(% colspan="1" %) 404 404 ((( ... ... @@ -414,7 +414,10 @@ 414 414 int 415 415 )))|(% colspan="1" %)(% colspan="1" %) 416 416 ((( 417 - 518 +\\ 519 +)))|(% colspan="1" %)(% colspan="1" %) 520 +((( 521 +motor.ftl 418 418 ))) 419 419 |(% colspan="1" %)(% colspan="1" %) 420 420 ((( ... ... @@ -431,6 +431,9 @@ 431 431 )))|(% colspan="1" %)(% colspan="1" %) 432 432 ((( 433 433 default volume is 10 538 +)))|(% colspan="1" %)(% colspan="1" %) 539 +((( 540 +sound.ftl 434 434 ))) 435 435 |(% colspan="1" %)(% colspan="1" %) 436 436 ((( ... ... @@ -447,6 +447,9 @@ 447 447 )))|(% colspan="1" %)(% colspan="1" %) 448 448 ((( 449 449 default volume is 10 557 +)))|(% colspan="1" %)(% colspan="1" %) 558 +((( 559 +sound.ftl 450 450 ))) 451 451 |(% colspan="1" %)(% colspan="1" %) 452 452 ((( ... ... @@ -467,6 +467,9 @@ 467 467 direction has to be one of Up, Down 468 468 469 469 default volume is 10 580 +)))|(% colspan="1" %)(% colspan="1" %) 581 +((( 582 +sound.ftl 470 470 ))) 471 471 |(% colspan="1" %)(% colspan="1" %) 472 472 ((( ... ... @@ -482,7 +482,10 @@ 482 482 int 483 483 )))|(% colspan="1" %)(% colspan="1" %) 484 484 ((( 485 - 598 +\\ 599 +)))|(% colspan="1" %)(% colspan="1" %) 600 +((( 601 +ultrasonic.ftl 486 486 ))) 487 487 |(% colspan="1" %)(% colspan="1" %) 488 488 ((( ... ... @@ -501,6 +501,9 @@ 501 501 Not available on NXT 502 502 503 503 mode hat to be one of Angle, Rate 620 +)))|(% colspan="1" %)(% colspan="1" %) 621 +((( 622 +gyro.ftl 504 504 ))) 505 505 |(% colspan="1" %)(% colspan="1" %) 506 506 ((( ... ... @@ -519,9 +519,12 @@ 519 519 )))|(% colspan="1" %)(% colspan="1" %) 520 520 ((( 521 521 autoReset is true per default 641 +)))|(% colspan="1" %)(% colspan="1" %) 642 +((( 643 +gyro.ftl 522 522 ))) 523 523 524 - 646 +\\ 525 525 526 526 ---- 527 527 ... ... @@ -539,6 +539,7 @@ 539 539 540 540 The following presents typical issues and how to solve them. 541 541 664 +(% class="wrapped" %) 542 542 |=((( 543 543 Issue 544 544 )))|=((( ... ... @@ -564,7 +564,7 @@ 564 564 Uploading to the brick does not respond 565 565 )))|(% colspan="1" %)(% colspan="1" %) 566 566 ((( 567 - 690 +\\ 568 568 )))|(% colspan="1" %)(% colspan="1" %) 569 569 ((( 570 570 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. ... ... @@ -590,7 +590,7 @@ 590 590 Brick does nothing after program finished and prints "Program exit" 591 591 )))|(% colspan="1" %)(% colspan="1" %) 592 592 ((( 593 - 716 +\\ 594 594 )))|(% colspan="1" %)(% colspan="1" %) 595 595 ((( 596 596 A program was uploaded and finished without errors. Afterwards the brick prints "Program exit" but does not open the main menu. ... ... @@ -599,8 +599,6 @@ 599 599 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. 600 600 ))) 601 601 602 - 725 +\\ 603 603 604 - 605 - 606 -input 727 +\\
- Confluence.Code.ConfluencePageClass[0]
-
- Id
-
... ... @@ -1,1 +1,1 @@ 1 - 155323041 +37814289 - URL
-
... ... @@ -1,1 +1,1 @@ 1 -https://rtsys.informatik.uni-kiel.de/confluence//wiki/spaces/KIELER/pages/ 15532304/LEGO Mindstorms with leJOS and SCCharts1 +https://rtsys.informatik.uni-kiel.de/confluence//wiki/spaces/KIELER/pages/37814289/LEGO Mindstorms with leJOS and SCCharts