|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
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! |
|
#2
|
||||
|
||||
|
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. |
|
#3
|
|||||
|
|||||
|
Re: Run a series of instructions when button is pressed
Quote:
|
|
#4
|
||||
|
||||
|
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.
|
|
#5
|
||||
|
||||
|
Re: Run a series of instructions when button is pressed
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.
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|