Well, for the flywheel we are adding, I need to add some code to the robot. I have a window motor that will be running off of a victor. The WM will be attached to the gimbal which the flywheel is attached. So, I want the WM to turn on for a certain speed and for a preset time when a button is pressed in. When the button is unpressed, I want the WM to return to the home position, doing so by running the speed in a negative direction, for the same amount of time.
- Press button, motor runs at speed V for T time and shuts off when T expires, even when button remains pressed.
2.When button is unpressed, returning from being pressed, motor runs at -V for T time and shuts off when T expires. This returns the motor to home position.
Unfortunately, I have not had much time to put towards learning programming in LabView, and I’m pretty much clueless on how to use it. Don’t ask me how I have working code on our robot right now, because I have no idea, haha.
Thanks!
-Sean, 3020
From what I understand, you want a button press to trigger an action of turning on the motor for x seconds. It will stay there until the button is released, then a new action will run to negate the other movement. The reason I review is that a short click and release will then go through both actions with nothing in between? No canceling the first movement? You also need to decide what happens when the driver clicks and releases multiple times rapidly – one movement or N movements, one for each click.
If my understanding is reasonably close to what you want, look up LabVIEW examples for state machines. I’ll name the motor positions home and engaged. You state machine has states of Home, Engaging, Engaged, Disengaging.
From home, a button press moves to Engaging. Time moves from Engaging to Engaging. A button release or pending one moved from Engaged to Disengaging. Time moves from DisEngaging to Home.
I’d set up a periodic task that runs the motor for time and contains the state variable. You can read the joystick button state in that loop at a given rate, or you can leave it in your teleop code and update a local or global that indicates the position of the button, up or down.
Hopefully this helps you think about how to approach the problem. I’ll leave the rest to you.
Greg McKaskle
Honestly, I kind of understand how you described it, but I have no idea how to di it in LabView. Seriously, I really don’t understand it, and don’t have the time to learn it right now. Any links maybe?
can you better describe the process of buttons pressed and movements for us?
what i’m getting is this:
your T time variable = 10 seconds
button A is held for T+5 seconds
Motor B is moved forward for T seconds and then stops [even though button A is still pressed]
button A is released
Motor B is moved reverse for T seconds
does this sound right?
if Button A is released after less than T seconds, what happens?
does the motor continue for the rest of the T time and then automatically reverse or does the motor reverse immediately when the button is released?
Preferably I’d want it to reverse and reset to it’s home position if the button is released too soon. However, the motor will only run for about .5 seconds, so it shouldn’t be too difficult to keep it pressed for at least 5 seconds. But as far as you described it, that’s correct.
Ok, I wrote a bunch of code in the past several hours.
I scrapped the original idea, and rather went with something slightly different.
- Button is TAPPED
- Motor Turns on for X seconds, for V speed
- Motor reverses, at V/4 for 4X seconds
- Motor is back at home position
To do this I used 2 case structures in my TeleOp Code. I used a joystick get button for, well, getting the button, and wired each joysticks button 1(trigger) to the case. When button is pressed, it is True, in turn running the code in that case. The code, how I have it written in the case, will take about 1.25 seconds to complete what I want it to do. However, I am concerned that the trigger, button 1, will have to be held for 1.25 seconds for the code to complete, insteads of just having to tap it to run the entire code. I haven’t done anything like this, and obviously I can’t test it on the robot. So, will the code finish if I only tap the trigger which activates it?
BTW, I am using Watchdog DELAY&FEED to do the timing. That is alright to do, right? I just finally understood autonomous coding today, so I applied the watchdog timing concept to this.
You don’t want to delay your teleop.
Move your code from the teleop loop into a parallel loop, like the one for periodic tasks. That way your teleop can return and be called again with more joystick info. I’d just move the joystick stuff to the parallel loop too. If it is in a parallel loop, you can use delay or delay and feed no problem.
Greg McKaskle