Skip to content

Commit f472bff

Browse files
authored
Merge pull request #252 from HyperloopUPV-H8/features/aidocs
ai documentation
2 parents 3fdd0e7 + 91796a2 commit f472bff

3 files changed

Lines changed: 99 additions & 1 deletion

File tree

.vscode/settings.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,8 @@
1717
"**/Makefile": true
1818
},
1919
"C_Cpp.default.cppStandard": "c++20",
20-
"C_Cpp.default.cStandard": "c17"
20+
"C_Cpp.default.cStandard": "c17",
21+
"docwriter.style": "Doxygen",
22+
"docwriter.progress.trackFunctions": true,
23+
"docwriter.progress.trackMethods": true
2124
}

Src/HALAL/Services/PWM/PhasedPWM/PhasedPWM.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77

88
#include <PWM/PhasedPWM/PhasedPWM.hpp>
99

10+
/**
11+
* The function initializes a PhasedPWM object with a given pin and sets its duty cycle and phase to 0.
12+
*
13+
* @param pin The pin to which the PhasedPWM object is being attached.
14+
*/
1015
PhasedPWM::PhasedPWM(Pin& pin) {
1116
if (not TimerPeripheral::available_pwm.contains(pin)) {
1217
ErrorHandler("Pin %s is not registered as an available PWM", pin.to_string());
@@ -30,6 +35,13 @@ PhasedPWM::PhasedPWM(Pin& pin) {
3035
phase = 0;
3136
}
3237

38+
/**
39+
* This function sets the duty cycle of a PWM signal and calculates the raw duty and phase values based
40+
* on the input duty cycle and phase.
41+
*
42+
* @param duty_cycle The duty cycle is a value between 0 and 100 that represents the percentage of time
43+
* that the PWM signal is high compared to the total period of the signal.
44+
*/
3345
void PhasedPWM::set_duty_cycle(float duty_cycle) {
3446
this->duty_cycle = duty_cycle;
3547
uint32_t arr = peripheral->handle->Instance->ARR;
@@ -45,12 +57,23 @@ void PhasedPWM::set_duty_cycle(float duty_cycle) {
4557
}
4658
}
4759

60+
/**
61+
* This function sets the frequency of a PWM signal using a timer in a microcontroller.
62+
*
63+
* @param frequency The desired frequency of the PWM signal in Hertz (Hz).
64+
*/
4865
void PhasedPWM::set_frequency(uint32_t frequency) {
4966
TIM_TypeDef& timer = *peripheral->handle->Instance;
5067
timer.ARR = (HAL_RCC_GetPCLK1Freq()*2 / (timer.PSC+1)) / 2 / frequency;
5168
set_duty_cycle(duty_cycle);
5269
}
5370

71+
/**
72+
* This function sets the phase of a PhasedPWM object and updates the duty cycle accordingly.
73+
*
74+
* @param phase The "phase" parameter is a floating-point value that represents the phase shift of a
75+
* PWM signal. In other words, it determines the timing offset of the PWM waveform relative to its center.
76+
*/
5477
void PhasedPWM::set_phase(float phase) {
5578
this->phase = phase;
5679
set_duty_cycle(duty_cycle);

Src/ST-LIB_LOW/StateMachine/StateMachine.cpp

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,26 @@ void State::exit() {
2020
}
2121
}
2222

23+
/**
24+
* This is a constructor for a StateMachine object that initializes the initial state and creates a
25+
* State object for it.
26+
*
27+
* @param initial_state The initial state parameter is an unsigned 8-bit integer that represents the
28+
* starting state of the state machine.
29+
*/
2330
StateMachine::StateMachine(uint8_t initial_state) :
2431
initial_state(initial_state), current_state(initial_state) {
2532
states[initial_state] = State();
2633
}
2734

35+
/**
36+
* The function adds a state to a state machine and sets it as the initial and current state if it is
37+
* the first state added.
38+
*
39+
* @param state The state to be added to the state machine.
40+
*
41+
* @return The function does not return anything. It has a void return type.
42+
*/
2843
void StateMachine::add_state(uint8_t state) {
2944
if (states.contains(state)) {
3045
ErrorHandler("The state %d is already added", state);
@@ -38,6 +53,13 @@ void StateMachine::add_state(uint8_t state) {
3853
states[state];
3954
}
4055

56+
/**
57+
* This function adds an action to be executed when entering the current state of a state machine.
58+
*
59+
* @param action The parameter "action" is a function pointer to a function that takes no arguments and
60+
* returns nothing (void). It represents an action that should be executed when the current state of
61+
* the state machine is entered.
62+
*/
4163
void StateMachine::add_enter_action(function<void()> action) {
4264
if (not current_state) {
4365
ErrorHandler("The state machine does not have a current state");
@@ -46,6 +68,15 @@ void StateMachine::add_enter_action(function<void()> action) {
4668
states[current_state].on_enter_actions.push_back(action);
4769
}
4870

71+
/**
72+
* This function adds an action to be executed when entering a specific state in a state machine.
73+
*
74+
* @param action The action parameter is a function pointer to a function that takes no arguments and
75+
* returns nothing. This function will be executed when the state machine transitions to the state
76+
* specified by the state parameter.
77+
* @param state The state parameter is an unsigned 8-bit integer that represents the state to which the
78+
* enter action is being added.
79+
*/
4980
void StateMachine::add_enter_action(function<void()> action, uint8_t state) {
5081
if (not states.contains(state)) {
5182
ErrorHandler("The state %d is not added to the state machine", state);
@@ -54,13 +85,31 @@ void StateMachine::add_enter_action(function<void()> action, uint8_t state) {
5485
states[state].on_enter_actions.push_back(action);
5586
}
5687

88+
/**
89+
* This function adds an exit action to the current state of a state machine.
90+
*
91+
* @param action `action` is a function pointer to a function that takes no arguments and returns
92+
* nothing (`void`). It represents an action that should be executed when the state machine exits the
93+
* current state and transitions to a new state. The `add_exit_action` function adds this action to the
94+
* list of exit actions for
95+
*/
5796
void StateMachine::add_exit_action(function<void()> action) {
5897
if (not current_state) {
5998
ErrorHandler("The state machine does not have a current state");
6099
return;
61100
}
62101
states[current_state].on_exit_actions.push_back(action);
63102
}
103+
104+
/**
105+
* This function adds an exit action to a specific state in a state machine.
106+
*
107+
* @param action The action parameter is a function pointer to a function that takes no arguments and
108+
* returns nothing. This function represents the action that will be executed when the state machine
109+
* exits the specified state.
110+
* @param state The state parameter is an unsigned 8-bit integer that represents the state to which the
111+
* exit action is being added.
112+
*/
64113
void StateMachine::add_exit_action(function<void()> action, uint8_t state) {
65114
if (not states.contains(state)) {
66115
ErrorHandler("The state %d is not added to the state machine");
@@ -69,6 +118,17 @@ void StateMachine::add_exit_action(function<void()> action, uint8_t state) {
69118
states[state].on_exit_actions.push_back(action);
70119
}
71120

121+
/**
122+
* This function adds a transition between two states in a state machine.
123+
*
124+
* @param old_state The current state of the state machine before the transition occurs. It is
125+
* represented as an unsigned 8-bit integer (uint8_t).
126+
* @param new_state The new state to transition to. It is of type uint8_t.
127+
* @param transition The parameter "transition" is a function pointer to a boolean function that takes
128+
* no arguments. This function represents the condition that must be met in order for the state machine
129+
* to transition from the old_state to the new_state. If the condition is true, the transition will
130+
* occur. If the condition is false
131+
*/
72132
void StateMachine::add_transition(uint8_t old_state, uint8_t new_state,
73133
function<bool()> transition) {
74134
if (not states.contains(old_state)) {
@@ -83,6 +143,14 @@ void StateMachine::add_transition(uint8_t old_state, uint8_t new_state,
83143
transitions[old_state][new_state] = transition;
84144
}
85145

146+
/**
147+
* The function adds a nested state machine to the current state machine and clears any timed actions
148+
* associated with the nested state machine's current state if it is not the current state.
149+
*
150+
* @param state_machine A reference to a StateMachine object that is being added as a nested state
151+
* machine to the current StateMachine object.
152+
* @param state The state to which the nested state machine is being added.
153+
*/
86154
void StateMachine::add_state_machine(StateMachine& state_machine, uint8_t state) {
87155
nested_state_machine[state] = &state_machine;
88156

@@ -99,6 +167,10 @@ void StateMachine::add_state_machine(StateMachine& state_machine, uint8_t state)
99167
}
100168
}
101169

170+
/**
171+
* The function checks for state transitions and changes the current state if necessary, and also
172+
* checks for transitions in a nested state machine if applicable.
173+
*/
102174
void StateMachine::check_transitions() {
103175
for (auto const state_transition : transitions[current_state]) {
104176
if (state_transition.second()) {

0 commit comments

Comments
 (0)