Skip to content

Commit

Permalink
Add Hw struct (#177)
Browse files Browse the repository at this point in the history
Signed-off-by: Javier Balloffet <[email protected]>
  • Loading branch information
jballoffet authored Nov 24, 2023
1 parent 861e7da commit c2dbd9c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 34 deletions.
12 changes: 6 additions & 6 deletions andino_firmware/src/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@ long arg2;

namespace andino {

Motor App::left_motor_(LEFT_MOTOR_ENABLE_GPIO_PIN, LEFT_MOTOR_FORWARD_GPIO_PIN,
LEFT_MOTOR_BACKWARD_GPIO_PIN);
Motor App::right_motor_(RIGHT_MOTOR_ENABLE_GPIO_PIN, RIGHT_MOTOR_FORWARD_GPIO_PIN,
RIGHT_MOTOR_BACKWARD_GPIO_PIN);
Motor App::left_motor_(Hw::kLeftMotorEnableGpioPin, Hw::kLeftMotorForwardGpioPin,
Hw::kLeftMotorBackwardGpioPin);
Motor App::right_motor_(Hw::kRightMotorEnableGpioPin, Hw::kRightMotorForwardGpioPin,
Hw::kRightMotorBackwardGpioPin);

Encoder App::left_encoder_(LEFT_ENCODER_A_GPIO_PIN, LEFT_ENCODER_B_GPIO_PIN);
Encoder App::right_encoder_(RIGHT_ENCODER_A_GPIO_PIN, RIGHT_ENCODER_B_GPIO_PIN);
Encoder App::left_encoder_(Hw::kLeftEncoderChannelAGpioPin, Hw::kLeftEncoderChannelBGpioPin);
Encoder App::right_encoder_(Hw::kRightEncoderChannelAGpioPin, Hw::kRightEncoderChannelBGpioPin);

PID App::left_pid_controller_(Constants::kPidKp, Constants::kPidKd, Constants::kPidKi,
Constants::kPidKo, -Constants::kPwmMax, Constants::kPwmMax);
Expand Down
57 changes: 29 additions & 28 deletions andino_firmware/src/hw.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,36 +29,37 @@
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#pragma once

// PC4 (pin 18), RIGHT ENCODER PIN A
#define RIGHT_ENCODER_A_GPIO_PIN 18
namespace andino {

// PC5 (pin 19), RIGHT ENCODER PIN B
#define RIGHT_ENCODER_B_GPIO_PIN 19
/// @brief Hardware configuration.
struct Hw {
/// @brief Left encoder channel A pin. Connected to PD2 (digital pin 2).
static constexpr int kLeftEncoderChannelAGpioPin{2};
/// @brief Left encoder channel B pin. Connected to PD3 (digital pin 3).
static constexpr int kLeftEncoderChannelBGpioPin{3};

// PD2 (pin 2), LEFT ENCODER PIN A
#define LEFT_ENCODER_A_GPIO_PIN 2
/// @brief Right encoder channel A pin. Connected to PC4 (digital pin 18, analog pin A4).
static constexpr int kRightEncoderChannelAGpioPin{18};
/// @brief Right encoder channel B pin. Connected to PC5 (digital pin 19, analog pin A5).
static constexpr int kRightEncoderChannelBGpioPin{19};

// PD3 (pin 3), LEFT ENCODER PIN B
#define LEFT_ENCODER_B_GPIO_PIN 3
/// @brief Left motor driver backward pin. Connected to PD6 (digital pin 6).
static constexpr int kLeftMotorBackwardGpioPin{6};
/// @brief Left motor driver forward pin. Connected to PB2 (digital pin 10).
static constexpr int kLeftMotorForwardGpioPin{10};
/// @brief Left motor driver enable pin. Connected to PB5 (digital pin 13).
/// @note The enable input of the L298N motor driver may be directly jumped to 5V if the board has
/// a jumper to do so.
static constexpr int kLeftMotorEnableGpioPin{13};

// PD5 (pin 5), RIGHT MOTOR DRIVER BACKWARD PIN
#define RIGHT_MOTOR_BACKWARD_GPIO_PIN 5
/// @brief Right motor driver backward pin. Connected to PD5 (digital pin 5).
static constexpr int kRightMotorBackwardGpioPin{5};
/// @brief Right motor driver forward pin. Connected to PB1 (digital pin 9).
static constexpr int kRightMotorForwardGpioPin{9};
/// @brief Right motor driver enable pin. Connected to PB4 (digital pin 12).
/// @note The enable input of the L298N motor driver may be directly jumped to 5V if the board has
/// a jumper to do so.
static constexpr int kRightMotorEnableGpioPin{12};
};

// PD6 (pin 6), LEFT MOTOR DRIVER BACKWARD PIN
#define LEFT_MOTOR_BACKWARD_GPIO_PIN 6

// PB1 (pin 9), RIGHT MOTOR DRIVER FORWARD PIN
#define RIGHT_MOTOR_FORWARD_GPIO_PIN 9

// PB2 (pin 10), LEFT MOTOR DRIVER FORWARD PIN
#define LEFT_MOTOR_FORWARD_GPIO_PIN 10

// PB4 (pin 12), RIGHT MOTOR DRIVER ENABLE PIN
#define RIGHT_MOTOR_ENABLE_GPIO_PIN 12

// PB5 (pin 13), LEFT MOTOR DRIVER ENABLE PIN
#define LEFT_MOTOR_ENABLE_GPIO_PIN 13

// Note: In order to save two pins, the motor driver enable pins could be
// directly jumped to 5V in case your L298N motor driver board has a jumper to
// do so.
} // namespace andino

0 comments on commit c2dbd9c

Please sign in to comment.