Skip to content

Commit

Permalink
Merge pull request #6 from FRCTeam4069/mechanisms
Browse files Browse the repository at this point in the history
Mechanisms
  • Loading branch information
Petelax authored Jan 18, 2025
2 parents 195f7be + bdd47b4 commit fb539a5
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 40 deletions.
18 changes: 14 additions & 4 deletions src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,28 @@

package frc.robot;

import com.revrobotics.spark.SparkFlex;

import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.button.CommandXboxController;
import edu.wpi.first.wpilibj2.command.button.Trigger;
import frc.robot.subsystems.TestSubsystem;

// adding a comment for testing
/**
* 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
* 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 {

// The robot's subsystems and commands are defined here...


// Replace with CommandPS4Controller or CommandJoystick if needed
private final CommandXboxController controller0 = new CommandXboxController(0);
private final CommandXboxController controller1 = new CommandXboxController(1);
Expand All @@ -26,7 +35,7 @@ public RobotContainer() {
// Configure the trigger bindings
configureBindings();
}

/**
* Use this method to define your trigger->command mappings. Triggers can be created via the
* {@link Trigger#Trigger(java.util.function.BooleanSupplier)} constructor with an arbitrary
Expand All @@ -53,3 +62,4 @@ public Command getAutonomousCommand() {
}
*/
}

48 changes: 48 additions & 0 deletions src/main/java/frc/robot/commands/TestCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// 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.subsystems.TestSubsystem;

/* 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 TestCommand extends Command {

TestSubsystem testSubsystem;

/** Creates a new TestCommand. */
public TestCommand(TestSubsystem testSubsystem) {
// Use addRequirements() here to declare subsystem dependencies.

this.testSubsystem = testSubsystem;

addRequirements(testSubsystem);
}

// Called when the command is initially scheduled.
@Override
public void initialize() {

testSubsystem.setPower(0.5);

}

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

// Called once the command ends or is interrupted.
@Override
public void end(boolean interrupted) {

}

// Returns true when the command should end.
@Override
public boolean isFinished() {
return Math.abs(testSubsystem.getPosition()) > 5000;

}
}
38 changes: 38 additions & 0 deletions src/main/java/frc/robot/subsystems/TestSubsystem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// 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.subsystems;

import com.revrobotics.spark.SparkFlex;
import edu.wpi.first.wpilibj2.command.SubsystemBase;

public class TestSubsystem extends SubsystemBase {

SparkFlex motor;

/** Creates a new TestSubsystem. */
public TestSubsystem() {

motor = new SparkFlex(0, SparkFlex.MotorType.kBrushless);

}

public void setPower(double power) {
motor.set(power);
}

public double getPosition() {
// read encoder
return motor.getEncoder().getPosition();
}

public void stop() {
motor.stopMotor();
}

@Override
public void periodic() {
// This method will be called once per scheduler run
}
}
Loading

0 comments on commit fb539a5

Please sign in to comment.