001// Copyright (c) FIRST and other WPILib contributors. 002// Open Source Software; you can modify and/or share it under the terms of 003// the WPILib BSD license file in the root directory of this project. 004 005package edu.wpi.first.wpilibj2.command; 006 007/** 008 * A command that runs another command in perpetuity, ignoring that command's end conditions. While 009 * this class does not extend {@link CommandGroupBase}, it is still considered a composition, as it 010 * allows one to compose another command within it; the command instances that are passed to it 011 * cannot be added to any other groups, or scheduled individually. 012 * 013 * <p>As a rule, CommandGroups require the union of the requirements of their component commands. 014 * 015 * <p>This class is provided by the NewCommands VendorDep 016 * 017 * @deprecated PerpetualCommand violates the assumption that execute() doesn't get called after 018 * isFinished() returns true -- an assumption that should be valid. This was unsafe/undefined 019 * behavior from the start, and RepeatCommand provides an easy way to achieve similar end 020 * results with slightly different (and safe) semantics. 021 */ 022@Deprecated(forRemoval = true, since = "2023") 023public class PerpetualCommand extends CommandBase { 024 protected final Command m_command; 025 026 /** 027 * Creates a new PerpetualCommand. Will run another command in perpetuity, ignoring that command's 028 * end conditions, unless this command itself is interrupted. 029 * 030 * @param command the command to run perpetually 031 */ 032 public PerpetualCommand(Command command) { 033 CommandScheduler.getInstance().registerComposedCommands(command); 034 m_command = command; 035 m_requirements.addAll(command.getRequirements()); 036 } 037 038 @Override 039 public void initialize() { 040 m_command.initialize(); 041 } 042 043 @Override 044 public void execute() { 045 m_command.execute(); 046 } 047 048 @Override 049 public void end(boolean interrupted) { 050 m_command.end(interrupted); 051 } 052 053 @Override 054 public boolean runsWhenDisabled() { 055 return m_command.runsWhenDisabled(); 056 } 057}