braitenberg vehicles in VREP

Typically: "How do I... ", "How can I... " questions
Post Reply
s.jung

braitenberg vehicles in VREP

Post by s.jung » 06 May 2013, 20:31

Hello everyone!

I am currently trying to simulate braitenberg vehicles with VREP for a small project, but i am not able to write a working script for it, based on the knowledge i gained from the tutorials only.

You can find my attempt in the following link and i would be very thankful if someone could tell me how to continue.

https://docs.google.com/file/d/0BzER-gY ... sp=sharing

The lightsensors are pointed to the ground and measure the intensity in greyscale mode. Since the value for the intensity is between 0 and 1 i figuered the speed for the joints had to be multiplied by 100.

thank you for your attention and i hope you can spare a some time to help me.

best regards,
s.jung

coppelia
Site Admin
Posts: 7314
Joined: 14 Dec 2012, 00:25

Re: braitenberg vehicles in VREP

Post by coppelia » 06 May 2013, 21:21

Hello,

I had a quick look at your scene. A few things:
  • You are mixing-up threaded and non-threaded constructs. Make sure you read this section carefully. Your child script is non-threaded, and in that case it should be used as a function (i.e. it will be called at each simulation pass, you can then do some sensor reading, motor velocity setting, but do not spend too much time in there). Basically it should be in, then out!
  • Your floor looks not good with the lighting. You can select the visible part of your floor, then enter the triangle edit mode, then click 1-2 times subdivide largest triangles. Do that procedure with DefaultFloor and patternB
  • When reading a vision sensor, you will have to do something like following (unless you have prepared a triggering mechanism, which is not the case in your scene):

Code: Select all

result,data=simReadVisionSensor(sensorHandle)
if (result>=0) then
    if (data[11]>thresholdValue) then
        print('we have white')
    else
        print('we have black')
    end
end
Refer also to the simReadVisionSensor command in the documentation: the data variable contains summarized values, that are easy to query. data[11] contains the average intensity value of your vision sensor image.

Cheers

s.jung

Re: braitenberg vehicles in VREP

Post by s.jung » 06 May 2013, 22:02

thank you for your quick reply!
the floor does look much nicer now

I will read the section about childscripts, work on it and see how far i can get.

I only have very basic (and very limited) knowlegde of programming,... so even if the childscript is not that complex, i might be back quite soon.

best regards

s.jung

Re: braitenberg vehicles in VREP

Post by s.jung » 10 May 2013, 15:17

hello,
this is the most recent version of my model:

https://docs.google.com/file/d/0BzER-gY ... sp=sharing

as predicted, i am back with a bunch of questions:

- where do i actually see the "print ('something')" line? i could not find it on the screen, in the console nor in the status bar

- part of my code now looks like this:

Code: Select all

leftresult,data=simReadVisionSensor(leftsensor)

if (leftresult>0) then
	print ('we have white')
	simSetJointTargetVelocity(leftmotor,100)
        else
	print ('we have black')
	simSetJointTargetVelocity(leftmotor,0)
end
as i understand: if the measured intensity is higher than 0, meaning the image is "not black", the motor velocity should be set to 100. However, the model does only move when i set the velocity in the "else" command also to 100.

- i want the velocity to be set according to the intensity (which is a value beweteen 0 and 1), so i added this line:

Code: Select all

leftspeed=leftresult*100
and set the

Code: Select all

simSetJointTargetVelocity(leftmotor,leftspeed)
but this does not work at all...

i think (or hope) there is now a pure non-threaded child script and no mix-up.

thank you for your time and help,

best regards,
s.jung

coppelia
Site Admin
Posts: 7314
Joined: 14 Dec 2012, 00:25

Re: braitenberg vehicles in VREP

Post by coppelia » 10 May 2013, 20:11

Hi,

For printing something, you can turn on the default console window (on Windows) here. From an embedded script, use print, from a c/c++ plugin, use printf or cout.

You can also use an autiliary console window, and print to it. This post suggests something neat.

You can also print to the status bar with simAddStatusbarMessage.

You should work with a threshold, because your image will never be completely black. so for instance:

Code: Select all

leftresult,data=simReadVisionSensor(leftsensor)
if (data[11]>threshold) then
    print('we have white')
    simSetJointTargetVelocity(leftmotor,velocityInDegreesPerSecond*math.pi/180)
else
    print('we have black')
    simSetJointTargetVelocity(leftmotor,0)
end
Remember that the API units are always radians, meters, seconds, kg, etc. Unless otherwise specified! Also, you didn't read carefully my previous post. You should use data[11], not leftresult.

If you want a gradual control, do something like:

Code: Select all

velocityInDegreesPerSecond=data[11]*maxVelocityInDegreesPerSecond
Cheers

s.jung

Re: braitenberg vehicles in VREP

Post by s.jung » 13 May 2013, 12:04

thank you very much for your help.

i was able to model the braitenberg vehicles in a very basic fashion. i guess the code is not optimal but it does work now.

best regards,
s.jung

Post Reply