Skip to content

Commit

Permalink
Merge pull request #2 from Superbro525Alt/align
Browse files Browse the repository at this point in the history
Added auto align
  • Loading branch information
Superbro525Alt authored Aug 15, 2023
2 parents 745077e + d182b74 commit 045139d
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/main/cpp/behaviour/LimelightBehaviours.cpp
Original file line number Diff line number Diff line change
@@ -1,2 +1,40 @@
#include "behaviour/LimelightBehaviours.h"


AlignBehaviour::AlignBehaviour(Limelight *limelight, frc::XboxController &driver, wom::SwerveDrive *swerve)
: _limelight(limelight), _driver(driver), _swerve(swerve) {
Controls(limelight);
Controls(swerve);
}

void AlignBehaviour::AlignToTarget(frc::Pose3d pose) {
//swerve->SetPose(pose);

_state = poseState::notAtPose;
_setPoint = pose;
}

void AlignBehaviour::CancelAlign() {
_state = poseState::atPose;
}

void AlignBehaviour::OnTick(units::second_t dt) {
if (_driver.GetAButton()) {
AlignToTarget(_SetPoints[0]);
} else if (_driver.GetXButton()) {
AlignToTarget(_SetPoints[1]);
} else if (_driver.GetYButton()) {
AlignToTarget(_SetPoints[2]);
} else if (_driver.GetBButton()) {
AlignToTarget(_SetPoints[3]);
} else if (_driver.GetBackButtonPressed()) {
CancelAlign();
}

if (_state == poseState::notAtPose && !_limelight->IsAtSetPoseVision(_setPoint, dt)) {
_swerve->SetPose(_setPoint.ToPose2d());
}
else {
_state = poseState::atPose;
}
}
32 changes: 32 additions & 0 deletions src/main/include/behaviour/LimelightBehaviours.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,44 @@

// wom includes
#include "behaviour/Behaviour.h"
#include "drivetrain/SwerveDrive.h"

// std lib includes
#include <vector>
#include <memory>


// units includes

// wpilib includes
#include <frc/geometry/Pose3d.h>
#include <frc/geometry/Pose2d.h>
#include "frc/XboxController.h"

// other external includes

enum class poseState {
atPose,
notAtPose
};

class AlignBehaviour : public behaviour::Behaviour {
public:
AlignBehaviour(Limelight *limelight, frc::XboxController &driver, wom::SwerveDrive *swerve);

void OnTick(units::second_t dt) override;

void AlignToTarget(frc::Pose3d pose);
void CancelAlign();

private:
Limelight *_limelight;
frc::XboxController &_driver;
wom::SwerveDrive *_swerve;

std::vector<frc::Pose3d> _SetPoints;
frc::Pose3d _setPoint;


poseState _state = poseState::notAtPose;
};

0 comments on commit 045139d

Please sign in to comment.