Position control of a Brushless Motor with Arduino and SOLO [+ Arduino Code]

In this article we are going to control the position of a Brushless DC or Permanent Magnet Synchronous Motor using SOLO with Arduino and more specifically using SOLO’s Arduino Library , in another word, we are turning SOLO into a precise servo drive to interface and control a brushless Motor using Incremental Quadrature Encoders, in this article the communication between SOLO and Arduino is done through UART by sending data packets.

This type of control can be interesting for precise systems like CNC machines, 3D printers, Robots ,etc, where the accurate position of the rotor of the motor is important, with SOLO thanks to Field Oriented Control, you can simultaneously make sure all the parameters like Torque, Speed and Position are observed and controlled, so during your trajectory tracking in case of having load disturbances, you can be confident that they are not going to affect the quality of position controlling.

In simple language, to achieve Position Controlling with SOLO you need to deal with 3 control loops that are participating in this architecture and each of them are having their own part, in simple language:

1    The Torque Loop: This is the closest controller to the motor and the fastest one, it will only control the Torque of the Motor regardless of the Speed, The Speed depends on how much Load you have on the shaft of the Motor, so the difference between the Motor’s Torque and Load’s Torque will define the final Speed of the rotor of the motor.

2    The Speed Loop: The Speed loop comes behind the Torque Loop, it is slower than the Torque controller (at least around 10X) and it basically tries to fix the Speed on a desired value, this controller will keep the speed fixed regardless of the load variation and it will adjust the torque accordingly. You might ask why the Speed controller comes after the Torque controller, this is a big topic, but to simplify it drastically the in principle an Electrical Motor is a Torque Generation machine, even the Speed is controlled finally by controlling the Torque, so the speed controller when it tries to command, it commands to Torque Controller to increase or decrease the Torque on the Motor to stabilize the motor on a specific Speed that it desires!

3    The Position Loop: this is the last loop coming behind the speed loop, it basically tries to set the exact position of the Motor on a specific value, so to make this loop functional, you need to make sure the Torque and Speed loop are firstly tuned and ready, then you can do the Position Controlling.

If you are interested to know more about this technique and what is happening behind the scene you can have a look on the video and article below:


The Wiring

The only wiring you need to apply will be the connection of the Motor to SOLO and by just connecting UART_TX, UART_RX and GND lines between SOLO and ARDUINO.




The UART_TX and UART_RX Lines of SOLO BETA are 3.3V, so if you are going to use it with ARDUINO boards with 5V level UART lines (like Arduino UNO), you need to use circuitry similar to image above, otherwise, if your ARDUINO has 3.3V UART lines (TX and RX) you can connect them directly to SOLO.
arduino uno and solo beta wiring

SOLO’s Setup

In This example make sure you put SOLO into Closed-Loop control mode by pressing the Piano Switch PIN NO# 5 DOWN similar to image below

Position control of a Brushless Motor with Arduino and SOLO [+ Arduino Code] 1

The Motor

The Motor used in this example is “teknic m-2310P-LN-04K” and you can download its datasheet from here. Practically this motor is a brushless motor with sinusoidal shape BEMF and they are known also as Brushless AC or PMSM motors. This Motor has 8 Poles with an internal Encoder with 1000 physical lines pre-quad, meaning that in 1 turn rotation SOLO will read 4000 pulses generated by this motor’s encoder in quadrature manner ( 4 times more)

Position control of a Brushless Motor with Arduino and SOLO [+ Arduino Code] 2

The Encoder and Motor Calibration

If this is the first time you are connecting this motor to your SOLO, you need to make sure at least for 1 time, you have correctly calibrated the Encoder with correct connection of the Motor’s windings to ABC outputs of SOLO, to do that you need to read the article below and do the steps there at least 1 time, and as long as your Motor or the Encoder is the same or the Encoder is not mechanically displaced with respect to the Motor ( in case of using portable encoders). All the calibrated parameters will reside in long term memory of SOLO and they will be remembered after power recycling.

The Article.

Important Note for ARDUINO UNO users

In ARDUINO UNO , there is only 1 line of UART which is shared between the UART to USB convertor of ARDUINO board itself which is also used for flashing the ARDUINO UNO board as well, so whenever you want to program your ARDUINO UNO board through the ARDUINO IDE, YOU need to disconnect the UART_TX of SOLO from being connected to RX of ARDUINO UNO, by not doing this, you might get some errors in ARDUINO IDE during uploading the code. To know more, read this post on ARDUINO website.

The Code

The Results

In This code as you can see, after setting up the essential parameters like the Motor’s number or Poles, Encoder lines and etc, we are periodically asking SOLO to spin the motor into two different positions of +50000 pulses with 5000RPM and stay there for a short time, then turning back the Motor into -32559 pulses with 1500RPM of speed.

It worth mentioning that when SOLO is in Position Mode, it counts the pulses in quadrature manner, so the feedbacks and the references are all in quadrature form, for instance in this example when we ask SOLO to traverse the shaft of the motor into +50000 pulses, if we consider the initial starting point is at zero, we are spinning the motor for (+50000 / ( 10000 * 4)) = 12.5 turns or 4500.0 degrees, so like this you can calculate the exact end point and then provide sufficient and desired reference to SOLO to reach your goal.

As an instance, while Arduino was commanding SOLO, we turned on Monitoring mode in Motion Terminal to monitor the Position controlling effect, and as you can see in Figure 1, the Motor went all the way up to near +50000 pulses with requested speed of 5000RPM, however on Figure 2 the next goal with different speed of 1500RPM and final position of -32559 is achieved.

Position control of a Brushless Motor with Arduino and SOLO [+ Arduino Code] 3

Figure 1 – Position Controlling with fixed speed of 5000 RPM and goal of +50000 pulses

Position control of a Brushless Motor with Arduino and SOLO [+ Arduino Code] 4

Figure 2 – Position Controlling with fixed speed of 1500 RPM and goal of -32559 pulses

As you can see while the position is approaching to the goal, SOLO automatically starts to reduce the speed so the position can settle softly on the final goal, however you might notice some errors in the final achieved goals, in that case you might want to tune further the Position controller gains and see how far you can improve your accuracy, clearly to have higher accuracy you can opt to select encoders with higher resolutions that will eventually increase your final position controlling quality, if you are interested you can also read about how SOLO can sustain it’s precision quality in noisy environments by reading this article. You can read more about our SOLO Motor Controller ARDUINO Library here.
Share This

Share This

Share this post with your friends!