Skip to content

Commit

Permalink
music lmao
Browse files Browse the repository at this point in the history
  • Loading branch information
cherriae committed Jan 20, 2024
1 parent 360b2e0 commit 2dcba87
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 9 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Powershell

### Linux
```bash
chmod +x gradlew
chmod +x gradlew
./gradlew build
```
> Alternatively you can run `chmod +x gradlew && gradlew build`
Expand All @@ -59,14 +59,14 @@ Note: `chmod +x gradlew` is giving it permission. Read more [here](https://en.wi
> All these commands are in the WPILIB (Icon) button (in the top right corner) options if you have WPILIB vscode.
### Deploying
Deploying will build your code, and deploy it to the robot.
Deploying will build your code, and deploy it to the robot.

```bash
./gradlew deploy
```
> (You have to be connected to the robot for this to work.)
### Clean
### Clean
This removes all cache (gradle default uses cache to rebuild) when gradle builds. This is to ensure your dependences/vendordeps work.

```bash
Expand All @@ -80,7 +80,7 @@ This outputs what is happening while its building and a good way to see what its
./gradlew --debug
```

### Scan
### Scan
This is preferbly not used, it will scan the project and send all the data into a website where it will give a link to email to you.

```bash
Expand Down
Binary file added src/main/deploy/output.chrp
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@
},
"folder": null,
"choreoAuto": false
}
}
8 changes: 8 additions & 0 deletions src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

package frc.robot;

import com.ctre.phoenix6.Orchestra;
import com.ctre.phoenix6.hardware.TalonFX;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.CommandScheduler;
Expand All @@ -18,6 +20,11 @@ public class Robot extends TimedRobot {

private RobotContainer m_robotContainer;

/* Talon FXs to play music through.
More complex music MIDIs will contain several tracks, requiring multiple instruments. */



/**
* This function is run when the robot is first started up and should be used for any
* initialization code.
Expand Down Expand Up @@ -69,6 +76,7 @@ public void teleopInit() {
// 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();
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/frc/robot/commands/swerve/BrakeSwerve.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class BrakeSwerve extends Command {
/** Creates a new BrakeSwerve. */
public BrakeSwerve(SwerveDriveSubsystem swerveDrive, double timeout) {
_swerveDrive = swerveDrive;

if (timeout != 0) {
_timeout = timeout;
}
Expand Down
28 changes: 25 additions & 3 deletions src/main/java/frc/robot/subsystems/SwerveDriveSubsystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@

package frc.robot.subsystems;

import java.util.ArrayList;
import java.util.Optional;

import com.ctre.phoenix6.Orchestra;
import com.ctre.phoenix6.hardware.TalonFX;
import com.pathplanner.lib.auto.AutoBuilder;
import com.pathplanner.lib.util.HolonomicPathFollowerConfig;
import com.pathplanner.lib.util.PIDConstants;
Expand Down Expand Up @@ -52,6 +55,9 @@ public class SwerveDriveSubsystem extends SubsystemBase {

private double _robotSpeed = 0;

Orchestra _orchestra;
String song = "output.chrp";

// estimated pose
private Pose2d _pose = new Pose2d();

Expand Down Expand Up @@ -94,6 +100,22 @@ public ChassisSpeeds getRobotRelativeSpeeds() {
public SwerveDriveSubsystem(VisionSubsystem visionSubsystem) {
_visionSubsystem = visionSubsystem;

SwerveModule[] modules = new SwerveModule[4];
modules[0] = _frontLeft;
modules[1] = _frontRight;
modules[2] = _backRight;
modules[3] = _backLeft;

for (int i = 0; i < modules.length; i++) {
for (int j = 0; j < 2; j++){
_orchestra.addInstrument(modules[i].returnTalons()[j]);
}
}

_orchestra.loadMusic(song);

_orchestra.play();

// pathplannerlib setup
AutoBuilder.configureHolonomic(
this::getPose,
Expand Down Expand Up @@ -146,8 +168,8 @@ public void periodic() {
_field.setRobotPose(_pose);
SmartDashboard.putData("FIELD", _field);

_robotSpeed = Math.sqrt(Math.pow(getRobotRelativeSpeeds().vxMetersPerSecond, 2) + Math.pow(getRobotRelativeSpeeds().vyMetersPerSecond, 2));
SmartDashboard.putNumber("DRIVE SPEED (m/s)", _robotSpeed);
_robotSpeed = Math.sqrt(Math.pow(getRobotRelativeSpeeds().vxMetersPerSecond, 2) + Math.pow(getRobotRelativeSpeeds().vyMetersPerSecond, 2));
SmartDashboard.putNumber("DRIVE SPEED (m/s)", _robotSpeed);
}

/**
Expand Down Expand Up @@ -225,6 +247,6 @@ public Rotation2d getHeadingRaw() {
return Rotation2d.fromDegrees(-Math.IEEEremainder(_gyro.getHeading(), 360));
}



}
9 changes: 9 additions & 0 deletions src/main/java/frc/robot/utils/SwerveModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public class SwerveModule {

private final CANcoder _encoder;



/**
* Represents a single swerve module built with talons for rotation and drive control, and a cancoder for angle.
* @param driveMotorId CAN ID of drive motor.
Expand Down Expand Up @@ -121,4 +123,11 @@ public void setState(SwerveModuleState state) {
public SwerveModuleState getState() {
return new SwerveModuleState(getDriveVelocity(), Rotation2d.fromDegrees(getAngle()));
}

public TalonFX[] returnTalons(){
TalonFX[] fxes = new TalonFX[2];
fxes[0] = _driveMotor;
fxes[1] = _rotationMotor;
return fxes;
}
}

0 comments on commit 2dcba87

Please sign in to comment.