Smart Knob Controller
motor.h
1/*
2 * motor.h
3 *
4 * Author: nickl
5 *
6 */
7
8#ifndef INC_MOTOR_H_
9#define INC_MOTOR_H_
10
11#include "stm32f4xx_hal.h"
12#include "gpio.h"
13#include "encoder.h"
14
18class Motor {
19public:
31 Motor(TIM_HandleTypeDef* htim,
32 uint32_t chA, uint32_t chB, uint32_t chC,
33 GPIO& enA, GPIO& enB, GPIO& enC,
34 Encoder& encoder);
35
37 void setEffort(int effort);
39 void commutate();
41 void enable();
43 void disable();
49 void testCommutation(int32_t theta, float Vq);
56 void applyPWM(float Va, float Vb, float Vc);
57
58private:
63 static const float commTable[16384];
64
65 TIM_HandleTypeDef* htim;
66 uint32_t chA, chB, chC;
67 GPIO& enA;
68 GPIO& enB;
69 GPIO& enC;
70 Encoder& encoder;
71
72 int targetEffort;
73
74 static constexpr float V_max = 12;
75 static constexpr uint16_t polePairs = 11;
76 static constexpr uint16_t resolution = 16384;
77
78};
79
80#endif /* INC_MOTOR_H_ */
Class to interface with a 14-bit SPI-based rotary encoder.
Definition encoder.h:20
Wrapper class for STM32 GPIO pin control.
Definition gpio.h:17
void commutate()
Applies 3-phase commutation based on current encoder angle and effort.
Definition motor.cpp:29
void applyPWM(float Va, float Vb, float Vc)
Sets PWM outputs based on given phase voltages.
Definition motor.cpp:89
void setEffort(int effort)
Sets the motor effort as a percentage (-100 to 100).
Definition motor.cpp:22
void testCommutation(int32_t theta, float Vq)
Applies open-loop commutation at specified angle and voltage.
Definition motor.cpp:69
void enable()
Enables all motor phases.
Definition motor.cpp:55
void disable()
Disables all motor phases.
Definition motor.cpp:62
Motor(TIM_HandleTypeDef *htim, uint32_t chA, uint32_t chB, uint32_t chC, GPIO &enA, GPIO &enB, GPIO &enC, Encoder &encoder)
Constructs a Motor object.
Definition motor.cpp:11