I’ve got a fan hooked up to a PWM Jaguar speed controller. I’m trying to make the fan turn full speed when I hold button 7, and turn full speed in the opposite direction when I hold button 8.
I’ve linked case structures to proper buttons (see pictures below).
I’ve opened the motor (plugged into PWM 7) twice (one to move forward, one to move in reverse) and set the refnum name to Shooter and NegShooter (reverse). The reason I opened the motor twice was because while I could get the motor to accept one case structure (containing the correct value) as a value, I could not get the motor to accept two.
Button 8 works fine, however when I hit button 7, nothing happens. What’s wrong here?
Now, I want Button 7 to set the value to 1, and button 8 to set it to -1. When neither are pressed, I’d like the motor to have a value of 0, thus my thought for case structures…
That should be okay. Just make sure that each iteration of the code, that you only set each motor once. You don’t have to set every motor every iteration, and you can set multiple motors per iteration, but don’t set a single motor more than once per iteration. It’s just bad practice and a waste of memory (it won’t actually break anything if you do so).
Here’s what I’ve come up with. It checks to see if the sums equal 0 (which would be the case if both buttons were pressed, or if neither were pressed), which activates the True case structure, stopping the motor. If it’s not equal to 0, it sets it to the value.
That will work, but think about what you’re doing. You’re checking if a value is equal to zero - if it is, then use a different zero constant for your motor output. If it’s not equal to zero, then set it to that value.
Here’s a question for you: why do you need that case structure? Is it necessary or a waste of processor cycles? How can you write that to be the most efficient?
when you program long enough, you eventually view everything in terms of processor cycles and efficiency…
EDIT: in response to above, case structures in LabVIEW are actually extremely powerful. They can function as both an if/else as well as switch statement (to compare to C(++)), depending on what you wire into it. Read about it.
Edit 2: Oh, and one more thing. On your most recent screenshot, on your 1 and -1 constants, see the little red dots? They’re called coercion dots. They happen when LabVIEW automatically changes a datatype of something (in this case from int to double). You want to avoid those, if possible, as they unnecessarily drain resources (it’s not a big draw, but an avoidable one). Right click on your int constants, and under Representation, choose DBL (for double) to make the wire orange/keep one constant datatype.
Well, here was our plan. We want to have 4 different motor ‘profiles’ bound to buttons on the joystick we are using for ball launching/collecting. For example, ‘Profile 1’ sets the output to -1 for 2.5 seconds, ‘Profile 2’ sets the output to .75 for 1.3 seconds and so on…
So, with the changing outputs and times, I thought these case structures would come in handy later down the road.
EDIT: Thanks for the tip regarding the coercion dots. I actually had about 8 of those in total in our teleop.vi !
Alright, after reading your link, I’m thinking about doing this.
If button 7 is pressed, this initiates a stacked sequence. The first frame of this sequence calls the motor “shooter” and sets the output to whatever value defined outside of the sequence. This frame runs for how many milliseconds we define it to run for. It then moves on to the second frame, calling the motor “shooter” and setting the output to 0.
Set a button on the joystick to set the output of a motor to a certain speed for a defined period of time before resetting the output to 0.
Here’s what I’ve come up with. I’ve got the first frame wired to the output of the Select module. Now that I look at it, I don’t believe it’ll work I think it’ll set the output to 0 then move on to the next frame.
Would my problem be solved if I wired a button directly to the stacked sequence which set the output of the motor to the value I want on the first frame, then returns it to 0 on the final frame?
After many Google searches, I think I found what I’m looking for. When button 2 is pressed, this initiates the stacked sequence. A timer begins. Once the timer reaches a value greater than the predefined stop time, it terminates the while loop.
Now, my two questions.
Once the while loop is terminated, does frame 1 pick up where frame 0 terminated?(will I have to TELL it to execute frame 2 immediately after 1?) ?
Will this confounded piece of code work? With only one motor output set, it appears to be too many steps. But, rest assured, there will be many, many many more added after I can get one working.
Yes, the frames in the stacked sequence will execute right after each other.
There’s one problem with this code, depending on where it is placed. Your telop VI needs to execute quickly and return. This allows more data to be received from the driver station. If your teleop vi takes longer then 20ms to execute, you will miss data from the driver station. If you miss too much data from the driver station, all outputs will be disabled.
There are too ways to work around this. The first would be to take this code, and put it in periodic tasks. The code in periodic tasks will execute in parallel with the rest of the code and not block communications. The second is to rewrite the code as a state machine. You would design the state to check if the time expired and exit quickly if it hadn’t. Then the next time in, it would go to the same place and check the time again. frcmastery.com has a tutorial on state machines http://www.frcmastery.com/labview-for-frc/2010-videos/state-machines/
So, if I were to place that code into the periodic.vi file, it would function the same if it were within teleop.vi? What I’m asking is if I need to make a refrence to pereodic.vi or place anything within teleop.vi which initalizes periodic.vi.
I’ve written it into teleop, and it works, but as you said, I lose data at later point of the execution.
I’ve moved the working code into periodic.vi and reopened the joystick, however nothing happens when I press the defined button. Do I need to call the VI within teleop?