LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Rotating clock - start from random clock position, stop when key is pressed

Solved!
Go to solution

Hi all,

 

I have just inherited a terrifying VI (first VI attached) from my supervisor - it is supposed to run a clock (with just the seconds arm on screen (starting the arm from a random seconds position i.e., not 12 oclock every time). The arm spins around until a user presses a button. Then a beep plays. Then the user can enter where they thought the clock arm was when the beep played.

 

This code has been used and abused by various previous students adding things, and I am trying to dilute it down to its purest form (clock start, button press, enter response), but am having trouble.

 

 

I tried to just pull the clock itself out (second VI) to start with, but the arm only cycles around the first quarter of the clock and then jumps back and starts again at 12...

 

Does anyone have any idea why this might be happening? Maybe I missed some 'continuation' code that gets it to keep spinning, but I can't see the wood from the trees in the parent VI...

 

Thank you for any help!

Download All
0 Kudos
Message 1 of 8
(3,533 Views)

just replace wire and set correct limits values

 

clock.png

0 Kudos
Message 2 of 8
(3,510 Views)

Without looking at your code, and without writing any code myself, let me try to "walk you through" the Clock problem.

 

  • What do you want to do?  Answer -- represent a "Second" clock.
  • I just erased the next series of points that I made because I re-read your Statement of the Problem and have some questions.  My original assumption was that the clock "ticked" one second at a time, so the hand went 1..2..3 etc.  If the clock is moving at one RPM (revolution around the dial per minute, then it should be reasonably trivial for the User to say where the dial/arm was when the Beep occurred even if there were no numbers on the Dial face.  So --
    • How fast does the hand move?  Does it take a minute to go around?
    • Does it move "smoothly" or in 1-second "steps"?
  • A Mundane question -- how do you want to represent the Clock?  I'm not quite sure what you used, but I'd suggest a Gauge.  You want to modify it slightly, turning it so that 0 is at the top and making the space between the first number (0) and the last (10, 12, 60, you choose) vanish.  You can do this, particularly with a steady hand and an accurate mouse.
  • How do you want to handle the "spinning around" movement of the hand?  For the sake of argument, let's assume a Watch (numbers 1 .. 12, which we will code as a Gauge, 0 .. 12, with 0 and 12 at the same place) and a hand that moves one tick at a time (to get started and make this problem easier).
    • Question 1 -- what is a "natural" way of representing numbers that go 0, 1, 2, 3, ...?
    • Question 2 -- how do you keep them in the range 1 .. 12 (or 0 .. 11)?
  • If you are still with me, we now have only one final issue -- getting the hand to move "smoothly" instead of jumping once/second.  How many steps do we need to break up the motion to appear smooth?  Well, your display is probably going at 60 Hz, so it doesn't make sense to update it much faster.  I'd recommend 100 Hz (it's certainly "fast enough", and powers-of-ten make the math simpler).  Think about what changes you'd need to make from the previous "one-tick-per-second clock" to "100 ticks-per-second", but with the same clock "face".

I urge you to try doing this on your own before you look at the code others might post for you.  You'll learn much more this way.

 

Bob Schor

 

P.S. -- I agree that the other code is Frightening.

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

Hi Artem.spb,

 

Thank you for your reply and the useful picture - however, weirdly, when I rewired lower output to 'clock' and upper output to 'clock2' the clock arm now just does not move at all...

 

I saw your other note about 'set correct limits value' do you mean the '60.00'? I see in your image that yours looks like it has a comma (60,00) not a decimal point (60.00), as mine has. I tried to enter a comma between but it wouldn't let me...

 

Sorry to be such a dunce but the issue is I don't really understand what that bit of code does (R / IQ), I looked it up but still fail to understand as I am mathematically illiterate 😞

 

 

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

Hi Bob, thanks for your feedback, to answer your questions:

 

  • What do you want to do?  Answer -- represent a "Second" clock.
    • Yes

  • I just erased the next series of points that I made because I re-read your Statement of the Problem and have some questions.  My original assumption was that the clock "ticked" one second at a time, so the hand went 1..2..3 etc.  If the clock is moving at one RPM (revolution around the dial per minute, then it should be reasonably trivial for the User to say where the dial/arm was when the Beep occurred even if there were no numbers on the Dial face.  So --
    • How fast does the hand move?  Does it take a minute to go around?
      • You are right, we are trying to make it a bit harder for them to tell where the clock hand was, so faster than 1 minute would be good, maybe even 5-10 seconds to do a full rotation or so?
    • Does it move "smoothly" or in 1-second "steps"?
      • Smoothly

  • A Mundane question -- how do you want to represent the Clock?  I'm not quite sure what you used, but I'd suggest a Gauge.  You want to modify it slightly, turning it so that 0 is at the top and making the space between the first number (0) and the last (10, 12, 60, you choose) vanish.  You can do this, particularly with a steady hand and an accurate mouse.
    • A gauge would suit. I think I am ok to leave the numbers on the clock - removing the numbers as the hand passes by might make the task easier? Also I am in a big rush!

  • How do you want to handle the "spinning around" movement of the hand?  For the sake of argument, let's assume a Watch (numbers 1 .. 12, which we will code as a Gauge, 0 .. 12, with 0 and 12 at the same place) and a hand that moves one tick at a time (to get started and make this problem easier).
    • Question 1 -- what is a "natural" way of representing numbers that go 0, 1, 2, 3, ...?
    • Question 2 -- how do you keep them in the range 1 .. 12 (or 0 .. 11)?
      • Ummm, make a vector with numbers 0-12 to 5 decimal places? then get the hand to represent these numbers in order? Would that make sense? Then it should move smoothly-ish around through all those numbers?

  • If you are still with me, we now have only one final issue -- getting the hand to move "smoothly" instead of jumping once/second.  How many steps do we need to break up the motion to appear smooth?  Well, your display is probably going at 60 Hz, so it doesn't make sense to update it much faster.  I'd recommend 100 Hz (it's certainly "fast enough", and powers-of-ten make the math simpler).  Think about what changes you'd need to make from the previous "one-tick-per-second clock" to "100 ticks-per-second", but with the same clock "face".
    • As above, I suppose you just need more decimal places so it moves smoothly?

I urge you to try doing this on your own before you look at the code others might post for you.  You'll learn much more this way.

I agree, normally I would hack away at this on my own but this is part of a larger project that I have 5 months to deliver, and 3 months have already expired :s (thanks for your comments on some of the other, accelerometry related, parts of the project Bob - that section seems to have come along well, I am planning on posting the solution to the forum within the next day or two so others can see if they are interested!)

 

I will have a go at this when I get in to work but any more hints would be amazing!

0 Kudos
Message 5 of 8
(3,465 Views)

I also tried this

 

https://forums.ni.com/t5/Example-Programs/Creating-an-Analogue-Clock-Using-Gauges/ta-p/3511908

 

Removing all arms but the second arm, and playing around with the numbers to get it to move faster. But when I removed the other arms, the seconds hand got stuck again... does it need the other arms to work properly? that seems weird...

0 Kudos
Message 6 of 8
(3,464 Views)
Solution
Accepted by topic author hdempseyjones

why you ignore my message?

You have 2 (3) arms, but only one with scale. Another scale(s) hidden. You need show scale for all arms and set correct ranges.
In your vi the second arm ("ms")  has range 0..2400, and get values 0..600. This is reason why it moves in first quarter only.

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

Hi Artem,

 

I did reply 😄 (see comment above)

Though that comment is not needed now as the clock rotates! I feel silly not realising that clock resolution meant how far around the arm would go.

 

Setting it to 2400 made it rotate all the way around, but it was jumping at the end. So I figured maybe I had not sufficient rotations in there for the other values, and set clock resolution to '2560' to match the other number being divided there, and it looks much better!

 

How come you suggested wiring the divided output to 'clock' instead of 'clock2'? this seems to make the arm get stuck on 60. No matter though, the other way around works! 

 

😄

 

So happy thank you!

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