STM32F303K8T6向けのモータ制御ファームウェア(CAN受信で速度指令、PWM出力、エンコーダフィードバック)。
- 対象: STM32F303K8T6
- PWM: TIM1
- エンコーダ: TIM2/TIM3
Core/Src/cpp_main.cpp: 制御ループ本体Core/Components/Motor: モータ制御(PID/エンコーダ/PWM)Core/Components/CAN: CAN送受信ラッパーCore/Components/FullColorLed: LED制御
以下のテーブルに従う
| 方向 | CAN ID | 内容 | 型 |
|---|---|---|---|
| 受信 | 0x201 | 左モーター目標速度 [m/s] | float |
| 受信 | 0x211 | 右モーター目標速度 [m/s] | float |
| 送信 | 0x300 | 左右実速度 [m/s] | float x2 |
classDiagram
direction TB
class main_c {
<<C entry point>>
+main() int
}
class cpp_main {
<<module>>
+cpp_main() void
}
class Motor {
-pid_: PIDController
-velocity_: float
+init() void
+update(dt, rate) void
+setTargetSpeed(speed) void
+getVelocity() float
}
class PIDController {
-kp_, ki_, kd_, kf_: float
-integral_: float
+compute(target, current, dt) float
+reset() void
}
class CanController {
+initialize(hcan) void
+send(id, data) bool
+onReceive(id, handler) void
}
class can {
<<HAL module>>
+MX_CAN_Init()
+hcan: CAN_HandleTypeDef
}
class FullColorLed {
+setColor(color) void
}
main_c --> cpp_main : calls cpp_main()
cpp_main --> Motor : motor_l, motor_r
cpp_main --> FullColorLed : LED制御
cpp_main --> CanController : CAN通信
CanController --> can : HAL呼び出し
Motor *-- PIDController : contains
classDiagram
direction TB
class main_c {
<<C entry point>>
+main() int
-velocity_: float
-integral_: float
-updateEncoder()
-computePID()
-applyVoltage()
}
class spi {
<<HAL module>>
+spiInit()
+getSpiData()
}
class can {
<<HAL module>>
+canInit()
+sendCanData()
}
main_c --> spi : SPI通信
main_c --> can : CAN通信