Hi,
Our competition starts tomorrow morning, and the robot had already passed all inspections and worked as expected on the field. However, there is still one thing that we’re missing.
(skip to bold part if you deem the following information unnecessary)
We’re using a conveyor which leads to a canon, and as things currently stand, if both the conveyor’s and the canon’s motors work, any ball that is collected is immediately shot. We don’t want that. What we want is to be able to collect the balls, store them in the conveyor, and move them up to the canon when a button is pressed.
And so, we made a little switch between the conveyor and the canon which can rotate a full 360 degrees, and would like it to always be inactive, unless a certain button is pressed. When this happens, the switch should rotate half-a-spin (180 degrees).
Problem is, I don’t know how to code such a thing in LabView. Physical sensors are out of the question as we’re already done with building the robot. The solution I’m looking for should be based on time. I can find how long it takes the switch to complete half-a-spin at full speed. What I can’t do is manage to make it into a program.
So, **if you’ve been lazy enough to skip through the post (which is perfectly fine), or don’t understand anything, here’s what I need to do step by step, but am having trouble doing so:
When a button is hit, one motor needs to be active for a certain period of time, stop, and prepare for another button hit. This should work even if the button is held, not necessarily tapped.**
Any sort of help is appreciated.
Thanks in advance,
#3075, rookie team
I’d suggest using a periodic loop for this. In the loop, check the button and wire to a switch. In the True case of the switch, turn on the motor, delay for the right amount of time, and set the motor speed to zero. Then return to scanning the button. To sequence the motor on/delay/motor off, you can use a dataflow dependency or a sequence structure.
As with the other periodic loop, put a delay in it to read the joystick at 50Hz or so.
Greg McKaskle
In addition to what Greg said, you’ll want to keep track of the last button value so you don’t do it over and over again. To do this, use a shift register and wire in the button value. Use one of the Boolean operators to make sure you execute the code only when the button is true and the last button value is false.
Is there any chance to receive a screenshot on what you guys mean? I’m not sure if I’m doing it right… the result is that there’s no delay, and that the switch keeps on moving only if the button is being held.
I hope this isn’t too late, but here it is. When I actually did it, Greg’s way means you don’t have to keep track of the last value because it doesn’t matter, once the button is hit it delays for the right time and then returns, ready for another one.
I’m attaching both a screen shot and the vi. Hope it helps!
Timed Button.vi (22.2 KB)
Timed Button.vi (22.2 KB)
Oh wow, that’s gotta count for something. Thanks a lot guys.
We’ve passed the qualification rounds, and will surely need this mechanism for the finals. If it works properly, we will be forever in your debt.
Just please oh please tell me that it won’t ruin our code, as we don’t have enough time for drastic changes tomorrow.
Edit: Ok, backed the old one up and implemented yours, Luke. We’ll have to see whether it works or not at the competition tomorrow.
Regardless of the result, we truly appreciate the time and effort you put into helping us.
Thanks,
#3075
Thanks for the kind words, assaf2b. I would really hate for it not to work, so I quick tested it and found something that could be changed. I think if you use that code, it would keep the motor going until you released it, then wait and stop. I don’t think this is the result you want, so I’m posting a revision of the code.
This time I took my own advice and stored the last button value and only took action when the button is true and the last value is false. Then when I ran it, it set the motor, waited the specified time, set the motor to zero, and didn’t do it again until I released the button and pressed again. I think this is the behavior you want, so here is a screen shot and vi. Just drop the while loop into the Periodic Tasks vi, hook up the motor and joystick, and you should be good. I have tested this on the front panel and works as advertised there.
Great job on getting to the finals!
Timed Button Test.vi (11.4 KB)
Timed Button Test.vi (11.4 KB)
Ah well, it didn’t work. But hey, who cares, we’re going to Atlanta! Rookie All-Star award, and 2nd place in our country’s competition.
What I did was move the opening reference of the joystick from Teleop Init to the Begin VI, add it to the Periodic typedef, insert your code in the Periodic VI, and yet it didn’t work - whenever the button was held, the motor kept going with it.
However, as I said, we’d all like to thank you regardless of the results.
HUGE thanks from team #3075, Israel!