-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Partial implementation of swerve_module
- Loading branch information
1 parent
b808d55
commit 1efb47e
Showing
10 changed files
with
151 additions
and
5 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
2 changes: 1 addition & 1 deletion
2
...frc846/control/config/SoftLimitsHelper.cc → .../cpp/frc846/control/config/soft_limits.cc
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,54 @@ | ||
#include "frc846/robot/swerve/swerve_module.h" | ||
|
||
namespace frc846::robot::swerve { | ||
|
||
SwerveModule::SwerveModule(Loggable& parent, std::string loc, | ||
frc846::control::config::MotorConstructionParameters drive_params, | ||
frc846::control::config::MotorConstructionParameters steer_params, | ||
frc846::control::base::MotorMonkeyType motor_types, int cancoder_id, | ||
steer_conv_unit steer_reduction, drive_conv_unit drive_reduction, | ||
std::string cancoder_bus) | ||
: frc846::robot::GenericSubsystem<SwerveModuleReadings, SwerveModuleTarget>( | ||
parent, loc), | ||
drive_{motor_types, drive_params}, | ||
steer_{motor_types, steer_params}, | ||
cancoder_{cancoder_id, cancoder_bus} { | ||
drive_helper_.SetConversion(drive_reduction); | ||
steer_helper_.SetConversion(steer_reduction); | ||
|
||
drive_helper_.bind(&drive_); | ||
steer_helper_.bind(&steer_); | ||
} | ||
|
||
void SwerveModule::Setup() { | ||
drive_.Setup(); | ||
steer_.Setup(); | ||
|
||
// TODO: finish. Refer to howler_monkey. | ||
} | ||
|
||
SwerveModuleTarget SwerveModule::ZeroTarget() const { | ||
return SwerveModuleOLControlTarget{0.0, 0_deg}; | ||
} | ||
|
||
bool SwerveModule::VerifyHardware() { | ||
bool ok = true; | ||
// TODO: Add a verify hardware to motor controllers. | ||
return ok; | ||
} | ||
|
||
SwerveModuleReadings SwerveModule::ReadFromHardware() { | ||
SwerveModuleReadings readings; | ||
readings.vel = drive_helper_.GetVelocity(); | ||
readings.drive_pos = drive_helper_.GetPosition(); | ||
readings.steer_pos = steer_helper_.GetPosition(); | ||
return readings; | ||
|
||
// TODO: recheck | ||
} | ||
|
||
void SwerveModule::WriteToHardware(SwerveModuleTarget target) { | ||
// TODO: finish. Refer to howler_monkey for open-loop. | ||
} | ||
|
||
} // namespace frc846::robot::swerve |
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
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#pragma once | ||
|
||
#include "frc846/robot/GenericSubsystem.h" | ||
#include "frc846/control/HigherMotorController.h" | ||
#include "frc846/control/HMCHelper.h" | ||
|
||
#include <units/angle.h> | ||
#include <units/torque.h> | ||
#include <units/velocity.h> | ||
#include <units/base.h> | ||
|
||
#include <variant> | ||
|
||
#include <ctre/phoenix6/CANCoder.hpp> | ||
|
||
namespace frc846::robot::swerve { | ||
|
||
struct SwerveModuleReadings { | ||
units::feet_per_second_t vel; | ||
units::foot_t drive_pos; | ||
units::degree_t steer_pos; | ||
}; | ||
|
||
struct SwerveModuleTorqueControlTarget { | ||
units::newton_meter_t drive; | ||
units::newton_meter_t steer; | ||
}; | ||
|
||
struct SwerveModuleOLControlTarget { | ||
double drive; | ||
units::degree_t steer; | ||
}; | ||
|
||
using SwerveModuleTarget = | ||
std::variant<SwerveModuleTorqueControlTarget, SwerveModuleOLControlTarget>; | ||
|
||
class SwerveModule | ||
: public frc846::robot::GenericSubsystem<SwerveModuleReadings, | ||
SwerveModuleTarget> { | ||
using steer_conv_unit = units::dimensionless::dimensionless_t; | ||
using drive_conv_unit = units::unit_t< | ||
units::compound_unit<units::foot, units::inverse<units::turn>>>; | ||
|
||
public: | ||
SwerveModule(Loggable& parent, std::string loc, | ||
frc846::control::config::MotorConstructionParameters drive_params, | ||
frc846::control::config::MotorConstructionParameters steer_params, | ||
frc846::control::base::MotorMonkeyType motor_types, int cancoder_id, | ||
steer_conv_unit steer_reduction, drive_conv_unit drive_reduction, | ||
std::string cancoder_bus = ""); | ||
|
||
void Setup() override; | ||
|
||
SwerveModuleTarget ZeroTarget() const override; | ||
|
||
bool VerifyHardware() override; | ||
|
||
void SetMaxSpeed(units::feet_per_second_t max_speed); | ||
|
||
private: | ||
SwerveModuleReadings ReadFromHardware() override; | ||
|
||
void WriteToHardware(SwerveModuleTarget target) override; | ||
|
||
units::feet_per_second_t max_speed_ = 10.0_fps; | ||
|
||
frc846::control::HigherMotorController drive_; | ||
frc846::control::HigherMotorController steer_; | ||
|
||
frc846::control::HMCHelper<units::foot> drive_helper_; | ||
frc846::control::HMCHelper<units::degree> steer_helper_; | ||
|
||
ctre::phoenix6::hardware::CANcoder cancoder_; | ||
}; | ||
|
||
} // namespace frc846::robot::swerve |