Merge branch 'main' of ssh://gitea.cs.ru.is:2222/helgie22/ESP_Project3_H26 into Isak_part2

This commit is contained in:
2026-09-30 12:21:01 +00:00
19 changed files with 256 additions and 627 deletions
+5
View File
@@ -6,6 +6,11 @@
class InitializationState : public State
{
private:
static const unsigned long WAIT_MS = 2000;
unsigned long enter_time_ms = 0;
public:
void enter() override;
+13 -2
View File
@@ -4,6 +4,7 @@
#include "rotary_encoder_driver.h"
#include "motor_driver.h"
#include "p_controller.h"
#include "digital_out.h"
class State;
@@ -11,6 +12,10 @@ class State;
class MotorController
{
private:
static constexpr double DEFAULT_REFERENCE_RPM = 40.0;
static constexpr double PWM_PER_PERCENT = 255.0 / 100.0;
static const uint8_t LED_PIN = 5; // PB5 = D13 = LED_BUILTIN
State* current_state;
State* initialization_state;
@@ -21,6 +26,8 @@ private:
MotorDriver& motor;
P_controller& controller;
Digital_out led;
double reference_rpm;
@@ -45,7 +52,7 @@ public:
void command(char c);
void transition_to(State* new_state);
void transition_to(State& new_state);
void to_initialization();
@@ -62,6 +69,10 @@ public:
void stop_motor();
void reset_speed_measurement();
void led_on();
void led_off();
};
#endif
#endif
+10 -11
View File
@@ -4,37 +4,36 @@
#include <stdint.h>
#include "digital_in.h"
//#include "digital_out.h"
#include "timer_usec.h"
class RotaryEncoderDriver {
static const uint8_t HIST_LEN = 4; // 4 x 4 ms = 16 ms gluggi fyrir rpm-utreikning
public:
static constexpr uint16_t SAMPLE_PERIOD_US = 4000; // Ts = 4 ms
static constexpr float COUNTS_PER_REV = 1050.0f;
volatile uint8_t cycle;
volatile int16_t count;
volatile int16_t prev_count;
private:
static const uint8_t HIST_LEN = 4; // 4 x Ts = 16 ms gluggi fyrir rpm-utreikning
volatile int32_t count;
volatile int16_t delta;
volatile bool speed_ready;
volatile int16_t history[HIST_LEN];
volatile int32_t history[HIST_LEN];
volatile uint8_t hist_idx;
//Digital_out led;
Digital_in eA;
Digital_in eB;
Timer_usec timer;
public:
volatile int16_t delta;
RotaryEncoderDriver();
void begin();
void update();
int position();
int32_t position();
void update_delta();
+1 -1
View File
@@ -6,7 +6,7 @@ class MotorController;
class State
{
protected:
MotorController* context;
MotorController* context = nullptr;
public:
virtual ~State()