Hi guys, I’m now trying to run a gimbal motor with as5600 and mega2560 for my project. My problem now is that the motor is spinning during the init process but the serial shows that this process failed because no movement was detected from the sensor. I’ve also checked the sensor with the magnet sensor iic test example in the utils and it works fine.
These are the messages I got from the serial:
MOT: Monitor enabled!
MOT: Init
MOT: Enable driver.
MOT: Align sensor.
MOT: Failed to notice movement
MOT: Init FOC failed.
and here is my program:
#include <SimpleFOC.h>
// magnetic sensor instance - analog output
MagneticSensorAnalog sensor1 = MagneticSensorAnalog(A1, 0, 1023);
// BLDC motor & driver instance
BLDCMotor motor1 = BLDCMotor(7);
BLDCDriver3PWM driver1 = BLDCDriver3PWM(11, 10, 9, 8);
float target_angle = 4;
// commander interface
Commander command = Commander(Serial);
void doTarget(char* cmd) {
command.scalar(&target_angle, cmd);
}
void setup()
{
// initialise magnetic sensor hardware
sensor1.init();
// link the motor to the sensor
motor1.linkSensor(&sensor1);
// driver config
// power supply voltage [V]
driver1.voltage_power_supply = 24;
driver1.init();
// link driver
motor1.linkDriver(&driver1);
// control loop type and torque mode
motor1.torque_controller = TorqueControlType::voltage;
motor1.controller = MotionControlType::angle;
motor1.motion_downsample = 10.0;
// velocity loop PID
motor1.PID_velocity.P = 0.4;
motor1.PID_velocity.I = 0.0;
motor1.PID_velocity.D = 0.0;
motor1.PID_velocity.output_ramp = 0.0;
motor1.PID_velocity.limit = 12.0;
// Low pass filtering time constant
motor1.LPF_velocity.Tf = 0.01;
// angle loop PID
motor1.P_angle.P = 29.0;
motor1.P_angle.I = 0.2;
motor1.P_angle.D = 0.0;
motor1.P_angle.output_ramp = 0.0;
motor1.P_angle.limit = 100.0;
// Low pass filtering time constant
motor1.LPF_angle.Tf = 0.02;
// Limits
motor1.velocity_limit = 25.0;
motor1.voltage_limit = 20.0;
motor1.current_limit = 5.0;
command.add(‘T’, doTarget, “target angle”);
// use monitoring with serial for motor init
// monitoring port
Serial.begin(115200);
// comment out if not needed
motor1.useMonitoring(Serial);
// initialise motor
motor1.init();
// align encoder and start FOC 1.14, Direction::CCW
motor1.initFOC();
_delay(1000);
}
void loop() {
// iterative setting FOC phase voltage
motor1.loopFOC();
// iterative function setting the outter loop target
// velocity, position or voltage
// if tatget not set in parameter uses motor.target variable
//Serial.println(sensor1.getAngle());
motor1.move(target_angle);
command.run();
}