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.
SOLO UNO wiring to ARDUINO UNO
SOLO MINI wiring to ARDUINO UNO
SOLO BETA wiring to ARDUINO UNO
![Position control of a Brushless Motor with Arduino and SOLO [+ Arduino Code] 3 arduino uno and solo beta wiring](https://www.solomotorcontrollers.com/wp-content/uploads/2021/01/IMG2_Arduino_UNO_SOLO_BETA_Wiring.jpg)
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
![IMG3_Closed_loop_Config_SOLO Position control of a Brushless Motor with Arduino and SOLO [+ Arduino Code] 1](https://www.solomotorcontrollers.com/wp-content/uploads/2021/01/IMG3_Closed_loop_Config_SOLO-scaled.jpg)
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)
![IMG1_BLAC_Motor_IMG Position control of a Brushless Motor with Arduino and SOLO [+ Arduino Code] 2](https://www.solomotorcontrollers.com/wp-content/uploads/2021/01/IMG1_BLAC_Motor_IMG.jpg)
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.
Important Note for ARDUINO UNO users
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.
![IMG1_Position_Control_Brushless_1 Position control of a Brushless Motor with Arduino and SOLO [+ Arduino Code] 3](https://www.solomotorcontrollers.com/wp-content/uploads/2021/04/IMG1_Position_Control_Brushless_1.png)
Figure 1 – Position Controlling with fixed speed of 5000 RPM and goal of +50000 pulses
![IMG2_Position_Control_Brushless_2 Position control of a Brushless Motor with Arduino and SOLO [+ Arduino Code] 4](https://www.solomotorcontrollers.com/wp-content/uploads/2021/04/IMG2_Position_Control_Brushless_2.png)
Figure 2 – Position Controlling with fixed speed of 1500 RPM and goal of -32559 pulses