Arduino FOC BLDC brushless motor haptic interface driver
HTML-код
- Опубликовано: 10 сен 2024
- Instructions to make your own Brushless Motor Power stage controller available for my patrons:
/ randomaccessprojects
Code libraries available for my patrons:
/ randomaccessprojects
A BLDC motor is controlled with an Arduino in different modes, emulating a knob that can behave as spring loaded with different elastic modulus, have different setpoints, torque feedback to resemble notches/mechanical positions, and behave as a boat forward/stop/reverse control lever.
First step, open loop control.
Here you will connect your BLDC and activate a routine that energizes all three coils (A, B and C) with a sinusoidal wave, this wave is generated using PWM on all 3 ports that connect to the coils through your power driver (L6234 or equivalent power stage). The sinusoidal wave will be generated for all 3 coils with 120° phase offset between coils. This should be done at a low frequency (sine frequency around 1Hz or lower). The motor should start continuously rotating at a slow speed. Now you can read the sensor output and see that for every complete shaft revolution, an integer number of complete cycles will occur for each coil. Each complete cycle of a sine wave will be called an “electrical revolution”, and if your motor had 1 electrical revolution, it would be said to have 1 pole (1 electrical revolution per shaft revolution), in reality, your BLDC will have more than 1 pole, for example: 7 or 11 ,21, etc. Let’s assume our motor has 11 poles, this means that to complete a shaft revolution, we must perform 11 electrical revolutions, or 11 complete sinusoidal cycles to the coils.
Second step, synchronizing the closed-loop control with no rotation.
The second step is closed loop control which means that you will take the position of the shaft (measured with the sensor) and apply power to each of the 3 coils. The amount of power to each coil will relate to the sinusoidal chart for the given position of the shaft, you will energize the 3 coils, so they want to be in the exact same position where you have it… at this point the motor will not rotate, but also, it will feel “free” to rotate, as for each of the positions you put the shaft on, the Arduino will generate the exact amount of voltage for all 3 coils to keep the shaft where it is. If you succeed at synchronizing the shaft positions to the electrical positions, then the phase between the magnetic field being applied to the rotor and the shaft encoder position will be said to be 0°.
Third step, making the shaft rotate by adding offset to the encoder reading.
Third step is to add a little bit of offset to the measurement of the encoder, this will “trick” the Arduino into believing the shaft is in a certain position when in reality it is a little bit behind… therefore the magnetic field generated for that position, will actually be a bit “ahead”, and this will make the shaft rotate as the magnets try to get in phase with the “leading” magnetic field being generated.
Given that the field is being generated by adding an “offset” to the reading of the sensor, the rotor will never be able to successfully reach that “leading field”, just as a donkey can never reach the carrot dangling in front from a stick attached to the donkeys head. The rotation can be regulated in terms of “torque”, this is done by varying the amount of offset that is used. Using the donkey analogy: if the carrot is very close to the donkeys mouth, the donkey slows down (the torque is less), but if the carrot is far away, the donkey will try harder to pursue and run, (more torque). In practice, we cannot put the “carrot” too far away, otherwise the field will lose strength, and also, it may cause the next donkey ahead (each donkey is a pole?) to smell the carrot and try to catch it by walking backwards. (hope this is clear! If the field is sent too far away from one coil, it will actually reach the next coil and the motor will try to rotate backwards.
90° of an electrical revolution is what should bring the optimal torque.
Proportional position control.
When trying to make a position control loop, the Error (difference between actual position and desired position) is used to feed the controller. We take the error and use it as the offset needed to drive the motor, but we limit the value to never be larger than +/- 90°. This way, when the error is very small (rotor almost at the desired position) the offset will be small, bringing the torque down, and slowing down the shaft as its almost where it should be… as the error increases, so does the offset, and therefore the torque, making the shaft rotate at max speed with max torque. The motor will rotate at maximum speed until the error starts decreasing, at this point the offset will proportionally be reduced and the desired position achieved. When the error is negative, then the offset will be negative, thus the motor will rotate backwards