Skip to content

Commit

Permalink
updated note vis
Browse files Browse the repository at this point in the history
  • Loading branch information
r4stered committed Sep 5, 2024
1 parent 30cedb8 commit 57f4807
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 16 deletions.
15 changes: 14 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,19 @@
"xstring": "cpp",
"xtr1common": "cpp",
"xutility": "cpp",
"shared_mutex": "cpp"
"shared_mutex": "cpp",
"charconv": "cpp",
"format": "cpp",
"ios": "cpp",
"locale": "cpp",
"xfacet": "cpp",
"xiosbase": "cpp",
"xlocale": "cpp",
"xlocbuf": "cpp",
"xlocinfo": "cpp",
"xlocmes": "cpp",
"xlocmon": "cpp",
"xlocnum": "cpp",
"xloctime": "cpp"
}
}
28 changes: 14 additions & 14 deletions src/main/cpp/RobotContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@ void RobotContainer::ConfigureBindings() {
},
true));

//controller.LeftTrigger().WhileTrue(swerveSubsystem.AlignToAmp());
controller.LeftBumper().WhileTrue(swerveSubsystem.XPattern());
controller.Back().WhileTrue(
swerveSubsystem.WheelRadius(frc2::sysid::Direction::kReverse));
controller.Start().WhileTrue(
swerveSubsystem.WheelRadius(frc2::sysid::Direction::kForward));
controller.LeftTrigger().WhileTrue(swerveSubsystem.AlignToAmp());
// controller.LeftBumper().WhileTrue(swerveSubsystem.XPattern());
// controller.Back().WhileTrue(
// swerveSubsystem.WheelRadius(frc2::sysid::Direction::kReverse));
// controller.Start().WhileTrue(
// swerveSubsystem.WheelRadius(frc2::sysid::Direction::kForward));

controller.A().OnTrue(frc2::cmd::RunOnce([this] {
noteVisualizer.LaunchNote(
frc::Pose3d{swerveSubsystem.GetRobotPose()},
swerveSubsystem.GetRobotRelativeSpeed(),
frc::Transform3d{frc::Translation3d{0_m, 0_m, 12_in},
frc::Rotation3d{0_deg, -30_deg, 0_deg}},
frc::Transform3d{frc::Translation3d{-4_in, 0_in, 13_in},
frc::Rotation3d{0_deg, -50_deg, 0_deg}},
41.71_fps);
}));

Expand All @@ -49,14 +49,14 @@ void RobotContainer::ConfigureBindings() {
// controller.X().WhileTrue(swerveSubsystem.SysIdDriveDynamicTorque(frc2::sysid::Direction::kForward));
// controller.Y().WhileTrue(swerveSubsystem.SysIdDriveDynamicTorque(frc2::sysid::Direction::kReverse));

controller.POVDown().OnTrue(swerveSubsystem.TuneSteerPID([this] { return controller.Start().Get(); }));
controller.POVUp().OnTrue(swerveSubsystem.TuneDrivePID([this] { return controller.Start().Get(); }));
// controller.POVDown().OnTrue(swerveSubsystem.TuneSteerPID([this] { return controller.Start().Get(); }));
// controller.POVUp().OnTrue(swerveSubsystem.TuneDrivePID([this] { return controller.Start().Get(); }));

controller.A().WhileTrue(shooterSubsystem.RunShooter([] { return consts::shooter::PRESET_SPEEDS::AMP; }));
controller.A().OnFalse(shooterSubsystem.RunShooter([] { return consts::shooter::PRESET_SPEEDS::OFF; }));
// controller.A().WhileTrue(shooterSubsystem.RunShooter([] { return consts::shooter::PRESET_SPEEDS::AMP; }));
// controller.A().OnFalse(shooterSubsystem.RunShooter([] { return consts::shooter::PRESET_SPEEDS::OFF; }));

controller.LeftTrigger().WhileTrue(intakeSubsystem.IntakeNote());
controller.RightTrigger().WhileTrue(intakeSubsystem.PoopNote());
// controller.LeftTrigger().WhileTrue(intakeSubsystem.IntakeNote());
// controller.RightTrigger().WhileTrue(intakeSubsystem.PoopNote());

// controller.A().WhileTrue(shooterSubsystem.TopWheelSysIdQuasistatic(frc2::sysid::Direction::kForward));
// controller.B().WhileTrue(shooterSubsystem.TopWheelSysIdQuasistatic(frc2::sysid::Direction::kReverse));
Expand Down
18 changes: 18 additions & 0 deletions src/main/cpp/str/NoteVisualizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@ void NoteVisualizer::LaunchNote(frc::Pose3d currentRobotPose,

launchedNotes.emplace_back(noteToAdd);
launchedNotePoses.emplace_back(noteToAdd.currentPose);
fmt::print("Meow\n");
}

void NoteVisualizer::Periodic() {
units::second_t now = frc::Timer::GetFPGATimestamp();
units::second_t loopTime = now - lastLoopTime;

UpdateLaunchedNotes(loopTime);
CleanUp();

stagedNotesPub.Set(initialNoteLocations);
launchedNotesPub.Set(launchedNotePoses);
Expand All @@ -67,6 +69,21 @@ void NoteVisualizer::UpdateLaunchedNotes(units::second_t loopTime) {
}
}

void NoteVisualizer::CleanUp() {
int i = 0;
for(auto mit = launchedNotes.begin(); mit != launchedNotes.end(); )
{
if(mit->shouldClean) {
mit = launchedNotes.erase(mit);
launchedNotePoses.erase(launchedNotePoses.begin() + i);
}
else {
mit++;
}
i++;
}
}

void NoteVisualizer::ProjectileMotion(FlyingNote &note,
units::second_t loopTime) {
note.currentVelocity.zVel =
Expand All @@ -86,6 +103,7 @@ void NoteVisualizer::ProjectileMotion(FlyingNote &note,
note.currentVelocity.xVel = 0_mps;
note.currentVelocity.yVel = 0_mps;
note.currentVelocity.zVel = 0_mps;
note.shouldClean = true;
}

note.currentPose = newPose;
Expand Down
2 changes: 1 addition & 1 deletion src/main/deploy/commit.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4b09746
30cedb8
2 changes: 2 additions & 0 deletions src/main/include/str/NoteVisualizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ struct FlyingNote {
NoteVelocity initialVelocity{};
NoteVelocity currentVelocity{};
frc::Pose3d currentPose{};
bool shouldClean{false};
};

class NoteVisualizer {
Expand All @@ -42,6 +43,7 @@ class NoteVisualizer {
private:
void UpdateLaunchedNotes(units::second_t loopTime);
void ProjectileMotion(FlyingNote &note, units::second_t loopTime);
void CleanUp();

units::second_t lastLoopTime;

Expand Down

0 comments on commit 57f4807

Please sign in to comment.