SimpleFOC configuration parameters help

Hi everyone, got a SimpleFOC setup and configuration help request.

I am currently developing a CANBus-able board with a protocol which would ideally talk to the board using CAN.

The problem I am facing is that certain parameters or modes for SimpleFOC which are specific to a motor must be pre-compiled in the code, which makes the configuration rather difficult as each time I need to attach a different motor I need to rebuild the code. For example, number of pole pairs.

Is it possible that we set these parameters “on-the-fly” instead of in the code during build time?

My goal is to build the base code, attach a motor to each node and perform the entire setup via CANBus, such as setting the pole pairs, mode of operation, etc, somewhat similar to SimpleFOC GUI Configuration/ Tunning tool where a centralized MCU will communicate the node/motor setup before the action begins, and then fine-tune the motors individual parameters as they perform. I remember there was a similar thread on this board however it didn’t go anywhere.

I got my code to a point where the nodes talk to each other and I am now compiling a list of commands that the nodes can exchange, and some of them are the initialization commands.

It is also possible I am not quite familiar with some of the setup and what I want is already there and I only need to use it?

In other words, what init setup params currently CANNOT be set during code run-time on the fly?

Thanks,
Valentine

Edit:

To give you an idea what commands could look like

{ “TEST_COMMAND”,
“INFO_GENERAL”,
“WARNING_GENERAL”,
“ERROR_GENERAL”,
“STOP_MOTOR”,
“INIT_MOTOR”,
“ANGLE_TARGET”,
“VELOCITY_TARGET”,
“ACCELERATION_TARGET”,
“VOLTAGE_INIT”,
“VOLTAGE_MAX”,
“VOLTAGE_MIN”,
“CURRENT_MAX”,
“CURRENT_MIN”,
“TEMPERATURE_MOTOR”,
“TEMPERATURE_BOARD”,
“TEMPERATURE_AMBIENT”,
“MODE_FOCSINE”,
“MODE_FOCSPACEVECTOR”,
“MODE_FOCTRAP120”,
“MODE_FOCTRAP150”,
“MODE_OPENLOOP”,
“MODE_VELOCITY”,
“MODE_TORQUE”,
“MODE_CURRENT”,
“MODE_POLEPAIRS”,
“GET_ANGLE”,
“GET_VELOCITY”,
“GET_ACCELERATION”,
“GET_TOTALCURRENT”,
“GET_TEMPERATURE_MOTOR”,
“GET_TEMPERATURE_BOARD”,
“GET_TEMPERATURE_AMBIENT”}

The implementation is interrupt/mask driven so it won’t affect the loop performance as long as there is no message for that node.

Thats a great feature request, it also could be used, to set the supply voltage on the fly, so one can measure the voltage and if it’s changing up or down the voltage is matched in software.

1 Like

Hey @Valentine,

You’re absolutely right. Pole pair number is hard coded for now and we should definitely include it into the motor commands. If you have some other variables please let me know.

Also i was thinking that it would be good to be able to call initFOC() from the commander.
If something goes wrong with the calibration so that we can easily restart everything without the need for the hardware restart/power off.
Do you think it is a good idea?
Do you have some other situations where you’d need some other functionality?

Btw, you can already change the pole pair number in the code if necessary. It is saved in the motor.pole_pairs variable and you can easily add it to the commander. The same goes for the calling of the motor.initFOC() it can be added to the commander inside a simple callback.

@Antun_Skuric

Thank you, thats really good news. Based on what you are saying, I could build the code with hardcoded pole pairs of say 1,

BLDCMotor motor = BLDCMotor(1);

do not really start the motor, then perform an initialization step where I re-set the pole pairs to say 7

motor.pole_pairs = 7

then I start the motor?

Exactly, that was my thinking too, as I can say

STOP_MOTOR

then re-initialize the MCU with the different parameters such as

MODE_POLEPAIRS 11

MODE_OPENLOOP true

VOLTAGE_INIT 12

VOLTAGE_MAX 3

ANGLE_TARGET 0

and then

INIT_MOTOR

which will call initFOC() and re-set the initialization parameters inside the main loop using an interrupt.

then I can say

ANGLE_TARGET 1.5

which will mode the motor to angle 1.5

Please let me know if I am imagining things.

Thanks,
Valentine

Edit:

Question, what will happen now if I put the

  // init motor hardware
  motor.init();

in an interrupt based call and stop the motor, change the

motor.controller = MotionControlType::velocity_openloop;

and then call again the

// init motor hardware
motor.init();

Would it re-initialize with velocity_openloop from scratch?

I will of course test this later. If it works I could perhaps worm my way around.

The idea is the board to be completely transparently controlled outside, so not just the voltage but anything could be set without ever rebuilding the code, and ideally would could store the default parameters in NVRAM and read them on start. Also you could request board/motor parameters on an interrupt basis to check on the motor status and with an outside tool to read them and visualize them. I know, this is nothing new, cars have been doing this for decades.