Go to Post Why is it considered shameful to do the smart thing? As the saying goes, "I don't make the rules, I just live by them." - Chris Hibner [more]
Home
Go Back   Chief Delphi > Technical > Programming > NI LabVIEW
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 10-11-2013, 14:39
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,044
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Gyro angle in simulation vs reality?


Here's a possible implementation of Joe's suggestion.

Code:
// initialization:
alpha=Go=getGyroReading();  // range -180 to +180

// iteration:
G=getGyroReading();
d=G-Go;
Go=G;
if (d>180) d-=360;
else if (d<-180) d+=360;
alpha+=d; // alpha is the continuous angle reading you've been asking for

Reply With Quote
  #2   Spotlight this post!  
Unread 13-11-2013, 13:22
GuyM142's Avatar
GuyM142 GuyM142 is offline
Registered User
AKA: Guy
FRC #3339 (BumbleBee)
Team Role: Mentor
 
Join Date: Jul 2013
Rookie Year: 2012
Location: Israel
Posts: 157
GuyM142 is just really niceGuyM142 is just really niceGuyM142 is just really niceGuyM142 is just really niceGuyM142 is just really nice
Re: Gyro angle in simulation vs reality?

Quote:
Originally Posted by Ether View Post

Here's a possible implementation of Joe's suggestion.

Code:
// initialization:
alpha=Go=getGyroReading();  // range -180 to +180

// iteration:
G=getGyroReading();
d=G-Go;
Go=G;
if (d>180) d-=360;
else if (d<-180) d+=360;
alpha+=d; // alpha is the continuous angle reading you've been asking for

Thank you! that's what I was looking for.
My goal was to make the simulated gyro work like a real FRC gyro for new programmers training.
I've attached my implementation (this is in periodic tasks)
Attached Thumbnails
Click image for larger version

Name:	gyro.png
Views:	40
Size:	32.6 KB
ID:	15410  
Reply With Quote
  #3   Spotlight this post!  
Unread 14-11-2013, 12:20
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,044
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Gyro angle in simulation vs reality?


At runtime if the result of the comparison circled in green is TRUE, does the LABview-generated code still perform the computations circled in red?

Attached Thumbnails
Click image for larger version

Name:	gyro2alphaQ.png
Views:	31
Size:	11.2 KB
ID:	15413  
Reply With Quote
  #4   Spotlight this post!  
Unread 14-11-2013, 20:41
Greg McKaskle Greg McKaskle is offline
Registered User
FRC #2468 (Team NI & Appreciate)
 
Join Date: Apr 2008
Rookie Year: 2008
Location: Austin, TX
Posts: 4,748
Greg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond repute
Re: Gyro angle in simulation vs reality?

There are two types of data flow diagrams, pull and push.

The pull type works from the answer backwards. It determines what it needs in order to compute the result and back propagates to the next layer of what it needs to know. Therefore, it doesn't need to calculate the red value.

The push type executes the other way around. It starts with what it knows and pushes it to the downstream areas until it has produced the result.

Because LV diagrams contain as much I/O as they do, it was decided to use the push model. This means that side-effects such as I/O in the red area will happen even if the results are not used. If you wish to avoid the red calculations, the technique is to use the switch/case statement.

The other way to determine this ...

When a LV diagram executes, it executes all nodes it contains exactly once. That requires both red and green to execute. The case/switch simply decides not to execute one of its diagrams. The for loop, by contrast, executes its diagram N times. Hope that helps.

Greg McKaskle
Reply With Quote
  #5   Spotlight this post!  
Unread 14-11-2013, 22:53
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,044
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Gyro angle in simulation vs reality?

Quote:
Originally Posted by Greg McKaskle View Post
When a LV diagram executes, it executes all nodes it contains exactly once. That requires both red and green to execute. The case/switch simply decides not to execute one of its diagrams.
Thanks for the informative post Greg.

Applying the above at face value as a general principle: if the portion circled in red was made into a separate diagram, then would that diagram not be executed if the portion in green evaluated to TRUE?

I suspect the answer is that it would still be executed, and the reason is that the green decision is in parallel with the red computation, whereas with the case/switch the diagrams are in series downstream. If that wording is awkward/incorrect, what's the proper way to articulate this distinction, in LABview-speak?

One more thing: wouldn't it be reasonably straightforward for the code generator to recognize these T/F decisions, and generate conditional code like the case/switch does? Or would that effectively mean abandoning the push model?


Reply With Quote
  #6   Spotlight this post!  
Unread 16-11-2013, 08:13
Greg McKaskle Greg McKaskle is offline
Registered User
FRC #2468 (Team NI & Appreciate)
 
Join Date: Apr 2008
Rookie Year: 2008
Location: Austin, TX
Posts: 4,748
Greg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond repute
Re: Gyro angle in simulation vs reality?

Let me elaborate on the statement I made about node and diagram execution. I don't remember why, but had to cut that short.

Quote:
When a LV diagram executes, it executes all nodes it contains exactly once. That requires both red and green to execute. The case/switch simply decides not to execute one of its diagrams. The for loop, by contrast, executes its diagram N times. Hope that helps.
Completing the thought ...

The for loop and case/switch are nodes. They must execute exactly once. Normal nodes such as + represent a closed operation. There is no sub diagram to schedule for execution. The control structures in LV that bring additional scheduling structure to the language are the loop, switch, sequence, and subVI. Each of these executes by scheduling one or more subDiagrams in a structured fashion. This is the same as how a procedural language structure such a loop or case will manipulate the execution of its "body" expression.

So to be more exact, the case/switch is a node and must execute exactly once for each execution of its owning diagram. It performs conditional execution by scheduling one diagram and ignoring the rest. A loop only contains one diagram, and it performs repetition by scheduling it multiple times. A sequence contains N diagrams and enforces sequencing by scheduling then in sequence. A subVI doesn't look much like a flow structure, but it acts to coordinate the execution of the calling and called diagrams so that they behave as a procedure call.

While LV supports, promotes, and promises parallelism, it can't change the fundamental characteristics of the CPU(s) it runs on. Code such as you've drawn, with simple operators do not benefit from parallelism. They are synchronous atomic operations and one of the optimizations LV makes is actually to serialize that code to avoid scheduling overhead. The "clumping" algorithm's job is to identify when to use the parallelism expressed in your diagram and when to arbitrarily serialize it to improve performance.

The compiler does eliminate code and move code around to eliminate unnecessary operations. It has to be careful that the code is functional and has no side-effects. Also, realtime users would often prefer that we calculate both and not introduce jitter in the calculation.

Greg McKaskle

Last edited by Greg McKaskle : 16-11-2013 at 09:04. Reason: word smithing
Reply With Quote
  #7   Spotlight this post!  
Unread 16-11-2013, 09:47
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,044
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Gyro angle in simulation vs reality?


Question for experienced veteran LabVIEW gurus:

Do you tend to prefer one method over the other, and why?


Reply With Quote
  #8   Spotlight this post!  
Unread 27-01-2014, 20:20
ProgrammerJoe ProgrammerJoe is offline
Registered User
FRC #2832
 
Join Date: Jan 2010
Location: Livonia
Posts: 36
ProgrammerJoe is an unknown quantity at this point
Re: Gyro angle in simulation vs reality?

Quick Question, but I'm messing around with the Robot Simulation Model Builder and I didn't notice a Gyro option under sensors. Is the Gyroscope inherent within the FRC Frame or does it need to be imported within the Model Library?
Reply With Quote
  #9   Spotlight this post!  
Unread 27-01-2014, 20:29
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,562
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: Gyro angle in simulation vs reality?

Quote:
Originally Posted by ProgrammerJoe View Post
Quick Question, but I'm messing around with the Robot Simulation Model Builder and I didn't notice a Gyro option under sensors. Is the Gyroscope inherent within the FRC Frame or does it need to be imported within the Model Library?
It's built into the frame as described here: https://decibel.ni.com/content/docs/DOC-26300
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 23:35.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi