Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   NI LabVIEW (http://www.chiefdelphi.com/forums/forumdisplay.php?f=182)
-   -   Timing Motor Functions in Teleop (http://www.chiefdelphi.com/forums/showthread.php?t=125281)

iggy_gim 26-01-2014 11:40

Timing Motor Functions in Teleop
 
Hi,

I'm new to Labview as my team recently switched over from Java. I was wondering how to time a motor turning function so that when I press a button on the joystick, the motor turns for 5 seconds then stops. I have everything but the timing part. Any help would be appreciated.

Thanks!

Mark McLeod 26-01-2014 11:48

Re: Timing Motor Functions in Teleop
 
Two common methods:

1) In Teleop, set a time and keep checking to see if it's expired. (is it done yet?...Is it done yet?...)


2) In Periodic Tasks, just set a timer.



Some other examples are found here.

Captain Planet 26-01-2014 11:56

Re: Timing Motor Functions in Teleop
 
First of all, Teleop is not the place to put this. Teleop is called around every 20 ms, if I recall correctly, so anything slower than that will "freeze" up teleop and make your controls unresponsive. So, instead you should place timed sequences like this in Periodic Tasks. As to how you would actually make the motor run for 5 seconds, there are a couple ways. You could do something like this, or just make a while loop with a 5000 ms delay in it that only runs once, and then put that inside a case structure to control it.

iggy_gim 26-01-2014 11:56

Re: Timing Motor Functions in Teleop
 
Thank you so much for your response.

As I said, I am new to Labview and programming it for FRC. When you said keep checking if a time expires, what do you mean by that?

I'm sorry if this question seems really dumb, but I would appreciate any answer you could give me. Thank you so much!

iggy_gim 26-01-2014 12:01

Re: Timing Motor Functions in Teleop
 
Quote:

Originally Posted by Captain Planet (Post 1332678)
First of all, Teleop is not the place to put this. Teleop is called around every 20 ms, if I recall correctly, so anything slower than that will "freeze" up teleop and make your controls unresponsive. So, instead you should place timed sequences like this in Periodic Tasks. As to how you would actually make the motor run for 5 seconds, there are a couple ways. You could do something like this, or just make a while loop with a 5000 ms delay in it that only runs once, and then put that inside a case structure to control it.

Thank you the second method solved my problem.

iggy_gim 26-01-2014 12:15

Re: Timing Motor Functions in Teleop
 
One last question...

what is the name of the green arrow function block and what does it do?

Thanks.

Captain Planet 26-01-2014 12:18

Re: Timing Motor Functions in Teleop
 
It's a way of making something only trigger once on a button press. There should be some explanation of it on this page, which is where the example was taken from.

Mark McLeod 26-01-2014 12:24

Re: Timing Motor Functions in Teleop
 
That arrow thingy is called a feedback node and is found on the Programming -> Structures palette.
Basically it remembers what the previous value of the data line was.

iggy_gim 26-01-2014 12:33

Re: Timing Motor Functions in Teleop
 
Thanks.

Ether 26-01-2014 13:29

Re: Timing Motor Functions in Teleop
 
Quote:

Originally Posted by Captain Planet (Post 1332678)
First of all, Teleop is not the place to put this. Teleop is called around every 20 ms, if I recall correctly, so anything slower than that will "freeze" up teleop and make your controls unresponsive.

For the sake of other rookies who may be reading, it's perfectly fine to put this in TeleOp if you use a "state machine" approach like Mark showed.

Quote:

Originally Posted by iggy_gim (Post 1332679)
When you said keep checking if a time expires, what do you mean by that?

When the button is first pressed, read the system clock and set a "target value" equal to the system clock plus 5 seconds (5000ms).

On every subsequent execution of TeleOp, check to see if the system clock has reached (or passed) that target value. If it has not, just finish the rest of your TeleOp and get out before your allotted 20ms; otherwise execute whatever code you wanted to run, and wait for the next button press to start the process again.




All times are GMT -5. The time now is 09:51.

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