![]() |
whileHeld() Motor Program Issue
Okay - I am programming a command based java and wrote a couple of commands defined by a subsystem called ForkMotor. One command was supposed to move a motor forward(1) while a button was pressed. The other was supposed to move a motor backwards(-1) while a button is pressed. When I hold the button down that is supposed to move it forward the motor glitches off and on but does stop when I let go - the motor is fine I tested it. The button that SHOULD turn it in the other direction doesn't work at all. If anyone knows how to fix this that would be AWESOME.
Here it is: Subsystem(called ForkMotor): Quote:
Quote:
Second Command(to move it in reverse -- called LowerForks): Quote:
Quote:
Quote:
Quote:
|
Re: whileHeld() Motor Program Issue
Check out the javadoc for the whileHeld method. It might not be doing what you expect.
whileHeld will repeatedly call the command's start method (50 times a second). The start method will add the command to the scheduler. In the command based project, the scheduler is the bit of code that is responsible for stepping all active commands through their steps of execution [initialize(), execute(), isfinished(), end()]. The comment on the start() method is worth reading: Quote:
Code:
ForksUp.whenPressed(new LiftForks());Other than the use of whileHeld, I don't see any other glaring errors in your code. |
Re: whileHeld() Motor Program Issue
Okay - THANKS a ton!
|
Re: whileHeld() Motor Program Issue
whileHeld() works as advertised, you just need to remember to shut down things in end() and interrupted()...
Our experience last summer was whileHeld called init() once, (execute(), getFinished()) repeatedly, and interrupted() is called when the button is released. We used whileHeld reliably with commands like this (note that we stop the motor from end() and interrupted(). We would see multiple init() if several whileHelds fired off commands that required the same subsystem(s) and those buttons were held at the same time. I don't remember the exact details. Code:
package org.usfirst.frc3620.FRC36202013RobotRedo.commands; |
Re: whileHeld() Motor Program Issue
I went through the code more closely than last time...
JoystickButton inherits whileHeld from Button. Button extends Trigger. whileHeld calls Trigger's whileActive method From Javadoc: Code:
whileActiveCommand.start() adds the command to a vector of command that should be added to the list of commands that the scheduler will process. Here's the catch, the scheduler doesn't do anything with the command if the command is already in the list. See line 145. So I agree. whileHeld should work as advertised. I know that I've had trouble with it in the past, and have always implemented commands as I outlined above. Maybe the problems I had with whileHeld were actually with something else, I haven't gone back to investigate. |
| All times are GMT -5. The time now is 09:30. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi