Heljarinnar breytingar til þess að laga nokkra hluti í part 1.
This commit is contained in:
+13
-4
@@ -4,19 +4,28 @@
|
||||
#include <stdint.h>
|
||||
#include <zephyr/drivers/gpio.h>
|
||||
|
||||
struct Digital_in {
|
||||
class Digital_in {
|
||||
public:
|
||||
enum : uint8_t {
|
||||
ENCODER_C1 = 0,
|
||||
ENCODER_C2 = 1
|
||||
};
|
||||
|
||||
const struct gpio_dt_spec *gpio;
|
||||
|
||||
explicit Digital_in(uint8_t pin_id);
|
||||
|
||||
void init();
|
||||
bool is_hi();
|
||||
bool is_lo();
|
||||
|
||||
// Calls handler on every rising edge of the pin. The caller owns the
|
||||
// gpio_callback struct so it can find its own object with CONTAINER_OF.
|
||||
// Returns 0 on success, or a negative Zephyr error code.
|
||||
int enable_rising_edge_interrupt(
|
||||
struct gpio_callback *callback,
|
||||
gpio_callback_handler_t handler);
|
||||
|
||||
private:
|
||||
const struct gpio_dt_spec *gpio;
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -4,10 +4,7 @@
|
||||
#include<stdint.h>
|
||||
#include <zephyr/drivers/gpio.h>
|
||||
|
||||
|
||||
struct Digital_out {
|
||||
// uint8_t pin_mask;
|
||||
|
||||
enum : uint8_t {
|
||||
STATUS_LED = 0
|
||||
};
|
||||
@@ -21,7 +18,6 @@ struct Digital_out {
|
||||
|
||||
private:
|
||||
const struct gpio_dt_spec *gpio;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -5,13 +5,9 @@
|
||||
|
||||
#include "state.h"
|
||||
|
||||
|
||||
class InitializationState : public State
|
||||
{
|
||||
private:
|
||||
// static const unsigned long WAIT_MS = 2000;
|
||||
|
||||
// unsigned long enter_time_ms = 0;
|
||||
|
||||
|
||||
static constexpr int64_t WAIT_MS = 2000;
|
||||
@@ -28,4 +24,4 @@ public:
|
||||
void exit() override;
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -14,9 +14,8 @@ class State;
|
||||
class MotorController
|
||||
{
|
||||
private:
|
||||
static constexpr double DEFAULT_REFERENCE_RPM = 40.0;
|
||||
static constexpr double DEFAULT_REFERENCE_RPM = 25.0;
|
||||
static constexpr double PWM_PER_PERCENT = 255.0 / 100.0;
|
||||
//static const uint8_t LED_PIN = 5; // PB5 = D13 = LED_BUILTIN
|
||||
static constexpr uint8_t LED_PIN = Digital_out::STATUS_LED;
|
||||
|
||||
State* current_state;
|
||||
|
||||
@@ -22,4 +22,4 @@ private:
|
||||
bool initialized; // Flag that ignores motor commands if setup fails
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -26,4 +26,4 @@ public:
|
||||
void exit() override;
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -13,12 +13,9 @@ private:
|
||||
P_controller &pi_controller;
|
||||
bool pi_selected;
|
||||
|
||||
//unsigned long previous_time;
|
||||
int64_t previous_time;
|
||||
bool led_state;
|
||||
|
||||
//bool waiting_for_kp;
|
||||
//bool waiting_for_ti;
|
||||
|
||||
enum InputMode
|
||||
{
|
||||
@@ -41,4 +38,4 @@ public:
|
||||
void exit() override;
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -3,8 +3,9 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include <zephyr/drivers/gpio.h>
|
||||
#include <zephyr/kernel.h>
|
||||
|
||||
//#include "digital_in.h"
|
||||
#include "digital_in.h"
|
||||
#include "timer_usec.h"
|
||||
|
||||
class RotaryEncoderDriver {
|
||||
@@ -25,6 +26,10 @@ public:
|
||||
bool new_speed_available();
|
||||
void reset_speed_measurement();
|
||||
|
||||
// Blocks until the next speed sample, or until the timeout expires.
|
||||
// Lets the main loop run in step with the 4 ms sampling.
|
||||
void wait_for_sample(k_timeout_t timeout);
|
||||
|
||||
private:
|
||||
static const uint8_t HIST_LEN = 4; // 4 x Ts = 16 ms gluggi fyrir rpm-utreikning
|
||||
|
||||
@@ -35,12 +40,11 @@ private:
|
||||
volatile int32_t history[HIST_LEN];
|
||||
volatile uint8_t hist_idx;
|
||||
|
||||
|
||||
|
||||
//Digital_in eA;
|
||||
//Digital_in eB;
|
||||
Digital_in eA;
|
||||
Digital_in eB;
|
||||
|
||||
struct gpio_callback encoder_c1_callback;
|
||||
struct k_sem sample_sem;
|
||||
Timer_usec timer;
|
||||
|
||||
static void gpio_edge_handler(
|
||||
@@ -49,28 +53,6 @@ private:
|
||||
uint32_t pins);
|
||||
|
||||
static void timer_expired(void *context);
|
||||
|
||||
|
||||
// public:
|
||||
// RotaryEncoderDriver();
|
||||
|
||||
// void begin();
|
||||
|
||||
// void update();
|
||||
|
||||
// int32_t position();
|
||||
|
||||
// void update_delta();
|
||||
|
||||
// float count_per_sec();
|
||||
|
||||
// float rpm();
|
||||
|
||||
// bool new_speed_available();
|
||||
|
||||
// void reset_speed_measurement();
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
+1
-3
@@ -11,7 +11,6 @@ protected:
|
||||
public:
|
||||
virtual ~State()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void set_context(MotorController* context)
|
||||
@@ -26,7 +25,6 @@ public:
|
||||
virtual void command(char c) = 0; // Listen for reset
|
||||
|
||||
virtual void exit() = 0; // Stop motor
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -8,9 +8,8 @@
|
||||
class StoppedState : public State
|
||||
{
|
||||
private:
|
||||
//unsigned long previous_time; // Used for blinking LED
|
||||
int64_t previous_time;
|
||||
bool led_state; // Ditto
|
||||
bool led_state;
|
||||
|
||||
public:
|
||||
StoppedState();
|
||||
@@ -22,7 +21,6 @@ public:
|
||||
void command(char c) override;
|
||||
|
||||
void exit() override;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,16 +1,9 @@
|
||||
#ifndef TIMER_USEC_H
|
||||
#define TIMER_USEC_H
|
||||
|
||||
//#include <avr/io.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <zephyr/kernel.h>
|
||||
|
||||
// struct Timer_usec {
|
||||
// Timer_usec();
|
||||
// void init(uint16_t period_us);
|
||||
//};
|
||||
|
||||
class Timer_usec {
|
||||
public:
|
||||
using callback_t = void (*)(void *context);
|
||||
|
||||
Reference in New Issue
Block a user