halx_driver
読み取り中…
検索中…
一致する文字列を見つけられません
incremental_encoder.hpp
[詳解]
1#pragma once
2
3#include <cstdint>
4
5#include <halx/core.hpp>
6
7namespace halx::driver {
8
10public:
11 IncrementalEncoder(TIM_HandleTypeDef *htim) : htim_{htim} {
12 HAL_TIM_Encoder_Start(htim_, TIM_CHANNEL_ALL);
13 }
14
15 ~IncrementalEncoder() { HAL_TIM_Encoder_Stop(htim_, TIM_CHANNEL_ALL); }
16
17 void update() {
18 int16_t delta = __HAL_TIM_GET_COUNTER(htim_);
19 __HAL_TIM_SET_COUNTER(htim_, 0);
20 position_ += delta;
21 }
22
23 int64_t get_position() { return position_; }
24
25private:
26 TIM_HandleTypeDef *htim_;
27 int64_t position_ = 0;
28};
29
30} // namespace halx::driver
IncrementalEncoder(TIM_HandleTypeDef *htim)
Definition incremental_encoder.hpp:11
~IncrementalEncoder()
Definition incremental_encoder.hpp:15
void update()
Definition incremental_encoder.hpp:17
int64_t get_position()
Definition incremental_encoder.hpp:23
Definition amt21.hpp:10