PID CAN setup fix

This commit is contained in:
Valentin Dabstep 2025-05-27 16:33:02 +03:00
parent 013768ad1c
commit 5fa3db6e6c
4 changed files with 37 additions and 23 deletions

View file

@ -1,5 +1,6 @@
#include "config.h"
void doMotor(char *cmd) {
command.motor(&motor, cmd);
digitalWrite(PC10, !digitalRead(PC10));
@ -10,8 +11,18 @@ void doMotor(char *cmd) {
void setup_foc(MagneticSensorAS5045 *encoder, BLDCMotor *motor,
DRV8313Driver *driver, LowsideCurrentSense *current_sense,
Commander *commander, CommandCallback callback) {
Commander *commander, CommandCallback callback,FLASH_RECORD* pid_data) {
encoder->init(&spi);
/* convert data from flash int value to float*/
conv_float_to_int.i = pid_data[pid_p].value;
float p = conv_float_to_int.f;
conv_float_to_int.i = pid_data[pid_i].value;
float i = conv_float_to_int.f;
conv_float_to_int.i = pid_data[pid_d].value;
float d = conv_float_to_int.f;
// Driver configuration
driver->pwm_frequency = 20000;
@ -37,14 +48,16 @@ void setup_foc(MagneticSensorAS5045 *encoder, BLDCMotor *motor,
motor->PID_velocity.P = 0.75f;
motor->PID_velocity.I = 20.0f;
motor->LPF_velocity.Tf = 0.005f;
motor->P_angle.P = 0.5f;
motor->P_angle.P = p;
motor->P_angle.I = i;
motor->P_angle.D = d;
motor->LPF_angle.Tf = 0.001f;
// Motor limits
motor->velocity_limit = 40; // Speed limit in rad/s (382 rpm)
motor->voltage_limit = 24;
motor->current_limit = 0.5;
motor->sensor_direction = Direction::CCW;
motor->init();
motor->initFOC();
@ -69,4 +82,4 @@ void foc_step(BLDCMotor *motor, Commander *commander) {
motor->move();
motor->monitor();
commander->run();
}
}