Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   NI LabVIEW (http://www.chiefdelphi.com/forums/forumdisplay.php?f=182)
-   -   Run a series of instructions when button is pressed (http://www.chiefdelphi.com/forums/showthread.php?t=115307)

cisasteelersfan 23-03-2013 13:00

Run a series of instructions when button is pressed
 
Hi all,
I'm trying to figure out how to 'automate' our shooting process. Currently in teleop we simply have a button wired to a solenoid: true means forward, and reverse means back.

When a button is held down, we want the solenoid to go forward and back four times in a certain amount of time.

What I've tried is putting a global variable that is true when the button is pressed. This gets passed to periodic tasks where if true, it runs a for loop four times. This outputs to another global variable that is passed to teleop that controls the solenoid (forward or reverse).

It doesn't work as programmed. Does anybody have any ideas? I considered putting an autonomous-style loop in teleop, but is that the optimal solution?

Any suggestions are greatly appreciated!

Suitster 23-03-2013 14:14

Re: Run a series of instructions when button is pressed
 
Putting a loop in teleop is usually the least optimal solution. It will drain processing speed, and likely cause lag.
The way that we programmed our shooter this year used the wheel RPM as an indicator for if a frisbee was shot. If the RPM suddenly dropped, then a frisbee was launched.

Another way we programmed it was using a timing VI, which would send a boolean based on the elapsed time. That timer can be kept in teleop without slowing down the program.

We got the fastest and most consistent shooting using the first method, paired with RPM monitoring in periodic tasks. The RPM sensor would write to an array, and the last 25 numbers in the array were sampled and tested to see if they were within 3% of one another. When the wheel speed leveled off,
we would send a true global variable to teleop, which would send the solenoid forward. When the RPM dropped from the disk leaving, that would change the variable to false, and the solenoid would retract.

Alan Anderson 23-03-2013 17:37

Re: Run a series of instructions when button is pressed
 
Quote:

Originally Posted by cisasteelersfan (Post 1251532)
What I've tried is putting a global variable that is true when the button is pressed. This gets passed to periodic tasks where if true, it runs a for loop four times. This outputs to another global variable that is passed to teleop that controls the solenoid (forward or reverse).

That seems kind of the long way around to do it. Why not just do everything in Periodic Tasks? Read the controller button and use it to either do nothing or run the For loop. Set the solenoid right there inside the For. Put the whole thing inside a While loop that has a 20 ms delay.

NeatNit 23-03-2013 18:42

Re: Run a series of instructions when button is pressed
 
If you want the process to stop when you let go of the button, the code gets more complicated. You would need a State Machine.

lorem3k 31-03-2013 16:08

Re: Run a series of instructions when button is pressed
 
2 Attachment(s)
We have a similar setup. In Teleop, we set a global variable whenever the shoot button is pressed, and then in Periodic Tasks, we have a flat sequence structure for timing the solenoid's activation. This structure is inside one of Periodic Task's while loops, so it runs continuously while the button is being held down. I've attached our code so you can take a look.


All times are GMT -5. The time now is 12:08.

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