My team wants me to program a system where, after I press a button, a motor activates and then another motor (connected to the same button impulse) activates after a short wait. I’m not sure how to implement the timer, though I’m sure there must be a simple way to do it. Does anybody know a good way of doing this?
Are you using command based?
I recommend checking the chapters 2 and 3 of the Secret Book of FRC LabVIEW (and control logic) version 2.07 as they talk about timing and building state machines.
If you are using the Command and Control LabVIEW architecture, I expect you to do a similar process, but you could call the command to start the second motor from wherever you process the first button movement then a command is generated.
^^ This. If using command based, it will be quite simple. Otherwise, not so simple, but definitely doable.
If you are using command based, two more questions will drive the specific solution:
- Are you using the new or legacy (old) command based?
- Do you want the “short wait” to begin when the first motor is started, or after it reaches its target position?
And OBTW, if not command based, my second question will still matter.
Or something like this for the traditional Arcade Drive type of project .
I tried using this code (editing it to suit my needs) but it doesn’t seem to work for me. Is there something I need to do or disable in teleop? (No errors show up in driver station when I use the code, there’s just no delay after pressing the button and the servo doesn’t start)
In response to previous questions, I’m not using command and control. I’ve tried looking at tutorials for it, but frankly I don’t even understand the vocabulary, much less the concept itself. (I’m not exactly what one might call a “computer extraordinaire”)
To be more specific, I want this series of events to happen:
-When button is pressed, set the angle for the servo immediately
-A short wait begins upon the button press, after which a motor starts
-After the second motor starts, I want it to run continuously for as long as the button is held
We will check your revised code if you would post it. (either a screen shot or a snippet-highlight code, choose “Create VI Snippet from Selection” and it’ll create an image that’s actual code)
Did you place the code in the Periodic Tasks.vi? (That’s required because of the loop)
Do you call your servo anywhere else? (other calls can/will override the calls in this loop)
Here’s the snippet (For reference, the servo is the one I want to go immediately and the elevator motors are what I want to delay)
Suggest that you add another sequence tab at the end to turn the motors off.
I’m assuming that safety config for these motors is turned off since they are not being written to periodically?
It’s probably lucky that it didn’t work.
You forgot to stop the elevator motors, so they would run forever.
This is in the Periodic Tasks.vi?
You needed to add in a while button is held check.
The servo would not move if it’s already at the 120 degree position.
Angles are in integer units, rather than floating point.
A half second might not be a long enough time to give a servo to move, but it ill continue to move as the elevator starts.
Something along these lines:
The last reply looks like a really good example. In case you wanted another way to do the same thing, I put another sample below. This one doesn’t block using waits. Instead it starts a timer and checks for completion to start the delayed action. (Instruction on how to make the timers and edge detection are in the book referenced above.)
The False case looks like this.
Operationally the examples do the same thing. The biggest difference is that this one doesn’t block. So it writes a value to the motors every 20 milliseconds.
In this example that you’ve shared, we see the SECRET .vi’s (Edge on, Timer Start, Timer Done?) Are these vi’s available for download? I downloaded the 2020 Secret Book Robot project, and I don’t find them there. Any help is appreciated.
While updating the book, I did create the library associated with the problems. However, I’ve been conflicted about if it is appropriate to provide this since I’m a mentor. I updated the book and added the problems for the library routines so students could learn to create these routines for themselves. I’d really like to hear the thoughts of others on this subject!!!
That being said. The EdgeOn, Time Get, Timer Start, and Is Timer Done subVIs are all fairly easy to create.
Edge On. This is problem 1.4 in the Secret book of LabVIEW 2.x) The truth table for this function can be found in Appendix A. A sample of the logic used in this subVI is found in figure 5.14. The feedback node used in this logic is described in Chapter 1.
Time Get (Used by Timer Start and Is Timer Done) , Timer Start, and Is Timer Done are described in Chapter 2, and problems 2.1, 2.2, 2.3. Compare figures 2.2 and 2.3 to get an idea of the logic that is needed for these.
Here are the steps needed to create your own subVI. (This is throughout chapter 1).
create a new VI.
On the front panel of the new subVI create the input “Controls” (in subVIs, “Controls” are inputs, “Indicators” are outputs) needed for the subVI you are making. Usually inputs are placed on the left. Double click on the default label and type a new name to change the label name.
On the front panel of the new subVI create the output “Indicators”. Usually outputs are placed on the right. Double click on the default label and type a new name to change the label name.
Now create terminals for your inputs (controls) and outputs (indicators). To do this, left click on the terminal you want to use, then left click on the control or indicator to associate with that terminal. The terminal template is shown in the right corner of the front panel.
Again inputs are on the left and outputs on the right. (This is not mandatory, but it is a lot easier
to read when the data all flows left to right.) For one input and one output the terminal template would look like this when done. (Yours may look different if you selected different locations. That is okay.)
For inputs, right click on the input terminals and select “This connection → is required” This will cause an error if you use this subVI and forget to wire an input. This will save you a lot of time debugging!!!.
Switch to the block diagram and add your logic.
Save the file. Give a name that has meaning so you can find it. Also make certain you know in what directory the file is being saved!. Best to keep the files inside the directory of your project (unless using libraries.)
Create an Icon for this subVI. On the front panel, double click the default icon to edit the icon.
Simple icons that let you know what this is are often the best. Often just the name of the function is enough.
Set the execution parameters. On the menu, select FILE, then select VI PROPERTIES.
Select the EXECUTION category and change the settings to look like this.
- Save the subVI!! (I’m calling it a subVI because it can be used by other VIs. However there really isn’t a difference between VI and subVI.)
Test and use.
Hope this helps this to create these routines.
(The link to the book is above, but just in case here it is.)
Thank you very much! This is excellent help, and a great tutorial that explains the subVI concept and implementation.
For this to work, would I have to disable the elevator motors in teleop? Or remove them from teleop entirely? I tried this example in the code, but it seems like the loop doesn’t activate at all (As in, the elevator works when the button is pressed but there’s no delay and the servo doesn’t activate)
As for @JSIMPSO , that looks very interesting! I’ll definitely give it a try
You can’t command the elevator in two different places.
Both Teleop and Periodic Tasks are running at the same time, so the elevator would get conflicting orders and whatever Teleop is doing would win.
I removed the elevator stuff in teleop and it worked like a charm! Thanks!
A side note: I usually program limit switches in teleop, but since I can’t use teleop for these elevators, is there a way to do limit switches where it doesn’t interfere with periodic tasks? (EX: When DIO 1 is activated, cancel the elevator loop)
You can put everything in Periodic Tasks.
Treat it just like Teleop, but with the code in forever loops.
You’d want to check the elevator limit switches during the automatic jobs, too.
That only checks the elevator limits before it starts, not while it is going.
I’d probably move the limit Get and both the motor Set Outputs into that little loop in the second frame.
Then it checks every 20ms and stops the motors as long as button 6 is held down.