Esempio n. 1
0
/**
 * Adds a new {@link Command Command} to the group.  The {@link Command Command} will be started after
 * all the previously added {@link Command Commands}.
 *
 * <p>Note that any requirements the given {@link Command Command} has will be added to the
 * group.  For this reason, a {@link Command Command's} requirements can not be changed after
 * being added to a group.</p>
 *
 * <p>It is recommended that this method be called in the constructor.</p>
 * 
 * @param command The {@link Command Command} to be added
 */
void CommandGroup::AddSequential(Command *command)
{
	if (command == NULL)
	{
		wpi_setWPIErrorWithContext(NullParameter, "command");
		return;
	}
	if (!AssertUnlocked("Cannot add new command to command group"))
		return;

	command->SetParent(this);

	m_commands.push_back(CommandGroupEntry(command, CommandGroupEntry::kSequence_InSequence));
	// Iterate through command->GetRequirements() and call Requires() on each required subsystem
	Command::SubsystemSet requirements = command->GetRequirements();
	Command::SubsystemSet::iterator iter = requirements.begin();
	for (; iter != requirements.end(); iter++)
		Requires(*iter);
}
Esempio n. 2
0
/**
 * Adds a new {@link Command Command} to the group with a given timeout.
 * The {@link Command Command} will be started after all the previously added
 * commands.
 *
 * <p>Once the {@link Command Command} is started, it will be run until it
 * finishes or the time expires, whichever is sooner.  Note that the given
 * {@link Command Command} will have no knowledge that it is on a timer.</p>
 *
 * <p>Note that any requirements the given {@link Command Command} has will be
 * added to the group.  For this reason, a {@link Command Command's}
 * requirements can not be changed after being added to a group.</p>
 *
 * <p>It is recommended that this method be called in the constructor.</p>
 *
 * @param command The {@link Command Command} to be added
 * @param timeout The timeout (in seconds)
 */
void CommandGroup::AddSequential(Command* command, double timeout) {
  if (command == nullptr) {
    wpi_setWPIErrorWithContext(NullParameter, "command");
    return;
  }
  if (!AssertUnlocked("Cannot add new command to command group")) return;
  if (timeout < 0.0) {
    wpi_setWPIErrorWithContext(ParameterOutOfRange, "timeout < 0.0");
    return;
  }

  command->SetParent(this);

  m_commands.push_back(CommandGroupEntry(
      command, CommandGroupEntry::kSequence_InSequence, timeout));
  // Iterate through command->GetRequirements() and call Requires() on each
  // required subsystem
  Command::SubsystemSet requirements = command->GetRequirements();
  auto iter = requirements.begin();
  for (; iter != requirements.end(); iter++) Requires(*iter);
}