Skip to content

Commit

Permalink
[ISSUE:31] Added Elevator Commands
Browse files Browse the repository at this point in the history
  • Loading branch information
SuzakuSar authored Jan 22, 2025
1 parent 38db2f0 commit 6db4f23
Show file tree
Hide file tree
Showing 8 changed files with 399 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

package frc.robot.commands;

import edu.wpi.first.wpilibj2.command.Command;
import frc.robot.constants.ElevatorConstants;
import frc.robot.constants.Global;
import frc.robot.subsystems.Elevator;

/* You should consider using the more terse Command factories API instead https://docs.wpilib.org/en/stable/docs/software/commandbased/organizing-command-based.html#defining-commands */
public class ElevatorDown extends Command
{
private final Elevator m_Elevator;
/**
* Creates a new ElevatorDown.
*/
public ElevatorDown(Elevator p_Elevator)
{
this.m_Elevator = p_Elevator;
addRequirements(this.m_Elevator);
}

/**
* Called when the command is initially scheduled.
*/
@Override
public void initialize()
{
m_Elevator.elevatorRequest(Global.MODE.VOLTAGE, ElevatorConstants.ELEVATOR_DOWN_VOLTAGE);// Applies negative voltage
}

/**
* Called every time the scheduler runs while the command is scheduled.
*/
@Override
public void execute()
{
// intentionally empty
}

/**
* Called once the command ends or is interrupted.
*/
@Override
public void end(boolean interrupted)
{
m_Elevator.elevatorRequest(Global.MODE.VOLTAGE, 0);// Shuts off voltage
}

/**
* Returns true when the command should end.
*/
@Override
public boolean isFinished()
{
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@

// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

package frc.robot.commands;

import edu.wpi.first.wpilibj2.command.Command;
import frc.robot.constants.ElevatorConstants;
import frc.robot.constants.Global;
import frc.robot.subsystems.Elevator;

/* You should consider using the more terse Command factories API instead https://docs.wpilib.org/en/stable/docs/software/commandbased/organizing-command-based.html#defining-commands */
public class ElevatorGoHome extends Command
{
private final Elevator m_Elevator;
/**
* Creates a new ElevatorGoHome.
*/
public ElevatorGoHome(Elevator p_Elevator)
{
this.m_Elevator = p_Elevator;
addRequirements(this.m_Elevator);
}

/**
* Called when the command is initially scheduled.
*/
@Override
public void initialize()
{
m_Elevator.elevatorRequest(Global.MODE.POSITION, ElevatorConstants.ELEVATOR_ZERO_POSITION);// Will set elevator to the home position
}

/**
* Called every time the scheduler runs while the command is scheduled.
*/
@Override
public void execute()
{
//intentionally empty
}

/**
* Called once the command ends or is interrupted.
*/
@Override
public void end(boolean interrupted)
{
m_Elevator.elevatorRequest(Global.MODE.VOLTAGE, 0);// Once command ends shuts off motor voltage
}

/**
* Returns true when the command should end.
*/
@Override
public boolean isFinished()
{
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

package frc.robot.commands;

import edu.wpi.first.wpilibj2.command.Command;
import frc.robot.constants.ElevatorConstants;
import frc.robot.constants.Global;
import frc.robot.subsystems.Elevator;

/* You should consider using the more terse Command factories API instead https://docs.wpilib.org/en/stable/docs/software/commandbased/organizing-command-based.html#defining-commands */
public class ElevatorLevelFour extends Command
{
private final Elevator m_Elevator;
/**
* Creates a new ElevatorLevelFour.
*/
public ElevatorLevelFour(Elevator p_Elevator)
{
this.m_Elevator = p_Elevator;
addRequirements(this.m_Elevator);
}

/**
* Called when the command is initially scheduled.
*/
@Override
public void initialize()
{
m_Elevator.elevatorRequest(Global.MODE.POSITION, ElevatorConstants.ELEVATOR_LEVEL_FOUR);// Sets elevator to Level 4
}

/**
* Called every time the scheduler runs while the command is scheduled.
*/
@Override
public void execute()
{
// Intentionally empty
}

/**
* Called once the command ends or is interrupted.
*/
@Override
public void end(boolean interrupted)
{
m_Elevator.elevatorRequest(Global.MODE.VOLTAGE, 0);// Once command ends shuts off motor voltage
}

/**
* Returns true when the command should end.
*/
@Override
public boolean isFinished()
{
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

package frc.robot.commands;

import edu.wpi.first.wpilibj2.command.Command;
import frc.robot.constants.ElevatorConstants;
import frc.robot.constants.Global;
import frc.robot.subsystems.Elevator;

/* You should consider using the more terse Command factories API instead https://docs.wpilib.org/en/stable/docs/software/commandbased/organizing-command-based.html#defining-commands */
public class ElevatorLevelThree extends Command
{
private final Elevator m_Elevator;
/**
* Creates a new ElevatorLevelThree.
*/
public ElevatorLevelThree(Elevator p_Elevator)
{
this.m_Elevator = p_Elevator;
addRequirements(this.m_Elevator);
}

/**
* Called when the command is initially scheduled.
*/
@Override
public void initialize()
{
m_Elevator.elevatorRequest(Global.MODE.POSITION, ElevatorConstants.ELEVATOR_LEVEL_THREE);// Sets elevator to Level 3
}

/**
* Called every time the scheduler runs while the command is scheduled.
*/
@Override
public void execute()
{
// Intentionally empty
}

/**
* Called once the command ends or is interrupted.
*/
@Override
public void end(boolean interrupted)
{
m_Elevator.elevatorRequest(Global.MODE.VOLTAGE, 0);// Once command ends shuts off motor voltage
}

/**
* Returns true when the command should end.
*/
@Override
public boolean isFinished()
{
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

package frc.robot.commands;

import edu.wpi.first.wpilibj2.command.Command;
import frc.robot.constants.ElevatorConstants;
import frc.robot.constants.Global;
import frc.robot.subsystems.Elevator;

/* You should consider using the more terse Command factories API instead https://docs.wpilib.org/en/stable/docs/software/commandbased/organizing-command-based.html#defining-commands */
public class ElevatorLevelTwo extends Command
{
private final Elevator m_Elevator;
/**
* Creates a new ElevatorLevelTwo.
*/
public ElevatorLevelTwo(Elevator p_Elevator)
{
this.m_Elevator = p_Elevator;
addRequirements(this.m_Elevator);
}

/**
* Called when the command is initially scheduled.
*/
@Override
public void initialize()
{
m_Elevator.elevatorRequest(Global.MODE.POSITION, ElevatorConstants.ELEVATOR_LEVEL_TWO);// Sets elevator to Level 2
}

/**
* Called every time the scheduler runs while the command is scheduled.
*/
@Override
public void execute()
{
// Intentionally empty
}

/**
* Called once the command ends or is interrupted.
*/
@Override
public void end(boolean interrupted)
{
m_Elevator.elevatorRequest(Global.MODE.VOLTAGE, 0);// Once command ends shuts off motor voltage
}

/**
* Returns true when the command should end.
*/
@Override
public boolean isFinished()
{
return false;
}
}
60 changes: 60 additions & 0 deletions Big-Bad-Wolf-2025/src/main/java/frc/robot/commands/ElevatorUp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

package frc.robot.commands;

import edu.wpi.first.wpilibj2.command.Command;
import frc.robot.constants.ElevatorConstants;
import frc.robot.constants.Global;
import frc.robot.subsystems.Elevator;

/* You should consider using the more terse Command factories API instead https://docs.wpilib.org/en/stable/docs/software/commandbased/organizing-command-based.html#defining-commands */
public class ElevatorUp extends Command
{
private final Elevator m_Elevator;
/**
* Creates a new ElevatorUp.
*/
public ElevatorUp(Elevator p_Elevator)
{
this.m_Elevator = p_Elevator;
addRequirements(this.m_Elevator);
}

/**
* Called when the command is initially scheduled.
*/
@Override
public void initialize()
{
m_Elevator.elevatorRequest(Global.MODE.VOLTAGE, ElevatorConstants.ELEVATOR_UP_VOLTAGE);// Applies voltage for elevator to go up
}

/**
* Called every time the scheduler runs while the command is scheduled.
*/
@Override
public void execute()
{
// Intentionally empty
}

/**
* Called once the command ends or is interrupted.
*/
@Override
public void end(boolean interrupted)
{
m_Elevator.elevatorRequest(Global.MODE.VOLTAGE, 0);// Once command ends shuts off motor voltage
}

/**
* Returns true when the command should end.
*/
@Override
public boolean isFinished()
{
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

package frc.robot.constants;

/** Add your docs here. */
public class ElevatorConstants
{
//All values are filler values and units until further testing
public static final double ELEVATOR_ZERO_POSITION = 0;
public static final double ELEVATOR_LEVEL_TWO = 10;
public static final double ELEVATOR_LEVEL_THREE = 20;
public static final double ELEVATOR_LEVEL_FOUR = 30;

public static final double ELEVATOR_UP_VOLTAGE = 4;
public static final double ELEVATOR_DOWN_VOLTAGE = -4;
}
Loading

0 comments on commit 6db4f23

Please # to comment.