Position/angle control problem

Hi everyone!
I’m trying to run Position/angle motion control example from simpleFOC (Github).

With:

  • Arduino Uno R3
  • simpleFOC shield
  • T-motor 36-1 gimbal type - 50kv - 12N14P - internal resistance 15.6
  • 20v power supply
  • Simple_FOC library
  • PciManager library
  • pin assigment (9,10,11,8)
  • amt103v (2,3,1024,4) - resolution PPR - 1024 (0010)

But the result is the motor moves just a litle bit when i set the target angle (e.g. 10) using serial terminal and when i set again 10 and gets stuck (and hot).
Any idea what it might be?

MOT: Monitor enabled!
MOT: Initialise variables.
MOT: Enable driver.
MOT: Align sensor.
MOT: Sensor failed to notice movement
MOT: Absolute zero align.
MOT: Success!
MOT: Motor ready.
Motor ready.
Set the target angle using serial terminal:
Target angle: 10.00
Target angle: 10.00
#include <SimpleFOC.h>
#include <PciManager.h>
#include <PciListenerImp.h>
BLDCMotor motor = BLDCMotor(7);
BLDCDriver3PWM driver = BLDCDriver3PWM(9, 10, 11, 8);
Encoder encoder = Encoder(2, 3, 1024, 4);
void doA(){encoder.handleA();}
void doB(){encoder.handleB();}
void doIndex(){encoder.handleIndex();}
PciListenerImp listenerIndex(encoder.index_pin, doIndex);
void setup() {
encoder.init();
encoder.enableInterrupts(doA, doB)
PciManager.registerListener(&listenerIndex);
motor.linkSensor(&encoder);
driver.voltage_power_supply = 20;
driver.init();
motor.linkDriver(&driver);
motor.voltage_sensor_align = 3;
motor.velocity_index_search = 3;
motor.controller = ControlType::angle;
motor.PID_velocity.P = 0.2;
motor.PID_velocity.I = 20;
motor.PID_velocity.D = 0;
motor.voltage_limit = 6;
motor.PID_velocity.output_ramp = 1000;
[motor.LPF_velocity.Tf](http://motor.lpf_velocity.tf/) = 0.01;
motor.P_angle.P = 20;
motor.velocity_limit = 4;
Serial.begin(9600);
motor.useMonitoring(Serial);
motor.init();
motor.initFOC();
Serial.println("Motor ready.");
Serial.println("Set the target angle using serial terminal:");
_delay(1000);
}

Thanks,
Nuno

Hey @Nuno,

You have a very nice set-up right there :slight_smile:

Try adding on the void loop this:

motor.monitor();

and share with us the log, maybe the encoder is not working properly.

Have you been through all the simpler modes first

  1. run encoder on its own. Check 360 rotation = 2PI
  2. Run velocity_openloop
  3. Run voltage mode
  4. Run velocity mode
  5. Run angle mode
    If you can get to 3 (which proves sensor alignment is good). Then the rest is simply PID and Tf tuning.

If your motor or driver is getting hot, then reduce voltage limit to 1.5V whilst in this test phase.

Hey David,

MOT: Initialise variables.
MOT: Enable driver.
MOT: Align sensor.
MOT: natural_direction==CW
MOT: Absolute zero align.
MOT: Searching…
MOT: Error: Not found!
MOT: Not available!
MOT: Motor ready.
Motor ready.
Set the target angle using serial terminal:
Target angle: 10.00
-6.00 0.00 6.44
Target angle: 20.00
6.00 10.00 6.44
Target angle: 20.00
6.00 20.00 6.44
Target angle: 30.00
6.00 20.00 6.44
Target angle: 30.00
6.00 30.00 6.44
Target angle: 40.00
6.00 30.00 6.44
Target angle: 40.00
6.00 40.00 6.44

In openloop is ok, velocity and position. But when I try to run it with encoder code (index search loop) the result is
MOT: Initialise variables.
MOT: Enable driver.
MOT: Align sensor.
MOT: natural_direction==CW
MOT: Absolute zero align.
MOT: Searching…

nothing happens besides the motor getting hot…

If your sensor has a PWM output and you have an oscilloscope or some logic analyzer at hand, you can see if it is working correctly or if, despite being properly powered, there is a mechanical problem.

Sometimes the magnet is not close enough to the sensor or the attached magnet does not have the proper diametrical polarization.

@JorgeMaker - he is using an encoder. No magnets involved! Just interrupts. Although logic analyser on the interrupts would be a good idea!

Alternatively can you put some Serial.prints in doA() doB() and doIndex() to see what’s happening? It’s not normally advisable to put ‘expensive’ Serial prints in interrupts but should be ok for a bit of debugging.

The simplefoc example uses pin A0 for index. I wonder if PciManager likes analog pins?