kramann.info
© Guido Kramann

Login: Passwort:










kramann.info
© Guido Kramann

Login: Passwort:




Voll ausgebildetes Schwarmfahrzeug

(EN google-translate)

(PL google-translate)

EN: Fully developed swarm vehicle


Latest swarm simulator version: LUAbot010groundcolor.zip

Corresponding sketch to generate ground picture: LUAbot010b_GROUND_PICTURE.zip

Vehikelkonzept / Vehicle Concept.

Bild 0-1: Vehikelkonzept / Vehicle Concept.

Die nachfolgend weiter entwickelte Version des LUAbot besitzt bereits:

  • einen Entfernungssensor
  • einen Farbsensor zur Erkennung von Farben in der Ferne
  • einen Bodensensor zum Erkennen von Farben

Diese Elemente können in den Verhaltensregeln im LUA-Skript verwendet werden.


EN:


The following, further-developed version of the LUAbot already includes:

  • a distance sensor
  • a color sensor for detecting colors at a distance
  • a ground sensor for detecting colors

These elements can be used in the behavior rules within the LUA script.

2. Rückgabe von Integer-Arrays bei in Java eingebetteten LUA-Funktionen

EN 2. Returning integer arrays in Lua functions embedded in Java

  • In LUA-Funktionen können die zurückzugebenden Variablen einfach mit Kommata getrennt aufgelistet werden, damit sie ein Array bilden.
  • Von Java aus gelingt der Empfang des zurückgegebenen Array durch Verwendung von "invoke" statt "call" in Kombination mit Varargs als Rückgabetyp.
  • Vergleiche dazu die LUAJ Referenz:

EN:


  • In Lua functions, the variables to be returned can simply be listed, separated by commas, to form an array.
  • From Java, the returned array can be received by using "invoke" instead of "call" in combination with varargs as the return type.
  • See the LUAJ reference for more information:
http://www.luaj.org/luaj/3.0/README.html -- siehe/see "LuaValue and Varargs ... Common Functions"
  • Außerdem kann der Pfad zum aktuellen Sketch mit Hilfe der Funktion sketchPath() ausgelesen werden.
  • EN: In addition, the path to the current sketch can be retrieved using the sketchPath() function.
Testbeispiel / Test Example:
function MyAdd( num1, num2 )
    return num1 + num2,num1,num2
end

Code 0-1: LUA Function in File test.lua

import org.luaj.vm2.*;
import org.luaj.vm2.lib.jse.*;

public void setup()
{
    Globals globals = JsePlatform.standardGlobals();
    //LuaValue chunk = globals.load("print 'hello, world'");
    //chunk.call();
    globals.get("dofile").call( LuaValue.valueOf(sketchPath()+"/test.lua"));
    //call the function MyAdd with two parameters 7, and 5
    LuaValue MyAdd = globals.get("MyAdd");
    LuaValue retvals = MyAdd.call(LuaValue.valueOf(7), LuaValue.valueOf(5));
    Varargs retvals2 = MyAdd.invoke(LuaValue.valueOf(7), LuaValue.valueOf(5));

    println("Number of returned variables: "+retvals2.narg());
    println("num1 + num2: "+retvals2.toint(1));
    println("num1: "+retvals2.toint(2));
    println("num2: "+retvals2.toint(3));
}

Code 0-2: Processing-Sketch using "MyAdd"

3. Erweiterung des Schwarmsimulators

EN 3. Expansion of the swarm simulator

  • Ein Fahrzeug bekommt über die der LUA-Funktion (function behavior) übergebenen Variablen Informationen aus seiner Umwelt.
  • Aus diesen Umweltinformationen wird das aktuelle Verhalten berechnet.
  • Das aktuelle Verhalten wird als Array von der LUA-Funktion zurückgegeben.
  • Um Informationen von einem Aufruf zum nächsten behalten zu können, werden eine Reihe Variablen (mem0..mem9) zur Verfügung gestellt, die von der LUA-Funktion zurückgegeben und beim nächsten Aufruf wieder mit ihrem letzten Wert der LUA-Funktion übergeben werden.
  • Es werden in der LUA-Funktion ausschließlich Integer-Variablen verwendet.

EN:


  • A vehicle receives information about its environment via variables passed to the LUA function (function behavior).
  • The current behavior is calculated based on this environmental information.
  • The current behavior is returned by the LUA function as an array.
  • To retain information from one call to the next, a set of variables (mem0..mem9) is provided; these are returned by the LUA function and passed back to the LUA function on the next call with their last value.
  • Only integer variables are used in the LUA function.
Input-Variablen

Folgende Variablen werden der LUA-Funktion als Umwelt-Informationen übergeben:

EN: The following variables are passed to the LUA function as environment information:

name range meaning
col 0..1 1=collision with other vehicle 0=not
colwall 0..1 1=collision with wall 0=not
d 0.. distance to next obstacle in front of vehicle in pixels.
dr 0..255 pixel color of next obstacle in front of vehicle. red part
dg 0..255 pixel color of next obstacle in front of vehicle. green part
db 0..255 pixel color of next obstacle in front of vehicle. blue part
pr 0..255 ground pixel color front edge of vehicle. red part
pg 0..255 ground pixel color front edge of vehicle. green part
pb 0..255 ground pixel color front edge of vehicle. blue part

Tabelle 0-1: Table of all input variables of function behavior

Folgende Variablen werden von der LUA-Funktion zurück gegeben:

EN: The following variables are returned by the LUA function:

name range meaning
v 0..20 translational speed in pixels per second
w -20..20 rotational speed in degree per second
r 0..255 vehicle color. red part.
g 0..255 vehicle color. green part.
b 0..255 vehicle color. blue part.

Tabelle 0-2: Table of all output variables of function behavior


Durch das Erfassen der Pixelfarbe des nächsten Hindernisses ist prinzipiell eine Kommunikation der Fahrzeuge untereinander möglich.


LUAJ reference, especially Varargs: http://luaj.org/luaj/3.0/api/org/luaj/vm2/Varargs.html

EN: By detecting the pixel color of the next obstacle, the vehicles can, in principle, communicate with one another.


Bildschirmfoto eines Simulationsdurchlaufs / Screenshot of Simulation

Bild 0-2: Bildschirmfoto eines Simulationsdurchlaufs / Screenshot of Simulation

LUA-Skript welches das Verhalten beschreibt / LUA-Script Describing Behavior

function behavior(col,colwall,d,dr,dg,db,pr,pg,pb,mem0,mem1,mem2,mem3,mem4,mem5,mem6,mem7,mem7,mem8,mem9)

    countdown=mem0

    v=0
    w=0
    r=pr/2
    g=pg/2
    b=pb/2
    if ( (col==1 or colwall==1) and countdown==0) then
        countdown=20        
    end

    if ( countdown>0 ) then
        w=5
        v=0
        countdown = countdown - 1
        r=dr
        g=dg
        b=db
    else
        w=0
        v=10
    end

    mem0=countdown

    return v,w,r,g,b,mem0,mem1,mem2,mem3,mem4,mem5,mem6,mem7,mem8,mem9
end

Code 0-3: behavior.lua -- LUA-Skript welches das Verhalten beschreibt / LUA-Script Describing Behavior