Skip to content

yumo13/G25_MotorController

Repository files navigation

MotorController

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通信

以下のテーブルに従う

方向 CAN ID 内容
受信 0x201 左モーター目標速度 [m/s] float
受信 0x211 右モーター目標速度 [m/s] float
送信 0x300 左右実速度 [m/s] float x2

MotorController クラス図

新プログラム(C++実装)

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
Loading

旧プログラム(C実装 - g15_STM32/MDC)

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通信
Loading

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages