Command within the command

Can you run command within a command without having to use command group? I use c++ command based programming.

I wouldn’t recommend it. Why can’t you use a command group?

What are you trying to accomplish? Maybe check out StartCommand.

A commandgroup is a command in the inheritance heirarchy.

So, what does avoiding the commandgroup buy you?

I agree with notmattlythgoe, maybe some context as to what you are trying to do and then see if we can give you some insight as to what we have observed work in the past, or help navigate the API docs to see what gets you where you want.

1 Like

Can you? Sure. Create a Command object and assign it to an instance of your command class and call the start() function on it. However, this could cause some weird behaviours, especially if you are unfamiliar with how the Command-Based Scheduler works. Some of the immediate things that come to my mind that you would need to think about is that as far as the Scheduler is concerned, the command that started the second command, and that second command are two separate commands. No Shared requires() and if one is finished or interrupted, it will not affect the other (except where you explicitly code such functionality). You would need to ensure that your command was properly tracking the state of the second command if you want it to affect the actions of the first command.

This is very possible, but not necessarily recommended. As stated above, more info on what you intend can help us, help you, come up with a more appropriate solution.


Maybe a possible solution for the OP, as well as a related question…

Yesterday, our team played with the idea of rumbling the driver’s joystick once an operator command has completed. For now, they added the following in the end() function of the operator command:

Scheduler.getInstance().add(new DriverRumble(0.3));

They also had to add super.interrupted() to the interrupted() function, so that end() is called properly.

DriverRumble is a TimedCommand. The operator command is triggered by whileHeld button press and always ends on an interruption when the button is released. In brief testing on our practice bot, this approach doesn’t seem to be causing any odd behavior, but I’m concerned that the brief 0.3 second exeuction is hiding issues and we might see problems in more complete testing. I would think that instead of the operator command being triggered directly, it should be part of a command group, the second command of which is DriverRumble. If the first command in a command group ends on an interruption, will the subsequent sequential commands execute or will the command group terminate immediately as if it itself was interrupted?

If you put the DriverRumble [requires(rumbleMotor)] in a command group with (for example) CloseJaws [requires(jaws)], then CloseJawsAndRumble requires both jaws and rumbleMotor. This means that if any other command is started which requires either jaws or rumbleMotor, CloseJawsAndRumble() will be interrupted. This is almost certainly not what you wanted.

I think you answered my question, but not in a way I was expecting. :slight_smile: DriverRumble doesn’t have any requires, at the moment - it operates directly on the joystick. So, although perhaps not the perfectly elegant approach with a subsystem and whatnot, it may very well work. ¯\_(ツ)_/¯ Worth a quick code and test. You helped me connect the dots between the logical relationship of command groups, requires(), and interruption that I wasn’t seeing, though. Thanks!

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.