Environment construction

Pymycobot is a Python package for serial communication with myCobot. It supports Python 2, Python 3.5 and later versions.

Before using pymycobot to control the mechanical arm, you need to set up a Python environment. The following describes the download and installation of Python in detail

1 Python Download and Installation

Applicable equipment:

  • ultraArm

At present, Python has two versions, one is version 2. x and the other is version 3. x, which are incompatible. As version 3. x is becoming more and more popular, our tutorial will take the latest version 3.10.7 as an example.

1.1 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/

  • ClickDownloadsoption,start to download Python,chooseAdd Python 3.10 to PATH,and clickInstall Now,start to install Python

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

1.2 Running Python

After the installation is successful, open a command prompt window (Win+R, enter cmd and enter). After typing in 'python', two situations will occur.

Situations 1:

The prompt in the picture indicates that Python is successfully installed.

The prompt>>>appears, indicating that we have been in the Python interactive environment. You can enter any Python code, and you will get the execution result immediately after pressing Enter.

Situations 2:

If you enter an error (such as pythonn), an error message will appear:

Note: The error information is generally caused by not configuring environment variables,please refer to 1.3 Configure environment variables to modify environment variables.

1.3 Configuring environment variables

Because Windows will search python. exe according to the path set by the environment variable of Path, if it is not found, an error will be reported. Therefore, if you omit to check Add Python 3.10 to PATH during installation, you need to manually add the path where python.exe is located to the Path, or reinstall Python. Remember to check the Add Python 3.10 to PATH option. The following steps are for manually adding the path of python. exe.

  • Right click My Computer –>Select Properties –>Select Advanced System Settings –>Select the environment variable in the lower right corner:

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

  • The user variable is the downloaded program that can be used in the cmd command. Write the absolute path of the program to the user variable, as shown in the following figure:

  • After the above steps are completed, open a command prompt window (Win+R, enter cmd, and enter), type Python, and the following prompt appears, indicating success:

2 Installation and use of Pycharm

Pycharm is a powerful Python editor with cross platform features. First, introduce the installation steps of Py Charm in Windows system.

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

2.1 Download and Installation

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

According to the interface introduction, download the file. Professional represents the Professional version, while Community is the community version. It is recommended to install the Community version because it is free to use.

  • Start to install after downloading,clickNext

  • Select the appropriate option according to your preference, and then click Next

  • In the following interface, continue to click Next:

  • Click Finish to finish the installation:

2.2 Create Project

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

  • Click Pycharm icon on the desktop to enter Pycharm, as shown in the following figure,clickNew Project

  • Click Interpreter to start setting the interpreter. Click Add Interpreter:

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

  • Set Location. Location is the place where Py Charm projects are stored, which can be selected as needed.

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

  • Name Python File:

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

2.3 Before using

  • 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 manipulator need to burn different firmware(You can refer to MyStudio section)。
  • Pymycobot installation。Open a console terminal(shotcut Win+R,type cmd to enter the terminal),enter the following command:
pip install pymycobot --upgrade --user

  • Source code installation。Open a console terminal(shotcut Win+R,type cmd to enter the terminal),enter the following command to install:
git clone https://github.com/elephantrobotics/pymycobot.git <your-path>   
#Where<your path>is filled in with your installation address. If it is not filled in, it defaults to the current path

cd <your-path>/pymycobot    
#Go to 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

3 Simple use of Python

After the above preparations are completed, start to control the mechanical arm through Python code. Here we take ultraArm as an example.

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

from pymycobot.ultraArm import ultraArm

注意:

  1. If you enterfrom pymycobot.ultraArm import ultraArm,There is no red wavy line below the font to prove that the installation is successful and can be used,If red wavy line appears, you can refer to how to install API Library How to call API Library

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

    First, enter the project address: https://github.com/elephantrobotics/pymycobot . Then click the Code button on the right side of the page, click Download ZIP to download to local, and put the pymycobot folder in the compressed package pymycobot file project into your python dependency library directory, which can be directly imported for use.

3.1 Simple demonstration

Create a Python file in PyCharm, and enter the following code to return to zero.

Note: The corresponding baud rate of each type of equipment is different. Please consult the data to understand its baud rate when using,Serial port number can be viewed through the calculator device manager or serial port assistant

  • ultraArm
from pymycobot.ultraArm import ultraArm
import time
#The above should be written at the beginning of the code, meaning to import the project package

# ultraArm class initialization requires two parameters: serial port and baud rate
#   The first is the serial port string, such as:
#       linux: "/dev/ttyUSB0"
#       windows: "COM3"
#   The second is the baud rate: 115200
#   Below like:
#           linux:
#              ua = ultraArm("/dev/ttyUSB0", 115200)
#           windows:
#              ua = ultraArm("COM3", 115200)
#
# Initialize an ultraArm object
# Create object code for Windows version
ua = ultraArm("COM3", 115200)
ua.go_zero()

#Return to zero position
ua.set_angles([0, 0, 0], 50)

results matching ""

    No results matching ""