Skip to content

Commit

Permalink
Format Code (#43)
Browse files Browse the repository at this point in the history
* refactor includes, add clang-format

* create github action

* Committing clang-format changes

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
AndrewLuGit and github-actions[bot] authored Jan 29, 2024
1 parent 4f4110e commit cd85077
Show file tree
Hide file tree
Showing 35 changed files with 1,144 additions and 1,069 deletions.
20 changes: 20 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
BasedOnStyle: LLVM
AlignAfterOpenBracket: Align
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: Never
BraceWrapping:
BeforeElse: true
BreakBeforeBraces: Attach
ColumnLimit: 80
DerivePointerAlignment: false
IndentCaseLabels: false
IndentWidth: 4
Language: Cpp
PointerAlignment: Left
SortIncludes: CaseInsensitive
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpacesBeforeTrailingComments: 1
Standard: Cpp11
TabWidth: 4
UseTab: Never
24 changes: 24 additions & 0 deletions .github/workflows/clang-format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Clang Format

on: pull_request

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}
- name: Format
uses: DoozyX/[email protected]
with:
source: './src ./include/VOSS'
clangFormatVersion: 14
inplace: True
- name: Commit
uses: EndBug/add-and-commit@v9
with:
default_author: github_actions
message: 'Committing clang-format changes'
6 changes: 3 additions & 3 deletions include/VOSS/api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
#include "controller/PIDController.hpp"
#include "controller/PIDControllerBuilder.hpp"

#include "localizer/AbstractLocalizer.hpp"
#include "localizer/ADILocalizer.hpp"
#include "localizer/ADILocalizerBuilder.hpp"
#include "localizer/AbstractLocalizer.hpp"
#include "localizer/GPSLocalizer.hpp"
#include "localizer/IMELocalizer.hpp"
#include "localizer/IMELocalizerBuilder.hpp"

#include "selector/Selector.hpp"

#include "utils/flags.hpp"
#include "utils/Point.hpp"
#include "utils/Pose.hpp"
#include "utils/flags.hpp"
#include "utils/Pose.hpp"
74 changes: 39 additions & 35 deletions include/VOSS/chassis/AbstractChassis.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,51 @@
#include "pros/motors.hpp"

#include "ChassisCommand.hpp"
#include "voss/controller/AbstractController.hpp"
#include "VOSS/controller/AbstractController.hpp"

#include "voss/utils/Point.hpp"
#include "voss/utils/Pose.hpp"
#include "voss/utils/flags.hpp"
#include "VOSS/utils/flags.hpp"
#include "VOSS/utils/Point.hpp"
#include "VOSS/utils/Pose.hpp"

namespace voss::chassis {

class AbstractChassis {

protected:
pros::Mutex m;
controller::AbstractController* default_controller;

void move_task(controller::AbstractController* controller, double max,
voss::Flags flags);

void turn_task(controller::AbstractController* controller, double max,
voss::Flags flags);

public:
AbstractChassis(controller::AbstractController& default_controller);

virtual void tank(double left_speed, double right_speed) = 0;
virtual void arcade(double forward_speed, double turn_speed) = 0;

virtual bool execute(ChassisCommand cmd, double max) = 0;

void move(Point target, controller::AbstractController* controller,
double max = 100.0, voss::Flags flags = voss::Flags::NONE);
void move(Pose target, controller::AbstractController* controller,
double max = 100.0, voss::Flags flags = voss::Flags::NONE);
void move(Point target, double max = 100.0, voss::Flags flags = voss::Flags::NONE);
void move(Pose target, double max = 100.0, voss::Flags flags = voss::Flags::NONE);

void turn(double target, controller::AbstractController* controller,
double max = 100.0, voss::Flags flags = voss::Flags::NONE);
void turn(double target, double max = 100.0, voss::Flags flags = voss::Flags::NONE);
void turn_to(Point target, controller::AbstractController* controller,
double max = 100.0, voss::Flags flags = voss::Flags::NONE);
void turn_to(Point target, double max = 100.0, voss::Flags flags = voss::Flags::NONE);
protected:
pros::Mutex m;
controller::AbstractController* default_controller;

void move_task(controller::AbstractController* controller, double max,
voss::Flags flags);

void turn_task(controller::AbstractController* controller, double max,
voss::Flags flags);

public:
AbstractChassis(controller::AbstractController& default_controller);

virtual void tank(double left_speed, double right_speed) = 0;
virtual void arcade(double forward_speed, double turn_speed) = 0;

virtual bool execute(ChassisCommand cmd, double max) = 0;

void move(Point target, controller::AbstractController* controller,
double max = 100.0, voss::Flags flags = voss::Flags::NONE);
void move(Pose target, controller::AbstractController* controller,
double max = 100.0, voss::Flags flags = voss::Flags::NONE);
void move(Point target, double max = 100.0,
voss::Flags flags = voss::Flags::NONE);
void move(Pose target, double max = 100.0,
voss::Flags flags = voss::Flags::NONE);

void turn(double target, controller::AbstractController* controller,
double max = 100.0, voss::Flags flags = voss::Flags::NONE);
void turn(double target, double max = 100.0,
voss::Flags flags = voss::Flags::NONE);
void turn_to(Point target, controller::AbstractController* controller,
double max = 100.0, voss::Flags flags = voss::Flags::NONE);
void turn_to(Point target, double max = 100.0,
voss::Flags flags = voss::Flags::NONE);
};

} // namespace voss::chassis
8 changes: 3 additions & 5 deletions include/VOSS/chassis/ChassisCommand.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ namespace voss::chassis {

struct Stop {};
struct Voltages {
double left;
double right;
double left;
double right;
};
struct Chained {
double left;
Expand All @@ -16,9 +16,7 @@ struct Chained {

using ChassisCommand = std::variant<Stop, Voltages, Chained>;

template <class... Ts> struct overload : Ts... {
using Ts::operator()...;
};
template <class... Ts> struct overload : Ts... { using Ts::operator()...; };
template <class... Ts> overload(Ts...) -> overload<Ts...>;

} // namespace voss::chassis
33 changes: 17 additions & 16 deletions include/VOSS/chassis/DiffChassis.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,34 @@ namespace voss::chassis {

class DiffChassis : public AbstractChassis {

private:
std::unique_ptr<pros::MotorGroup> left_motors;
std::unique_ptr<pros::MotorGroup> right_motors;
private:
std::unique_ptr<pros::MotorGroup> left_motors;
std::unique_ptr<pros::MotorGroup> right_motors;

double slew_step;
Voltages prev_voltages;
double slew_step;
Voltages prev_voltages;

double slew(double target, bool is_left);
double slew(double target, bool is_left);

public:
DiffChassis(std::initializer_list<int8_t> left_motors,
std::initializer_list<int8_t> right_motors,
controller::AbstractController& default_controller,
double slew_step = 8);
public:
DiffChassis(std::initializer_list<int8_t> left_motors,
std::initializer_list<int8_t> right_motors,
controller::AbstractController& default_controller,
double slew_step = 8);

void tank(double left_speed, double right_speed);
void arcade(double forward_speed, double turn_speed);
void tank(double left_speed, double right_speed);
void arcade(double forward_speed, double turn_speed);

bool execute(ChassisCommand cmd, double max);
bool execute(ChassisCommand cmd, double max);

auto getMotors() const {
struct ChassisMotorSet{
struct ChassisMotorSet {
pros::MotorGroup* left;
pros::MotorGroup* right;
};

return ChassisMotorSet{this->left_motors.get(), this->right_motors.get()};
return ChassisMotorSet{this->left_motors.get(),
this->right_motors.get()};
}
};

Expand Down
28 changes: 14 additions & 14 deletions include/VOSS/controller/AbstractController.hpp
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
#pragma once

#include "voss/chassis/ChassisCommand.hpp"
#include "voss/localizer/AbstractLocalizer.hpp"
#include "VOSS/chassis/ChassisCommand.hpp"
#include "VOSS/localizer/AbstractLocalizer.hpp"

namespace voss::controller {

class AbstractController {

protected:
std::shared_ptr<localizer::AbstractLocalizer> l;
Pose target;
double angular_target;
protected:
std::shared_ptr<localizer::AbstractLocalizer> l;
Pose target;
double angular_target;

public:
AbstractController(std::shared_ptr<localizer::AbstractLocalizer> l);
public:
AbstractController(std::shared_ptr<localizer::AbstractLocalizer> l);

virtual chassis::ChassisCommand get_command(bool reverse, bool thru) = 0;
virtual chassis::ChassisCommand get_angular_command(bool reverse,
bool thru) = 0;
virtual chassis::ChassisCommand get_command(bool reverse, bool thru) = 0;
virtual chassis::ChassisCommand get_angular_command(bool reverse,
bool thru) = 0;

virtual void reset() = 0;
virtual void reset() = 0;

void set_target(Pose target, bool relative);
void set_angular_target(double angle, bool relative);
void set_target(Pose target, bool relative);
void set_angular_target(double angle, bool relative);
};

} // namespace voss::controller
24 changes: 12 additions & 12 deletions include/VOSS/controller/BoomerangController.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@

#include "AbstractController.hpp"
#include "PIDController.hpp"
#include "voss/chassis/ChassisCommand.hpp"
#include "voss/localizer/AbstractLocalizer.hpp"
#include "VOSS/chassis/ChassisCommand.hpp"
#include "VOSS/localizer/AbstractLocalizer.hpp"

namespace voss::controller {

class BoomerangController : public AbstractController {
protected:
std::shared_ptr<PIDController> child = nullptr;
double lead_pct;
protected:
std::shared_ptr<PIDController> child = nullptr;
double lead_pct;

public:
BoomerangController(std::shared_ptr<localizer::AbstractLocalizer> l);
public:
BoomerangController(std::shared_ptr<localizer::AbstractLocalizer> l);

chassis::ChassisCommand get_command(bool reverse, bool thru) override;
chassis::ChassisCommand get_angular_command(bool reverse,
bool thru) override;

chassis::ChassisCommand get_command(bool reverse, bool thru)override;
chassis::ChassisCommand get_angular_command(bool reverse, bool thru)override;
void reset();

void reset();

friend class BoomerangControllerBuilder;
friend class BoomerangControllerBuilder;
};

} // namespace voss::controller
44 changes: 22 additions & 22 deletions include/VOSS/controller/BoomerangControllerBuilder.hpp
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
#pragma once

#include "voss/controller/BoomerangController.hpp"
#include "VOSS/controller/BoomerangController.hpp"

namespace voss::controller {

class BoomerangControllerBuilder {
private:
controller::BoomerangController ctrl;

public:
BoomerangControllerBuilder(std::shared_ptr<localizer::AbstractLocalizer> l);

static BoomerangControllerBuilder
new_builder(std::shared_ptr<localizer::AbstractLocalizer> l);

BoomerangControllerBuilder& with_linear_constants(double kP, double kI,
double kD);
BoomerangControllerBuilder& with_angular_constants(double kP, double kI,
double kD);
BoomerangControllerBuilder& with_tracking_kp(double kP);
BoomerangControllerBuilder& with_exit_error(double error);
BoomerangControllerBuilder& with_angular_exit_error(double error);
BoomerangControllerBuilder& with_min_error(double error);
BoomerangControllerBuilder& with_lead_pct(double lead_pct);
BoomerangControllerBuilder& with_settle_time(double time);

BoomerangController build();
private:
controller::BoomerangController ctrl;

public:
BoomerangControllerBuilder(std::shared_ptr<localizer::AbstractLocalizer> l);

static BoomerangControllerBuilder
new_builder(std::shared_ptr<localizer::AbstractLocalizer> l);

BoomerangControllerBuilder& with_linear_constants(double kP, double kI,
double kD);
BoomerangControllerBuilder& with_angular_constants(double kP, double kI,
double kD);
BoomerangControllerBuilder& with_tracking_kp(double kP);
BoomerangControllerBuilder& with_exit_error(double error);
BoomerangControllerBuilder& with_angular_exit_error(double error);
BoomerangControllerBuilder& with_min_error(double error);
BoomerangControllerBuilder& with_lead_pct(double lead_pct);
BoomerangControllerBuilder& with_settle_time(double time);

BoomerangController build();
};

} // namespace voss::controller
Loading

0 comments on commit cd85077

Please sign in to comment.