Python Library
Last updated
Last updated
SMD Python library provides easy-to-use Python modules and methods to extensively use Acrome Smart Motion Device products. It's user friendly for programmers at any level who have desire to learn and countless projects in mind.
Whether you need simple tasks like changing the speed of each motor or more complex processes like precise positioning, PID auto-tuning etc., this library lets you do it with the versatility of Python. You can easily implement various motor control methods.
The library also enhances your projects by allowing easy integration with SMD sensor modules. This means that it allows you to perform numerous applications by using the necessary modules for your needs. It eliminates the hassle of integrating third-party sensors and their software modules into your system, thus improving the functionality and efficiency of your project.
All you need to develop your projects with the SMD is a computer capable of running your Python scripts.
To use Acrome Smart Motion Devices with Python library, follow the installation steps below. The library is compatible with Python 3.x and can be installed on both Windows and Linux systems.
Before you begin, make sure you have the following prerequisites:
Python 3.x: Python Official Website
Pip (comes default with Python)
Beware that you should check the pip
feature while installing Python 3.x. If you didn't, you always can install pip
from the source for any OS.
pip
installation with Python setup is demonstrated below for Windows.
"Add python.exe to PATH" is necessary for using Python from any terminal.
You can check if pip
is installed properly by typing this command in terminal of any OS:
This command will return you the version and directory of pip
, which means it is installed and ready to use.
Once you have met the prerequisites, you can follow the steps for whichever OS you use.
Open a Command Prompt with administrative privileges.
Install the SMD library using pip
(Python package manager) by running the following command:
Wait until the installation is complete. Pip will automatically download and install the library and any required dependencies.
To verify that the SMD library has been successfully installed, open a Python interpreter and run the following command:
If no errors are raised, the installation was successful.
For usage and more info, see our Github page.
First of all, PC and SMD connections should be made. Connect your USB gateway module to your PC's USB port and connect your SMD to the gateway module with an RJ-11 cable. Lastly, connect a 12V adapter to supply power to the SMD.
There are basics to start programming with SMD Python library. First, the user needs to know the serial port (COM...
or /dev/tty...
) of the connected USB gateway module, COM3 as an example.
Since SMD cards can be connected to each other, each of them can have a different ID by user's choice. However, an SMD Red has an ID of 0 by default. This value can be intentionally changed between 0 - 255 .
SMD can communicate with different baud rates, user may want to change baud rate depending on the needs of project. SMD Red has a default baud rate of 115200.
With all this information, the crucial part of coding can begin.
Here is the first part of the code:
This code snippet acts as a communication setup for SMD.
We defined baud rate as 115200 and ID as 0 (default SMD ID, if it wasn't changed), and used Master
class to create an object named master
, object name depends on user. Then, we used necessary parameters of Master
class, which are serial port and baud rate.
Serial port value can be different device to device, so the user can change the code of the serial port as COM...
or /dev/tty...
according to the OS.
Then we can do our first application , PID auto-tune and velocity control, to practice with our library. You will need an SMD and a brushed DC motor, which are included in the Starter Kit.
We start with the communication setup, and then add the necessary motor control functions, which will be explained below.
You should specify the ID of the target SMD when using functions, in this application there is only one SMD and it has an ID of 0, which is also defined as ID
variable.
There are various operation modes for motor control, for example, we have selected "Velocity" control mode, which allows the motor to be controlled in terms of RPM value.
Then, we specified the RPM and CPR value of motor, in order to be tuned properly. Brushed DC motor in Starter Kit has 100 RPM and 6533 CPR value.
To run the PID auto-tune process, we use the pid_tuner()
function with the ID of the target SMD. After running the function, the motor will start spinning and the process will take about 30 seconds. That's why we put the time.sleep(30)
in order to wait for any other processes before the end of the process. The calculated PID values are printed with the get_control_parameters_...()
function, the last part of function name changes with the operation mode of the motor, which in our application is "Velocity".
For all detailed function and feature explanations of Python library, visit the Python library GitHub page.
For more use cases, visit the projects and see the Python codes: