2025-10-31 01:17:52 +08:00
|
|
|
#ifndef _angsensor_H
|
|
|
|
|
#define _angsensor_H
|
2025-11-01 23:41:32 +08:00
|
|
|
#include <cstdio>
|
2025-09-23 00:27:51 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
#include "gd32c10x_eval.h"
|
2025-10-02 23:50:12 +08:00
|
|
|
#include "stdio.h"
|
2025-09-23 00:27:51 +08:00
|
|
|
|
|
|
|
|
u16 spi_rw_half_word(u32 spi_periph, const u16 i_HalfWord);
|
2025-11-01 23:41:32 +08:00
|
|
|
int spi_rw_half_word_dma(uint32_t spi_periph, uint16_t tx_data,
|
|
|
|
|
uint16_t *rx_data);
|
|
|
|
|
|
2025-11-08 02:15:14 +08:00
|
|
|
constexpr u16 VEL_FILTER_SIZE = 4;
|
2025-11-03 02:38:43 +08:00
|
|
|
|
2025-11-01 23:41:32 +08:00
|
|
|
class angle_sensor {
|
|
|
|
|
public:
|
|
|
|
|
angle_sensor();
|
2025-11-02 01:54:01 +08:00
|
|
|
float read_sensorAngle(void);
|
|
|
|
|
float update(void);
|
|
|
|
|
void reset(void);
|
|
|
|
|
float getAngle(void) const;
|
2025-11-03 02:38:43 +08:00
|
|
|
float getRawAngle(void) const;
|
|
|
|
|
float getVelocity(void) const;
|
|
|
|
|
float getRawVelocity(void) const;
|
2025-11-08 21:04:35 +08:00
|
|
|
float getcurrent_sensorangle(void) const;
|
2025-11-01 23:41:32 +08:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
void KTH7823_init(void);
|
2025-11-08 21:04:35 +08:00
|
|
|
float m_cumulativeAngle;
|
|
|
|
|
float current_angle_deg;
|
|
|
|
|
float current_angle_rad;
|
2025-11-02 01:54:01 +08:00
|
|
|
bool m_firstUpdate;
|
|
|
|
|
float m_lastAngle;
|
2025-11-03 02:38:43 +08:00
|
|
|
float m_lastcumulativeAngle;
|
|
|
|
|
float velocity[VEL_FILTER_SIZE] = {0.0f};
|
2025-11-01 23:41:32 +08:00
|
|
|
};
|
2025-11-01 21:03:57 +08:00
|
|
|
|
2025-09-23 00:27:51 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2025-11-01 21:03:57 +08:00
|
|
|
#endif
|