Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
e9ffa7f
✨ Add maze graph
GabrielCosme May 14, 2025
8c3d7bc
✨ Add action id and total time to actions
GabrielCosme May 14, 2025
ce53401
✨ Add get_relative_side to GridPose
GabrielCosme May 14, 2025
e573ef0
✨ Add push_solving function to action queuer
GabrielCosme May 14, 2025
d9769e6
📝 Add comments to nav methods
GabrielCosme May 15, 2025
0170858
✨ Make graph return best route
GabrielCosme May 15, 2025
9416dd0
🚸 Split maze constructor
GabrielCosme May 16, 2025
8eeb0bf
✨ Add route optimizations to action queuer
GabrielCosme May 17, 2025
b64cdaa
🐛 Fix trim distance on diagonals
GabrielCosme May 18, 2025
0aa894b
🐛 Fix turn action orientation
GabrielCosme May 18, 2025
5b92998
🐛 Fix deceleration angle on turn
GabrielCosme May 18, 2025
03a4ea4
🐛 Fiz erase order on maze graph
GabrielCosme May 18, 2025
91f2d64
🐛 Fix action queuer diagonal check
GabrielCosme May 18, 2025
f891be8
🐛 Fix start action when solving
GabrielCosme May 18, 2025
e3b0c6b
🐛 Fix action queuer pop
GabrielCosme May 18, 2025
a98aed9
🐛 Remove 180 turns from remove_extra_nodes function
GabrielCosme May 19, 2025
33221a1
🐛 Fix dijkstra pop top
GabrielCosme May 19, 2025
10db7ad
🐛 Fix speed calculation on turn action
GabrielCosme May 19, 2025
b1bf5d5
🐛 Disable diagonal follow wall
GabrielCosme May 19, 2025
bfbc288
🐛 Fix correction factor on turn action
GabrielCosme May 19, 2025
d0d99e8
⚡️ Improve correction factor on turn action
GabrielCosme May 19, 2025
1de33c6
🐛 Fix diagonal distance and total time on action queuer
GabrielCosme May 19, 2025
cf9b8e6
⚡️ Change actions to be time based
GabrielCosme May 19, 2025
c3c3697
⚡️ Make move action use current robot pose
GabrielCosme May 19, 2025
fcc792e
🐛 Remove const from action finished
GabrielCosme May 19, 2025
34b67de
🐛 Fix get_relative_side function
GabrielCosme May 19, 2025
34ad865
🐛 Fix second turn angle on diagonal
GabrielCosme May 19, 2025
2b87c51
✨ Fix trim distances before and after diagonals
GabrielCosme May 20, 2025
8cfb3a7
🐛 Fix side displacement on action queuer trim distance
GabrielCosme May 20, 2025
ba07a17
🐛 Fix forward displacement from turn action
GabrielCosme May 20, 2025
740ac53
🐛 Fix action queuer get_trim_distances
GabrielCosme May 21, 2025
fc400d8
🐛 Fix turn max_angular_speed calculation
GabrielCosme May 21, 2025
f33a695
🥅 Add reset function to maze_graph
GabrielCosme May 21, 2025
326841d
🐛 Fix total time calculations on actions
GabrielCosme May 21, 2025
7e310c4
✨ Add variable radius to action queuer
GabrielCosme May 22, 2025
cd8d53f
✨ Improve maze graph node connections
GabrielCosme May 22, 2025
d808742
🐛 Fix max angular speed on exploration turn actions
GabrielCosme May 22, 2025
636a818
🐛 Fix displacement calculation from solving turn actions
GabrielCosme May 22, 2025
bb977b3
🐛 Fix solve start action distance
GabrielCosme May 22, 2025
eda19fb
🐛 Disable follow wall on diagonal
GabrielCosme May 22, 2025
9014edf
⚡️ Calibrate constants
GabrielCosme May 22, 2025
5b43e33
✨ Add remove_node method to maze_graph
GabrielCosme May 23, 2025
83b0451
⚡️ Remove time from diagonal trim on get_edge_cost
GabrielCosme May 23, 2025
d93e993
✨ Add fan events to interface
GabrielCosme May 24, 2025
cf5a9d3
✨ Add curve safety margin to action queuer
GabrielCosme May 24, 2025
d55885f
♿️ Improve action queuer constructor
GabrielCosme May 24, 2025
c28a83b
🐛 Disable follow wall on actions
GabrielCosme May 24, 2025
b52fd9d
⚡️ Add move_from_turn action
GabrielCosme May 24, 2025
dcdc909
🐛 Fix curve parameters access
GabrielCosme May 24, 2025
0fc5d20
🐛 Can't skip using 180 turn
GabrielCosme May 24, 2025
cc26d10
⚡️ Add first run flag to pid
GabrielCosme May 24, 2025
ba45531
⚡️ Clamp follow wall response
GabrielCosme May 24, 2025
a0b21ea
⚡️ Fix exploration linear speed on action queuer
GabrielCosme May 25, 2025
b29118b
✨ Clear the odometry positional error from the follow wall
GabrielCosme May 25, 2025
4719bbf
🐛 Add odometry initial pose
GabrielCosme May 25, 2025
6c328c0
⚡️ Use reading instead of error on follow wall check posts
GabrielCosme May 25, 2025
b56c2dc
🐛 Fix post reference on follow wall
GabrielCosme May 25, 2025
ffc53a4
⏪ Add post clearance back
GabrielCosme May 25, 2025
c2bf977
🐛 Move odometry reset to reset function
GabrielCosme May 25, 2025
26a028a
⚡️ Remove feed forward limiter
GabrielCosme May 25, 2025
377a40c
🍻 Add handle events to idle state
GabrielCosme May 25, 2025
837fce9
🔥 Disable follow wall near post references
GabrielCosme May 26, 2025
7551351
🔥 Remove max_linear_speed from follow wall
GabrielCosme May 26, 2025
179db34
🐛 Fix angle to grid conversion
GabrielCosme May 26, 2025
e9eac72
⚡️ Reset pid after follow wall change
GabrielCosme May 26, 2025
81fa952
🚧 Use dfs instead of graph to compute best route
GabrielCosme May 26, 2025
b85e40d
✨ Add diagonals post processing to action queuer
GabrielCosme May 27, 2025
9bfd795
⚡️ Change best_route computation to recursive approach
GabrielCosme May 27, 2025
6e3faa3
⚗️ Add heuristic function to compute best route
GabrielCosme May 27, 2025
99c94c3
🐛 Fix action queuer join actions
GabrielCosme May 28, 2025
344cac0
✨ Add signal handler
GabrielCosme May 30, 2025
bd033f8
🚸 Change imu submodule to CMake fetch
GabrielCosme Jun 8, 2025
a6877b7
Merge branch 'main' into feature/solving-graph
GabrielCosme Jun 8, 2025
a7b38c9
🚨 Fix linter warnings
GabrielCosme Jun 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .gitmodules

This file was deleted.

5 changes: 0 additions & 5 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,5 @@

"doxdocgen.file.fileOrder": [
"file",
],

"clangd.arguments": [
"--pretty",
"--compile-commands-dir=${workspaceFolder}/build/",
]
}
36 changes: 18 additions & 18 deletions config/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ constexpr float cell_size{0.18};
constexpr uint32_t loop_time_us{1042};
constexpr float wall_thickness{0.0126F};
constexpr float start_offset{0.04F + wall_thickness / 2.0F};
constexpr float exploration_speed{0.5F};
constexpr float max_linear_acceleration{1.0F};
constexpr float max_angular_acceleration{200.0F};
constexpr float crash_acceleration{20.0F};
constexpr float max_linear_acceleration{9.0F};
constexpr float max_linear_deceleration{9.0F};
constexpr float max_angular_acceleration{300.0F};
constexpr float crash_acceleration{35.0F};
constexpr float fan_speed{100.0F};

constexpr core::WallSensorsIndex wall_sensors_index{
.left_front = 0,
Expand All @@ -51,24 +52,23 @@ using Maze = TMaze<maze_width, maze_height>;
const nav::ActionQueuer::Config action_queuer_config{
.cell_size = cell_size,
.start_offset = start_offset,
.curve_safety_margin = 0.0375F + 0.015F,
.exploring =
{
.max_linear_speed = exploration_speed,
.max_linear_speed = 0.4F,
.max_linear_acceleration = max_linear_acceleration,
.max_linear_deceleration = max_linear_acceleration,
.curve_radius = cell_size / 2.0F,
.max_linear_deceleration = max_linear_deceleration,
.max_centrifugal_acceleration = 2.78F,
.max_angular_acceleration = max_angular_acceleration,
},
.solving =
{
.max_linear_speed = exploration_speed,
.max_linear_speed = 3.0F,
.max_linear_acceleration = max_linear_acceleration,
.max_linear_deceleration = max_linear_acceleration,
.curve_radius = cell_size / 2.0F,
.max_centrifugal_acceleration = 1.0F,
.max_linear_deceleration = max_linear_deceleration,
.max_centrifugal_acceleration = 5.0F,
.max_angular_acceleration = max_angular_acceleration,
},
}
};

const nav::FollowWall::Config follow_wall_config{
Expand All @@ -81,10 +81,11 @@ const nav::FollowWall::Config follow_wall_config{
.saturation = 1.0F,
.max_integral = -1.0F,
},
.max_linear_speed = 0.1F,
.post_threshold = 16.5F,
.max_angular_acceleration = max_angular_acceleration,
.cell_size = cell_size,
.post_clearance = 0.2F * cell_size,
.post_threshold = 16.5F,
.post_reference = 0.44F * cell_size,
.post_clearance = 0.025F,
};

const nav::Maze::Config maze_config{
Expand All @@ -96,17 +97,16 @@ const nav::Maze::Config maze_config{
{(maze_width - 1) / 2, (maze_height - 1) / 2},
}},
.cost_margin = 1.2F,
.action_queuer_config = action_queuer_config,
};

const nav::Odometry::Config odometry_config{
.linear_cutoff_frequency = 5.0F,
.wheel_radius = 0.0112F,
.initial_pose = {{0.0F, 0.0F}, 0.0F},
.initial_pose = {{cell_size / 2.0F, start_offset}, std::numbers::pi / 2.0F},
};

const nav::SpeedController::Config speed_controller_config{
.max_linear_acceleration = max_linear_acceleration,
.max_angular_acceleration = max_angular_acceleration,
.linear_pid =
{
.kp = 10.0F,
Expand Down
25 changes: 24 additions & 1 deletion include/micras/interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,15 @@ class Interface {
SOLVE = 1,
CALIBRATE = 2,
ERROR = 3,
NUMBER_OF_EVENTS = 4,
TURN_ON_FAN = 4,
TURN_OFF_FAN = 5,
TURN_ON_DIAGONAL = 6,
TURN_OFF_DIAGONAL = 7,
TURN_ON_BOOST = 8,
TURN_OFF_BOOST = 9,
TURN_ON_RISKY = 10,
TURN_OFF_RISKY = 11,
NUMBER_OF_EVENTS = 12,
};

/**
Expand Down Expand Up @@ -74,6 +82,16 @@ class Interface {
bool peek_event(Event event) const;

private:
/**
* @brief Enum for what each dip switch pin does.
*/
enum DipSwitchPins : uint8_t {
FAN = 0,
DIAGONAL = 1,
BOOST = 2,
RISKY = 3,
};

/**
* @brief Addressable RGB LED object.
*/
Expand Down Expand Up @@ -103,6 +121,11 @@ class Interface {
* @brief Array of the listed events.
*/
std::array<bool, Event::NUMBER_OF_EVENTS> events{};

/**
* @brief Array to store the last dip switch states.
*/
std::array<bool, 4> dip_switch_states{};
};
} // namespace micras

Expand Down
9 changes: 7 additions & 2 deletions include/micras/micras.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,16 @@ class Micras {
*/
void load_best_route();

/**
* @brief Handle events from the interface.
*/
void handle_events();

private:
/**
* @brief Enum for the type of calibration being performed.
*/
enum CalibrationType : uint8_t {
enum class CalibrationType : uint8_t {
SIDE_WALLS = 0, // Calibrate side walls and front free space detection.
FRONT_WALL = 1, // Calibrate front wall detection.
};
Expand Down Expand Up @@ -190,7 +195,7 @@ class Micras {
/**
* @brief Finite state machine for the robot.
*/
core::FSM fsm{State::INIT};
core::Fsm fsm{State::INIT};

/**
* @brief Class for controlling the interface with the external world.
Expand Down
2 changes: 1 addition & 1 deletion include/micras/states/base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "micras/micras.hpp"

namespace micras {
class BaseState : public core::FSM::State {
class BaseState : public core::Fsm::State {
public:
/**
* @brief Construct a new BaseState object.
Expand Down
2 changes: 2 additions & 0 deletions include/micras/states/idle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class IdleState : public BaseState {
* @return The id of the next state.
*/
uint8_t execute() override {
this->micras.handle_events();

if (this->micras.acknowledge_event(Interface::Event::EXPLORE)) {
this->micras.set_objective(core::Objective::EXPLORE);

Expand Down
4 changes: 2 additions & 2 deletions micras_core/include/micras/core/fsm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <unordered_map>

namespace micras::core {
class FSM {
class Fsm {
public:
class State {
public:
Expand Down Expand Up @@ -67,7 +67,7 @@ class FSM {
*
* @param initial_state_id The id of the initial state.
*/
explicit FSM(uint8_t initial_state_id);
explicit Fsm(uint8_t initial_state_id);

/**
* @brief Add a state to the FSM.
Expand Down
5 changes: 5 additions & 0 deletions micras_core/include/micras/core/pid_controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ class PidController {
*/
float max_integral;

/**
* @brief Flag indicating whether this is the first run of the controller.
*/
bool first_run = true;

/**
* @brief Accumulated error for integrative term.
*/
Expand Down
2 changes: 1 addition & 1 deletion micras_core/include/micras/core/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct Observation {
/**
* @brief Possible objectives of the robot.
*/
enum Objective : uint8_t {
enum class Objective : uint8_t {
EXPLORE = 0,
RETURN = 1,
SOLVE = 2
Expand Down
2 changes: 1 addition & 1 deletion micras_core/include/micras/core/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ constexpr T remap(T value, T in_min, T in_max, T out_min, T out_max) {
*/
template <typename T>
constexpr T move_towards(T value, T target, T step) {
return std::max(std::min(value + step, target), value - step);
return std::clamp(target, value - step, value + step);
}

/**
Expand Down
10 changes: 5 additions & 5 deletions micras_core/src/fsm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
#include "micras/core/fsm.hpp"

namespace micras::core {
FSM::State::State(uint8_t id) : id{id} { }
Fsm::State::State(uint8_t id) : id{id} { }

uint8_t FSM::State::get_id() const {
uint8_t Fsm::State::get_id() const {
return this->id;
}

FSM::FSM(uint8_t initial_state_id) : current_state_id{initial_state_id} { }
Fsm::Fsm(uint8_t initial_state_id) : current_state_id{initial_state_id} { }

void FSM::add_state(std::unique_ptr<State> state) {
void Fsm::add_state(std::unique_ptr<State> state) {
this->states.emplace(state->get_id(), std::move(state));
}

void FSM::update() {
void Fsm::update() {
if (this->current_state_id != this->previous_state_id) {
this->states.at(this->current_state_id)->on_entry();
}
Expand Down
6 changes: 6 additions & 0 deletions micras_core/src/pid_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,15 @@ void PidController::reset() {
this->error_acc = 0;
this->prev_state = 0;
this->last_response = 0;
this->first_run = true;
}

float PidController::compute_response(float state, float elapsed_time, bool save) {
if (first_run) {
this->prev_state = state;
this->first_run = false;
}

const float state_change = (state - this->prev_state) / elapsed_time;
return this->compute_response(state, elapsed_time, state_change, save);
}
Expand Down
Loading