Environment setup

pymycobot is a Python package for serial communication with myCobot, supporting Python3.5 and later versions.

Before using pymycobot to control the robot arm, you need to build a Python environment. The following is a detailed description of Python download and installation.

Linux System

Install the pymycobot library in the console terminal:

pip install pymycobot --upgrade --user

Windows System

Download and install Python

Applicable devices:

  • myCobot Pro 450

Currently, there are two versions of Python, one is 2.x version and the other is 3.x version. These two versions are incompatible. As 3.x version is becoming more and more popular, our tutorial will take the latest 3.10.7 version as an example.

Install Python

Note: Before installing, please confirm whether your computer is 64-bit or 32-bit. Right-click My Computer and select Properties. As shown in the figure below, it is a 64-bit operating system, so select the 64-bit Python installation package.

  • Python official download address: https://www.python.org/downloads/

  • Click the Downloads option to start downloading Python, click Add Python 3.10 to PATH, click Install Now to start installing Python

  • The prompt "Setup was successful" appears, indicating that the installation is complete

Run Python

After successful installation, open the command prompt window (Win+R, enter cmd and press Enter), and type python. Two situations will occur.

Situation 1:

The prompt in the picture indicates that Python has been successfully installed.

The prompt >>> indicates that we are already in the Python interactive environment. We can enter any Python code and get the execution result immediately after pressing Enter.

Case 2:

If the input is wrong (for example, enter pythonn), an error message will appear:

Note: The error message is generally caused by not configuring the environment variables. You can refer to 1.3 Configure environment variables to modify the environment variables.

Configure environment variables

Since Windows will search for python.exe according to the path set by a Path environment variable, if it is not found, an error will be reported. Therefore, if you miss checking Add Python 3.10 to PATH during installation, you need to manually add the path where python.exe is located to Path, or reinstall Python and remember to check the Add Python 3.10 to PATH option.

The following are the steps to manually add the path where python.exe is located.

  • Right-click My Computer –> Select Properties –> Select Advanced System Settings –> Select Environment Variables in the lower right corner:

  • Environment variables mainly include user variables and system variables. The environment variables that need to be set are in these two variables. As shown in the figure below:

  • User variables are used to download programs that can be used in cmd commands. Write the absolute path of the program to the user variable and you can use it, as shown in the figure below:

  • After completing the above steps, open the command prompt window (Win+R, then enter cmd, press Enter), type Python, and the prompt in the figure below indicates success:

PyCharm installation and use

PyCharm is a powerful Python editor with cross-platform capabilities. First, let's introduce the installation steps of PyCharm in Windows system.

Download address: https://www.jetbrains.com/pycharm/download/#section=windows

Download and install

  • After entering the website, we will see the following interface:

Download the file according to the interface introduction. Professional means professional version, and Community means community version. It is recommended to install the community version because it is free to use.

  • After downloading, start installing and click Next:

  • Select the corresponding options according to your personal preferences, and then click Next:

  • The following interface appears and continue to click Next:

  • Click Finish to complete the installation:

Create a project

After PyCharm is installed, enter the software and create the first program.

  • Click the PyCharm icon on the desktop to enter PyCharm, as shown in the figure below, and click New Project:

  • After clicking, find Interpreter, start setting the interpreter, and click Add Interpreter:

  • Click New, find the python.exe storage location, and check the Inherit global site-package option:

  • Set Location. Location is where the PyCharm project is stored. You can choose it according to your needs.

  • Create a new PyCharm file. Right-click the document icon pointed by the arrow, click New, click Python File, and the new file is created successfully.

  • Name Python File:

  • After the file is successfully created, you will enter the following interface and you can write your own program

Before use

  • Firmware burning. Firmware refers to the device "driver" stored inside the device. Only through firmware can the operating system implement the operation of a specific machine according to the standard device driver. Different versions of the robot arm need to burn different firmware (refer to the MyStudio chapter).

  • pymycobot installation. Open a console terminal (shortcut Win+R, enter cmd to enter the terminal), and enter the following command:

pip install pymycobot --upgrade --user

The following words appear, indicating that the pymycobot package has been successfully installed

  • Source code installation. Open a console terminal (shortcut Win+R, enter cmd to enter the terminal), enter the following command to install:
git clone -b develop https://github.com/elephantrobotics/pymycobot.git <your-path>
#Where <your-path> fills in your installation address, if not filled in, the current path is used by default

cd <your-path>/pymycobot
#Enter the pymycobot folder of the download package

#Run one of the following commands according to your python version
# Install
python2 setup.py install
# or
python3 setup.py install

Simple use of Python

After the above preparations are completed, start to control the robot arm through Python code. Here, the MyCobot Pro 450 version is used as an example for demonstration.

First, open the PyCharm you installed, create a new Python file, enter the following code, and import our library:

from pymycobot import Pro450Client

Note:

  1. If you enter from pymycobot import Pro450Client, there is no red wavy line under the font, which proves that it has been successfully installed and can be used. If a red wavy line appears, you can refer to How ​​to install the API library , How ​​to call the API library.

  2. If you do not want to install the API library through the above command, you can download the project to your local computer through the following github.

First, go to the project address: https://github.com/elephantrobotics/pymycobot. Then click the Code button on the right side of the webpage, and then click Download ZIP to download it locally. Put the pymycobot folder in the compressed package pymycobot file project into your python dependency library directory, and you can directly import and use it.

Pre-use Preparation

Before using the sample functions, please ensure that the following hardware and environment are complete:

  • Hardware

    • MyCobot Pro 450 robot arm
    • Network cable (for connecting the robot arm to the computer)
    • Power adapter
    • Emergency stop switch (for safe operation)
  • Software and Environment

    • Python 3.6 or later installed
    • The pymycobot library installed (using the pip install pymycobot terminal command)
    • Ensure that the MyCobot Pro 450 is properly powered on and in standby mode.
    • Note: The Pro 450 server automatically starts upon powering on; no manual operation is required.
  • Network Configuration

    • MyCobot Pro 450 default IP address: 192.168.0.232
    • Default port number: 4500
    • Note: PC The local network card IP address must be set to the same network segment as the robot (e.g., 192.168.0.xxx, where xxx is a number between 2 and 254 and must not conflict with the robot).
    • Example:

      • Robot IP: 192.168.0.232
      • PC IP: 192.168.0.100
      • Subnet mask: 255.255.255.0
    • Verification: After completing the network configuration, execute the following command on the PC terminal. If data packets are successfully returned, the network connection is normal:

      ping 192.168.0.232
      

Simple Demonstration

import time
from pymycobot import Pro450Client

# The default IP address is "192.168.0.232" and the default port number is 4500
pro450 = Pro450Client('192.168.0.232', 4500) # Client connection communication

if pro450.is_power_on() !=1:
    pro450.power_on()  # Power on

print(pro450.get_angles()) # Read all joint angles

pro450.send_angle(1, 90, 50) # Control J1 joint movement to 90 degrees at a speed of 50

← Previous Chapter | Next Chapter→

results matching ""

    No results matching ""