Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elevator mech #1

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id "java"
id "edu.wpi.first.GradleRIO" version "2024.1.1"
id "edu.wpi.first.GradleRIO" version "2024.3.2"
}

java {
Expand Down
Empty file modified gradlew
100644 → 100755
Empty file.
8 changes: 8 additions & 0 deletions src/main/java/frc/robot/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,13 @@
public final class Constants {
public static class OperatorConstants {
public static final int kDriverControllerPort = 0;

public static final int leftelevator = 6;
public static final int limitSwitch = 9;

public static final int elevatorP = 0;
public static final int elevatorI = 0;
public static final int elevatorD =0;

}
}
32 changes: 29 additions & 3 deletions src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,40 @@

import frc.robot.Constants.OperatorConstants;
import frc.robot.subsystems.DriveSubsystem;
import frc.robot.subsystems.ElevatorSubsystem;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.ConditionalCommand;
import edu.wpi.first.wpilibj2.command.InstantCommand;
import edu.wpi.first.wpilibj2.command.RunCommand;
import edu.wpi.first.wpilibj2.command.button.CommandXboxController;
import edu.wpi.first.wpilibj2.command.button.Trigger;


/**
* This class is where the bulk of the robot should be declared. Since Command-based is a
* "declarative" paradigm, very little robot logic should actually be handled in the {@link Robot}
* periodic methods (other than the scheduler calls). Instead, the structure of the robot (including
* subsystems, commands, and trigger mappings) should be declared here.
*/
public class RobotContainer {

private double upPosition;
// The robot's subsystems and commands are defined here...
private final DriveSubsystem driveSubsystem;
private final ElevatorSubsystem elevatorSubsystem;

// Replace with CommandPS4Controller or CommandJoystick if needed
private final CommandXboxController driverController =
new CommandXboxController(OperatorConstants.kDriverControllerPort);

private final CommandXboxController mechController= new CommandXboxController(0);
private Trigger rightBumper = mechController.rightBumper();

/** The container for the robot. Contains subsystems, OI devices, and commands. */
public RobotContainer() {
driveSubsystem = new DriveSubsystem();
elevatorSubsystem = new ElevatorSubsystem();

// Configure the trigger bindings
configureBindings();
}
Expand All @@ -42,10 +54,24 @@ public RobotContainer() {
* joysticks}.
*/
private void configureBindings() {
driveSubsystem.setDefaultCommand(new RunCommand(() -> {
driveSubsystem.setDrivePowers(driverController.getLeftY(), driverController.getRightY());
}, driveSubsystem));
// driveSubsystem.setDefaultCommand(new RunCommand(() -> {
// driveSubsystem.setDrivePowers(driverController.getLeftY(), driverController.getRightY());
// }, driveSubsystem));

rightBumper.onTrue(
new ConditionalCommand(
new InstantCommand(()-> elevatorSubsystem.setElevatorState(upPosition)),
new InstantCommand(()-> elevatorSubsystem.setElevatorState(0)),
()->elevatorSubsystem.atFloor()
)
);

elevatorSubsystem.setDefaultCommand(new InstantCommand( () -> {
elevatorSubsystem.setPower(mechController.getLeftTriggerAxis()-mechController.getRightTriggerAxis());
}));



}

/**
Expand Down
65 changes: 65 additions & 0 deletions src/main/java/frc/robot/subsystems/ElevatorSubsystem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package frc.robot.subsystems;


import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
import frc.robot.Constants.OperatorConstants;

import com.revrobotics.CANSparkMax;
import com.revrobotics.RelativeEncoder;
import com.revrobotics.CANSparkBase;
import com.revrobotics.CANSparkLowLevel.MotorType;
import com.revrobotics.SparkPIDController;

import edu.wpi.first.math.proto.System;
import edu.wpi.first.wpilibj.DigitalInput;

public class ElevatorSubsystem extends SubsystemBase{
private CANSparkMax leftelevator;
private SparkPIDController elevatorpid;
private DigitalInput limitSwitch;
private RelativeEncoder encoder;



public ElevatorSubsystem (){
leftelevator = new CANSparkMax (OperatorConstants.leftelevator, MotorType.kBrushless);
elevatorpid = leftelevator.getPIDController();
limitSwitch = new DigitalInput (OperatorConstants.limitSwitch);
encoder = leftelevator.getEncoder();
encoder.setPosition(0);

elevatorpid.setP(OperatorConstants.elevatorP);
elevatorpid.setI(OperatorConstants.elevatorI);
elevatorpid.setD(OperatorConstants.elevatorD);
}

public void setElevatorState(double state){

elevatorpid.setReference(state, CANSparkBase.ControlType.kPosition);
}

public boolean atFloor(){

return limitSwitch.get();
}

public double position(){
return encoder.getPosition();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should add a function to reset the encoder value to 0 when the elevator limit switch is triggered.


public void resetEncoder(){
encoder.setPosition(0);
}

public void setPower(double speed) {
leftelevator.set(speed);
}

@Override
public void periodic() {
if (atFloor()){
resetEncoder();
}
}
}
74 changes: 74 additions & 0 deletions vendordeps/REVLib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{
"fileName": "REVLib.json",
"name": "REVLib",
"version": "2024.2.4",
"frcYear": "2024",
"uuid": "3f48eb8c-50fe-43a6-9cb7-44c86353c4cb",
"mavenUrls": [
"https://maven.revrobotics.com/"
],
"jsonUrl": "https://software-metadata.revrobotics.com/REVLib-2024.json",
"javaDependencies": [
{
"groupId": "com.revrobotics.frc",
"artifactId": "REVLib-java",
"version": "2024.2.4"
}
],
"jniDependencies": [
{
"groupId": "com.revrobotics.frc",
"artifactId": "REVLib-driver",
"version": "2024.2.4",
"skipInvalidPlatforms": true,
"isJar": false,
"validPlatforms": [
"windowsx86-64",
"windowsx86",
"linuxarm64",
"linuxx86-64",
"linuxathena",
"linuxarm32",
"osxuniversal"
]
}
],
"cppDependencies": [
{
"groupId": "com.revrobotics.frc",
"artifactId": "REVLib-cpp",
"version": "2024.2.4",
"libName": "REVLib",
"headerClassifier": "headers",
"sharedLibrary": false,
"skipInvalidPlatforms": true,
"binaryPlatforms": [
"windowsx86-64",
"windowsx86",
"linuxarm64",
"linuxx86-64",
"linuxathena",
"linuxarm32",
"osxuniversal"
]
},
{
"groupId": "com.revrobotics.frc",
"artifactId": "REVLib-driver",
"version": "2024.2.4",
"libName": "REVLibDriver",
"headerClassifier": "headers",
"sharedLibrary": false,
"skipInvalidPlatforms": true,
"binaryPlatforms": [
"windowsx86-64",
"windowsx86",
"linuxarm64",
"linuxx86-64",
"linuxathena",
"linuxarm32",
"osxuniversal"
]
}
]
}