hello.
i use shield v2.0.4 and AS5600 magnetic sensor, MKS 2808 bldc motor
i want to control motor velocity_control
so i use example code “velocity_control.ino”
but there was error that current sensor error
so i added code about current sensor, that is below.
but i’m not sure that’s right.
#include <SimpleFOC.h>
MagneticSensorI2C sensor = MagneticSensorI2C(AS5600_I2C);
InlineCurrentSense current_sense = InlineCurrentSense(0.01f, 50.0f, A0, A2);
BLDCMotor motor = BLDCMotor(7);
BLDCDriver3PWM driver = BLDCDriver3PWM(9, 5, 6, 8);
float target_velocity = 1.57;
Commander command = Commander(Serial);
void doTarget(char* cmd) { command.scalar(&target_velocity, cmd); }
void setup() {
Serial.begin(115200);
sensor.init();
// link the motor to the sensor
motor.linkSensor(&sensor);
// driver config
// power supply voltage [V]
driver.voltage_power_supply = 12;
driver.init();
// link the motor and the driver
motor.linkDriver(&driver);
current_sense.init();
current_sense.gain_b *=-1;
current_sense.skip_align = true;
motor.linkCurrentSense(¤t_sense);
motor.controller = MotionControlType::velocity;
motor.PID_velocity.P = 0.2f;
motor.PID_velocity.I = 20;
motor.PID_velocity.D = 0;
motor.voltage_limit = 6;
motor.PID_velocity.output_ramp = 1000;
motor.LPF_velocity.Tf = 0.01f;
//motor.useMonitoring(Serial);
motor.init();
motor.initFOC();
command.add(‘T’, doTarget, “target velocity”);
Serial.println(F(“Motor ready.”));
Serial.println(F(“Set the target velocity using serial terminal:”));
_delay(1000);
}
void loop() {
motor.loopFOC();
motor.move(target_velocity);