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 == ... ... @@ -40,7 +40,7 @@ 40 40 41 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. 42 42 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 ,whichseemsto benottrivial 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"]]).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"]]). 44 44 45 45 ---- 46 46 ... ... @@ -57,7 +57,7 @@ 57 57 58 58 Download and unpack the nightly build of KIELER for your OS. It is available at the [[doc:Downloads]] page.\\ 59 59 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.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. 61 61 62 62 === The Eclipse plugin for leJOS === 63 63 ... ... @@ -71,17 +71,19 @@ 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 80 +**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). 81 + 74 74 [[image:attach:lejos_eclipse_plugin.png]] 75 75 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 -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). 86 +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). 79 79 80 80 ---- 81 81 82 82 == Creating an Example Project == 83 83 84 -The following shows how to create a project, thatwill turn on a light if a button is pressed.92 +The following shows how to create a project, which will turn on a light if a button is pressed. 85 85 86 86 === Create a new project: === 87 87 ... ... @@ -115,7 +115,7 @@ 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// directory of the project in ftl files (FreeMarker template files). 126 +The available wrapper code snippets are defined in the //snippets// directory of the project 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 ... ... @@ -130,6 +130,490 @@ 130 130 131 131 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 132 141 +=== Available Wrapper Code Snippets === 142 + 143 +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. 144 + 145 +For sensors, the port has to be on of S1, S2, S3, S4. 146 + 147 +For motors / actuators the port has to be one of A, B, C, D. 148 + 149 +(% class="wrapped" %) 150 +|=((( 151 +Snippet Name and Parameters 152 +)))|=((( 153 +Description 154 +)))|=((( 155 +Use on 156 +)))|=(% colspan="1" %)(% colspan="1" %) 157 +((( 158 +Variable type 159 +)))|=((( 160 +Remark 161 +)))|=(% colspan="1" %)(% colspan="1" %) 162 +((( 163 +Defined in File 164 +))) 165 +|(% colspan="1" %)(% colspan="1" %) 166 +((( 167 +**Clock,** milliseconds 168 +)))|(% colspan="1" %)(% colspan="1" %) 169 +((( 170 +Sets a variable to true for one tick if the time in milliseconds passed since the last time it was set to true. 171 +)))|(% colspan="1" %)(% colspan="1" %) 172 +((( 173 +input 174 +)))|(% colspan="1" %)(% colspan="1" %) 175 +((( 176 +bool 177 +)))|(% colspan="1" %)(% colspan="1" %) 178 +((( 179 +See also ResetClock. 180 +)))|(% colspan="1" %)(% colspan="1" %) 181 +((( 182 +timing.ftl 183 +))) 184 +|(% colspan="1" %)(% colspan="1" %) 185 +((( 186 +**ResetClock,** clockVariableName, autoFalse 187 +)))|(% colspan="1" %)(% colspan="1" %) 188 +((( 189 +Resets a clock, such that the full time intervall of the clock has to elapse, before the clock will be set to true again. 190 + 191 +If autoFalse is true, the reset variable will be set to false automatically. 192 +)))|(% colspan="1" %)(% colspan="1" %) 193 +((( 194 +output 195 +)))|(% colspan="1" %)(% colspan="1" %) 196 +((( 197 +bool 198 +)))|(% colspan="1" %)(% colspan="1" %) 199 +((( 200 +autoFalse is true per default. 201 +)))|(% colspan="1" %)(% colspan="1" %) 202 +((( 203 +timing.ftl 204 +))) 205 +|(% colspan="1" %)(% colspan="1" %) 206 +((( 207 +**Time** 208 +)))|(% colspan="1" %)(% colspan="1" %) 209 +((( 210 +Reads the elapsed time since program start 211 +)))|(% colspan="1" %)(% colspan="1" %) 212 +((( 213 +input 214 +)))|(% colspan="1" %)(% colspan="1" %) 215 +((( 216 +int 217 +)))|(% colspan="1" %)(% colspan="1" %) 218 +((( 219 + 220 +)))|(% colspan="1" %)(% colspan="1" %) 221 +((( 222 +timing.ftl 223 +))) 224 +|(% colspan="1" %)(% colspan="1" %) 225 +((( 226 +**TickLoopDuration,** targetInMilliseconds 227 +)))|(% colspan="1" %)(% colspan="1" %) 228 +((( 229 +Delays the execution until the tick loop takes at least as long as the given target duration. 230 + 231 +The input variable is set to the actual tick loop duration. 232 +)))|(% colspan="1" %)(% colspan="1" %) 233 +((( 234 +input 235 +)))|(% colspan="1" %)(% colspan="1" %) 236 +((( 237 +int 238 +)))|(% colspan="1" %)(% colspan="1" %) 239 +((( 240 +Should be used on the very first input variable in the model, such that waiting is the last action in the tick loop. 241 +)))|(% colspan="1" %)(% colspan="1" %) 242 +((( 243 +timing.ftl 244 +))) 245 +|(% colspan="1" %)(% colspan="1" %) 246 +((( 247 +**TickWakeUp** 248 +)))|(% colspan="1" %)(% colspan="1" %) 249 +((( 250 +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. 251 + 252 +This means the next tick function call is delayed until the wake up time has been reached. 253 +)))|(% colspan="1" %)(% colspan="1" %) 254 +((( 255 +input 256 +)))|(% colspan="1" %)(% colspan="1" %) 257 +((( 258 +int 259 +)))|(% colspan="1" %)(% colspan="1" %) 260 +((( 261 +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. 262 +)))|(% colspan="1" %)(% colspan="1" %) 263 +((( 264 +timing.ftl 265 +))) 266 +|(% colspan="1" %)(% colspan="1" %) 267 +((( 268 +**Sleep** 269 +)))|(% colspan="1" %)(% colspan="1" %) 270 +((( 271 +Lets the current thread sleep the time in milliseconds of the variable value. 272 +)))|(% colspan="1" %)(% colspan="1" %) 273 +((( 274 +output 275 +)))|(% colspan="1" %)(% colspan="1" %) 276 +((( 277 +int 278 +)))|(% colspan="1" %)(% colspan="1" %) 279 +((( 280 + 281 +)))|(% colspan="1" %)(% colspan="1" %) 282 +((( 283 +timing.ftl 284 +))) 285 +|(% colspan="1" %)(% colspan="1" %) 286 +((( 287 +**Print,** autoReset 288 +)))|(% colspan="1" %)(% colspan="1" %) 289 +((( 290 +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 291 +)))|(% colspan="1" %)(% colspan="1" %) 292 +((( 293 +output 294 +)))|(% colspan="1" %)(% colspan="1" %) 295 +((( 296 +string 297 +)))|(% colspan="1" %)(% colspan="1" %) 298 +((( 299 +autoReset is true per default. 300 +)))|(% colspan="1" %)(% colspan="1" %) 301 +((( 302 +print.ftl 303 +))) 304 +|(% colspan="1" %)(% colspan="1" %) 305 +((( 306 +**DrawString,** x, y 307 +)))|(% colspan="1" %)(% colspan="1" %) 308 +((( 309 +Prints a string to the given x and y coordinate on the LCD. 310 +)))|(% colspan="1" %)(% colspan="1" %) 311 +((( 312 +output 313 +)))|(% colspan="1" %)(% colspan="1" %) 314 +((( 315 +string 316 +)))|(% colspan="1" %)(% colspan="1" %) 317 +((( 318 + 319 +)))|(% colspan="1" %)(% colspan="1" %) 320 +((( 321 +print.ftl 322 +))) 323 +|(% colspan="1" %)(% colspan="1" %) 324 +((( 325 +**Button, **buttonId 326 +)))|(% colspan="1" %)(% colspan="1" %) 327 +((( 328 +Sets a variable to true iff the button on the Mindstorms device is pressed. 329 +)))|(% colspan="1" %)(% colspan="1" %) 330 +((( 331 +input 332 +)))|(% colspan="1" %)(% colspan="1" %) 333 +((( 334 +bool 335 +)))|(% colspan="1" %)(% colspan="1" %) 336 +((( 337 +The buttonId has to be one of ENTER, LEFT, RIGHT 338 +)))|(% colspan="1" %)(% colspan="1" %) 339 +((( 340 +touch_and_buttons.ftl 341 +))) 342 +|(% colspan="1" %)(% colspan="1" %) 343 +((( 344 +**TouchSensor**, port 345 +)))|(% colspan="1" %)(% colspan="1" %) 346 +((( 347 +Sets a variable to true iff the touch sensor on the given port is pressed. 348 +)))|(% colspan="1" %)(% colspan="1" %) 349 +((( 350 +input 351 +)))|(% colspan="1" %)(% colspan="1" %) 352 +((( 353 +bool 354 +)))|(% colspan="1" %)(% colspan="1" %) 355 +((( 356 + 357 +)))|(% colspan="1" %)(% colspan="1" %) 358 +((( 359 +touch_and_buttons.ftl 360 +))) 361 +|(% colspan="1" %)(% colspan="1" %) 362 +((( 363 +**LightSensor,** port, percentValue 364 +)))|(% colspan="1" %)(% colspan="1" %) 365 +((( 366 +Reads the value of a light sensor. 367 + 368 +If percentValue is true, the a percent value is retured, based on the light sensor calibration. 369 +)))|(% colspan="1" %)(% colspan="1" %) 370 +((( 371 +input 372 +)))|(% colspan="1" %)(% colspan="1" %) 373 +((( 374 +int 375 +)))|(% colspan="1" %)(% colspan="1" %) 376 +((( 377 +percentValue is not available on EV3 378 +)))|(% colspan="1" %)(% colspan="1" %) 379 +((( 380 +light.ftl 381 +))) 382 +|(% colspan="1" %)(% colspan="1" %) 383 +((( 384 +**CalibrateLightSensor,** port, signal 385 +)))|(% colspan="1" %)(% colspan="1" %) 386 +((( 387 +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. 388 +)))|(% colspan="1" %)(% colspan="1" %) 389 +((( 390 +output 391 +)))|(% colspan="1" %)(% colspan="1" %) 392 +((( 393 +bool 394 +)))|(% colspan="1" %)(% colspan="1" %) 395 +((( 396 +signal has to be one of High, Low 397 +)))|(% colspan="1" %)(% colspan="1" %) 398 +((( 399 +light.ftl 400 +))) 401 +|(% colspan="1" %)(% colspan="1" %) 402 +((( 403 +**Floodlight,** port 404 +)))|(% colspan="1" %)(% colspan="1" %) 405 +((( 406 +Reads / Sets the state of the red lamp of the light sensor. 407 +)))|(% colspan="1" %)(% colspan="1" %) 408 +((( 409 +input 410 + 411 +output 412 +)))|(% colspan="1" %)(% colspan="1" %) 413 +((( 414 +bool 415 +)))|(% colspan="1" %)(% colspan="1" %) 416 +((( 417 + 418 +)))|(% colspan="1" %)(% colspan="1" %) 419 +((( 420 +light.ftl 421 +))) 422 +|(% colspan="1" %)(% colspan="1" %) 423 +((( 424 +**RCXLamp,** port 425 +)))|(% colspan="1" %)(% colspan="1" %) 426 +((( 427 +Turns an RCX lamp on (variable is true) or off (variable is false) 428 +)))|(% colspan="1" %)(% colspan="1" %) 429 +((( 430 +output 431 +)))|(% colspan="1" %)(% colspan="1" %) 432 +((( 433 +bool 434 +)))|(% colspan="1" %)(% colspan="1" %) 435 +((( 436 + 437 +)))|(% colspan="1" %)(% colspan="1" %) 438 +((( 439 +light.ftl 440 +))) 441 +|(% colspan="1" %)(% colspan="1" %) 442 +((( 443 +**MotorSpeed,** port, brake 444 +)))|(% colspan="1" %)(% colspan="1" %) 445 +((( 446 +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). 447 +)))|(% colspan="1" %)(% colspan="1" %) 448 +((( 449 +input 450 + 451 +output 452 +)))|(% colspan="1" %)(% colspan="1" %) 453 +((( 454 +int 455 +)))|(% colspan="1" %)(% colspan="1" %) 456 +((( 457 +brake is true per default. 458 +)))|(% colspan="1" %)(% colspan="1" %) 459 +((( 460 +motor.ftl 461 +))) 462 +|(% colspan="1" %)(% colspan="1" %) 463 +((( 464 +**MotorIsMoving,** port 465 +)))|(% colspan="1" %)(% colspan="1" %) 466 +((( 467 +Sets a variable to true iff the motor on the given port is moving. 468 +)))|(% colspan="1" %)(% colspan="1" %) 469 +((( 470 +input 471 +)))|(% colspan="1" %)(% colspan="1" %) 472 +((( 473 +bool 474 +)))|(% colspan="1" %)(% colspan="1" %) 475 +((( 476 + 477 +)))|(% colspan="1" %)(% colspan="1" %) 478 +((( 479 +motor.ftl 480 +))) 481 +|(% colspan="1" %)(% colspan="1" %) 482 +((( 483 +**MotorRotation,** port 484 +)))|(% colspan="1" %)(% colspan="1" %) 485 +((( 486 +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. 487 +)))|(% colspan="1" %)(% colspan="1" %) 488 +((( 489 +output 490 +)))|(% colspan="1" %)(% colspan="1" %) 491 +((( 492 +int 493 +)))|(% colspan="1" %)(% colspan="1" %) 494 +((( 495 + 496 +)))|(% colspan="1" %)(% colspan="1" %) 497 +((( 498 +motor.ftl 499 +))) 500 +|(% colspan="1" %)(% colspan="1" %) 501 +((( 502 +**Beep,** volume 503 +)))|(% colspan="1" %)(% colspan="1" %) 504 +((( 505 +Plays a beep sound as long as the variable is true. 506 +)))|(% colspan="1" %)(% colspan="1" %) 507 +((( 508 +output 509 +)))|(% colspan="1" %)(% colspan="1" %) 510 +((( 511 +bool 512 +)))|(% colspan="1" %)(% colspan="1" %) 513 +((( 514 +default volume is 10 515 +)))|(% colspan="1" %)(% colspan="1" %) 516 +((( 517 +sound.ftl 518 +))) 519 +|(% colspan="1" %)(% colspan="1" %) 520 +((( 521 +**Buzz,** volume 522 +)))|(% colspan="1" %)(% colspan="1" %) 523 +((( 524 +Plays a buzz sound as long as the variable is true. 525 +)))|(% colspan="1" %)(% colspan="1" %) 526 +((( 527 +output 528 +)))|(% colspan="1" %)(% colspan="1" %) 529 +((( 530 +bool 531 +)))|(% colspan="1" %)(% colspan="1" %) 532 +((( 533 +default volume is 10 534 +)))|(% colspan="1" %)(% colspan="1" %) 535 +((( 536 +sound.ftl 537 +))) 538 +|(% colspan="1" %)(% colspan="1" %) 539 +((( 540 +**BeepSequence,** direction, volume 541 +)))|(% colspan="1" %)(% colspan="1" %) 542 +((( 543 +Plays a sequence of tones in either ascending or descending tone frequency if the variable is true. 544 + 545 +The variable is set to false automatically. 546 +)))|(% colspan="1" %)(% colspan="1" %) 547 +((( 548 +output 549 +)))|(% colspan="1" %)(% colspan="1" %) 550 +((( 551 +bool 552 +)))|(% colspan="1" %)(% colspan="1" %) 553 +((( 554 +direction has to be one of Up, Down 555 + 556 +default volume is 10 557 +)))|(% colspan="1" %)(% colspan="1" %) 558 +((( 559 +sound.ftl 560 +))) 561 +|(% colspan="1" %)(% colspan="1" %) 562 +((( 563 +**UltrasonicSensor,** port 564 +)))|(% colspan="1" %)(% colspan="1" %) 565 +((( 566 +Reads the distance that an ultrasonic sensor measures. 567 +)))|(% colspan="1" %)(% colspan="1" %) 568 +((( 569 +input 570 +)))|(% colspan="1" %)(% colspan="1" %) 571 +((( 572 +int 573 +)))|(% colspan="1" %)(% colspan="1" %) 574 +((( 575 + 576 +)))|(% colspan="1" %)(% colspan="1" %) 577 +((( 578 +ultrasonic.ftl 579 +))) 580 +|(% colspan="1" %)(% colspan="1" %) 581 +((( 582 +**Gyro,** port, mode 583 +)))|(% colspan="1" %)(% colspan="1" %) 584 +((( 585 +Reads the value of a gyroscope. 586 +)))|(% colspan="1" %)(% colspan="1" %) 587 +((( 588 +input 589 +)))|(% colspan="1" %)(% colspan="1" %) 590 +((( 591 +int 592 +)))|(% colspan="1" %)(% colspan="1" %) 593 +((( 594 +Not available on NXT 595 + 596 +mode hat to be one of Angle, Rate 597 +)))|(% colspan="1" %)(% colspan="1" %) 598 +((( 599 +gyro.ftl 600 +))) 601 +|(% colspan="1" %)(% colspan="1" %) 602 +((( 603 +**CalibrateGyro,** port, autoReset 604 +)))|(% colspan="1" %)(% colspan="1" %) 605 +((( 606 +Resets a gyroscope if the variable is true. 607 + 608 +If autoReset is true, the variable is set to false automatically. 609 +)))|(% colspan="1" %)(% colspan="1" %) 610 +((( 611 +output 612 +)))|(% colspan="1" %)(% colspan="1" %) 613 +((( 614 +bool 615 +)))|(% colspan="1" %)(% colspan="1" %) 616 +((( 617 +autoReset is true per default 618 +)))|(% colspan="1" %)(% colspan="1" %) 619 +((( 620 +gyro.ftl 621 +))) 622 + 623 + 624 + 133 133 ---- 134 134 135 135 == Using the Remote Console (RConsole) == ... ... @@ -146,6 +146,7 @@ 146 146 147 147 The following presents typical issues and how to solve them. 148 148 641 +(% class="wrapped" %) 149 149 |=((( 150 150 Issue 151 151 )))|=((( ... ... @@ -209,3 +209,5 @@ 209 209 210 210 211 211 705 + 706 +input
- Confluence.Code.ConfluencePageClass[0]
-
- Id
-
... ... @@ -1,1 +1,1 @@ 1 - 155322301 +27459607 - URL
-
... ... @@ -1,1 +1,1 @@ 1 -https://rtsys.informatik.uni-kiel.de/confluence//wiki/spaces/KIELER/pages/ 15532230/LEGO Mindstorms with leJOS and SCCharts1 +https://rtsys.informatik.uni-kiel.de/confluence//wiki/spaces/KIELER/pages/27459607/LEGO Mindstorms with leJOS and SCCharts