Initial commit: SmartCar Framework v0.1 — 龙芯2K0300智能车开发框架\n\n- HAL: GPIO/PWM/Encoder/Framebuffer 驱动\n- Control: PID/IMU/Motor/Servo 控制\n- Vision: HSV双Otsu→4点标定IPM→洪泛填充→逐行搜线\n- Strategy: 三区前瞻偏差+速度策略\n- Debug: 文件热调参+LCD预览+cv截帧\n- Scheduler: 5ms timerfd+epoll 中央调度器
This commit is contained in:
26
hal/encoder.hpp
Normal file
26
hal/encoder.hpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
#include "types.hpp"
|
||||
#include "gpio.hpp"
|
||||
|
||||
class Encoder {
|
||||
public:
|
||||
Encoder(int pwm_channel, int dir_gpio, int direction_polarity);
|
||||
~Encoder();
|
||||
|
||||
void update();
|
||||
float getRPS() const { return _rps; }
|
||||
int getDirection() const;
|
||||
|
||||
private:
|
||||
int _channel;
|
||||
GPIO _dir_gpio;
|
||||
int _polarity; // 1 或 -1
|
||||
volatile uint32* _reg_base;
|
||||
int _mem_fd;
|
||||
float _rps;
|
||||
uint32 _last_period;
|
||||
static constexpr unsigned int REG_OFFSET = 0x0100;
|
||||
void _mmapRegs();
|
||||
void _munmapRegs();
|
||||
uint32 _readRegister(unsigned int offset) const;
|
||||
};
|
||||
Reference in New Issue
Block a user