Search This Blog

Wednesday, February 9, 2011

LightCatcher–Framstick creatures example

LightCatcher - Framstick genotype + neuron

author: Bartosz Kosarzycki

Introduction

The main idea behind this project was to create a framstick that could follow a flying torch in a 3-d area. The example creature however isn't able to discern three dimensions as it is limited to 2-d.
The implementation was divided into two steps:
  • designing the body structure
  • implementing neuron "brain"

Designing the body structure

The simplest body structure allowing us to follow a light in (x,y) is a simple cross with Catchlight neuron in the middle. There has to be a SeeLight neuron on each end of the four sides.
Such a genotype is presented below:
lightCatcherBody
There are neural connections from SeeLights to Catchlight neuron which acts as a command center. Every SeeLight neuron is placed exactly 2 measument units from the center. LightCatcher body was written in //f0 language of framsticks.
Body structure on 2-d plane is presented below:
body2dPlane
This architecture has a serious flaw: when we want to move the creature across (e.g. up & left) we cannot do this as the framstick's function applyForce() applied two times in one go() function does not work as we would expect. The effect is that when we chase a light that moves in a straight line and it suddenly turns to a side we need some time to adjust our path (we will start turning left when the value from left neuron is greater than the value of top neuron.)

The Catchlight neuron

Catchlight neuron is the command center of the whole creature. This type of neuron has to be connected to 4 other Seelight neurons. If that's not the case the command center will cease to work and print an exception: "Wrong number of inputs in 'CatchLight' neuron.".
The Catchlight neuron code can be downloaded in the download section below.
We get values of all four SeeLight neurons like this:
var leftVal = Neuro.getInputState(0);
Then we get maximum values from horizontal and vertical neurons:
var halfMaxVert = Math.max(topVal, bottomVal);
var halfMaxHor = Math.max(leftVal, rightVal);
Later we decide whether to go in vertical or horizontal direction. We cannot move in both as the limitation of applyForce() forbids us that. In the end we calculate Force values to apply (in x and y axis) with the use of calcDirections() function. ThedecideToPush() decides whether to push the creature. If the function weren't there we would push the creature indifinately towards the light even if it was going in the right direction. This would cause it to gain more and more speed. Every creature in Framsticks has mass so it would be hard to change the creature's direction with that much speed gained.
If we have calculated force x,y value and decided whether to push the creature or not we can apply the force at last. This can be done like this:
middlePart.applyForce(dir[0]*vbv[0], dir[1]*vbv[1], 0);
The force is applied to the middlePart (that is where the Catchlight neuron is placed). We would expect the creature to bend and leave its SeeLight neurons behind. Fortunately there is a mode we can set in Framsticks called "ODE" which makes creatures stiff and enables the whole structure to work as we need it to.
lightCatcherInAction

The Flashlight neuron

The Flashlight neuron is used to create 'a moving torch'. It's a very simple creature that moves randomly in 2-d. It should 'run away' and be hard to catch but cannot move too fast as the LightCatcher wouldn't be able to catch up. The body is nothing more than: X[LightStill].

Debugging

The creature has extensive debugging built in. During runtime press ctrl+m in Framsticks to see the debugging messages. Example messages.out can be gotten from downloads section.

Downloads

Catchlight.neuro
Flashlight.neuro
LightCatcher.body
LightCather.expt
messages.out

All the above files: here

Instructions on Framsticks environment usage

To use this creature in Framsticks do the following:
  • copy Catchlight.neuro and Flashlight.neuro to: $FramsticksMainDirectory$/scripts
  • copy LightCatcher.expt to the main Framsticks directory
  • disable gravity in Framsticks
  • change initial elevation of framsticks to 0 (Experiment - Parameters)
  • change the world simulation engine to "ODE" (it's set to "MechaStick" at default)
  • it's not neccessary but it's better to set Experiment - Parameters - Initial placement to "Central" and initial orientation to "Always 0 degrees"
You can open the experiment by pressing ctrl+O and selecting LightCatcher.expt file. It has preset "world parameters" so the experiment works out-of-the-box and there is no need to set anything. Now place a creature called 'Light catcher' on the plane by selecting it in gene pool and pressing ctrl+alt+s. Place 'moving still-emiting flashlight' in the same manner and start the simulation.

 

Link to Framstick Environment:
http://www.framsticks.com/a/al_download

No comments:

Post a Comment

If you like this post, please leave a comment :)