FIRST Tech Challenge Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

DC Motor Stops after 3 sec

I have been mentoring two teams and both have ran into this problem.  They have a DC motor controlled by a button press, 'run while pressed'.  While still holding down the button the motor stops responding after 3 seconds.  This has happened in single loop programs and multiple loop programs.  I have narrowed it down to this: if there is joystick to power VI feeding any motor power VI you get continuous control of all motors in that loop.  If you have a loop without a joystick to power VI feeding a motor you get the 3 second shutdown.  I have attached a zip file with a nxt project and sample VIs, one that works and one that doesn't.

Thanks in advance.

-Steve

0 Kudos
Message 1 of 7
(6,572 Views)

Hey Steve,

I think the issue you are seeing is with the NXT watchdog not being called. This year the watchdog is built into the NXT wait function. This function gets called inside the motor and servo VI's which is why calling a motor VI every loop resets the watchdog.  I would try adding a wait function to your outer loop to reset the watchdog timer and keep the watchdog from disabling the motors. Alternatively instead of writing to the motors on state changes (pressed or released) you could write based on state (button up or down) because then you would write to the motors every loop instead of just when a button is pressed or released.  Let me know if this fixes the issue you are seeing.

Kevin Fort
Principal Software Engineer
NI
Message 2 of 7
(4,187 Views)

Kevin,

Thanks for your quick reply.  I tried your suggestion and it did not work.  I would have been baffled if it did because the way the program is setup, if the driver is pushing the button to run the motor, every iteration of the loop should be writing to the motor VI.  We did have a piece of code that would toggle on a button press and your suggestion makes sense there.  I have attached a snapshot of the VI with the wait in it.

Any other suggestions?

Button no work.JPG

0 Kudos
Message 3 of 7
(4,187 Views)

Hey Steve,

I will take more of a look at what might be going on here.  I do think that the way your code is set up you only write to the motors when the button is first pressed because that is the only time the button event will be generated.  If you generated a pressed event every time through the loop when the button was held down then in your toggle situation the output would just toggle back and forth.  I think if you make it so that you write those motor values every loop iteration you will probably fix the issue. I would do that by checking the state of each button instead of looking for button events.  Let me know how that works.

Kevin Fort
Principal Software Engineer
NI
Message 4 of 7
(4,187 Views)

Kevin,

That makes total sense.  The generate code function put a label that said "Runs motor while button is pressed" (or something close to that) and I guess when I read that I thought it was executing that case every iteration while the button was pressed.  I didn't look at it as event based with press then release.  Thanks for the wake up nudge.

All that said you are correct.  We could use the button state instead of events to run something while pressed.  I do still think something isn't quite right with the motor stopping after 3 seconds though the way it is.  We do have functions that we want to toggle on/off with a button press involving a DC motor.

Thanks for your help!

0 Kudos
Message 5 of 7
(4,187 Views)

Hey Steve,

I think the the wait VI will only reset the watchdog if you are waiting for at least 1 second.

The quick solution is to add the feedwatchdog vi to your loop.(its on the tetrix palette), or write to the motors every loop iteration.

The problem with both of those solutions is you are slowing down your overall loop rate which will add lag, especially as you add the rest of your drive code.

A better solution is to add another infinite loop to your program that just contains the wait vi that waits for 1 second. That will refresh the motors every second without taxing your drive loop.

Now that I think about it, this is actually a bug, the FCS Communication vis should manage the watchdog without interaction from the user. I will address it in the next patch/release.

Thanks,

Ethan

0 Kudos
Message 6 of 7
(4,187 Views)

Ethan,

I put the feedwatchdog VI in it's own loop with a one second timer in it and this fixed the problem.  I did it this way to make it obvoius as to what is going on.  Thanks for your and Kevin's help on this.

-Steve

p.s. I am starting another discussion about library linking.

0 Kudos
Message 7 of 7
(4,187 Views)