Hi everyone,
I am currently working on an esp32-s3 with Simplefoc shield v2.0.4. I am using AS5048A magnetic encoder and Cubemars GL40 motor. You can check the test evrimoment from the image.
You can also check the code that I am using
#include <Arduino.h>
#include <SimpleFOC.h>
BLDCMotor motor = BLDCMotor(14, 2.25, 70);
BLDCDriver3PWM driver = BLDCDriver3PWM(15,16,17,7);
InlineCurrentSense currentSense = InlineCurrentSense(0.01, 50, 40, 41);
MagneticSensorSPI sensor = MagneticSensorSPI(10, 14, 0x3FFF);
float target = 0;
Commander command = Commander(Serial);
void doTarget(char* cmd) { command.scalar(&target, cmd); }
void doCommand(char* cmd) { command.motor(&motor, cmd); }
void sensor_test(void)
{
sensor.update();
Serial.print(sensor.getAngle());
Serial.print("\t");
Serial.println(sensor.getVelocity());
_delay(100);
}
void setup() {
// sensor
sensor.init();
motor.linkSensor(&sensor);
//driver
driver.voltage_power_supply = 16;
driver.init();
motor.linkDriver(&driver);
//current sense
currentSense.linkDriver(&driver);
currentSense.init();
motor.linkCurrentSense(¤tSense);
//sensor index
motor.voltage_sensor_align = 1;
motor.velocity_index_search = 3;
//motion control
motor.torque_controller = TorqueControlType::foc_current;
motor.controller = MotionControlType::torque;
motor.foc_modulation = FOCModulationType::SpaceVectorPWM;
motor.motion_downsample = 0.0;
// PID
motor.PID_velocity.P = 0.2;
motor.PID_velocity.I = 10;
motor.PID_velocity.D = 0;
motor.PID_velocity.output_ramp = 100.0;
motor.PID_velocity.limit = 0.3;
motor.LPF_velocity.Tf = 0.1;
motor.P_angle.P = 20.0;
motor.P_angle.I = 0.0;
motor.P_angle.D = 0.0;
motor.P_angle.output_ramp = 0.0;
motor.P_angle.limit = 1000.0;
motor.LPF_angle.Tf = 0.0;
// motor.PID_current_q.P = 3.0;
// motor.PID_current_q.I = 300.0;
// motor.PID_current_q.D = 0.0;
// motor.PID_current_q.output_ramp = 0.0;
// motor.PID_current_q.limit = 7.0;
// motor.LPF_current_q.Tf = 0.02;
// motor.PID_current_d.P = 3.0;
// motor.PID_current_d.I = 300.0;
// motor.PID_current_d.D = 0.0;
// motor.PID_current_d.output_ramp = 0.0;
// motor.PID_current_d.limit = 7.0;
// motor.LPF_current_d.Tf = 0.02;
motor.velocity_limit = 50.0;
motor.current_limit = 2.0;
//motor.modulation_centered = 1.0;
//monitor
Serial.begin(115200);
motor.useMonitoring(Serial);
motor.monitor_variables = _MON_VEL | _MON_TARGET | _MON_CURR_D | _MON_CURR_Q;
motor.monitor_downsample=500;
//motor
motor.init();
motor.initFOC();
//commander
command.add('T', doTarget, "target angle");
command.add('M', doCommand, "motor command");
Serial.println(F("Motor ready."));
Serial.println(F("Set the target using serial terminal:"));
_delay(1000);
}
void loop() {
#if 1
motor.loopFOC();
motor.move(target);
motor.monitor();
command.run();
#else
sensor_test();
#endif
}
Here is the issue; I am trying to drive in a torque control mode. When I tried to debug from Simplefoc studio, Current Q and Current D do not respond to anyting. They remain 0 and do not give responds to any change I made. When I give target like 0.1A, driver gives full force up to 2.3A (I checked from Oscilloscope). Even I change target to 0, it remains like that and do not stop. Also there is a shaking issue on motor drive. You can check screenshots from the below.
as seen in the upper image, Current Q remain 0 and do not goes to target. Also there is a shaking issue that I mentioned can be seen in velocity graph.
I couldn’t solve the issue. Any idea to solve? I am glad to hear any advice. Thanks