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

Example code 2025 new member #1

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
Empty file added 2025newmembot.git
Empty file.
59 changes: 59 additions & 0 deletions Constants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// 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;

import com.ctre.phoenix6.mechanisms.swerve.SwerveRequest.Idle;
import com.revrobotics.CANSparkBase.IdleMode;

/**
* The Constants class provides a convenient place for teams to hold robot-wide numerical or boolean
* constants. This class should not be used for any other purpose. All constants should be declared
* globally (i.e. public static). Do not put anything functional in this class.
*
* <p>It is advised to statically import this class (or one of its inner classes) wherever the
* constants are needed, to reduce verbosity.
*/
public final class Constants {
public static class OperatorConstants {
public static final int kDriverControllerPort = 0;
public static final int kShooterControllerPort = 0;
}

public static final String CANBUS_NAME = null;
public static final int PIGEON2_ID = 1;

// ID of Motors
public abstract static class kDrivetrain {
public static final int LEFT_LEADER_ID = 2;
public static final int LEFT_FOLLOW_ID = 17;
public static final int RIGHT_LEADER_ID = 14;
public static final int RIGHT_FOLLOW_ID = 20;

public static final IdleMode kIdleMode = IdleMode.kBrake;

public final static double driveMulti = 0.4;
}

// Auto Constants
public abstract static class kAutoDrive {
public final static double driveTime = 10;
public final static double leftSpeed = 0.5;
public final static double rightSpeed = 0.5;
}

public abstract static class kShooter {
public final static int LEFT_SHOOTING_MOTOR = 15;
public final static int RIGHT_SHOOTING_MOTOR = 13;

public final static double shootMulti = 0.6;

public static final IdleMode kIdleMode = IdleMode.kBrake;
}

public abstract static class kXboxController {
public final static int x = 1;
}
//public final static Idle motorState = Idle.kBrake;
}
15 changes: 15 additions & 0 deletions Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// 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;

import edu.wpi.first.wpilibj.RobotBase;

public final class Main {
private Main() {}

public static void main(String... args) {
RobotBase.startRobot(Robot::new);
}
}
103 changes: 103 additions & 0 deletions Robot.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// 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;

import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.CommandScheduler;

/**
* The VM is configured to automatically run this class, and to call the functions corresponding to
* each mode, as described in the TimedRobot documentation. If you change the name of this class or
* the package after creating this project, you must also update the build.gradle file in the
* project.
*/
public class Robot extends TimedRobot {
private Command m_autonomousCommand;

private RobotContainer m_robotContainer;

/**
* This function is run when the robot is first started up and should be used for any
* initialization code.
*/
@Override
public void robotInit() {
// Instantiate our RobotContainer. This will perform all our button bindings, and put our
// autonomous chooser on the dashboard.
m_robotContainer = new RobotContainer();
}

/**
* This function is called every 20 ms, no matter the mode. Use this for items like diagnostics
* that you want ran during disabled, autonomous, teleoperated and test.
*
* <p>This runs after the mode specific periodic functions, but before LiveWindow and
* SmartDashboard integrated updating.
*/
@Override
public void robotPeriodic() {
// Runs the Scheduler. This is responsible for polling buttons, adding newly-scheduled
// commands, running already-scheduled commands, removing finished or interrupted commands,
// and running subsystem periodic() methods. This must be called from the robot's periodic
// block in order for anything in the Command-based framework to work.
CommandScheduler.getInstance().run();
}

/** This function is called once each time the robot enters Disabled mode. */
@Override
public void disabledInit() {}

@Override
public void disabledPeriodic() {}

/** This autonomous runs the autonomous command selected by your {@link RobotContainer} class. */
@Override
public void autonomousInit() {
m_autonomousCommand = m_robotContainer.getAutonomousCommand();

// schedule the autonomous command (example)
if (m_autonomousCommand != null) {
m_autonomousCommand.schedule();
}
}

/** This function is called periodically during autonomous. */
@Override
public void autonomousPeriodic() {}

@Override
public void teleopInit() {
// This makes sure that the autonomous stops running when
// teleop starts running. If you want the autonomous to
// continue until interrupted by another command, remove
// this line or comment it out.
if (m_autonomousCommand != null) {
m_autonomousCommand.cancel();
}
}

/** This function is called periodically during operator control. */
@Override
public void teleopPeriodic() {}

@Override
public void testInit() {
// Cancels all running commands at the start of test mode.
CommandScheduler.getInstance().cancelAll();
}

/** This function is called periodically during test mode. */
@Override
public void testPeriodic() {}

/** This function is called once when the robot is first started up. */
@Override
public void simulationInit() {}

/** This function is called periodically whilst in simulation. */
@Override
public void simulationPeriodic() {}
}
91 changes: 91 additions & 0 deletions RobotContainer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// 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;

import frc.robot.Constants.OperatorConstants;
import frc.robot.commands.Autos;
import frc.robot.commands.ComplexAuto;
import frc.robot.commands.DriveCommand;
import frc.robot.commands.FeedCommand;
import frc.robot.commands.IntakeCommand;
import frc.robot.commands.ShootCommand;

import frc.robot.subsystems.Drivetrain;
import frc.robot.subsystems.Intake;
import frc.robot.subsystems.Shooter;
import edu.wpi.first.wpilibj.XboxController;
import edu.wpi.first.wpilibj2.command.Command;
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 {
// The robot's subsystems and commands are defined here...
private final Drivetrain m_drivetrain = Drivetrain.getInstance();
private final Shooter m_shooter = Shooter.getInstance();

// private final Intake m_Intake = Intake.getInstance();

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

/** The container for the robot. Contains subsystems, OI devices, and commands. */
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
* predicate, or via the named factories in {@link
* edu.wpi.first.wpilibj2.command.button.CommandGenericHID}'s subclasses for {@link
* CommandXboxController Xbox}/{@link edu.wpi.first.wpilibj2.command.button.CommandPS4Controller
* PS4} controllers or {@link edu.wpi.first.wpilibj2.command.button.CommandJoystick Flight
* joysticks}.
*/


private void configureBindings() {
// Schedule `DriveCommand` when `exampleCondition` changes to `true`
/* new Trigger(m_drivetrain::exampleCondition)
.onTrue(new DriveCommand(m_drivetrain, () -> m_driverController.getLeftTriggerAxis(), () -> m_driverController.getRightTriggerAxis(), () -> m_driverController.getLeftX()));
*/

// Drivetrain controller
m_drivetrain.setDefaultCommand(
new DriveCommand(
()-> -m_driverController.getLeftX(),
()-> -m_driverController.getLeftY(),
()-> m_driverController.getRightX()));

// m_shooter.setDefaultCommand(new ShootCommand(() -> m_driverController.getRightTriggerAxis()));
// m_shooter.setDefaultCommand(new IntakeCommand(() -> m_driverController.getLeftTriggerAxis()));
m_driverController.rightTrigger().whileTrue(new ShootCommand(() -> m_driverController.getRightTriggerAxis()));
m_driverController.leftTrigger().onTrue(new IntakeCommand(() -> m_driverController.getLeftTriggerAxis()));
m_driverController.a().onTrue(new FeedCommand());
// m_driverController.rightTrigger().whileTrue(new ShootCommand(m_shooter, () -> m_driverController.getRightTriggerAxis()));

// m_Intake.setDefaultCommand(new IntakeCommand(() -> m_driverController.getLeftTriggerAxis()));
/**
* Use this to pass the autonomous command to the main {@link Robot} class.
*
* @return the command to run in autonomous
*/

}

public Command getAutonomousCommand() {
return new Autos (Constants.kAutoDrive.driveTime, Constants.kAutoDrive.leftSpeed, Constants.kAutoDrive.rightSpeed, m_drivetrain);
}
}