Hi Guys, i am working with 36v 350W hub motor, B-G431-ESC and AB encoder. i connected the encoder with gear ratio of 1:5. i am wanted to use closed loop with Space Vector PWM for better efficiency. Two condition it got while motor initialize if motor cant move then click noise ESC not working anymore and other condition while tuning q_current and p_current parameters some time motor get vibrate while move and sudden jerk and B-G431 not working anymore. so anyone tried Pat92fr FOC2 code. what you guys think about that code. this is the code i am using
#include <SimpleFOC.h>
// Motor instance
BLDCMotor motor = BLDCMotor(15,0.7,40);
BLDCDriver6PWM driver = BLDCDriver6PWM(A_PHASE_UH, A_PHASE_UL, A_PHASE_VH, A_PHASE_VL, A_PHASE_WH, A_PHASE_WL);
LowsideCurrentSense currentSense = LowsideCurrentSense(0.003f, -64.0f/7.0f, A_OP1_OUT, A_OP2_OUT, A_OP3_OUT);
// encoder instance
Encoder encoder = Encoder(A_ENCODER_A, A_ENCODER_B, 3360);
unsigned long previousMillis = 0;
// Interrupt routine intialisation
// channel A and B callbacks
void doA(){encoder.handleA();}
void doB(){encoder.handleB();}
void doIndex(){encoder.handleIndex();}
// instantiate the commander
Commander command = Commander(Serial);
void doTarget(char* cmd)
{
command.motor(&motor, cmd);
previousMillis = millis();
}
// will store last time LED was updated
// constants won't change:
const long interval = 1000; // interval at which to blink (milliseconds
void setup() {
// initialize encoder sensor hardware
encoder.init();
encoder.enableInterrupts(doA, doB);
// link the motor to the sensor
motor.linkSensor(&encoder);
// driver config
// power supply voltage [V]
driver.voltage_power_supply = 20;
driver.init();
// link the motor and the driver
motor.linkDriver(&driver);
// link current sense and the driver
currentSense.linkDriver(&driver);
// aligning voltage [V]
motor.voltage_sensor_align = 1;
// // index search velocity [rad/s]
motor.velocity_index_search = 1;
// set motion control loop to be used
motor.controller = MotionControlType::velocity;
// motor.torque_controller = TorqueControlType::foc_current;
motor.motion_downsample = 0.1;
// contoller configuration
// default parameters in defaults.h
// velocity PI controller parameters
motor.PID_velocity.P = 0.6;
motor.PID_velocity.I = 0.8;
motor.PID_velocity.D = 0.00;
motor.PID_velocity.limit = 20.0;
// jerk control using voltage voltage ramp
// default value is 300 volts per sec ~ 0.3V per millisecond
motor.PID_velocity.output_ramp = 300;
// velocity low pass filtering time constant
motor.LPF_velocity.Tf = 0.01;
// angle P controller
// motor.P_angle.P = 0.8;
// maximal velocity of the position control
motor.velocity_limit = 20.0;
motor.current_limit = 8.0;
motor.voltage_limit = 20.0;
// Q axis
// PID parameters - default
motor.PID_current_q.P = 5; // 3 - Arduino UNO/MEGA
motor.PID_current_q.I = 0; // 300 - Arduino UNO/MEGA
motor.PID_current_q.D = 0;
motor.PID_current_q.limit = motor.voltage_limit;
motor.PID_current_q.output_ramp = 300; // 1000 - Arduino UNO/MEGA
// Low pass filtering - default
motor.LPF_current_q.Tf= 0.01; // 0.01 - Arduino UNO/MEGA
// D axis
// PID parameters - default
motor.PID_current_d.P = 5; // 3 - Arduino UNO/MEGA
motor.PID_current_d.I = 0; // 300 - Arduino UNO/MEGA
motor.PID_current_d.D = 0;
motor.PID_current_d.limit = motor.voltage_limit;
motor.PID_current_d.output_ramp = 300; // 1000 - Arduino UNO/MEGA
// Low pass filtering - default
motor.LPF_current_d.Tf= 0.01; // 0.01 - Arduino UNO/MEGA
motor.foc_modulation = FOCModulationType::SpaceVectorPWM;
motor.modulation_centered = 1.0;
// use monitoring with serial
Serial.begin(115200);
// comment out if not needed
// motor.useMonitoring(Serial);
// initialize motor
motor.init();
currentSense.init();
// no need for aligning
currentSense.skip_align = true;
motor.linkCurrentSense(¤tSense);
// // align encoder and start FOC
motor.initFOC();
command.verbose = VerboseMode::on_request;
// // add target command T
command.add('M', doTarget, "target angle");
_delay(1000);
previousMillis = millis();
}
void loop() {
// main FOC algorithm function
// Motion control function
motor.loopFOC();
motor.move();
// function intended to be used with serial plotter to monitor motor variables
// significantly slowing the execution down!!!!
motor.monitor();
command.run();
// unsigned long currentMillis = millis();
// if (currentMillis - previousMillis >= interval) {
// // save the last time you blinked the LED
// // command.motor(&motor, "0.0");
// previousMillis = currentMillis;
// }
}
Any suggestion please.