-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from CyberCoyotes/W2-FlywheelAndOrchestra
W2 flywheel and orchestra
- Loading branch information
Showing
13 changed files
with
501 additions
and
149 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
69 changes: 69 additions & 0 deletions
69
src/main/java/frc/robot/subsystems/DualFlyWheelSubsystem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package frc.robot.subsystems; | ||
import com.ctre.phoenix6.*; | ||
import com.ctre.phoenix6.controls.ControlRequest; | ||
import com.ctre.phoenix6.controls.DutyCycleOut; | ||
import com.ctre.phoenix6.controls.Follower; | ||
import com.ctre.phoenix6.hardware.TalonFX; | ||
|
||
import edu.wpi.first.wpilibj.Notifier; | ||
import edu.wpi.first.wpilibj2.command.SubsystemBase; | ||
|
||
/** Serves as a base for any flywheel system driven by 2 motors. Fire and forget, enabling and diabling will be done by singular calls.\ | ||
* Set configs before creating this class/subsystem. | ||
* {@link #SetStatePower} is used to set the main power. | ||
*/ | ||
public class DualFlyWheelSubsystem extends SubsystemBase { | ||
private TalonFX m_main; | ||
private TalonFX m_sub; | ||
/**The state percentage */ | ||
private double percentage; | ||
/**The multiplier that converts from "primary speed" to "secondary speed"*/ | ||
private double ratio = 1; | ||
private DutyCycleOut mainDutyCycle; | ||
private DutyCycleOut subDutyCycle; | ||
|
||
public DualFlyWheelSubsystem(TalonFX main, TalonFX sub) { | ||
this.m_main = main; | ||
this.m_sub = sub; | ||
//default to off | ||
m_main.setControl(mainDutyCycle = new DutyCycleOut(0)); | ||
m_sub.setControl(subDutyCycle = new DutyCycleOut(0)); | ||
} | ||
/** | ||
* Sets the power the primary motor will use. Does not enable or disable. | ||
*/ | ||
private void SetMotorPowers(double arg) | ||
{ | ||
mainDutyCycle.Output = arg; | ||
subDutyCycle.Output = -arg * ratio; | ||
|
||
m_main.setControl(mainDutyCycle); | ||
m_sub.setControl(subDutyCycle); | ||
} | ||
/** | ||
*Sets the multiplier that converts from "primary speed" to "secondary speed". Inversion is automatic; supplying a value of -1 here will make both motors identical. | ||
*/ | ||
public void SetRatio(double arg) | ||
{ | ||
ratio = arg; | ||
} | ||
public void SetStatePower(double percent) | ||
{ | ||
// percent = Math.max(0, Math.min(percent,1)); | ||
this.percentage = percent; | ||
mainDutyCycle = new DutyCycleOut(percentage); | ||
} | ||
public void Enable() | ||
{ | ||
SetMotorPowers(percentage); | ||
} | ||
public void Disable() | ||
{ | ||
SetMotorPowers(0); | ||
} | ||
public void Toggle() | ||
{ | ||
double set = Math.abs( mainDutyCycle.Output - percentage); | ||
SetMotorPowers(set); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
46 changes: 46 additions & 0 deletions
46
src/main/java/frc/robot/subsystems/OrchestraSubsystem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package frc.robot.subsystems; | ||
|
||
import java.util.ArrayList; | ||
import com.ctre.phoenix6.Orchestra; | ||
import com.ctre.phoenix6.controls.MusicTone; | ||
import com.ctre.phoenix6.hardware.TalonFX; | ||
import edu.wpi.first.wpilibj2.command.SubsystemBase; | ||
|
||
public class OrchestraSubsystem extends SubsystemBase{ | ||
|
||
ArrayList<TalonFX> instruments; | ||
Orchestra m_orchestra; | ||
|
||
public OrchestraSubsystem(TalonFX[] motors) { | ||
|
||
m_orchestra = new Orchestra(); | ||
//add instruments | ||
for (int i = 0; i < motors.length; i++ ) { | ||
m_orchestra.addInstrument(motors[i], i); | ||
motors[i].setControl(new MusicTone(i)); | ||
}} | ||
|
||
// Attempt to load the chrp | ||
|
||
public void SetTune(Song song) | ||
{ | ||
|
||
m_orchestra.loadMusic(song.name()+ ".chrp"); | ||
} | ||
public void Play() | ||
{ | ||
m_orchestra.play(); | ||
} | ||
public void Shud() | ||
{ | ||
m_orchestra.stop(); | ||
} | ||
|
||
public enum Song{ | ||
ICE_CREAM, | ||
E1M1, | ||
ONE_ONE_FIVE, | ||
ULTRA_INSTINCT, | ||
SANS | ||
} | ||
} |
Oops, something went wrong.