Saving hall sensor positions

I am trying to use simple foc for a wheeeled rover but the initalisation it does on startup is a problem. is there a simple way to detect the hall sensor values then write them into the code?

5 Answers

5

Hey @geofrancis,

You can skip the direction check (the part of the init when the motor moves) if you provide the motor with the sensor direction. And the init should be a bit more repetitive if you use the hall sensor without interrupts.

// set the direction
motor.sensor_direction = Direction::CW; // CW or CCW
// then call initFOC()
motor.initFOC();

I have done this but the motors still move a little on startup and if its held still the wheels start turning the wrong way etc. i can only get it to initialize with the wheels off the ground.

You have probably set voltage_align too low. Or the motor moves to angle=0 after init, because it is preset in your program.

I am using hall sensors I dont see why it needs to move. its only very slighly i just thought it was from it switching on but if the wheels cant move that tiny amount they can end up turning the wrong way.

OK I have found this, it looks like a way to save the settings to non volatile memory, but not on esp32, would it be possible to do the detection then just hard code the settings rather than using volitile memory?

I was looking at this,

and i found this

motor.zero_electric_angle NOT SET Needed for FOC control. Normally set during motor FOC initialization. If set before motor.initFOC(), measurement of zero electric angle is skipped during alignment.
motor.sensor_direction NOT SET Normally set during motor FOC initialization. Determines sensor direction vs positive motor direction (can be opposite, depending how you connect your motor cables). If set before motor.initFOC(), measurement of sensor’s natural direction is skipped during alignment.

I have motor.sensor_direction = Direction::CCW; so is the remaining movement the motor.zero_electric_angle being detected? if i set that then all movement should stop as far as i can find.



  //commect out for auto detect

motor1.sensor_direction = Direction::CCW;  // CW or CCW

motor1.zero_electric_angle = 4.19;

this looks to have fixed my issue, i just got the zero angle when its being detected then set it to be used on startup and no more movement.