Hi folks !! Hapy new year !!
After some months keeping my SimpleFoc project on the project stack, I decided too try again and
restart again with a new configuration, back to the basics. So i’ve been working on a new setup using the following:
- MCU: Arduino Mega 2560 REV3
- Motor: GM5208-12 [15Ω Phase resistance, Config: 12N14P]
- Driver: SimpleFocShield 1.3.3
- Magnetic Sensor: AS5048A (SPI interface)
- IDE: PlatformIO
My code is:
#include <SimpleFOC.h>
#define MOSI_ENC 51 // Blue
#define MISO_ENC 50 // Green
#define CLK_ENC 52 // Orange
#define CS_ENC 53 // Yellow
#define INH_A 12
#define INH_B 11
#define INH_C 10
#define ENA_GATE 8
// motor instance
BLDCMotor motor = BLDCMotor(7);
BLDCDriver3PWM driver = BLDCDriver3PWM(INH_A, INH_B, INH_C, ENA_GATE);
MagneticSensorSPIConfig_s AS5047A_SPI_Config{
.spi_mode = SPI_MODE1,
.clock_speed = 10000000,
.bit_resolution = 14,
.angle_register = 0x3FFF,
.data_start_bit = 13,
.command_rw_bit = 14,
.command_parity_bit = 15};
MagneticSensorSPI sensor = MagneticSensorSPI(AS5047A_SPI_Config, CS_ENC);
// instantiate the commander
Commander commander = Commander(Serial);
void doMotor(char *cmd) {
commander.motor(&motor, cmd);
}
void setup(){
// use monitoring with serial
Serial.begin(115200);
motor.useMonitoring(Serial);
Serial.println("Starting Motor configuration ....");
// initialize magnetic sensor hardware
sensor.init();
// link the motor to the sensor
motor.linkSensor(&sensor);
// driver config
driver.init();
motor.linkDriver(&driver);
driver.voltage_power_supply = 20;
// set motion control loop to be used
motor.controller = MotionControlType::velocity_openloop;
motor.foc_modulation = FOCModulationType::SpaceVectorPWM;
// set control loop type to be used
// contoller configuration based on the control type
motor.PID_velocity.P = 0.2;
motor.PID_velocity.I = 20;
motor.PID_velocity.D = 0;
motor.LPF_velocity.Tf = 0.2;
motor.P_angle.P = 20;
// angle loop velocity limit
motor.velocity_limit = 10;
motor.voltage_limit = 20;
// initialize motor
motor.init();
motor.initFOC();
commander.add('M', doMotor, "my motor");
Serial.println("Motor ready.");
_delay(1000);
motor.target = 10;
}
void loop(){
motor.loopFOC();
motor.move();
commander.run();
motor.monitor();
}
This is my Platformio.ini:
[env:megaatmega2560]
platform = atmelavr
board = megaatmega2560
framework = arduino
monitor_speed = 115200
lib_deps =
askuric/Simple FOC@^2.2.3
Wire
SPI
When I test the magnetic sensor in isolation the readings seem perfect adding 2 Pi each turn I give to the motor shaft and without any noise.
This is the output after initialization with the full sketch:
MOT: Monitor enabled!
Starting Motor configuration ....
MOT: Init
MOT: Enable driver.
MOT: Align sensor.
MOT: sensor_direction==CCW
MOT: PP check: OK!
MOT: Zero elec. angle: 4.18
MOT: No current sense.
MOT: Ready.
Motor ready.
10.0000 12.0000 10.0000 6.0935
10.0000 12.0000 10.0000 0.8449
10.0000 12.0000 10.0000 1.8829
10.0000 12.0000 10.0000 2.9200
10.0000 12.0000 10.0000 3.9554
10.0000 12.0000 10.0000 4.9930
My setup works perfectly, very smoothly both in OpenLoopVelocity mode and in
OpenLoopPosition mode.
However, when I change to OpenLoopVelocity and OpenLoopAngle,… things get weird
Some times simple stop moving quietly and other times starts slightly vibrating without moving. This is what is shown after executing the MC1 to change to Closed Loop Velocity:
20.0000 12.0000 20.0000 0.4662
20.0000 12.0000 20.0000 2.5351
Warn: \r detected!
Motion:vel
20.0000 12.0000 13.9292 2347.0766
20.0000 12.0000 7.2132 2347.0405
20.0000 12.0000 3.7746 2347.0385
20.0000 12.0000 1.9817 2347.0397
- Does anyone know where the problem could be or give some indication of how to solve it or continue investigation eje root of the problem?
- Could it be due to the tuning of the coefficients of the PIDs?
- Any clues to figure out where the problem might be?
Any suggestion is welcome