how to control Braitenberg with keyboard?

Sorry, but I am a member of Guadalajara´s University and I´m trying to get control of the Braitenberg Vehicle, that means, i would like to move the vehicle by pressing a key(maybe 4 or 5 keys) in all the possible ways (to the front, left, right, back. whithout sensors). Can i get control of the motor instead or all vehicle?. i will be gratefully about the info.

how to control Braitenberg with keyboard?

Hi roca,
I decided to try this for a while, and I have something, but it's a bit of a hack, and there's probably much better ways (anyone?).

I've got a variable:
wheels (list).
Then in my main init, I set it to refer to all of the wheels:
wheels = all BraitenbergWheels.

Then, I have methods for the keys:
+ to catch-key-up-down:
wheels set-natural-velocity to 1.

+ to catch-key-down-down:
wheels set-natural-velocity to -1.

This sets the natural velocity (the speed the vehicle does when no sensor input), which only moves it forwards and backwards.

I had a look at the Braitenberg class, and can't see how to move it left or right, since the variable newVelocity that moves the vehicle is just a float.
Perhaps this can be set individually for each wheel.

A better way might be to create a class that extends the Braitenberg one(s).

Thank´s .

Thank you for your attention and reply, but i was trying to do the next code. can you run it and take a look. i am not a great programmer but i think this maybe work. (my next ploblem is that the wheels, when a big collide happens they get out of it´s original position). The roca object is a try to intend a stone (with mass, density, if the stone is bigger or smaller could be heavy or lightly that does not matter - that means, if the stone is bigger the vehicle will try to move it; if the stone move, then means that is not heavy). Thank´s for your attention and comments.

@use PhysicalControl.
@use Link.
@use Genome.
@use Shape.
@use Stationary.
@use MultiBody.

@define CANTIDAD 4.

Controller Walker.

PhysicalControl : Walker {
+ variables:
wigglyThing (object).
piedra (object).
# the following are flags that can be controlled by the user
# via the simulation menu
locked (int).
cloudTexture (object).
vx, gx (float).

+ to init:
floor (object).
vx = 1.
gx = 0.
locked = 0.

self enable-fast-physics.
self full-gravity.
#self set-fast-physics-iterations to 5.

# these are the default values anyway...

self enable-lighting.
self enable-smooth-drawing.

self move-light to (0, 20, 0).

# Create the floor for the critter to walk on.

floor = new Floor.
floor catch-shadows.
floor set-color to (1.0, 1.0, 1.0).
floor set-eT to .9.

cloudTexture = (new Image load from "images/clouds.png").

self enable-shadow-volumes.
self enable-reflections.

self set-background-color to (.4, .6, .9).
self set-background-texture-image to cloudTexture.

# Create the Creature.

wigglyThing = new Creature.
wigglyThing move to (0, 6, 0).
self offset-camera by (3, 13, -13).
self watch item wigglyThing.
piedra = new Roca.
piedra move to (20, 4, 5).

+ to iterate:
if random[50] == 0: self drop-Caja.

super iterate.

+ to drop-Caja:
new Caja.

+ to catch-key-r-down: {
#eje iterate con-velocidad v con-giro g.
#eje1 iterate con-velocidad v con-giro g.
print("presionaste la tecla y el valor de ´v es: $vx el valor de ´g: $gx ").
}

+ to catch-key-w-down: {
vx++.
print("velocidad incrementada a: $vx").
wigglyThing controla-carro con-velocidad vx con-giro gx.
}

+ to catch-key-a-down: {
gx = gx + .1.
print("giro incrementado a: $gx").
wigglyThing controla-carro con-velocidad vx con-giro gx.
}

+ to catch-key-d-down: {
gx = gx - .1.
print("giro decrementado a: $gx").
wigglyThing controla-carro con-velocidad vx con-giro gx.
}

+ to catch-key-s-down: {
vx--.
print("velocidad decrementada a: $vx").
wigglyThing controla-carro con-velocidad vx con-giro gx.
}

+ to catch-key-0x20-down: {
self destruye.
self init.
}

super iterate.

}

MultiBody : Creature {
+ variables:
bodyLink (object).
links (list).
joints (list).
v, g (float).

+ to get-root:
return bodyLink.

+ to init:
linkShape, bodyShape (object).
#v = 2.
#g = 0.

self add-menu named "Send to Center" for-method "center".

linkShape = (new PolygonDisk init-with radius 1 sides 40 height .3).
bodyShape = (new Cube init-with size (7, 3, 1)).

links = 4 new Links.
joints = 4 new UniversalJoint.

links{0} set-shape to linkShape.
links{1} set-shape to linkShape.
links{2} set-shape to linkShape.
links{3} set-shape to linkShape.

self add-dependency on joints{0}.
self add-dependency on joints{1}.
self add-dependency on joints{2}.
self add-dependency on joints{3}.

links set-color to random[(1.0, 1.0, 1.0)].

bodyLink = new Link.
bodyLink set-shape to bodyShape.

joints{0} = new eje.

joints{0} link parent bodyLink to-child links{0}
with-normal (0, 1, 0)
with-parent-point (2.0, -1.5, 0)
with-child-point (0, .5, 0).
joints{1} = new eje.

joints{1} link parent bodyLink to-child links{1}
with-normal (0, 1, 0)
with-parent-point (2.0, 1.5, 0)
with-child-point (0, -.5, 0).

joints{2} = new eje1.
joints{2} link parent bodyLink to-child links{2}
with-normal (0, 1, 0)
with-parent-point (-2.0, -1.5, 0)
with-child-point (0, .5, 0).

joints{3} = new eje1.
joints{3} link parent bodyLink to-child links{3}
with-normal (0, 1, 0)
with-parent-point (-2.0, 1.5, 0)
with-child-point (0, -.5, 0).

self set-root to bodyLink.

# rotate the creature and move it to above the origin.

self rotate around-axis (1, 0, 0) by 1.57.

joints set-double-spring with-strength 500 with-max .8 with-min -.8.
joints set-strength-limit to 5000.

+ to controla-carro con-velocidad vx (float) con-giro gx (float):
v = vx.
g = gx.

+ to iterate:
joints{0} asigna-valores-eje con-velocidad v con-giro g .
joints{1} asigna-valores-eje con-velocidad v con-giro g .
joints{2} asigna-valores-eje1 con-velocidad v.
joints{3} asigna-valores-eje1 con-velocidad v.

+ to center:
# to center the object, we set the X and Z components to 0, but not
# the Y, otherwise we would push the walker into the ground
currentLocation (vector).
currentLocation = (self get-location).
self move to (0, currentLocation::y, 0).
+ to destroy:
free links.
free bodyLink.
}

UniversalJoint : eje {
+ variables:
v1, g1 (float).

+ to asigna-valores-eje con-velocidad v (float) con-giro g (float):
v1 = v.
g1 = g.

+ to iterate:
self set-joint-velocity axis-1 v1 axis-2 g1.
self set-joint-limits a1-min -10 a1-max 30 a2-min -1 a2-max 1.
}

UniversalJoint : eje1 {
+ variables:
v2 (float).
g2 (float).

+ to asigna-valores-eje1 con-velocidad v (float):
v2 = v.

+ to iterate:
g2 = 0.
self set-joint-velocity axis-1 v2 axis-2 g2.
self set-joint-limits a1-min -10 a1-max 30 a2-min 0 a2-max 0.
}

MultiBody : Roca {
+ variables:
bodyLink (object).
links (list).
joints (list).
l,m,n (int).

+ to init:
linkShape, lowerLinkShape, bodyShape (object).

self add-menu named "Send to Center" for-method "center".

lowerLinkShape = (new Cube init-with size (2.0, 1.0, 1.5)).
linkShape = (new Cube init-with size (1.5, 1.0, 3)).
bodyShape = (new Cube init-with size (1.5, 1.0, 1)).

linkShape set-mass to (1).
links set-density to (1).

links = CANTIDAD new Links.
joints = CANTIDAD new FixedJoint.

for l=0,l<CANTIDAD,l+=2: {
links{l} set-shape to linkShape.
}

for m=1,m<CANTIDAD,m+=2: {
links{m} set-shape to lowerLinkShape.
}

links set-color to(.5, .5, .5).

bodyLink = new Link.
bodyLink set-shape to bodyShape.
bodyLink set-color to (.5, .5, .5).

for n=0,n<CANTIDAD,n+=2: {

joints{n} link parent bodyLink to-child links{n}
#with-normal (0, 0, 1)
with-parent-point random[(1.0, 1.0, 2.0)]
with-child-point random[(1.0, 2.0, 1.0)].

joints{n+1} link parent links{n} to-child links{n+1}
#with-normal (1, 0, 0)
with-parent-point random[(1.0, 2.0, 1.0)]
with-child-point random[(2.0, 1.0, 2.0)].
}

self register with-link bodyLink.

+ to center:
# to center the object, we set the X and Z components to 0, but not
# the Y, otherwise we would push the walker into the ground

self move to (0, 10, 0).

}

Mobile : Caja {
+ to init:
self set-shape to (new Cube init-with size random[(3.5, 3.5, 3.5)]).

self set-color to random[(1, 1, 1)].

self move to random[(20, 0, 20)] + (-5, 15, -5).

self enable-physics.

+ to iterate:
if (self get-age) > 15: free self.
}

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.