Toggle Motor Using Button

This year with shooting something again I promised my team the ability to simply press a button on the joystick and a motor will run until pressed again (essentially a latch) as opposed to last year the motor being controlled by a joystick itself. I thought I had finally figured out the solution which I have a screenshot of below, but it doesn’t seem to work right. When the button is pressed, the motor starts up for about a second, then shuts off. This repeats indefinitely until I press the button again to stop (or disable the robot). There are rare chances I can spam the button in certain ways and get it to run forever, but that is really inconsistent.

http://i.imgur.com/kxFEDFf.png
all 3 are of the same code but it is showing what is inside the case structures

Do you guys have a solution to this specific code, or a new code that works better for what I need?

Thanks

You could use a global that turns on/off with each press of the button, then check to see if the global is true/false when the button is pressed and then start or stop the motors depending on that.

The attached image shows some of the useful techniques that may help. You can even make some of these into subVIs for use elsewhere.

I’d encourage you to build this with the button, right click on the button and change the mechanical action to a “switch until released”, and run it on the My Computer. You can place probes on any of the wires or add indicators to them to understand how the values change when you interact. Then, when you understand and trust it, move it to the robot simply by retargeting it or by copying the code or using the subVIs.

Ask questions if parts of it don’t make sense or you want to compare it to your approach.

Greg McKaskle





I either copied it wrong or I guessed what was in the case and diagram disable structures incorrectly because after many a run through it seemed ok but when I actually tested it the motor didn’t move. Here is what I made:

I noticed that the stop on the while loop was set to false so I switched that to true and nothing changed.

Please give it to me straight, doc.

As I explained in this thread, our team developed a very simple VI to toggle a boolean input, essentially making any input act like a latching button. I’ve attached both the VI and a screenshot of how you could use it in your particular situation.

Toggle.vi (9.41 KB)
Capture.PNG


Toggle.vi (9.41 KB)
Capture.PNG

I forgot to point out that you just want to place the code from inside the loop into your TeleOp. If you put an infinite while loop in Teleop, it messes with the framework and you won’t process joysticks or move as you are supposed to.

And the Toggle VI worked well and is simpler than what I wrote. They are equivalent functionally.

Greg McKaskle

I went with bv’s and it works fine, thanks for the help.

Okay so a follow up question I have would be:

How would I be able to control the speed of a motor using the “precise throttle” feature on the, specifically, Attack3 joystick (the little knob in the front that would be fantastic for constant control but in increments, unlike using the joystick itself)?

Thanks

Do you mean proportional scaling of the motor speed?

Read the Attack 3 joystick’s throttle button as “axis 3 (throttle)”. It’ll give a value between +1 (full back/down) and -1 (full forward/up).

If you want to turn that into a value between 0 and 1, just subtract one and divide by negative two.

Is that enough information? I’m not sure if you’re asking how to read the throttle control, or how to set the speed of a motor, or something else.

What you can do to take it a step further is something like this VI I designed for my team. The 4 can be changed to any number you want and it controls the fraction (in this case, 1/4) that putting the throttle all the way down will give while keeping the top value at 1.

http://www.chiefdelphi.com/forums/attachment.php?attachmentid=13785&d=1360018159

well we actually have it working this way on the four buttons on top of the joystick, so the robot can go forward, left, right and backwards with only the 4 buttons on top.

I will leave you with the vi.

Teleop.vi (27 KB)


Teleop.vi (27 KB)