Pull to refresh

Controlling Brushless Motors using Raspberry PI

Reading time5 min
Views3.6K

In this video tutorial, we will control a pair of brushless motors from a Raspberry PI computer. We will use one of the computer's USB ports to connect a network of brushless motor controllers. We will power the computer, the controllers, and the brushless motors using a single battery, similar to a autonomous vehicle design.

The first motor is an outrunner type, a kind of what you would use for a vehicle propulsion. The bigger motor comes with a quadrature encoder which means it can be used as a powerful servo.

Servosila brushless motor controllers come in rectangular or circular form factors. The controllers have USB and CANbus ports for connecting to control computers such as Raspberry PI.

I made a cable to power my set up. On one end, the cable has a socket for plugging the battery. The cable splits into a two parallel parts to power the controllers, and the Raspberry PI. The bottom part of the cable further splits to power a pair of brushless motor controllers.
By the way, the controllers need 7 to 60 Volts DC. I put proper connectors at the ends of the cable, so that I could just plug it into the controllers.

I am using an 11.1 Volts RC battery that I got in a local hobby store. The upper part of the cable goes into a BEC module that I got in the same hobby store. The BEC module converts whatever voltage the battery provides, into a regulated 5 Volts DC voltage that Raspberry PI wants. I extended my setup with a USB cable. This way I provide a 5 Volts DC power from BEC to my Raspberry PI via a USB connector that the computer needs.

Although the motors have Hall sensors, I will only plug the motor's phase wires for this video. The controllers will treat the motors as sensorless ones. I suggest that you watch separate videos dedicated to Sensored, Direct Drive or Servo Control modes of operation.

A regular USB cable is used to connect the brushless motor controllers to the computer. Only one of the controllers in the network needs to be connected to the computer. We need to build an internal CANbus network between the controllers. We are going to use a CANbus cable to interconnect the controllers. Each controller comes with two identical CANbus ports that help chain multiple controllers together in a network.

Up to 16 controllers can be connected this way via a single USB cable to the same control computer or a PLC.

If one of the interconnected brushless motor controllers is connected to a computer via USB, then that particular controller becomes a USB-to-CANbus gateway for the rest of the network.

Once you plug the power supply cables into the motor controllers, and into the Raspberry PI computer, you will see the following cabling network. I spread it out on the floor to make it easier to trace. Be very careful with voltage polarity when connecting the motor controllers to a power supply.

This should look like an autonomous vehicle to an eye of an electrical engineer. The setup has an autonomous source of power, a WIFI-based radio link, an on-board computer, and a set of actuators.

We need to install a software tool called Servoscope on the Raspberry PI computer. Download the Servoscope package to your Windows or Linux computer. Launch VNC client software and connect to the Raspberry PI computer. Go to the drop-down menu and click Send File item. Choose the downloaded file with Servoscope software.

Now that the package has been uploaded to Raspberry PI, we need to un-zip it, and launch the Servoscope application. Open the Terminal and navigate to the directory with un-zipped file. Launch the Servoscope application by launching a script. To connect to the motor controllers, pick a proper serial port from the drop-down menu, and click the Connect button. Both controllers in our network appear in the list of devices. Double-click on a device name to open a command and configuration window.

You may wish to close the Network Viewer and Help Viewer windows to free up screen space for monitoring multiple controllers at the same time. Please note that the motor controller appears to Raspberry PI OS as a virtual serial port. Any application running on Raspberry can read and write to the serial port. There is a way to find the virtual serial port in the Terminal by listing all serial devices. Here it is. The motor controllers send telemetry via the virtual serial port.

The motor controller uses a text protocol to send telemetry. Your applications can send commands back to the controller by writing the same kind of text strings back to the serial port. The other option is by using CANbus. We will look at CANbus interface in a dedicated video.

Next, we need to initiate an Auto-Configuration routine for both of our motor controllers. From a drop-down menu, pick the Auto-Configuration command. Specify a maximum phase-to-phase electric current that your motor can handle. Specify the number of poles your motor has. By the way, these values normally come from the motor's datasheet. Click the Send button.

The motor starts making what looks like mysterious moves during the auto-configuration routine. What happens is that the controller sends sounding electrical signals to the motor. This way the controller measures various characteristics of the motor, and then configures itself for this particular motor. The probing signals cause the motor to make the kong-fu moves. The motor accelerates to its maximum speed. Be careful as the motor is producing its maximum torque at this moment. The rapid accelerations may take place a few times during the auto-configuration procedure.

The beauty of the Auto-Configuration function is that the controller automatically configures itself when commissioning a new motor. I suggest that you watch a separate video dedicated to peculiarities of the Auto-Configuration routine.

Now that the controller of the out-runner motor is configured, we need to repeat the procedure for the second motor. Switch to the other window. Pick Auto-Configuration command from the drop-down menu. Specify a maximum phase-to-phase electric current that your motor can handle. Specify the number of poles your motor has. Click the Send button. The second motor starts making the auto-configuration moves. The auto-configuration routine takes several seconds. The duration depends on the responses the controller receives from the motor. As both motors have been commissioned, we can start sending commands to the motors.

For example, lets issue an Electronic Speed Control command to the bigger motor. Pick the command from the drop-down menu. I specified the speed of 100 electrical revolutions per second. The motor starts spinning with the commanded speed

The way the Electronic Speed Control works is that the controller automatically increases or decreases torque to maintain a constant commanded speed. We will look at Servo Control, Direct Drive Control, and other modes of operation in subsequent videos.

The green LED light tells that the controller is receiving commands from a parent control system.

Now it is time to develop your control logic. By the way, if you want to know how a motor command looks like, the one you can send to the controller via the virtual serial port or CANbus, you may click the View button.

That's it for now. In this video we looked at how to connect brushless motor controllers to a Raspberry PI computer powered by a battery. We will look at CANbus interface option in a separate tutorial.

Tags:
Hubs:
Total votes 3: ↑2 and ↓1+4
Comments0

Articles