Different rotation speed

when rotating clockwise, the engine runs gently. When I enter a negative number, the engine rotates in the opposite direction, but the rotation speed is lower and there is noise and vibration. What could be the reason?

Hey @nikolaewich1988,

This is a alignement issue probably.
What is your setup?
Black or stepper?
Which sensor which MCU?

#include <SimpleFOC.h>
int S;
// BLDC motor & driver instance
BLDCMotor motor= BLDCMotor(15);
BLDCDriver3PWM driver= BLDCDriver3PWM(9, 10, 11, 8);
// Stepper motor & driver instance
//StepperMotor motor = StepperMotor(50);
//StepperDriver4PWM driver = StepperDriver4PWM(9, 5, 10, 6, 8);
// encoder instance
Encoder encoder= Encoder(2, 3, 600);
// Interrupt routine intialisation
// channel A and B callbacks
void doA()
{
encoder.handleA();
}
void doB()
{
encoder.handleB();
}
// commander interface
Commander command= Commander(Serial);
void onMotor(char* cmd)
{
command.motor(&motor, cmd);
}
struct _poligonInexes
{
int minIndex;
int maxIndex;
}
;
int _Poligon_InArray_2[4] = {0, 12, 22, 1000};
int _Poligon_OutArray_2[4] = {0, 0, -3, -7};
int _Poligon_InArray_3[4] = {0, 12, 22, 1000};
int _Poligon_OutArray_3[4] = {0, 0, 3, 7};
int _gtv2;
void setup()
{
// initialize encoder sensor hardware
encoder.init();
encoder.enableInterrupts(doA, doB);
// link the motor to the sensor
motor.linkSensor(&encoder);
// driver config
// power supply voltage [V]
driver.voltage_power_supply = 24;
driver.init();
// link driver
motor.linkDriver(&driver);
// choose FOC modulation
motor.foc_modulation = FOCModulationType::SpaceVectorPWM;
// set control loop type to be used
motor.controller = MotionControlType::torque;
// contoller configuration based on the controll type
motor.PID_velocity.P = 0.1f;
motor.PID_velocity.I = 6;
motor.PID_velocity.D = 0;
// default voltage_power_supply
motor.voltage_limit = 8;
// velocity low pass filtering time constant
motor.LPF_velocity.Tf = 0.01f;
// angle loop controller
motor.P_angle.P = 20;
// angle loop velocity limit
motor.velocity_limit = 50;
// initialise motor
motor.init();
// align encoder and start FOC
motor.initFOC();
// set the inital target value
motor.target = 2;
}
void loop()
{
//Плата:2
S = _gtv2;
// 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(S);
// user communication
command.run();
if (!(((analogRead (0))) > (20)))
{
_gtv2 = (_poligon(((analogRead (1))), _Poligon_InArray_3, _Poligon_OutArray_3, 4));
}
if (!(((analogRead (1))) > (20)))
{
_gtv2 = (_poligon(((analogRead (0))), _Poligon_InArray_2, _Poligon_OutArray_2, 4));
}
}
int _poligon(int value, int intArray[], int outArray[], int arraySize)
{
struct _poligonInexes indexes;
indexes = _getPoligonIndexes(value, intArray, arraySize);
return map(value, intArray[indexes.minIndex], intArray[indexes.maxIndex], outArray[indexes.minIndex], outArray[indexes.maxIndex]);
}
struct _poligonInexes _getPoligonIndexes(int value, int array[], int arraySize)
{
struct _poligonInexes result;
int i;
result.minIndex = 0;
result.maxIndex = 0;
for (i = 0; i < arraySize; i++)
{
if (array [result.minIndex] > array[i])
{
result.minIndex = i;
}
if (array [result.maxIndex] < array[i])
{
result.maxIndex = i;
}
}
for (i = 0; i < arraySize; i++)
{
if ((array [i] >= value) && (array [result.maxIndex] > array[i]))
{
result.maxIndex = i;
}
}
if (result.maxIndex==0)
{
result.minIndex = 0;
result.maxIndex=1;
}
else
{
result.minIndex = result.maxIndex -1;
}
return result;
return result;
}

Calibration gave me non-accurate electric zero, if you repeat the search for the electrical zero, do you always find the same value?
I had the same issue. I solved it by manually changing the electric zero by the function motor.initFOC( zero electric,Direction::CW); and skiping the calibration. By trial and error and watching the power supply current in both directions you can find the good angle for same speed in both direction and same current consumed. You can do a first automatic calibration to help you know what value to start from . It was not a problem of mechanical or motor misalignment (full homemade) because with a Mjbot moteus card and the same magnet, my actuator works perfectly.
This does not explain the source of the issue.

Good afternoon. I use Google translator, so maybe my explanation will look strange. I use a motor from a gyro scooter and an encoder 600 pp. I am faced with the problem that the engine rotates clockwise quickly and gently, but counterclockwise it happens slowly and with noise. If I swap the phase wires of the encoder in places, then everything happens the other way around, the motor rotates clockwise slowly and noisily, and counterclockwise quickly and quietly. It seems to me there is an error in the calibration algorithm

Good afternoon. I use Google translator, so maybe my explanation will look strange. I use a motor from a gyro scooter and an encoder 600 pp. I am faced with the problem that the engine rotates clockwise quickly and gently, but counterclockwise it happens slowly and with noise. If I swap the phase wires of the encoder in places, then everything happens the other way around, the motor rotates clockwise slowly and noisily, and counterclockwise quickly and quietly. It seems to me there is an error in the calibration algorithm.

I have the same problem. Is it possible to set electric zero values for the direction of rotation? I now tried to rotate the encoder housing while the engine was rotating and got a good result. But unfortunately, when the motor rotates in the opposite direction, I need to rotate the encoder housing too