Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   Commands Ending Other Commands (http://www.chiefdelphi.com/forums/showthread.php?t=144508)

King Nerd III 02-23-2016 11:55 AM

Commands Ending Other Commands
 
I have a commands that runs the rollers outwards and a command that runs the rollers inwards, but if one is running and you call the other one (through pressing a button), then both commands attempt to run at the same time. Is there any way to have each command end the other one when called?
I had an idea where you declare a Command object in the command of the other command (i.e. Inwards has an Outwards Command object in it) and when one is initialized it calls End() from the object, but I don't know if that would work, and don't have the robot electronics board with me to test right now. Any ideas?

euhlmann 02-23-2016 12:17 PM

Re: Commands Ending Other Commands
 
Make them both call Requires(YourRollerSubsystem) and SetInterruptible(true) in the constructor. Wpilib will then take care of ending the running one when the other is called for you.

King Nerd III 02-23-2016 01:15 PM

Re: Commands Ending Other Commands
 
Quote:

Originally Posted by euhlmann (Post 1545046)
Make them both call Requires(YourRollerSubsystem) and SetInterruptible(true) in the constructor. Wpilib will then take care of ending the running one when the other is called for you.

Thanks. I knew about the Requires, but I had no clue SetInterruptible was a thing. I'll add that in now.

Joe Ross 02-23-2016 02:17 PM

Re: Commands Ending Other Commands
 
Quote:

Originally Posted by euhlmann (Post 1545046)
Make them both call Requires(YourRollerSubsystem) and SetInterruptible(true) in the constructor.

interruptable is true by default.

King Nerd III 02-23-2016 02:49 PM

Re: Commands Ending Other Commands
 
Quote:

Originally Posted by Joe Ross (Post 1545174)
interruptable is true by default.

I thought that was the case, but calling a command that requires the same subsystem doesn't interrupt the original command for us. Any clue on how to fix this?

Waz 02-24-2016 01:31 PM

Re: Commands Ending Other Commands
 
Quote:

Originally Posted by King Nerd III (Post 1545210)
I thought that was the case, but calling a command that requires the same subsystem doesn't interrupt the original command for us. Any clue on how to fix this?

We have never had a problem with this in several years of using the command based programming model. Is it possible that you have accidentally created two instances of the subsystem and the two commands each have their own? That could cause this behavior.

Hope this helps,
Steve


All times are GMT -5. The time now is 10:24 AM.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi