Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Is my pure pursuit algorithm/pseudocode alright?

Status
Not open for further replies.

watchdog545

New Member
I don't want to code it, even if I code it, there's no way of knowing if it's semantically correct or not. So I am asking it here-:

Pure Pursuit Problem
My pseudocode-:

Code:
Read the following-:
a) Bomber's path xb(t), yb(t) for t=0,1,2...12
b) initial position of fighter xf(0) and yf(0)
c) fighter's velocity vf

while(1)
{
dist(t)=sqrt((xb(t)-xf(t))²+(yb(t)-yf(t))²)

if dist<=10kms=>print target caught at time "t"mins and distance "dist" kms=>stop

else if t>11=>print "target escaped"=>stop

else

cos(th)=[yb(t)-yf(t)]/[dist(t)]
sin(th)=[xb(t)-xf(t)]/[dist(t)]
t=t+1
xf(t)=xf(t)+vf*cos(th)
yf(t)=yf(t)+vf*sin(th)
}
 
Code:
t=t+1
xf(t)=xf(t)+vf*cos(th)
yf(t)=yf(t)+vf*sin(th)

I am thinking of writing this line as this-:

Code:
xf(t+1)=xf(t)+vf*cos(th)
yf(t+1)=yf(t)+vf*sin(th)
t=t+1

Would it make any technical difference?
 
But by " semantic by running" you can switch to debug mode and go through it step by step to check the values to ensure you didn't over flow them or miscalculate. You can analyse all you want but a mistake may not show until you do acutal test. I think if you were to run this code the ships would jump all over the place and display random data, which is correct if thats what you want to do.

also maybe its just me but i dont understand why you are using (t), are you keeping each of the values for somthing or are there multiple planes? you are going to overload your memory doing this too much.
and what is (th)?
and does the bomber ever move?
and i dont think you are using the dist calculation properly, but that could be me.

actually psudo code is ment to be more in english, to express exactly what is to be done, i can see here you are attempting to calculate vectors and positions and causing a little motion but thats about it.

I would reccomend to think of psudo code as the comment lines before you do the actual code.
 
The bombers path appear to be a list of specific coordinates?
Should that not be a start location and speed, as with the fighter.

Plus either destination coordinates, or a list of waypoints it tracks towards at each stage using the defined speed?

Having it able to jump arbitrary distances does not fit with a simulation, to me.
 
I don't want to code it, even if I code it, there's no way of knowing if it's semantically correct or not. So I am asking it here-:

Pure Pursuit Problem
My pseudocode-:

Code:
Read the following-:
a) Bomber's path xb(t), yb(t) for t=0,1,2...12
b) initial position of fighter xf(0) and yf(0)
c) fighter's velocity vf

while(1)
{
dist(t)=sqrt((xb(t)-xf(t))²+(yb(t)-yf(t))²)

if dist<=10kms=>print target caught at time "t"mins and distance "dist" kms=>stop

else if t>11=>print "target escaped"=>stop

else

cos(th)=[yb(t)-yf(t)]/[dist(t)]
sin(th)=[xb(t)-xf(t)]/[dist(t)]
t=t+1
xf(t)=xf(t)+vf*cos(th)
yf(t)=yf(t)+vf*sin(th)
}

so at the beginning-> dist(t)=sqrt((xb(t)-xf(t))²+(yb(t)-yf(t))²) this is using pythagorous to get the hypotenuse length, that seems good.

cos(th)=[yb(t)-yf(t)]/[dist(t)]
sin(th)=[xb(t)-xf(t)]/[dist(t)]
t=t+1
xf(t)=xf(t)+vf*cos(th)
yf(t)=yf(t)+vf*sin(th)

then this bit, is just getting the difference of the two positions and normalizing it, then the fighter is attenuating his position with it, vf being the speed of the fighter.


that last bit should be

xf(t)=xf(t-1)+vf*cos(th)

cause u need to grab the last position off the last time frame, not that its that important cause u probably wouldn't want to keep a history of values anyway.


This looks like good code to put into analogue hardware!!! (transistors or opamps!!!)
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top