10-06-2017 06:01 AM
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
10-06-2017 09:21 AM
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) --
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
10-06-2017 10:35 AM - edited 10-06-2017 10:45 AM
@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.
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)
10-06-2017 11:48 AM
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