In a lot of applications it’s important to control precisely the positioning of an electrical Motor, like in lots of Robots, 3D printers, CNC machines and so on, and to make that happen there are numerous methods including using external sensors mounted on the Motors known as Encoders or position sensors.
There are various types of encoders like Incremental Encoders , Absolute Encoders , etc, but in this article we are going to discuss how you can control precisely the position of a Brushless motor of almost any kind ( BLDC, PMSM or coreless EC brushless ) with the identical method using SOLO in SOLO Motion Terminal.
However, you can use any other module or controller that has USB, UART or CAN bus line to send the control commands similar to what is going to be done in Motion Terminal using SOLO’s digital control protocol or if you use Arduino or Raspberry Pi or similar modules, you can use our libraries written in C and Python languages:
C library for Arduino:
Python library for Raspberry Pi:
To proceed on with this article we will go step by step as below to discuss all the required actions to be done.
1. Apply the Wirings and Calibrate your Encoder
As we are going to control SOLO with Motion Terminal, we just need to connect the USB port of SOLO to a computer and run the Motion Terminal similar to Figure 1 below:
Figure 1 – Required wirings for doing Position Control using Encoders in Digital Mode using USB
Basically you need to connect the 3 wires of the Motor to ABC output of SOLO plus proper wirings of the Encoder signals to the encoder inputs of the SOLO. The order of wiring of the Motor and the Encoder should be done as explained in this article.
2. Do the System Configurations
In Motion terminal you need to select proper settings for each of the following parameters:
1. PWM or Switching frequency: This is the output switching frequency of SOLO on the Motor, as a rule of thumb, the lower the Motor’s inductance the higher should be the switching frequency, you can either leave this parameter on its default value or you can change it to anything from 8kHz to 80kHz with steps of 1kHz based on your need.
2. Encoder Lines: this is the physical encoder lines engraved mechanically on the disk of your Motor’s encoder, they are also known as Encoder Slits. You need to properly set this value so that SOLO can control your motor precisely.
3. Motor Type: Make sure you are selecting either of the “BLDC-PMSM” or “BLDC-PMSM ultrafast” as they represent brushless motors for SOLO. if the Nominal speed of your Motor is below 8000 RPM, you can go for the first type, but if it’s higher than that, you can select the “BLDC_PMSM ultrafast” version.
Current Limit: This will be the maximum amount of current that SOLO will allow into your motor, so you need to make sure this value is within the nominal current rating of your Motor.
4. Number of Poles: for 3-phase motors and specifically brushless motors, this parameter should be set based on the mechanical design of the Motor, so in general on Brushless motors the number of Poles can be derived from the number of magnets used on the Rotor of the Motor. Please keep in mind that: Number of Poles = Number of Pole pairs * 2
3. Put SOLO in Closed Loop Mode
Figure 2 – Closed-loop configuration of SOLO using Pin Number 5 of the Piano Switch
NOTE: If you want to use SOLO in analogue Mode , you need to select the Motor Type and the Control Type using the Piano switch, but since in this tutorial we are puting SOLO in digital Mode, the only thing that needed to be set at hardware level will be Pin Number 5 of the Piano switch which defines for us whether we want to stay in Open-Loop or Closed-Loop.
4. Identify your Motor Parameters
Now you need to run the “Motor Identification”, after this step SOLO will automatically tune the Torque controller Gains as also explained in the video above.
5. Calibrate Your Encoder
After you properly wire up the Motor wires’ and the Encoder, you need to calibrate the encoder, by just pressing the “Encoder Calibration ” button in Motion Terminal, after the calibration is done, the offset values for Encoder will be stored in long term memory of SOLO, to learn more about this crucial step please read this article.
6. Go to “Digital Mode”
Since in this tutorial we are sending all the commands digitally through USB, you need to put SOLO in Digital Mode by selecting it from the “Command Mode” section in Motion Terminal. In Digital Mode all the commands are sent through data packets.
SOLO operates in two independante modes of Digital or Analogue Mode, meaning that once you are in Analog mode, the references for Speed and Torque, The Motor Type Selection, Direction of rotation and the Torque or Speed control type are commanded and selected at hardware level by Analogue inputs ( S/T, P/F , DIR) or the Piano switch as well as Kp an Ki potentiometers for Speed controller , and they have priority over Digital commands of the same nature as long as you are in Analogue Mode.
Another point is as long as you are in Analogue Mode the commands with same nature will not be accepted from digital packets, meaning that if you are in Analogue mode, you can only set the Speed reference from analogue input “S/T” using analogue voltages or PWM pulses and the value of the speed reference sent through a data packet will not have any effect. The same will be for Motor type selection, Control type, Speed controller Kp and Ki , Current limit and Motor direction.
So it’s important to decide whether you want to stay in Digital mode or Analogue Mode to be able to understand how you need to send and set your desired parameters.
It is also worth mentioning that you can remain in Analogue mode, do your Encoder settings and control the speed and torque in a sensor-based manner by sending analogue voltages to the “S/T” pin.
7. Select “Using Encoders” as the Control Mode
Make sure in Motion terminal, the section of “Speed/Torque Control Mode” is selected on “Using Encoders” as Encoder now is the primary source of our measurements and controls, this selection will be remembered by SOLO after power recycle as it will be saved on its long term memory.
8. Check the Torque Loop
As mentioned before, after Motor Identification, the torque loop is ready to be checked without any further action, so at this part if you put the “Control Type” in Motion Terminal on “TORQUE” you will be able to put some values in “Torque Reference_Iq [A]” section which will define for SOLO the desired quadrature current to achieve.
This current which is known as Iq, has a direct relation with torque as below:
Brushless Motor Torque [Nm] = Quadrature current (Iq) [A] * Motor Torque constant [N.m/A]
Please note that, The trend of Iq will be identical to the trends of the real Motor Torque as the torque constant is just a constant value that can be found on the datasheet of a Brushless Motor.
The best practice to check the Torque loop is firstly letting the Motor to run freely, then applying some Torque reference like 30% of the maximum current of your Motor and see if the Motor freely and nicely rotates and accelerates up to its nominal speed in both Clockwise and Counterclockwise directions, if the Motor fails to do this you can increase the Torque Reference and see if anything changes, if the motor kept remaining in the Position or getting Locked, it means the calibration or Motor wiring is not done properly and you need to go back in step 4 and double check everything.
Once you make sure the Motor is freely moving in both directions with some certain amount of Torque Reference and reaching its Nominal speed, you are basically done with this step.
9. Tune and Check the Speed Controller Loop
The speed controlling Loop despite the Torque loop, needs to be tuned by the user, and there are basically two gains of Speed controller Kp and Speed controller Ki to be tuned.
So in this part, you need to make sure that in Motion Terminal, you are putting the “Control Type” in “SPEED” mode and as previously in Torque controller mentioned, the “Control Mode” is already selected on “USING ENCODERS”.
Now you can start by applying some gain for Speed controller Kp and a much less value for Speed controller Ki in Motion terminal, as shown in the video and trying to see their behaviour while you give a speed reference in RPM in “Speed Reference [RPM]” section of the Motion Terminal.
For example after setting the Speed controller Kp and Ki gains, you can give a desired speed like, 1000RPM and see if the Motor can go into that speed and remains there or not, by this practice you can optimize your gains for how fast you want to reach to the goal and also how stable you want your motor to react against load disturbance by changing the values of Kp and Ki gains for the speed controller.
To learn further about this you can have a look at this article.
10. Tune and Check the Position Controller Loop
The last control loop that we need to tune is the Position Controller loop, and similarly to the Speed controller loop again here the user needs to tune the two gains of Position Controller Kp and Position Controller Ki. Agin in this part, you need to make sure that in Motion Terminal, you are putting the “Control Type” on “Position” and in this case SOLO will automatically put the “Control Mode” on “USING ENCODERS” as for now the only source of position controlling for SOLO is using Incremental Encoders.
While you are setting the Kp and Ki gains for the position controller in the Motion terminal you can check the quality of the control by having in mind the fact that the “Speed Limit [RPM]” parameter will define how fast you want your position to be tracked, so basically this value defines the speed that you like to traverse a trajectory with and it can be changed dynamically during the process as you like. For initial tests you can put this value near the nominal speed of your motor and check the Position controller by sending values in “ Desired Position [Quad_pulses]” that are actually the amount of quadrature pulses that you want your motor to pass in either of positive or negative directions.
For instance, if you put there a value like +10000 pulses, and your encoder has 1000 slits or lines, it means for each mechanical slit on the encoder disk, you are going to have 4 pulses counted by SOLO, so it means for 10000 pulses, you are actually traversing 10000/4 = 2500 slits or (2500/1000)*360 = 900 degrees.
The value of Desired position similarly can be changed dynamically to any positive or negative values between +2,147,483,647 to -2,147,483,647. The same possibility exists for dynamic variation of Speed Limit and the maximum speed limit now at the moment is allowed up to 30,000 RPM (mechanical).
Once you properly tune your position controller you can have an effect like in Figure 3 below in which the position of the shaft of the Motor has been changed from -1,000,000 pulses to +1,000,000 pulses and as you can see how the Torque and Speed are playing their roles there, as a matter fact the speed is kept constant at 3000RPM while the position reaches to its goal, also as can be seen, once the position is getting near to the goal, the Speed slowly starts to decay and settles down at Zero at the reference Position.
Figure 3- Brushless Position controlling and the effect of Speed and Torque controllers.
In this article we are going to demonstrate a practical method to correctly connect and setup your quadrature Encoder to SOLO for Torque, Speed and Position controlling purposes. To this end, based on the type of the motor you are using the tuning process will be...
In this article the goal is to set up and calibrate properly the Hall sensors to SOLO for controlling Speed or Torque of your 3-phase motors specially BLDC or PMSM motors. These types of sensors come with 3 wires as each of these wires are representing a digital...
The Easiest way to control the Torque of a BLDC with Raspberry Pi using SOLO with Hall sensors feedback [+ Code]
To control the Torque of a BLDC or PMSM motor that is equipped with HALL sensors, you need to have a Motor controller like SOLO, that has the capability of delivering High powers to the motor and at the same time, it’s smart enough to take care of stabilizing the...