-
Notifications
You must be signed in to change notification settings - Fork 1
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
Logging #104
Merged
Logging #104
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
fc0023d
Enabled logging
2491NoMythic 64b0a03
Enabled intake logging
2491NoMythic 2853d55
Add a helper class for logging motor data.
trixydevs 18a7b07
Swich intake logging to use helper class.
trixydevs 249fd28
add logging to shooter and indexer
trixydevs cca57ef
logging more intake data
trixydevs 552a584
note tracking added to indexer
trixydevs c1e957e
Merge branch 'main' into Logging2
zack0022 3647105
changed method name
zack0022 3b982b2
rename motor
zack0022 8b22a36
added needed import
zack0022 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package frc.robot.helpers; | ||
|
||
import com.ctre.phoenix6.hardware.TalonFX; | ||
import com.revrobotics.CANSparkMax; | ||
|
||
import edu.wpi.first.util.datalog.DataLog; | ||
import edu.wpi.first.util.datalog.DoubleLogEntry; | ||
|
||
/** | ||
* logs moter data to a logger | ||
*/ | ||
public class MotorLogger { | ||
DoubleLogEntry percentOutput; | ||
DoubleLogEntry current; | ||
DoubleLogEntry velocity; | ||
|
||
public MotorLogger(DataLog log, String path) { | ||
percentOutput = new DoubleLogEntry(log, path + "/output"); | ||
current = new DoubleLogEntry(log, path + "/current"); | ||
velocity = new DoubleLogEntry(log, path + "/velocity"); | ||
} | ||
|
||
public void log(CANSparkMax motor) { | ||
current.append(motor.getOutputCurrent()); | ||
percentOutput.append(motor.getAppliedOutput()); | ||
velocity.append(motor.getEncoder().getVelocity()/60); | ||
} | ||
|
||
public void log(TalonFX motor) { | ||
current.append(motor.getStatorCurrent().getValueAsDouble()); | ||
percentOutput.append(motor.get()); | ||
velocity.append(motor.getVelocity().getValueAsDouble()); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,10 +1,13 @@ | ||
package frc.robot.subsystems; | ||
|
||
import java.util.function.BooleanSupplier; | ||
|
||
import com.ctre.phoenix6.configs.CurrentLimitsConfigs; | ||
import com.ctre.phoenix6.configs.MotionMagicConfigs; | ||
import com.ctre.phoenix6.configs.MotorOutputConfigs; | ||
import com.ctre.phoenix6.configs.Slot0Configs; | ||
import com.ctre.phoenix6.configs.TalonFXConfiguration; | ||
import com.ctre.phoenix6.configs.TalonFXConfigurator; | ||
import com.ctre.phoenix6.controls.MotionMagicDutyCycle; | ||
import com.ctre.phoenix6.controls.MotionMagicVelocityDutyCycle; | ||
import com.ctre.phoenix6.controls.MotionMagicVelocityVoltage; | ||
|
@@ -13,22 +16,38 @@ | |
import com.ctre.phoenix6.signals.InvertedValue; | ||
import com.revrobotics.SparkAnalogSensor; | ||
|
||
import edu.wpi.first.util.datalog.DoubleLogEntry; | ||
import edu.wpi.first.wpilibj.DataLogManager; | ||
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; | ||
import edu.wpi.first.wpilibj2.command.SubsystemBase; | ||
import frc.robot.helpers.MotorLogger; | ||
import frc.robot.settings.Constants.IndexerConstants; | ||
|
||
public class IndexerSubsystem extends SubsystemBase { | ||
TalonFX indexerMotor; | ||
SparkAnalogSensor distanceSensor; | ||
TalonFX m_IndexerMotor; | ||
CurrentLimitsConfigs currentLimitsConfigs; | ||
TalonFXConfigurator configurator; | ||
BooleanSupplier isNoteIn; | ||
double noteStart; | ||
boolean wasNoteIn = false; | ||
MotorLogger motorLogger; | ||
DoubleLogEntry notePositionLog; | ||
|
||
public IndexerSubsystem() { | ||
|
||
indexerMotor = new TalonFX(IndexerConstants.INDEXER_MOTOR); | ||
public IndexerSubsystem(BooleanSupplier isNoteIn) { | ||
m_IndexerMotor = new TalonFX(IndexerConstants.INDEXER_MOTOR); | ||
m_IndexerMotor.setInverted(false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this m_indexer stuff newer than the other no m_ stuff? |
||
this.isNoteIn = isNoteIn; | ||
|
||
currentLimitsConfigs = new CurrentLimitsConfigs(); | ||
currentLimitsConfigs.SupplyCurrentLimit = IndexerConstants.CURRENT_LIMIT; | ||
currentLimitsConfigs.SupplyCurrentLimitEnable = true; | ||
|
||
configurator = m_IndexerMotor.getConfigurator(); | ||
configurator.apply(currentLimitsConfigs); | ||
|
||
motorLogger = new MotorLogger(DataLogManager.getLog(), "/indexer/motor"); | ||
notePositionLog = new DoubleLogEntry(DataLogManager.getLog(),"/indexer/notePosistion"); | ||
|
||
TalonFXConfiguration talonFXConfig = new TalonFXConfiguration().withCurrentLimits(currentLimitsConfigs) | ||
.withMotorOutput(new MotorOutputConfigs().withInverted(InvertedValue.CounterClockwise_Positive)) | ||
.withSlot0(new Slot0Configs(). | ||
|
@@ -40,7 +59,7 @@ public IndexerSubsystem() { | |
.withMotionMagicCruiseVelocity(IndexerConstants.INDEXER_CRUISE_VELOCITY) | ||
.withMotionMagicAcceleration(IndexerConstants.INDEXER_ACCELERATION) | ||
.withMotionMagicJerk(IndexerConstants.INDEXER_JERK)); | ||
indexerMotor.getConfigurator().apply(talonFXConfig); | ||
m_IndexerMotor.getConfigurator().apply(talonFXConfig); | ||
|
||
} | ||
/** | ||
|
@@ -49,50 +68,66 @@ public IndexerSubsystem() { | |
* uses percentage of full power | ||
*/ | ||
public void on() { | ||
indexerMotor.set(IndexerConstants.INDEXER_INTAKE_SPEED); | ||
m_IndexerMotor.set(IndexerConstants.INDEXER_INTAKE_SPEED); | ||
} | ||
/** | ||
sets the indxer motor's percent-of-full-power to 0 | ||
*/ | ||
public void off() { | ||
indexerMotor.set(0); | ||
m_IndexerMotor.set(0); | ||
} | ||
/** | ||
* sets the indexer motor to -INDEXER_INTAKE_SPEED (from constants) | ||
* <p> | ||
* uses percentage of full power | ||
*/ | ||
public void reverse() { | ||
indexerMotor.set(-IndexerConstants.INDEXER_INTAKE_SPEED); | ||
m_IndexerMotor.set(-IndexerConstants.INDEXER_INTAKE_SPEED); | ||
} | ||
/** | ||
* sets the percentage-of-full-power on the indexer | ||
* @param speed the desired speed, from -1 to 1 | ||
*/ | ||
public void set(double speed) { | ||
indexerMotor.set(speed); | ||
m_IndexerMotor.set(speed); | ||
} | ||
/** | ||
* uses the indexer motor's onboard Motion Magic control to move the indexer forward. To move backwards, use negative inches. | ||
* @param inches the inches to move forward. | ||
*/ | ||
public void forwardInches(double inches) { | ||
double rotationsRequested = inches/IndexerConstants.MOTOR_ROTATIONS_TO_INCHES; | ||
double position = indexerMotor.getPosition().getValueAsDouble()+rotationsRequested; | ||
double position = m_IndexerMotor.getPosition().getValueAsDouble()+rotationsRequested; | ||
MotionMagicVoltage distanceRequest = new MotionMagicVoltage(position); | ||
indexerMotor.setControl(distanceRequest); | ||
m_IndexerMotor.setControl(distanceRequest); | ||
} | ||
|
||
public void trackNote() { | ||
boolean noteIn = isNoteIn.getAsBoolean(); | ||
if (!wasNoteIn && noteIn) { | ||
noteStart = m_IndexerMotor.getPosition().getValueAsDouble(); | ||
} | ||
wasNoteIn = noteIn; | ||
} | ||
|
||
public double getNotePosition() { | ||
return m_IndexerMotor.getPosition().getValueAsDouble() - noteStart; | ||
} | ||
/** | ||
* uses the indexer motor's onboard Motion Magic control to set the motor to a desired RPS | ||
* @param RPS the desired speed, in rotations per second | ||
*/ | ||
public void magicRPS(double RPS) { | ||
MotionMagicVelocityVoltage speedRequest = new MotionMagicVelocityVoltage(RPS); | ||
indexerMotor.setControl(speedRequest); | ||
m_IndexerMotor.setControl(speedRequest); | ||
} | ||
|
||
@Override | ||
public void periodic() { | ||
SmartDashboard.putNumber("indexer current", indexerMotor.getSupplyCurrent().getValueAsDouble()); | ||
trackNote(); | ||
motorLogger.log(m_IndexerMotor); | ||
double pos = getNotePosition(); | ||
notePositionLog.append(pos); | ||
SmartDashboard.putNumber("note pos", pos); | ||
} | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we know where all the non logging code came from?