Force feedback controller control loop problem

Hi, I’m trying to build an FFB controller using two large NEMA 23 steppers linked to a controller stick.
I want to use the two motors axis like spings, tunable on the go, to crate vibrations and different forces on the stick during the usage.
I’m trying with only one axis now, my setup is a teensy 3.6 board, for position control a AH503 hall effect( i am using only 1-1.5 rad, so only one is in the linear zone) a L296N board.
My problem is choosing the right control method: I’ve tried with no success angle loop, but it can’t hold my desired angle, torque control also does not provide constant torque, is my driver bad?
The angle reading at 16 BIT with averaging seems very precise and reliable.
If needed i can post the code but is a copy and paste of what I’ve found the examples.
Thanks for the help!

Hi, and welcome @Xarin94 ,

What do you mean by this? Is the torque low, so that the force is weak, or is the position not holding at the value when you command a constant position? Could you post a video maybe of what is going on?

In general terms: L298N is not a great driver, it can work depending on the situation, but it is a bit inefficient… without knowing a bit more about what is going on I would not blame the driver yet though!

That means when i use torque mode, i expect the motor with no load to accelerate, ar at least with speed =/0, but nothing happens.
I can post a screenshot of my motor monitoring and my code.
In velocity mode and angle mode, the motor makes a normal startup, fails pp check, and don’t spin even in velocity mode.
motor monitoring
this is the code, i’m using a teensy 4.1(reading analog between 0-2024 for two rotations of the sensor):

#include <SimpleFOC.h>
MagneticSensorAnalog x = MagneticSensorAnalog(A0, 14, 2048); //zero a 4.60
StepperMotor motor = StepperMotor( 50 );
StepperDriver4PWM driver = StepperDriver4PWM(4, 3, 2, 1);

void setup()
{
analogReadAveraging(10);
Serial.begin(115200);
motor.useMonitoring(Serial);
motor.monitor_variables = _MON_TARGET | _MON_VEL | _MON_ANGLE;
motor.monitor_downsample = 100; // default 10
x.init();
motor.linkSensor(&x);
driver.voltage_power_supply = 20;
driver.init();
motor.linkDriver(&driver);
motor.foc_modulation = FOCModulationType::SinePWM;
motor.controller = MotionControlType::angle;

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

_delay(1000);
}

void loop()
{
motor.loopFOC();
motor.target = 2.34;
motor.move();
motor.monitor();
}

Found the problem, need better position sensing technique, the hall effect sensor must be tuned for the little range and used the correct value in MagneticSensorAnalog x = MagneticSensorAnalog(A0, 14, 2048);

1 Like

Oh, I am glad you found it! Is it working now?

I was going to ask about the Analog sensor and how well it works? It is not often used with SimpleFOC…

worked a bit better but not well, tried with as5600 but the same result, I suspect is the driver not very suitable,for a stepper motor what driver is good with a teensy for stepper?
thanks

The teensy is a very fast, very good MCU. It depends which one, but they are all pretty fast.

The AS5600 and the analog sensors are among the worst-performing sensors with SimpleFOC. They can work, but they don’t work as well as other models.

So you have a situation where you have a MCU like a Ferrari engine, but are using a driver and sensors like a Toyota Corolla… they don’t fit together, you won’t get the benefits of the fast MCU using these sensors and this driver.

Any FET-based driver will be better than the L298N. It is difficult right now due to components shortage, but keep looking in the SimpleFOC shop, and maybe in the meantime you can search for “SimpleFOC” on AliExpress…

When using the teensy, the loop normally runs very fast (although when using the I2C sensor this will slow it down). Sometimes it can be too fast - this can make the PIDs very hard to tune, and cause other problems, so if your loop is executing at more than 10000 iterations/second then maybe you can slow it down a bit (delayMicroseconds()).
Also the L298N may be more sensitive to the PWM speed due to its long switching times. Lowering the PWM frequency can help to reduce noise and heat, and also in some cases improve the motor performance.

Do you use SimpleFOCStudio? If you can install it and use it to connect to your motor the outputs it can show can help to find problems…

thanks for the valuable info, I’ll make improvements on my setup and keep it posted.
Do you have any idea of a suitable single or dual h bridge MOSFET based? I’m finding only ones with a dir input ad a pwm, not true l298 similar