Skip to content

Commit

Permalink
swerve field relative behaviour added
Browse files Browse the repository at this point in the history
  • Loading branch information
spacey-sooty committed Nov 22, 2023
1 parent 0ccf05d commit d0fd92b
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 11 deletions.
3 changes: 2 additions & 1 deletion wombat/src/main/cpp/drivetrain/Drivetrain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ void wom::drivetrain::Drivetrain::SetSpeed(wom::drivetrain::TankSpeed speed) {
_speed = speed;
}

void wom::drivetrain::Drivetrain::TankControl(double rightSpeed, double leftSpeed) {
void wom::drivetrain::Drivetrain::TankControl(double rightSpeed,
double leftSpeed) {
_config->left1.transmission->SetVoltage(leftSpeed * maxVolts);
_config->left2.transmission->SetVoltage(leftSpeed * maxVolts);
_config->left3.transmission->SetVoltage(leftSpeed * maxVolts);
Expand Down
4 changes: 4 additions & 0 deletions wombat/src/main/cpp/drivetrain/SwerveDrive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,7 @@ void wom::drivetrain::Swerve::OnUpdate(units::second_t dt,
break;
}
}

wom::vision::Limelight wom::drivetrain::Swerve::GetLimelight() {
return _vision;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ wom::drivetrain::behaviours::TankDrive::TankDrive(
void wom::drivetrain::behaviours::TankDrive::OnTick(units::second_t dt) {
wom::drivetrain::TankSpeed speed;
speed.right = wom::utils::deadzone(_driver.GetRightY());
speed.left = wom::utils::deadzone(_driver.GetLeftY());
speed.left = wom::utils::deadzone(_driver.GetLeftY());
_drivebase->SetSpeed(speed);
_drivebase->SetState(wom::drivetrain::DrivetrainState::kTank);
}
19 changes: 19 additions & 0 deletions wombat/src/main/cpp/drivetrain/behaviours/SwerveBehaviours.cpp
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);
}
8 changes: 4 additions & 4 deletions wombat/src/main/include/drivetrain/Drivetrain.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ namespace drivetrain {

protected:
private:
DrivetrainConfig *_config;
DrivetrainState _state;
units::volt_t maxVolts = 9_V;
TankSpeed _speed;
DrivetrainConfig *_config;
DrivetrainState _state;
units::volt_t maxVolts = 9_V;
TankSpeed _speed;
};
} // namespace drivetrain
} // namespace wom
6 changes: 3 additions & 3 deletions wombat/src/main/include/drivetrain/SwerveDrive.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ namespace drivetrain {
wom::utils::PIDController<units::meters, units::meters_per_second>
_movementPID;


units::volt_t voltageRotation;
units::volt_t voltageMovement;

Expand Down Expand Up @@ -114,8 +113,9 @@ namespace drivetrain {
explicit Swerve(SwerveConfig config, SwerveState state,
wom::vision::Limelight vision);

SwerveConfig GetConfig();
SwerveState GetState();
SwerveConfig GetConfig();
SwerveState GetState();
wom::vision::Limelight GetLimelight();

void SetState(SwerveState state);
void FieldRelativeControl(frc::Pose3d desiredPose, units::second_t dt);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ namespace drivetrain {
namespace behaviours {
class TankDrive : public behaviour::Behaviour {
public:
TankDrive(wom::drivetrain::Drivetrain *drivebase, frc::XboxController &driver);
TankDrive(wom::drivetrain::Drivetrain *drivebase,
frc::XboxController &driver);

void OnTick(units::second_t dt);

protected:
private:
wom::drivetrain::Drivetrain *_drivebase;
frc::XboxController &_driver;
frc::XboxController &_driver;
};
} // namespace behaviours
} // namespace drivetrain
Expand Down
26 changes: 26 additions & 0 deletions wombat/src/main/include/drivetrain/behaviours/SwerveBehaviours.h
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

0 comments on commit d0fd92b

Please sign in to comment.