LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how do i animate a continued smooth motion of a small marker around

How do i get started in creating a VI 

to animate the continued smooth motion of a small marker around a series of geometrical shapes on a display.

Im a newbie in labview and any help will be greatly appreciated.  I also need to

 

Add controls to select between shapes, size and speed of rotation and direction of rotation.

labviewimage.png

0 Kudos
Message 1 of 8
(3,769 Views)

Define your shapes as an array of points. Each point can be represented as a cluster of two doubles (your x and y coordinates).

Split your points into separate x and y arrays and pass the to an XY plot to display it. You will have to add a copy of the first point at the end of the array to close the shape.

Use a while loop that updates your spot location continually.

Choose a time step in seconds.

Distance travelled in one step=spot speed*time step.

Keep a record of how far the spot has travelled along the current leg.

Add the distance moved in the time step to the distance along the current leg.

Calculate the x,y position corresponding to the current distance along the leg and plot the spot.

If the spot moved further than the length of the leg, take the difference and use this as the distance along the following leg and increment the index indicating the current leg.

At end of final leg, move to beginning of first.

 

This is roughly it- circle could be made of multiple legs or you could define a circle path with slightly more complicated code.

 

I wouldn't even try implementing this until you've got a good grasp of how LabVIEW code works. There are free training materials available, I think they are called core1 and core2 these days? Someone with more up to date knowledge on that can fill you in.

Message 2 of 8
(3,746 Views)

thanks, it sounds a bit complicated but let me impliment your ideas and see how far i can go.

0 Kudos
Message 3 of 8
(3,741 Views)

It sounds a bit complicated because it is not what I would call a beginner task.

 

To reiterate my best bit of advice- learn the labview basics before attempting. You'll be in a world of hurt if you don't. 😄

0 Kudos
Message 4 of 8
(3,738 Views)

Since that other thread is marked Solved, let's keep the continuing discussion here.

 

I was asked in a PM how to make it go the rest of the way around.  It is better to keep the discussions public - on the Forums - so that others can both contribute to the threads as has happened her and so that someone with a similar problem can benefit from what you have learned.

 

Rather than creating multiple loops and trying to get them to play nicely together, this is a situation which calls for a state machine.  The behavior is very similar on each edge, but some things change such as horizontal and vertical and the limit comparisons. Consider the following;

 

Edge       New position                 Change?                        Next

Top          H[i] = H[i-1] + incr        H[i] >= right - incr           Right

Bottom     H[i] = H[i-1] - incr         H[i] <= left                     Left

Right        V[i] = V[i-1] + incr        V[i] >= bottom               Bottom

Left          V[i] = V[i-1] - incr         V[i] <= top                     Idle or Exit

 

By adding a case structure and a shift register the VI can be converted to a state machine implementing this behavior.  Want to reverse the direction?  Just change the order of the Next states.

 

If the lengths of the sides do not divide evenly by 20, the marker does not align properly with the edges of the rectangle. You can decide how you want to fix that.

 

The state is represented as a typedef enum. By making it a typedef any changes automatically propagate to all the constants so you do not have to make changes in many places.

 

Lynn

Download All
Message 6 of 8
(3,703 Views)

Thank you so much Lynn for your detailed explanation, i really appreciate ur time. i am still trying to understand what exactly is going on inside your case structure.

can you please show us how to adapt solution for the marker to go around the circle of a given radious. Thanks.

0 Kudos
Message 7 of 8
(3,677 Views)

Each case represents one state of a state machine. In addition to the "border" states there are states for initialization, idle, and exit.  If you do want the Idle state,  you can just change the state enum constant in the Left state to Exit. Note that each state selects the next state. In most states a choice is possible.

 

For example the Top state is entered after the Init state runs. It changes the position of the marker circle by one increment. It also tests to see if the marker has reached the right edge of the rectangle. Then it either repeats the Top state or switches to the Right state.

 

To adapt to a circle is more complex.  For the circle you have the radius and the coordinates of the center. You do not have fixed corners as in the rectangle. So you will need to do the mathematics to find coordinates of various points along the circle. Consult any text on analytic geometry. You will need to set both horizontal and vertical coordinates for the center of the marker on each iteration of the loop. 

 

Other shapes such as your triangle will also require changing both horizontal and vertical coordinates simultaneously.

 

For any shape the key is to think about how you will determine the points where the marker is to be placed. Once you know how to calculate the required values on paper, then planning the implementation in LV is usually not too difficult.

 

Lynn

Message 8 of 8
(3,663 Views)