Getting closer - Shield setup!

I have three FOC controllers ready to go. I purchased Three Emax GB4114-42kv motors and three of the AS5600 encoders from Ebay. If one searches Ebay the first few that come up on the square white proto board are what I have. I would like to ask for guidance in hooking up the encoder and configuring the SimpleFOC board (jumpers?). Also what is needed to make the software match this hardware setup.

Thank you !

Keshka

1 Like

Are you planning to have three separate unos attached to your 3 simplefoc boards?

Whilst it is possible to stack 2 boards (and use 1 uno) it limits your comms options with the sensor, you’ll be forced to use ‘analog’ rather than i2c as the as5600 has a fixed i2c address.

Yes, Owen. One Uno per simpleFOC board.

Sounds like you have a straightforward setup.
Read the docs, have a look at the examples in github. I’m sure you can work it out!

If you have some specific problems, then post back.

yup! digging and reading. I did not realize examples were included in the FOC libs for Arduino. On finding an example of code using the AS5600 many things became clear. On hookup the motor now has a high pitched whine and handing values to the serial interface using the “Angle Control” example results in movement. Just not quite the movement I would expect yet. Perhaps the pole count value in the script of 11 needs changed but to what? The Emax motor I am using does not list this information on their website.

Any ideas how to find this value?

HAH! …found this:

If you are not sure what your pole_paris number is. The library provides an example code to estimate your pole_paris number in the examples find_pole_pairs_number.ino .

off to the work bench!

1 Like

hmmm…
Pole pairs (PP) estimator

Estimated PP : 0
PP = Electrical angle / Encoder angle
1080.00/0.00 = inf

PP number cannot be negative

  • Try changing the search_voltage value or motor/sensor configuration.

then found out encoder configured wrong (I missed it in the pole pair program). So now upon getting accurate encoder counts I still did not have great luck. It returned 8, 12 and 14. Fourteen being the most common.

Problem is, even using numbers 6-16 to test, the motor will not make a complete revolution and position seems random.

I found this page: https://granitedevices.com/wiki/Determining_motor_pole_count. According to that test, motor has 22 poles. Am off to try that in the open loop example.

ok…stuck. I can not find any examples that will reliably rotate the motor. I have been working with the open loop example and various poll counts to no avail. I tried to write some code to let me try various poll counts but I am unsure if I did it correctly

clues: the motor will rotate about 90’ when I run the pole pair estimator but when it gets to the point in the program were the motor should run…just buzz, no rotation.

will this code work to change the poll count? IE, can driver.init and motor.init be called more than once in the code?
void restart_motor()
{
BLDCMotor motor = BLDCMotor(poll_count);
driver.init();
motor.linkDriver(&driver);

// init motor hardware
motor.init();
Serial.print("poll count: ");
Serial.println(poll_count);
}

ps. aux question. what is the recommended power on sequence? 12v motor power before or after arduino power via usb. I notice without the 12v the SimpleFOC board led lights dim and the motor seems to have some small amount of power via usb. Is that harmful?

would a video of the “find_pole_pairs_number” help?

obtw…if the ‘pole count’ derived from the above web site instructions is 22…should motor.pole_pairs be set to 11?

another test. I used the “open_loop_velocity_example”. With a value of 11 for pole count. The motor WILL rotate (finally!) up to a value of 17 or 18 but 20 is very jittery. With the pole count at 22 only about 10 results in stable rotation. (negative values result in rotation the opposite direction)

I just found “full_control_serial”…uh, I have NO idea the effect of those parameters on the SimpleFOC controller. 10+ variables. Is there a page that gives some sort of instructions for this? I see this page: https://docs.simplefoc.com/communication but nothing that might indicate what affect something like “P gain” will have on making my motors work. A “motor tuning” page would help.

does this look familiar?


For small, low torque motors with little or no gearing, one procedure you can use to get a good baseline tune is to probe it’s response to a disturbance.

To tune a PID use the following steps:

  1. Set all gains to zero.
  2. Increase the P gain until the response to a disturbance is steady oscillation.
  3. Increase the D gain until the the oscillations go away (i.e. it’s critically damped).
  4. Repeat steps 2 and 3 until increasing the D gain does not stop the oscillations.
  5. Set P and D to the last stable values.
  6. Increase the I gain until it brings you to the setpoint with the number of oscillations desired (normally zero but a quicker response can be had if you don’t mind a couple oscillations of overshoot)

What disturbance you use depends on the mechanism the controller is attached to. Normally moving the mechanism by hand away from the setpoint and letting go is enough. If the oscillations grow bigger and bigger then you need to reduce the P gain.

If you set the D gain too high the system will begin to chatter (vibrate at a higher frequency than the P gain oscillations). If this happens, reduce the D gain until it stops.


…still don’t know what to do with:

    • R: velocity PID controller voltage ramp
    • F: velocity Low pass filter time constant
    • K: angle P controller P gain
    • N: angle P controller velocity limit

Hey @Keshka,

I like how detail oriented you are. And you are making progress!

If your motor is not really moving smoothly in the voltage control mode then you still have a problem of either pole pair count or the sensor. We have discussed few time recently the situations where the as5600 are shipped with wrong magnets. Are your magnets polarized axially or radially? They should be polarized radially. Here is a recent thread https://community.simplefoc.com/t/drv8302-tarot-motor-control-type-voltage-magnet-polarization-problem/401/17

Now in terms of PID, once when everything works i don’t think you’ll have many problems running it. Your guide from the post before will work well.
Simplefoc has some docs in the motion control here is the link:
https://docs.simplefoc.com/velocity_loop

22 poles means 22 magnets on the rotor. You might be able to count them. The magnets are arranged N S N S etc so if you have 22 poles then you have 11 pole pairs. A pole pair defines an electrical rotation so an 11 pole pair motor undergoes 11 electrical rotations per shaft rotation.

Antun,
I believe my sensor is working correctly, using “magnetic_sensor_12c_example” shows stable readings for both pos and rate. Values for pos are 0 to roughly 6.2 for one revolution. Rotating in the opposite direction yields -6.2.

if I concentrate on the “open_loop_velocity_example”. The sensor/encoder is not used. It should be able to produce smooth rotation up to the theoretical max rpm of the motor (42kv * 12v). Is this correct?

Owen,
for pole count. Using the test I mentioned above, with a small voltage applied to one pair of motor wires, rotating the motor gives 11 distinct ‘notches’. As I understand it, that would be 22 poles or 11 pole pairs.

I ran this modified version of “open_loop_velocity_example” and experimented with various pole counts. The motor will run with values of 1 through 17 with the speed increasing with greater pole counts. Above 17 and the motor shakes. Hence, I should be able to use a value of 11 from the earlier tests.

[quote="program"]

// Open loop motor control example
#include <SimpleFOC.h>

// BLDC motor & driver instance
BLDCMotor motor = BLDCMotor(11);
BLDCDriver3PWM driver = BLDCDriver3PWM(9, 5, 6, 8);

void setup() {

driver.voltage_power_supply = 12;
driver.init();
motor.linkDriver(&driver);
motor.voltage_limit = 3; // rad/s
motor.velocity_limit = 20; // rad/s
motor.controller = ControlType::velocity_openloop;
motor.init();

Serial.begin(57600);
Serial.println(“Motor ready!”);
_delay(1000);
}

float target_velocity = 13; // rad/s should be about 2 rotations per second
int pole_pair = 11; // start value

void loop() {
motor.move(target_velocity);
serialReceiveUserCommand();
}

void serialReceiveUserCommand() {

static String received_chars;

while (Serial.available()) {
char inChar = (char)Serial.read();
received_chars += inChar;
if (inChar == ‘\n’) {

  // change the motor poles
  pole_pair = received_chars.toInt();
  Serial.print("pole pair ");
  Serial.println(pole_pair);
  
  // reset the command buffer 
  received_chars = "";
  motor.move(0);
  motor.pole_pairs = pole_pair;
  motor.init();
}

}
}
[/quote]

ugh! I did not understand the “nomenclature”
“Framework:…24N22P”
says 24 coils and 22 magnets.
IE …11 pole pairs.

another note. This motor I have will oscillate badly at voltages higher than 2 with the default pids while sitting on my desk. There for I need to have it anchored down to tune it further.

Hi Keshka,

Is it working for you? I have the 4114 - it has 11 Pole Pairs as you correctly found out.

It works fairly well for me with the default example settings. I don’t need to tune it to get decent commutation at 10V. This is true for different drivers.

Which MCU are you using? SAMD (Arduino MRK and others) is not yet supported. An Arduino Uno in combination with an I2C sensor might be a bit slow for really nice commutation, depending on how much other stuff you’re doing in the main loop…

If open loop is working but closed loop is not, then there is a high probability that it is a sensor problem. Is the I2C address set correctly? Are the I2C pull-ups installed? Is your magnet the right kind - i.e. radially magnetised?

:slight_smile: even if it is not oscillating it needs to be fixed - when changing direction or stopping it moves a lot otherwise. Its quite a heavy beast for a gimbal motor.