RogiStandard-hal
STM32 向けサークル共通ライブラリ
読み取り中…
検索中…
一致する文字列を見つけられません
DCMotor.hpp
[詳解]
1
8#pragma once
9#include "main.h"
10#ifndef HAL_TIM_MODULE_ENABLED
11#error \
12 "DCMotor には TIM が必要です。CubeMX で TIM を有効にしてコードを再生成してください。"
13#endif
14#ifndef HAL_GPIO_MODULE_ENABLED
15#error \
16 "DCMotor には GPIO が必要です。CubeMX で GPIO を有効にしてコードを再生成してください。"
17#endif
18#include <cstdint>
19
31class DCMotor {
32 public:
42 DCMotor(TIM_HandleTypeDef* htim, uint16_t channel, GPIO_TypeDef* GPIO_Port,
43 uint16_t GPIO_Pin, bool direction = 1, float max_duty = 1.0f);
44
54 void setDuty(float duty);
55
61 void start();
62
67 float getDuty() const { return current_duty; }
68
73 void setMaxDuty(float max_duty) { this->max_duty = max_duty; }
74
75 private:
76 void setDirection(bool direction);
77 TIM_HandleTypeDef* htim;
78 uint16_t channel;
79 bool direction;
80 float current_duty;
81 float max_duty;
82 uint16_t pwm_resolution;
83
84 GPIO_TypeDef* GPIO_Port;
85 uint16_t GPIO_Pin;
86};
PWM で回転速度を、DIR ピンで回転方向を指令する DC モーター
Definition DCMotor.hpp:31
void start()
PWM の出力を開始する
Definition DCMotor.cpp:16
void setMaxDuty(float max_duty)
Duty の上限を変更する
Definition DCMotor.hpp:73
float getDuty() const
最後に指令した Duty を返す
Definition DCMotor.hpp:67
void setDuty(float duty)
Duty を指令する
Definition DCMotor.cpp:24