LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Creating a 3d solar system

Hello,

 

I am trying to create a 3d solar system on labview taking inspiration from the 3d solar system example provided by NI. I have writtern the code so that I have a cluster of buttons corresponding to each planet in the solar system. eg.: If I click 'Mercury', Mercury shows up at a certain distance from the sun. I am trying to rotate and revolve these planets around the sun. Because, I am using an event structure for all the buttons, I can't use a while loop within the event structure to get continuous iterations to make the planets rotate/revolve continuously. Is there a way to get continuous iterations within an event structure without using a while loop? I thought about using a producer-consumer design but I couldn't figure out what the producer and consumer queues will be.  

0 Kudos
Message 1 of 5
(3,250 Views)

You can use the timeout case of an event structure to execute code at a regular interval when a button has not been pressed.

0 Kudos
Message 2 of 5
(3,240 Views)

Thanks for your answer, but the basic problem of a continuous real-time rotation/revolution remains. For example, if i want to show the earth rotating about its axis, i would need the output of the iterations of a while loop being executed continuously, multiplied by a constant to show the earth rotating in real time. But since, i am using an event structure, i can't create another while loop within it, nor can i use the existing while loop because the existing while loop only executes when an event occurs, and hence the iteration count is not continuous. 

0 Kudos
Message 3 of 5
(3,218 Views)

There are many ways to do this.  One conceptually simple method is, in fact, the Producer/Consumer Design Pattern for Events (you can pull up a template for this by opening LabVIEW, clicking File, New ... (the dots are important), and finding From Template, Producer/Consumer Design Pattern (Events).

 

The Event Loop is the Producer, which sends "Events" to the Consumer.  The question is, what is the Consumer?  Make the Consumer a State Machine or a Queued Message Handler (sort of a State Machine on Steroids).  When you push a button, it should enqueue a State that is designed to "handle" that button.

 

The trick is that the State Machine can also run repetetively and "clock" itself.  Suppose I wanted to make a clock that ticked once a second, with a Start and a Stop button.  I have three States -- Start, Stop, and Run.  (OK, I also need a state, Idle).  I start in Idle.  Pushing the Start Button generates a Start Event which results in the Start State being put on the Consumer's Queue.  The Consumer has a Shift Register that holds the "next" State -- what the Start State does is to put "Run" on this Shift Register, and then enqueue to itself the Run State.  So immediately after Start, the Run State "runs".  It updates the clock, waits 1 second, and puts the "Next State" on the Shift Register, keeping the clock running.

 

So now you push "Stop".  It puts Stop on the Queue, but the clock is still running, so when the current Run state finishes, it will put Run also on the Queue.  But Stop is first, and the Stop State puts Idle into the Next State Shift Register without putting anything else on the Queue.  So Run, waiting on the Queue, runs one more time, and when it gets Next State, it uses Idle, and the Idle State does nothing.  

 

Hmm.  How do you end this program?  Need an Exit State (triggered by the Exit button).  The Exit State stops the While loop, letting the Consumer end.  How about the Producer?  Why not have the Exit Event also stop the Event Loop?

 

I did this all in words rather than a VI (not quite 1000 words) -- you should be able to create such a Queued State Machine + Producer/Consumer yourself, and when you get it to work, you'll say "Aha, I get it!".  Have fun.

 

Bob Schor

0 Kudos
Message 4 of 5
(3,202 Views)

@am53g10 wrote:

Thanks for your answer, but the basic problem of a continuous real-time rotation/revolution remains. For example, if i want to show the earth rotating about its axis, i would need the output of the iterations of a while loop being executed continuously, multiplied by a constant to show the earth rotating in real time. But since, i am using an event structure, i can't create another while loop within it, nor can i use the existing while loop because the existing while loop only executes when an event occurs, and hence the iteration count is not continuous. 


No.  That is not true.  You are missing the point of the timeout case.  The timeout case will execute when no event has occurred.  That is where you'll put the code that updates the revolution and rotation.  I would set it to a very small timeout value (the number wired into the node at the top left of the event structure) so that you'll have the smoothest update.

 

What is true is that you really don't want a while loop in an event case.  But follow what I'm telling you and you won't need to.

0 Kudos
Message 5 of 5
(3,183 Views)