LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Fuzzy Logic Car Parking Example

Hi 

Im new new to labview and am playing around with the Car Parkling fuzzy logic tutorial 

Theres a sub vi called simulate car position vi

 

Im having trouble understanding the logical statement

 

arc=(2*pi/360);

r=a*cot(arc*Phi);
Eta=Dir*50*tan(arc*Phi);

Bo=(((Bi-Eta)>-90)&&((Bi-Eta)<270)) ? Bi-Eta : ((Bi-Eta)<-90) ? Bi-Eta+360 : Bi-Eta-360;

xo=xi+r*(sin(arc*Bi)-sin(arc*Bo));
yo=yi+r*(cos(arc*Bi)-cos(arc*Bo));

 

where

r - Turning circle radius as function of the steering angle Phi
Eta - Driving angle as function of the steering angle Phi
Bi - Current vehicle orientation (beta input)
Bo - New vehicle orientation (beta output)
arc - Constant for converting Angle in degree to radian

 

especially the third line 

Bo=(((Bi-Eta)>-90)&&((Bi-Eta)<270)) ? Bi-Eta : ((Bi-Eta)<-90) ? Bi-Eta+360 : Bi-Eta-360;

 

The end goal of my tweeking of this example is to give the car a desired direction and drive towards it without reversing so to drive forward in an arc

 

0 Kudos
Message 1 of 4
(3,567 Views)

That is one of the problems with text-based languages -- you have to parse them yourself.  Here is 1000 words in a VI Snippet (drag this picture onto a blank LabVIEW 2016 or 2017 Block Diagram) --

New Beta.png

 

A little explanation: 

     The function just before the outer Case Statement is the "In Range and Coerce", which is True if the middle quantity (Bi - Eta) is strictly between 270 and -90.  The True case (not visible in the image above) is just wired straight through to Bo.  The False case of the inner Case Statement does a Subtract instead of an Add.

 

Bob Schor 

Message 2 of 4
(3,534 Views)

@macfernan wrote:

 

especially the third line 

Bo=(((Bi-Eta)>-90)&&((Bi-Eta)<270)) ? Bi-Eta : ((Bi-Eta)<-90) ? Bi-Eta+360 : Bi-Eta-360;


It seems that all you want to do is wrap an angle into the range -90...270.

Instead of making all these decisions with mutilple case structures and comparisons, it might be more efficient to "just do it!". See image.

 

WrapAngle.png

 

This will give the same result as Bob's code in the typical range of -450 ...630, but also wraps correctly for any output value outside this range. (As you can see from the graph, while Bobs code is a literal translation of your code, it will give values outside -90...270 for extreme inputs, which does not look correct for a "Bo - New vehicle orientation (beta output)". Even if extreme inputs cannot occur, my code is safer and simpler to debug)

 

 

Message 3 of 4
(3,520 Views)

Altenbach is (as always) absolutely correct!  I thought of "doing the Mod solution", but thought that the problem the Original Poster was having was untangling that C-style syntax, whether or not the code was optimal ...

 

BS

Message 4 of 4
(3,510 Views)