-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
swerve field relative behaviour added
- Loading branch information
1 parent
0ccf05d
commit d0fd92b
Showing
8 changed files
with
62 additions
and
11 deletions.
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
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
19 changes: 19 additions & 0 deletions
19
wombat/src/main/cpp/drivetrain/behaviours/SwerveBehaviours.cpp
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,19 @@ | ||
#include <drivetrain/behaviours/SwerveBehaviours.h> | ||
|
||
wom::drivetrain::behaviours::FieldRelativeSwerveDrive::FieldRelativeSwerveDrive( | ||
wom::drivetrain::Swerve *swerve, frc::XboxController &driver) | ||
: _swerve(swerve), _driver(driver) {} | ||
|
||
void wom::drivetrain::behaviours::FieldRelativeSwerveDrive::OnTick( | ||
units::second_t dt) { | ||
_swerve->SetState(wom::drivetrain::SwerveState::kFieldRelative); | ||
frc::Pose3d currentPose = _swerve->GetLimelight().GetPose(); | ||
frc::Pose3d desiredPose = frc::Pose3d( | ||
currentPose.X() + units::meter_t{_driver.GetRightX()}, | ||
currentPose.Y() + units::meter_t{_driver.GetRightY()}, currentPose.Z(), | ||
frc::Rotation3d(currentPose.Rotation().X(), currentPose.Rotation().Y(), | ||
currentPose.Rotation().Z() + | ||
units::radian_t{std::atan( | ||
(_driver.GetLeftY() / _driver.GetLeftX()))})); | ||
_swerve->OnUpdate(dt, _swerve->GetLimelight(), desiredPose); | ||
} |
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 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
26 changes: 26 additions & 0 deletions
26
wombat/src/main/include/drivetrain/behaviours/SwerveBehaviours.h
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,26 @@ | ||
#pragma once | ||
|
||
#include <frc/XboxController.h> | ||
|
||
#include "behaviour/Behaviour.h" | ||
#include "drivetrain/SwerveDrive.h" | ||
|
||
namespace wom { | ||
namespace drivetrain { | ||
namespace behaviours { | ||
|
||
class FieldRelativeSwerveDrive : public behaviour::Behaviour { | ||
public: | ||
explicit FieldRelativeSwerveDrive(wom::drivetrain::Swerve *swerve, | ||
frc::XboxController &driver); | ||
|
||
void OnTick(units::second_t dt) override; | ||
|
||
private: | ||
wom::drivetrain::Swerve *_swerve; | ||
frc::XboxController &_driver; | ||
}; | ||
|
||
} // namespace behaviours | ||
} // namespace drivetrain | ||
} // namespace wom |