Skip to content

Commit

Permalink
create swerve drive hardware interface per #11
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbrownmsm committed Dec 24, 2022
1 parent 4d65374 commit e8767c6
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/main/cpp/hardware/HardwareInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,35 @@ bool SetupDrivetrainInterface(
return true;
}

bool SetupSwerveDriveInterface(
std::unique_ptr<HardwareInterface> &hardware,
std::shared_ptr<SwerveDriveHardwareInterface> *interface) {
OKC_CHECK(interface != nullptr);
OKC_CHECK(hardware->actuators != nullptr);
OKC_CHECK(hardware->sensors != nullptr);

// Get actuators interface for swerve drive.
std::unique_ptr<ActuatorInterface> &actuators = hardware->actuators;
std::unique_ptr<SensorInterface> &sensors = hardware->sensors;

// set up swerve drive interface.
SwerveDriveHardwareInterface swerve_drive_interface = {
actuators->left_front_drive_motor.get(),
actuators->left_back_drive_motor.get(),
actuators->right_front_drive_motor.get(),
actuators->right_back_drive_motor.get(),
actuators->left_front_steer_motor.get(),
actuators->left_back_steer_motor.get(),
actuators->right_front_steer_motor.get(),
actuators->right_back_steer_motor.get(),

sensors->ahrs.get(),
};

// set the output interface
*interface = std::make_shared<SwerveDriveHardwareInterface>(swerve_drive_interface);
}

bool SetupIntakeInterface(
std::unique_ptr<HardwareInterface> &hardware,
std::shared_ptr<IntakeHardwareInterface> *interface) {
Expand Down
14 changes: 14 additions & 0 deletions src/main/include/hardware/HardwareInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

// Subsystem I/O
#include "io/DrivetrainIO.h"
#include "io/SwerveDriveIO.h"
#include "io/IntakeIO.h"

typedef struct hardware_t {
Expand Down Expand Up @@ -36,6 +37,19 @@ bool SetupDrivetrainInterface(
std::unique_ptr<HardwareInterface> &hardware,
std::shared_ptr<DrivetrainHardwareInterface> *interface);

/**
* @brief Link the Swerve drive to the hardware interfaces.
*
* @param interface
* @return true
* @return false
*/
bool SetupSwerveDriveInterface(
std::unique_ptr<HardwareInterface> &hardware,
std::shared_ptr<SwerveDriveHardwareInterface> *interface);



/**
* @brief Link the Intake to the hardware interfaces.
*
Expand Down

0 comments on commit e8767c6

Please sign in to comment.