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 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 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 139 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 )))|=((( ... ... @@ -158,7 +158,7 @@ 158 158 **Clock,** milliseconds 159 159 )))|(% colspan="1" %)(% colspan="1" %) 160 160 ((( 161 -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. 162 162 )))|(% colspan="1" %)(% colspan="1" %) 163 163 ((( 164 164 input ... ... @@ -207,7 +207,7 @@ 207 207 int 208 208 )))|(% colspan="1" %)(% colspan="1" %) 209 209 ((( 210 - 235 +\\ 211 211 )))|(% colspan="1" %)(% colspan="1" %) 212 212 ((( 213 213 timing.ftl ... ... @@ -214,7 +214,7 @@ 214 214 ))) 215 215 |(% colspan="1" %)(% colspan="1" %) 216 216 ((( 217 -**TickDuration,** targetInMilliseconds 242 +**TickLoopDuration,** targetInMilliseconds 218 218 )))|(% colspan="1" %)(% colspan="1" %) 219 219 ((( 220 220 Delays the execution until the tick loop takes at least as long as the given target duration. ... ... @@ -235,6 +235,27 @@ 235 235 ))) 236 236 |(% colspan="1" %)(% colspan="1" %) 237 237 ((( 263 +**TickWakeUp** 264 +)))|(% colspan="1" %)(% colspan="1" %) 265 +((( 266 +Sets the input variable to the current system time. The model can add to this variable to get a new value. This is the next system time it will be called. 267 + 268 +This means the next tick function call is delayed until the wake up time has been reached. 269 +)))|(% colspan="1" %)(% colspan="1" %) 270 +((( 271 +input 272 +)))|(% colspan="1" %)(% colspan="1" %) 273 +((( 274 +int 275 +)))|(% colspan="1" %)(% colspan="1" %) 276 +((( 277 +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. 278 +)))|(% colspan="1" %)(% colspan="1" %) 279 +((( 280 +timing.ftl 281 +))) 282 +|(% colspan="1" %)(% colspan="1" %) 283 +((( 238 238 **Sleep** 239 239 )))|(% colspan="1" %)(% colspan="1" %) 240 240 ((( ... ... @@ -247,7 +247,7 @@ 247 247 int 248 248 )))|(% colspan="1" %)(% colspan="1" %) 249 249 ((( 250 - 296 +\\ 251 251 )))|(% colspan="1" %)(% colspan="1" %) 252 252 ((( 253 253 timing.ftl ... ... @@ -285,7 +285,7 @@ 285 285 string 286 286 )))|(% colspan="1" %)(% colspan="1" %) 287 287 ((( 288 - 334 +\\ 289 289 )))|(% colspan="1" %)(% colspan="1" %) 290 290 ((( 291 291 print.ftl ... ... @@ -323,7 +323,7 @@ 323 323 bool 324 324 )))|(% colspan="1" %)(% colspan="1" %) 325 325 ((( 326 - 372 +\\ 327 327 )))|(% colspan="1" %)(% colspan="1" %) 328 328 ((( 329 329 touch_and_buttons.ftl ... ... @@ -384,7 +384,7 @@ 384 384 bool 385 385 )))|(% colspan="1" %)(% colspan="1" %) 386 386 ((( 387 - 433 +\\ 388 388 )))|(% colspan="1" %)(% colspan="1" %) 389 389 ((( 390 390 light.ftl ... ... @@ -403,7 +403,7 @@ 403 403 bool 404 404 )))|(% colspan="1" %)(% colspan="1" %) 405 405 ((( 406 - 452 +\\ 407 407 )))|(% colspan="1" %)(% colspan="1" %) 408 408 ((( 409 409 light.ftl ... ... @@ -443,7 +443,7 @@ 443 443 bool 444 444 )))|(% colspan="1" %)(% colspan="1" %) 445 445 ((( 446 - 492 +\\ 447 447 )))|(% colspan="1" %)(% colspan="1" %) 448 448 ((( 449 449 motor.ftl ... ... @@ -462,7 +462,7 @@ 462 462 int 463 463 )))|(% colspan="1" %)(% colspan="1" %) 464 464 ((( 465 - 511 +\\ 466 466 )))|(% colspan="1" %)(% colspan="1" %) 467 467 ((( 468 468 motor.ftl ... ... @@ -542,7 +542,7 @@ 542 542 int 543 543 )))|(% colspan="1" %)(% colspan="1" %) 544 544 ((( 545 - 591 +\\ 546 546 )))|(% colspan="1" %)(% colspan="1" %) 547 547 ((( 548 548 ultrasonic.ftl ... ... @@ -590,7 +590,7 @@ 590 590 gyro.ftl 591 591 ))) 592 592 593 - 639 +\\ 594 594 595 595 ---- 596 596 ... ... @@ -608,6 +608,7 @@ 608 608 609 609 The following presents typical issues and how to solve them. 610 610 657 +(% class="wrapped" %) 611 611 |=((( 612 612 Issue 613 613 )))|=((( ... ... @@ -633,7 +633,7 @@ 633 633 Uploading to the brick does not respond 634 634 )))|(% colspan="1" %)(% colspan="1" %) 635 635 ((( 636 - 683 +\\ 637 637 )))|(% colspan="1" %)(% colspan="1" %) 638 638 ((( 639 639 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. ... ... @@ -659,7 +659,7 @@ 659 659 Brick does nothing after program finished and prints "Program exit" 660 660 )))|(% colspan="1" %)(% colspan="1" %) 661 661 ((( 662 - 709 +\\ 663 663 )))|(% colspan="1" %)(% colspan="1" %) 664 664 ((( 665 665 A program was uploaded and finished without errors. Afterwards the brick prints "Program exit" but does not open the main menu. ... ... @@ -668,8 +668,6 @@ 668 668 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. 669 669 ))) 670 670 671 - 718 +\\ 672 672 673 - 674 - 675 -input 720 +\\
- Confluence.Code.ConfluencePageClass[0]
-
- Id
-
... ... @@ -1,1 +1,1 @@ 1 - 187761041 +37814287 - URL
-
... ... @@ -1,1 +1,1 @@ 1 -https://rtsys.informatik.uni-kiel.de/confluence//wiki/spaces/KIELER/pages/ 18776104/LEGO Mindstorms with leJOS and SCCharts1 +https://rtsys.informatik.uni-kiel.de/confluence//wiki/spaces/KIELER/pages/37814287/LEGO Mindstorms with leJOS and SCCharts