## Pioneer p3dx

Typically: "How do I... ", "How can I... " questions
cena
Posts: 7
Joined: 14 Jun 2014, 11:08

### Pioneer p3dx

Hello,
I just started using the software and was interested in understanding the pioneer robot algorithm used. I will be very grateful if you could answer the 6 questions related to the code highlighted in red.
The code used for the pioneer p3dx is given below,

-- This is a very simple EXAMPLE navigation program, which avoids obstacles using the Braitenberg algorithm

if (simGetScriptExecutionCount()==0) then
usensors={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}
for i=1,16,1 do
usensors=simGetObjectHandle("Pioneer_ultrasonicSensor"..i)
end
motorLeft=simGetObjectHandle("Pioneer_leftMotor")
motorRight=simGetObjectHandle("Pioneer_rightMotor")
noDetectionDist=0.5 -- what does this line mean, does it mean dont detect obstacle further than 0.5m
maxDetectionDist=0.2
detect={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} -- why are all the values zero, what does this do?
braitenbergL={-0.2,-0.4,-0.6,-0.8,-1,-1.2,-1.4,-1.6, 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0} -- why are the values like this, how is it calculated
braitenbergR={-1.6,-1.4,-1.2,-1,-0.8,-0.6,-0.4,-0.2, 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0}
v0=2 -- what is v0 and why is it set to 2, does it mean a velocity of 2m/s or something
end

simHandleChildScript(sim_handle_all_except_explicit)

for i=1,16,1 do
if (res>0) and (dist<noDetectionDist) then
if (dist<maxDetectionDist) then
dist=maxDetectionDist
end
detect=1-((dist-maxDetectionDist)/(noDetectionDist-maxDetectionDist)) -- Finally, what is this equation doing, more explanation about the bracket numerator and denominator please
else
detect=0
end
end

vLeft=v0
vRight=v0

for i=1,16,1 do
vLeft=vLeft+braitenbergL*detect
vRight=vRight+braitenbergR*detect
end

simSetJointTargetVelocity(motorLeft,vLeft)
simSetJointTargetVelocity(motorRight,vRight)

Regards
Maruf

Eric
Posts: 186
Joined: 11 Feb 2013, 16:39

### Re: Pioneer p3dx

Hi,

These kind of questions are not really related to V-REP but mostly programming.
1_what does this line mean, does it mean dont detect obstacle further than 0.5m
yes
2_why are all the values zero, what does this do?
initialisation values only
3_ why are the values like this, how is it calculated
the braitenberg parameters are "tuned" by hand to achieve the wanted comportment. try to change them to see how the robot behaves.
4_ what is v0 and why is it set to 2, does it mean a velocity of 2m/s or something
it s the traveling velocity of the robot when it does not detect any obstacle
5_what is res
result... As for any api fucntions there is a doc. For this one, check here
6_ Finally, what is this equation doing, more explanation about the bracket numerator and denominator please
it s an equation to be used later as a factor to modify the velocity of each wheel. to define a % of V0. Each detect will be multiplied by the sensor s corresponding braitenberg parameter in order to influence the final wheel velocity.

Cheers

Eric

cena
Posts: 7
Joined: 14 Jun 2014, 11:08

### Re: Pioneer p3dx

Hello,

Could anyone please tell me where can I read more about how to write the codes that has been used for the Pioneer p3dx in vrep?
I do not know much about lua script.
In particular the braitenberg algorithm if I am starting from scratch and do not know anything about programming.

Kind regards
Maruf

coppelia
Posts: 7918
Joined: 14 Dec 2012, 00:25

### Re: Pioneer p3dx

Hello Maruf,

the code in that robot model is just an example, and we are not specialists of control codes. You can read everything you need to know about the Braitenberg algorithm here. And you can also learn Lua here.

Cheers

cena
Posts: 7
Joined: 14 Jun 2014, 11:08

### Re: Pioneer p3dx

Hello Eric,

Thank you so much for your replies.
Could you please kindly tell me what are the changes I would have to make to the pioneer p3dx model and the code if I wanted to use just 3 sensors ( left,right and center) instead of the 16 that are used?
Also what should i put in the code if I want more random movement for example for the robot to go reverse at times instead of always turning clockwise ?

Regards
Maruf

Eric
Posts: 186
Joined: 11 Feb 2013, 16:39

### Re: Pioneer p3dx

hi
you could do something like this to check only 3 sensors

Code: Select all

for i=1,16,1 do
if i==2 or i==5 or i==7 then --consider only sensor 2 , 5 and 7
vLeft=vLeft+braitenbergL[i]*detect[i]
vRight=vRight+braitenbergR[i]*detect[i]
end
end
and to randomize the motion, you could try to modify the braitenberg parameters with something like that, inside the main loop:

Code: Select all

math.randomseed(simGetSystemTimeInMilliseconds())
braitenbergL={-0.2,-0.4*math.random(-20,20)/5,-0.6,-0.8,-1*math.random(-20,20)/10,-1.2,-1.4*math.random(-20,20)/10,-1.6, 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0}
braitenbergR={-1.6,-1.4*math.random(20)/10,-1.2,-1,-0.8*math.random(20)/10,-0.6,-0.4*math.random(20)/10,-0.2, 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0}

you ll have to tune the *math.random(20)/10 though

cena
Posts: 7
Joined: 14 Jun 2014, 11:08

### Re: Pioneer p3dx

Dear Eric,

I have a few questions,

Question 1) For the line
braitenbergL={-0.2,-0.4,-0.6,-0.8,-1,-1.2,-1.4,-1.6, 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0}

What is for example -0.2 exactly? What does this particular value have effect on? Does it affect the speed ?
Does it affect the angle of rotation?

Question 2)
where did you get this equation from?
detect=1-((dist-maxDetectionDist)/(noDetectionDist-maxDetectionDist)

Question 3)
Can you please suggest a way by which i can make the robot go reverse at times ?

Question 4)
About you last reply to randomize the movement, I did not understand what you meant by " you ll have to tune the *math.random(20)/10 though "

Thank you so much for your kind response.
Maruf

Eric
Posts: 186
Joined: 11 Feb 2013, 16:39

### Re: Pioneer p3dx

Hi

As I already answered in your first post, the -0.2 is just a parameter. As also suggested before, try to understand how Braitenberg algo works. It affects both speed and rotation. If you can not understand this implementation, you d rather implement your own controller based on Braitenberg or other obstacle avoidance algorithm. Braitenberg is not designed to implement the "go reverse at a time" feature you are willing to implement. You can try to tune it and add some random inside the parameters as I already suggested but you d rather follow an other strategy. Please before trying to get the implementation of the algo if you don t understand the code, study what Braitenberg does.

Eric