View Single Post
  #11   Spotlight this post!  
Unread 12-03-2015, 17:13
otherguy's Avatar
otherguy otherguy is offline
sparkE
AKA: James
FRC #2168 (The Aluminum Falcons)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: CT
Posts: 429
otherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to behold
Re: COmmand based software Interrupts

Your switches may be wired correctly... but that doesn't mean that your code is reading their states correctly. Hence my suggestion to check that it's doing what you expect. If you're confident that's not the problem, good. I can't make you check it. You're the one that's saying it's not working correctly, so It may be prudent to verify your assumptions.


Other things that could be wrong:

Which commands in particular are you referring to as "new" command and "old" command?

The reason I ask is in OI all the MoveElevatorXXX commands are started when you press a button. These are the command I thought you were talking about previously wrt your logs. They will only execute once unless you're repeatedly pressing the button in question. This is not consistent with the logs you've provided.



On the other hand, if the one of the commands that's running happens to be the DropElevator() or LiftElevator() commands, then there's a different explanation for what may be going on.

I have yet to come up with a case where WhileHeld() actually does what you want it to (if someone has a use case, please let me know). If I understand your code correctly, the way you're attempting to use this command is to have your Lift/DropElevator() commands run until you let go of the button. But what's actually going to happen is each loop iteration, you're going to start a new copy of the Lift/DropElevator() command. Since you have a call to stop the elevator as part of the command, you're going to be in this endless loop of driving the elevator, stopping it, driving it, stopping it, until you let go of the button.

Here's why using the joy1button4->WhileHeld(new DropElevator()); as an example:
  1. Joy 1 Button 4 is pressed.
  2. A new command is created and added into the scheduler (DropElevator)
  3. The active command on the subsystem (elevator) is ElevatorIdle() and it's going to be canceled. Since a new
  4. When the scheduler come around to execute the active command, it runs the execute() function, assume that you're not at end of travel on the elevator, so you're going to run the DropElevatorArm() function, which presumably commands a motor to move the arm.
  5. assume isFinished on this command returns false.
  6. the next time around (assuming the button is still pressed) a new instance of the DropElevator() command is created. It requires the Elevator subsystem, so all active commands on that subsystem are canceled.
  7. The scheduler calls the end method on the first instance of the on the DropElevator command. This in turn calls the StopElevatorArm() function, presumably commanding the elevator motors to zero.
  8. now it's time for the new instance of the DropElevator() command to run: the scheduler runs the execute() function, assume that you're not at end of travel on the elevator, so you're going to run the DropElevatorArm() function, which presumably commands a motor to move the arm.
  9. and the cycle of starting and stopping this command repeats forever until you let go of the button.

What you probably want to do is instead execute the command WhenPressed, then call a command that stops the elevator (ElevatorIdle) When the same button is released.

Code:
joy1button3->WhileHeld(new LiftElevator()); 
joy1button4->WhileHeld(new DropElevator()); 
joy2button3->WhileHeld(new LiftElevator());
becomes
Code:
joy1button3->WhenPressed(new LiftElevator()); 
joy1button3->WhenReleased(new ElevatorIdle()); 
joy1button4->WhenPressed(new DropElevator()); 
joy1button4->WhenReleased(new ElevatorIdle()); 
joy2button3->WhenPressed(new LiftElevator()); 
joy2button3->WhenReleased(new ElevatorIdle());
__________________
http://team2168.org
Reply With Quote