Hello, I’m trying to use a stepper motor in combination with the AS5600 but its doesn’t seem to be working correctly, I can’t figure out why.
#include <SimpleFOC.h>
// Stepper motor instance
StepperMotor motor = StepperMotor(50);
// Stepper driver instance
StepperDriver4PWM driver = StepperDriver4PWM(10, 9, 6, 5, 11, 3);
// encoder instance
MagneticSensorI2C encoder = MagneticSensorI2C(AS5600_I2C);
// commander interface
Commander command = Commander(Serial);
void onMotor(char* cmd){ command.motor(&motor, cmd); }
void setup() {
// encoder initialiseren en linken
encoder.init();
motor.linkSensor(&encoder);
// choose FOC modulation
motor.foc_modulation = FOCModulationType::SpaceVectorPWM;
// power supply voltage [V]
driver.voltage_power_supply = 12;
driver.init();
// link the motor to the sensor
motor.linkDriver(&driver);
// set control loop type to be used
motor.controller = MotionControlType::angle;
// controller configuration based on the control type
motor.PID_velocity.P = 0.2;
motor.PID_velocity.I = 20;
motor.PID_velocity.D = 0;
// default voltage_power_supply
motor.voltage_limit = 12;
// velocity low pass filtering time constant
motor.LPF_velocity.Tf = 0.01;
// angle loop controller
motor.P_angle.P = 20;
// angle loop velocity limit
motor.velocity_limit = 50;
// use monitoring with serial for motor init
// monitoring port
Serial.begin(115200);
// comment out if not needed
motor.useMonitoring(Serial);
// initialise motor
motor.init();
// align encoder and start FOC
motor.initFOC();
// set the initial target value
motor.target = 2;
// define the motor id
command.add('M', onMotor, "motor");
// Run user commands to configure and the motor (find the full command list in docs.simplefoc.com)
Serial.println(F("Motor commands sketch | Initial motion control > torque/voltage : target 2V."));
_delay(1000);
}
void loop() {
// iterative setting FOC phase voltage
motor.loopFOC();
// iterative function setting the outter loop target
// velocity, position or voltage
// if tatget not set in parameter uses motor.target variable
motor.move();
// user communication
command.run();
}
Thanks in advance.
Carelsbergh Stijn