Alignment failure

Hello guys!

I have a problem with the sensor allignment, because it always fails even though I have the right amount of polepairs.

This is my current code:

#include <SimpleFOC.h>
int U_EN = 18;   // inhu
int V_EN = 5;  // inhv
int W_EN = 17;  // inhw
float target_velocity = 0;
 // Motor instance
BLDCMotor motor = BLDCMotor(1);
// driver instance
BLDCDriver3PWM driver = BLDCDriver3PWM(16, 4, 32);

HallSensor sensor = HallSensor(25, 26, 27, 1);
// Interrupt routine initialization
// channel A, B and C callbacks
void doA(){sensor.handleA();}
void doB(){sensor.handleB();}
void doC(){sensor.handleC();}
// instantiate the commander
Commander command = Commander(Serial);
void doTarget(char* cmd) { command.scalar(&target_velocity, cmd); }

void setup() {
  pinMode(U_EN, OUTPUT);
  pinMode(V_EN, OUTPUT);
  pinMode(W_EN, OUTPUT);
  digitalWrite(U_EN, HIGH);
  digitalWrite(V_EN, HIGH);
  digitalWrite(W_EN, HIGH);
  Serial.begin(115200);
  
  SimpleFOCDebug::enable(&Serial);
  
  // initialize sensor hardware
  sensor.init();
  // hardware interrupt enable
  //sensor.enableInterrupts(doA, doB, doC);

  // link the motor and the sensor
  motor.linkSensor(&sensor);

  // driver config
  // power supply voltage [V]
  driver.voltage_power_supply = 12;
  // driver init
  if(!driver.init()){
    Serial.println("Driver init failed!");
    return;
  }
  // link driver
  motor.linkDriver(&driver);

  // set motion control loop to be used
  motor.controller = MotionControlType::velocity;

  // aligning voltage [V]
  motor.voltage_sensor_align = 1;

  // contoller configuration
  // default parameters in defaults.h

  // velocity PI controller parameters
  motor.PID_velocity.P = 0.1f;
  motor.PID_velocity.I = 0.1f;
  motor.PID_velocity.D = 0;
  // default voltage_power_supply
  motor.voltage_limit = 12;
  
  // default value is 300 volts per sec  ~ 0.3V per millisecond
  motor.PID_velocity.output_ramp = 300;

  // velocity low pass filtering time constant
  motor.LPF_velocity.Tf = 0.1f;

  // comment out if not needed
  motor.useMonitoring(Serial);

  // initialize motor
  motor.init();
  // align sensor and start FOC
  motor.initFOC();

  // add target command T
  command.add('T', doTarget, "target voltage");

  Serial.println(F("Motor ready."));
  Serial.println(F("Set the target velocity using serial terminal:"));
  _delay(1000);
}


void loop() {
  // main FOC algorithm function
  // the faster you run this function the better
  // Arduino UNO loop  ~1kHz
  // Bluepill loop ~10kHz
  motor.loopFOC();

  // Motion control function
  // velocity, position or voltage (defined in motor.controller)
  // this function can be run at much lower frequency than loopFOC() function
  // You can also use motor.move() and set the motor.target in the code
  motor.move(target_velocity);

  // function intended to be used with serial plotter to monitor motor variables
  // significantly slowing the execution down!!!!
  // motor.monitor();

  // user communication
  command.run();
}

Thanks for your help!

I am using 10kOhm resistors and the motor is moving during the alignment process but the amount of polepairs is always wrong

I already checked the output signals from the hall sensors and everything is working fine. Still i get this output when I start my code:

MOT: Align sensor.
MOT: sensor_direction==CW
MOT: PP check: fail - estimated pp: 1.20
MOT: Zero elec. angle: 3.14
MOT: No current sense.
MOT: Ready.
Motor ready.
Set the target velocity using serial terminal:

The problem I face is that after the initialization the motor isn’t spinning it’s twiching

If somebody knows the solution to my problem please inform me

Kind regards

Leon

Hi @leon1,

I think most likely your problem is that 1PP motors are a special case that don’t work well with our alignment.

Generally speaking the very low pole pair motors will move a lot (large angle) when we snap them to the zero angle position. Because they only have one zero angle in the full revolution of the motor, the travel during alignment can be very large, the motor gets very fast, and then its own inertia carries it far past the zero position, and then back, and past the other way, etc, in an oscillation around the correct position.

If the position is sampled while the motor is still moving you’ll get an incorrect zero, failed PP check, and subsequent bad performance.

you can try to manually tune the zero position, by setting motor.zero_electrical_angle to different values (0-2PI) and checking the result.

You can try to modify the alignment procedure, for example by increasing the delay for it to wait to settle…

Perhaps you can also share a video of the alignment in action so we can see how it’s looking…

Thank you very much for your response!

I found a different solution for my problem.

I implemented following line in my code

motor.sensor_direction = Direction::CW;

Now the motor is working fine

1 Like