Raspberry Pi Six-axis Robotic Arm Wiki - DFRobot

[](Product Link)

Introduction

This Raspberry Pi robotic arm will definitely lead you to a wonderful robot programming world!
Based on a Raspberry Pi microprocessor and built-in Ubuntu system, this small but powerful Raspberry Pi Six-axis Robotic Arm comes with a working range of 280mm and supports multi-platform secondary
development. It runs independently without a PC and quickly creates a perfect programming environment for robotic algorithm developing, ROS simulation, etc.
Just connecting it to peripherals, then users can use it for scientific research and teaching, smart home, light industry, or other commercial applications.

Embedded Raspberry Pi ecology providing unlimited development possibilities

Raspberry Pi 4B, 1.5GHz quad-core microprocessor, running with Debian/Ubuntu platform. Supports 4-way USB, 2-way HDMI, standardized GPIO interface, and a pluggable TF card.

Provided with ROS, and graphical programming Mind+/Blockly

The built-in ROS simulates the running state of the robot arm, with super expansibility. Mind+/blockly visual programming; supporting general Python software interface.

Image recognition, rich accessories and wide application

Provided with image recognition algorithms; any camera can be selected. Equipped with different accessories such as monitors, grippers and sucking pumps to achieve more application scenarios.

Unique industrial design and extremely compact

With integrated design, the product has a compact body structure and the net weight is only 850g, so it is very easy to carry. Using a modular design, it is characterized by less spare parts, low maintenance cost, quick disassembly and replacement, and plug-and-play.

High configuration and being equipped with LEGO interface

Being equipped with 6 high-performance servo motors, the product features fast response, small inertia and smooth rotation. With LEGO interfaces, the base and end are suitable for the development of various miniature embedded devices.

Specification

Basic Usage

myStudio

Burn & Update Firmware

myStudio is a one-stop platform for robots of myCobot. Supporting Windows, Mac, and linux, it is convenient for users to choose different firmware and download it according to their own usage scenarios, and learn relevant textbooks and videos.

Please download different PC, BASIC firmware and Atom firmware depending on your development environment.

ROB0182-Basic

ROB0182-Environment

Installing myStudio

myStudio downloading address, GitHub: https://github.com/elephantrobotics/myStudio
Select the latest version (The version shown on the web page should prevail. The following figure just for reference only.)

Then select the version corresponding to the system.
Notice: Different suffixes are for different systems.

Install driver

According to the operating system used, click the button below to download the corresponding CP210X or CP34X driver zip file. After decompressing the file, select and install the installation package corresponding to the operating system.

There are currently two driver chip versions, CP210X (applicable to CP2104 version) / CP34X (applicable to CH9102 version) driver package. If you are not sure which USB chip your device is using, you can install both drivers at the same time. (During the installation of CH9102_VCP_SER_MacOS, an error may be reported, however, the installation has been done, and the error can be ignored.)

For Mac OS, ensure correct settings of the system Preferred settings -> Security and privacy ->General before installation, and allow users to get it from App Store or an approved developer.

Download the Basic serial port driver CP210X

Serial port driver CP34X

Download the Atom serial port driver

How to distinguish between CP210X and CP34X

As shown in the figure below, open the device manager and check port (COM and LPT). If the port (COM and LPT) shows USB-Enhanced-SERIAL CH9102, the chip is CP34X.

If the port (COM and LPT) shows Silicon Labs CP210x USB to UART Bridge, the chip is CP210X.

Burning Basic and Atom firmwares

The way for connecting Basic with PC is shown in the figure below.

First connect the Basic development board with USB, and then the connection window of myStudio will display the connected development board. Select it and Clik on "Connect" .

Then there are Basic-related firmwares in Basic and Tool. Click to burn. (For the firmwares that haven't been downloaded, click "download" first.)

Burning Atom firmware
The same as Basic firmware burning, first connect Atom at the end with USB.

Select ATOM in the Board bar, click Basic at the side column, then the ATOM firmware will appear. There is only one Atom firmware. Just click to burn it.

Factory Firmware

  1. Robot drag teaching

Robot drag teaching: The operator can drag robot joints directly to make them do ideal postures, and then save the actions in the robot through button operation. The cobot is a system that has this function earlier. This kind of teaching avoids various disadvantages of traditional teaching, so it is a prospective technology for robot applications.

Operation methods vary among device types. They have the approximate steps below:

  1. Robot arm calibration

Calibration

Calibrating the robot arm is the precondition for precise control of the robot arm, and setting joint zero and initializing the potential of the motor are basic jobs for subsequent advanced development.

Operation methods vary among equipment types. They have the approximate steps below:

  1. Communication forwarding

Communication timeliness is vital to the micro-controller robot arm. For such arm, we often send control instructions to Basic of the base. Through communication forwarding, the end effector analyzes the instructions and then implements target actions.
This function is mainly used for the customer to develop robot arms independently in different environments.
Operation methods vary among equipment types. They have the approximate steps below:

  1. Connection detection

Connection detection is a detection function that uses the motor in the robot arm and the connection state of Atom. The function allows the user to remove equipment faults easily.

During the connection detection, the connection state of the equipment for the robot arm, including the connection of the servo and the communication state of Atom can be seen. In micro-controller devices, the versions of their current firmwares are shown on Basic.

Operation methods vary among equipment types. They have the approximate steps below:

Use for the first time

1.Items included in Raspberry Pi robotic arm standard kit

2.Confirming the operational environment and indexes

Install the robot system in the environment that meets the conditions described in the table in order to give full play to and maintain the performance of this machine and to use it safely.

Environment Index
Temperature -10℃~45℃
Relative Humidity 20%~70%
Indoor & Outdoor Requirements Indoor
Other Environmental Requirements Don't expose it to the sunshine; keep it away from dust, oil fume, salt, iron chips, etc; keep it away from flammable and corrosive liquids and gases; it should not come into contact with water; No transmission of shock, vibration, etc; keep it away from strong electromagnetic interference sources

3.Connection
Connect the power adapter

Connect the computer

4.Power Supply
The power for the robotic arm must be supplied by an external power supply to provide it with sufficient power:

Note: Don't supply power only using TypeC inserted into Basic.
Use the power supply officially provided to avoid damage to the robotic arm.

5.Fix robotic arm
During the movement of the robotic arm, if the bottom surface of it is not connected to the table top or other surfaces, it will shake or overturn. The common way to fix the robotic arm is to fix it on a base with LEGO interface by using a LEGO inserting key. Two types of bases are provided: flat base and G-shape base.
Flat Base

Tip: A small amount of non-conductive liquid can be added under the suction cups to fill the gap between them and the surface so as to maximize absorption efficiency.

G-shape Base

Development & Use

Mind+

Mind+ is a visual programming software that enables anyone to make fast prototypes intuitively and enjoy hardware hacking even without programming background. Just drag and drop blocks, set up parameters and connect modules after building the circuit. Then your DIY project is good to go!
For users, Mind+ is an easy-to-use visual tool for generating codes. And for the developer, myBlockly is a text box containing the code that the user has done.
When users drag and drop blocks, codes are generated in the text box.

Download and Install Mind+:

1) Enter Mind+ and select Python mode

2) Select Extensions

3) Select User Library and enter keywords (elephant, mycobot, pi) in the search box to get the relevant user library of elephant robotics, then click Return to back to the operation interface.

4) Slide the left command section to the bottom to find the user library for Elephant Robotics, and drag the blocks to perform the relevant operations.

A simple sample for robotic arm:

For more details on using Mind+, click here.

RoboFlow

The RoboFlow operating system provides man-machine interfaces (with coordinate control, angle control, IO control, track recording, gripper control and other functions) to make it easy for the operator to interact with the the robot arm and to use them properly. Namely, most of the time the users operate the cobot through the RoboFlow operating system.

Fox example, because the RoboFlow operating system runs in a teaching pendant, users may use the pendant to control the cobot manually, do programming and perform other operations. They also can use the operating system (OS) to realize the communication between the cobot system and other robots or devices. In one word, with friendly interfaces, rich functions and other advantages, the RoboFlow operating system makes it easier for the users to use the cobot, thus making each user become a robot commander.

Preconditions for use: Use mystudio to burn the corresponding firmware. Burn the latest version of atomMain in Atom (factory default burnt).

Environment Building

1) Connect devices

2) Download RoboFlow

Simple Use of RoboFlow

(1) Login
Note: password is mycobot
After the system starts successfully, it will enter the login interface of the RoboFlow operating system shown in the following figure.

Select the login user name "Admin" or other administrator user names (only administrators are allowed to edit and debug programs), click the password box, and a pop-up window will appear as shown in the following figure.

The login password for administrator user "Admin" is "aaa" by default (enter the corresponding login password when selecting other administrator user names). Enter the password and click "OK", then click "Login", and you will login successfully.
(2) Powering up
After successful login, you will enter the main menu interface as shown in the figure below.

In this interface, select "Configuration Center", and you will enter the interface as shown in the figure below.
After making sure that the emergency stop knob is not pressed, click the "Start Robot" button. At this point, the interface will change, and a "Powering up is in process" icon will appear. If powering up is successful, the "normal" state will appear. If it fails, check to see which steps are not implemented.
After completing the previous step, click the "< Main Menu" button in the configuration center to return to the main menu.

(3) Creating a new blank program
As shown in the figure below, click "Write program" and select "Blank program".

After performing the previous step, enter the program editing interface.

(4) Adding and editing instructions
As shown in the figure below, add two waypoints: absolute point command, and teach two points (that is to say, control the robot to move to a certain posture and then move it back to its original position with a fast moving tool, and click "Save current point". The teaching procedure for both points is the same. To verify the saved point, long press the "Move to this point" button to manually control the robot to move to the teaching point).
After editing, don't forget to save the program file. Click "Save" in the file option bar, and the window will pop up. Click "File name", and the input keyboard will appear. After entering a file name, click "OK". It will return to the save interface. And then click "OK" to save the program file successfully. After successful saving, the program name at the upper left corner of the program editing interface will be changed.

(5) Debugging the program
In addition to the two functions "Next" and "Run" provided in the program running control bar, click "Advanced function" to enter the interface for more settings.
The "Next" function corresponds to step-by-step execution of the program. Click it once, and only a step will be run. If you want to continue running, click "Next" again. The "Run" function corresponds to automatically running the program once.
In the "Advanced function", you can set the number of loop runs, or run it in an infinite loop. You can also control the program to make it run in an automatic or manual mode. In the automatic mode, "Next", "Run" and loop run are available. In the interface, select "Manual mode", and then select "Run" or "Infinite loop" in the loop run. Then you will enter the running interface in the manual mode.

If you debugs the program in the manual mode, you have to keep pressing the "Press Down" button to continue running. If you release the button, the program pauses; press again, it will continue to run.
(6) Saving and running the program
If debugging is completed, make sure to save the debugged program. After returning to the main menu, select Write program -> "Load program". The pop-up window will appear, select the program that has been debugged, and then click "OK".

After selecting the program, you will enter the program running interface. And in this interface, you can run the program and view the information on the program running.

Note: If you can't control the robot arm, check whether it is powered up successfully (If not, check whether the firmware is under Tansponder -> UART USB function), and then select Tools -> Basic settings. The following picture shows the status of successful powering up: (You can also check the powering-up steps).

Simple Sample

In RoboFlow, the control of joints and coordinates are performed on the QuickMove page. Run RoboFlow, enter the program editing interface, and select Tools–QuickMove.
The way to control the robot arm is divided into continuous motion and discrete motion. For the former, press the button, and the robot arm will not stop moving until the button is released; for the latter, set an increment, and the robot arm will stop when it reaches a set point.

1.Joint control

Joint Control means the control of joints. Joints 1-6 correspond to the joints 1, 2, 3, 4, 5 and 6 respectively.
Function description:

2.Coordinate control

Note: Before using the coordinate control, you have to press the home button (For 280, press the home button, while for 320 click the home button) to make the robot arm reach a certain posture; after that, click the home button again, a prompt that "The robot arm has reached the required point" will be provided.

Coordinates Control means the control of coordinates.
Function description:

Python

Environment Building

pymycobot is a Python package used for serial communication with myCobot. It supports Python2, Python3.5 and later versions.

Before using pymycobot, make sure that you have built a Python environment, have a robot arm, and have made preparations.

  1. Install Python
    Enter Python's official downloading webpage

Python Webpage

There are many versions, and we choose the latest version here.

Version

To confirm whether your PC is a 64-bit or 32-bit operating system, you can right-click on the My Computer icon on the left and select Properties. The following figure shows a 64-bit operating system, so we select the 64-bit Python installation package.

OS

Device Specification

After downloading is complete, click Run, and the installation interface will appear. Remember to check Add Python 3.9 to PATH.

Installation

When the figure below appears, it means that the 64-bit Python is successfully installed.

Installation OK

Running Python. After successful installation, open the command prompt window (win+R, input cmd and press Enter), and type Python, there will be two situations:
Situation 1:

Situation 1

When this appears, it means that Python is successfully installed. When you see the prompt >>>, it means that we have been in the Python interactive environment. Input any Python code, press Enter and we will obtain the execution result immediately.

Situation 2:
Because I installed it successfully, I still want to provide a demo in which I used the wrong pythonn instead of python, so that an error message was prompted.

Configuring environment variables: The reason for doing so is that Windows will search python.exe according to the path set by a Path environment variable. If it is not found, an error will be reported. If you fail to check Add Python 3.9 to PATH during installation, you have to manually add the path where python.exe is located into Path. If you find that you forgot to check Add Python 3.9 or you cannot set the PATH, you have to reinstall Python, and do remember to check Add Python 3.9 to PATH. (Step 2: When an error message appear, it is generally due to failure to configure environment variables.)

Steps: Right-click My Computer -> select Properties -> select Advanced System Settings -> Select Environment Variables in the lower right corner.

The environment variables mainly include user variables and system variables. The environment variables that need to be set are in these two variables. The user variables means that you can use your own downloaded program in the cmd command, and that you can use it after writing the absolute path of the program into the user variables.

Envronmental variable setup

Path

Here go back to and open the command prompt window (win+R; input cmd and press Enter), and type Python, displaying this means that there are no problems.

  1. Detailed installation steps of pycharm
    Pycharm is a powerful python editor with the nature of cross-platform. The way to install pycharm into Windows is introduced below.

PyCharm downloading address

After entering the website, we will see the following interface.

Pycharm download

Download the file according to the introduction on the interface. Professional means the professional version, and community is the community version. It is recommended to install the latter version because it is free.
After downloading, click the file to install it. Here I install it in the E disk. Of course, you can install it in another disk after modifying the installation path.

Click Next to enter the next step:

Click Next to enter the next step:

Click Install to install it. After installation is completed, the following interface appears, and click Finish to end the installation:

After completing the above steps, it means that Pycharm is successfully installed. At this time, let's enter the software and create our first program:
(1) Click the pycharm icon on the desktop, enter pycharm, and click OK directly, as shown in the figure below:

(2) Select the second one, and then click OK:

(3) Click the Accept in the figure above to enter the next step:

(4) Click the OK in the figure above to enter the next step

Pycharm Interface

(5) Click New Project to enter the interface shown in the figure below. The interpreter therein is used for you to select the python to be installed; Location is used to customize the project storage directory; after selecting the directory, click Create.

(6) In the interface you have entered as shown in the figure below, right-click the place pointed by the arrow in the figure, select python file, and fill in the file name in the pop-up box (It is allowed to fill in any file name).

1

2

3

(7) After the file is successfully created, you will enter the following interface where you can write your own program.

Programming Interface

Shortcuts

  1. Preparations
    Be sure to burn AtomMain for Atom at the top and minirobot for Basic at the bottom. And then choose transponder function. For device firmware burning, refer to MyStudio) chapter.
    The downloading address for firmwares AtomMain and minirobot

You can also use myStudio to burn the firmware. MyStudio's downloading address

Pip installation command

Open a console terminal (shortcut key: Win+R; input cmd and enter the terminal), and input the following command:

pip install pymycobot --upgrade --user

Notes:
Currently only Atom2.4 and later versions are available. If you are using previous versions, install pymycobot 1.0.7.
Open a console terminal (shortcut key: Win+R; input cmd and enter the terminal), and input the following command:

pip install pymycobot==1.0.7 --user

Installing source code
Open a console terminal (shortcut key: Win+R; input cmd and enter th terminal), and input the following command to install it:

git clone https://github.com/elephantrobotics/pymycobot.git <your-path>   
#Fill in your installation address in <your-path>, if you fill in nothing, the current path is used by default


cd <your-path>/pymycobot    
#Go to the pymycobot folder of the downloaded package.

#Run one of the following commands according to your python version.    

# Install
 python2 setup.py install    
# or
 python3 setup.py install
  1. Simple use of Python
    Use method
    After completing the steps above, open the installed pycharm, create a new python file, enter the code and import to our library:
from pymycobot import MyCobot, Angle, Coord, utils

After you import the installed project package on pycharm, for example, inputting: from pymycobot.mycobot import MyCobot, if no red wavy line appears below the font, this proves that it has been successfully installed and can be used; and if a red wavy line appears there,you can refer to How to install the API library and How to call the API library.
If you don't want to install the API library through the above command, you can use it the following operations.
First, you need to go to the project's github to download it locally.

Enter the project address: https://github.com/elephantrobotics/pymycobot

Then click the code button on the right side of the webpage, and click Download ZIP to download it locally; put the pymycobot file in the zip pymycobot file into your python dependent library directory, and then you can import and use it directly.

LED Blinking

Create a new Python file, and enter the following code to realize the LED blinking.

Notice: The baud rates corresponding to all types of devices are not the same. Before using them, refer to the information related to get the baud rate. The serial port number can be viewed through calculator device manager or a serial helper.

from pymycobot.mycobot import MyCobot

from pymycobot import PI_PORT, PI_BAUD      # When using the Raspberry Pi version of mycobot, you can refer to these two variables to initialize MyCobot, if not, you can omit this line of code
import time
#The above needs to be written at the beginning of the code, which means importing the project package

# MyCobot 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:
#       M5 version is: 115200
#   Example:
#       mycobot-M5:
#           linux:
#              mc = MyCobot("/dev/ttyUSB0", 115200)
#           windows:
#              mc = MyCobot("COM3", 115200)
#       mycobot-raspi:
#           mc = MyCobot(PI_PORT, PI_BAUD)
#
# Initialize a MyCobot object
# Create object code here for windows version
mc = MyCobot("COM3", 115200)

i = 7
#loop 7 times
while i > 0:                            
    mc.set_color(0,0,255) #blue light on
    time.sleep(2)    #wait for 2 seconds
    mc.set_color(255,0,0) #red light on
    time.sleep(2)    #wait for 2 seconds
    mc.set_color(0,255,0) #green light on
    time.sleep(2)    #wait for 2 seconds
    i -= 1

Result: The top light of the robot flashes 7 times continuously in blue, red and green at 2-second intervals.

  1. Use Case
    LED Blinking
from pymycobot.mycobot import MyCobot

from pymycobot import PI_PORT, PI_BAUD      # When using the Raspberry Pi version of mycobot, you can refer to these two variables to initialize MyCobot, if not, you can omit this line of code
import time
#The above needs to be written at the beginning of the code, which means importing the project package

# MyCobot 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:
#       M5 version is: 115200
#   Example:
#       mycobot-M5:
#           linux:
#              mc = MyCobot("/dev/ttyUSB0", 115200)
#           windows:
#              mc = MyCobot("COM3", 115200)
#       mycobot-raspi:
#           mc = MyCobot(PI_PORT, PI_BAUD)
#
# Initialize a MyCobot object
# Create object code here for windows version
mc = MyCobot("COM3", 115200)

i = 7
#loop 7 times
while i > 0:                            
    mc.set_color(0,0,255) #blue light on
    time.sleep(2)    #wait for 2 seconds
    mc.set_color(255,0,0) #red light on
    time.sleep(2)    #wait for 2 seconds
    mc.set_color(0,255,0) #green light on
    time.sleep(2)    #wait for 2 seconds
    i -= 1

Control the robot arm to make it return to the origin

from pymycobot.mycobot import MyCobot
from pymycobot import PI_PORT, PI_BAUD  # When using the Raspberry Pi version of mycobot, you can refer to these two variables to initialize MyCobot

# MyCobot class initialization requires two parameters:
#   The first is the serial port string, such as:
#       linux: "/dev/ttyUSB0"
#       windows: "COM3"
#   The second is the baud rate:
#       M5 version is: 115200
#
#   Example:
#       mycobot-M5:
#           linux:
#              mc = MyCobot("/dev/ttyUSB0", 115200)
#           windows:
#              mc = MyCobot("COM3", 115200)
#       mycobot-raspi:
#           mc = MyCobot(PI_PORT, PI_BAUD)
#
# Initialize a MyCobot object
# Create object code here for Raspberry Pi version
mc = MyCobot(PI_PORT, PI_BAUD)

# Check whether the program can be burned into the robot arm
if mc.is_controller_connected() != 1:
    print("Please connect the robot arm correctly for program writing")
    exit(0)

# Fine-tune the robotic arm to ensure that all the bayonets are aligned in the adjusted position
# Subject to the alignment of the mechanical arm bayonet, this is only a case
mc.send_angles([0, 0, 0, 0, 0, 0], 30)

# To calibrate the position at this time, the calibrated angular position represents [0,0,0,0,0,0], and the potential value represents [2048,2048,2048,2048,2048,2048]
# The for loop is equivalent to the method set_gripper_ini()
#for i in range(1, 7):
    #mc.set_servo_calibration(i)

Single-joint motion

from pymycobot import MyCobot

from pymycobot.genre import Angle

import time

# MyCobot class initialization requires two parameters:

#  The first is the serial port string, such as:

#    linux: "/dev/ttyUSB0"

#    windows: "COM3"

#  The second is the baud rate:

#    M5 version is: 115200

#

#  Example:

#    mycobot-M5:

#      linux:
#        mc = MyCobot("/dev/ttyUSB0", 115200)

#      windows:

#        mc = MyCobot("COM3", 115200)

#    mycobot-raspi:

#      mc = MyCobot(PI_PORT, PI_BAUD)

#

# Initialize a MyCobot object

# Create object code for Raspberry Pi version

# mc = MyCobot(PI_PORT, PI_BAUD)

# Create object code for M5 version

mc=MyCobot('COM3',115200)

# Robotic arm recovery

mc.send_angles([0, 0, 0, 0, 0, 0], 40)

time.sleep(3)

# Control joint 3 to move 70°

mc.send_angle(Angle.J3.value,70,40)

time.sleep(3)

# Control joint 4 movement -70°

mc.send_angle(Angle.J4.value,-70,40)

time.sleep(3)

# Control joint 1 to move 90°

mc.send_angle(Angle.J1.value,90,40)

time.sleep(3)

# Control joint 5 movement -90°

mc.send_angle(Angle.J5.value,-90,40)

time.sleep(3)

# Control joint 5 to move 90°

mc.send_angle(Angle.J5.value,90,40)

time.sleep(3)

Multi-joint motion

import time
from pymycobot import MyCobot
# MyCobot class initialization requires two parameters:
#   The first is the serial port string, such as:
#       linux: "/dev/ttyUSB0"
#       windows: "COM3"
#   The second is the baud rate:
#       M5 version is: 115200
#
#   Example:
#       mycobot-M5:
#           linux:
#              mc = MyCobot("/dev/ttyUSB0", 115200)
#           windows:
#              mc = MyCobot("COM3", 115200)
#       mycobot-raspi:
#           mc = MyCobot(PI_PORT, PI_BAUD)
#
# Initialize a MyCobot object
# Create object code for Raspberry Pi version
# mc = MyCobot(PI_PORT, PI_BAUD)

# Create object code for 280-M5 version
mc=MyCobot('COM3',115200)
# Robotic arm recovery
mc.send_angles([0,0,0,0,0,0],50)
time.sleep(2.5)
# Control different angles of rotation of multiple joints
mc.send_angles([90,45,-90,90,-90,90],50)
time.sleep(2.5)
# Return the robotic arm to zero

mc.send_angles([0,0,0,0,0,0],50)
time.sleep(2.5)
# Control different angles of rotation of multiple joints
mc.send_angles([-90,-45,90,-90,90,-90],50)
time.sleep(2.5)

Control the robot arm to make it sway left and right

from pymycobot.mycobot import MyCobot
from pymycobot.genre import Angle
from pymycobot import PI_PORT, PI_BAUD  # When using the Raspberry Pi version of mycobot, these two variables can be referenced to initialize MyCobot
import time
# Initialize a MyCobot object
# Pi version
# mc = MyCobot(PI_PORT, PI_BAUD)
# M5 version
mc = MyCobot("COM3", 115200)
# Get the coordinates of the current location
angle_datas = mc.get_angles()
print(angle_datas)

# By passing the angle parameter, let each joint of the robotic arm move to the specified position
mc.send_angles([0, 0, 0, 0, 0, 0], 50)
print(mc.is_paused())
# Set the waiting time to ensure that the robotic arm has reached the specified position
# while not mc.is_paused():
time.sleep(2.5)

# Move joint 1 to the 90 position
mc.send_angle(Angle.J1.value, 90, 50)

# Set the waiting time to ensure that the robotic arm has reached the specified position
time.sleep(2)

# set loop times
num = 5

# The following code can make the robotic arm swing left and right
while num > 0:
    # Move joint 2 to the 50 position
    mc.send_angle(Angle.J2.value, 50, 50)
    # Set the waiting time to ensure that the robotic arm has reached the specified position
    time.sleep(1.5)
    # Move joint 2 to the -50 position
    mc.send_angle(Angle.J2.value, -50, 50)
    # Set the waiting time to ensure that the robotic arm has reached the specified position
    time.sleep(1.5)
    num -= 1
# Make the robotic arm retract. You can manually swing the robotic arm, and then use the get_angles() function to get the coordinate sequence, 
# use this function to let the robotic arm reach the position you want.
mc.send_angles([88.68, -138.51, 155.65, -128.05, -9.93, -15.29], 50)

# Set the waiting time to ensure that the robotic arm has reached the specified position
time.sleep(2.5)
# Let the robotic arm relax, you can manually swing the robotic arm
mc.release_all_servos()

Control the robot arm to make it dance

from pymycobot.mycobot import MyCobot
from pymycobot import PI_PORT, PI_BAUD  # When using the Raspberry Pi version of mycobot, these two variables can be referenced to initialize MyCobot
import time

if __name__ == '__main__':
    # MyCobot class initialization requires two parameters:
    #   The first is the serial port string, such as:
    #       linux: "/dev/ttyUSB0"
    #       windows: "COM3"
    #   The second is the baud rate:
    #       M5 version is: 115200
    #
    #   Example:
    #       mycobot-M5:
    #           linux:
    #              mc = MyCobot("/dev/ttyUSB0", 115200)
    #           windows:
    #              mc = MyCobot("COM3", 115200)
    #       mycobot-raspi:
    #           mc = MyCobot(PI_PORT, PI_BAUD)
    #
    # Initialize a MyCobot object
    # Create object code for Raspberry Pi version below
    mc = MyCobot(PI_PORT, PI_BAUD)
    # M5 version
    # mc = MyCobot("COM3",115200)

    # set start start time
    start = time.time()
    # Let the robotic arm reach the specified position
    mc.send_angles([-1.49, 115, -153.45, 30, -33.42, 137.9], 80)
    # Determine if it reaches the specified position
    while not mc.is_in_position([-1.49, 115, -153.45, 30, -33.42, 137.9], 0):
        # Return the robotic arm to motion
        mc.resume()
        # Let the robotic arm move for 0.5s
        time.sleep(0.5)
        # Pause arm movement
        mc.pause()
        # Determine if the move timed out
        if time.time() - start > 3:
            break
    # set start time
    start = time.time()
    # Let the exercise last for 30 seconds
    while time.time() - start < 30:
        # Let the robotic arm quickly reach this position
        mc.send_angles([-1.49, 115, -153.45, 30, -33.42, 137.9], 80)
        # Set the color of the light to [0,0,50]
        mc.set_color(0, 0, 50)
        time.sleep(0.7)
        # Let the robotic arm quickly reach this position
        mc.send_angles([-1.49, 55, -153.45, 80, 33.42, 137.9], 80)
        # Set the color of the light to [0,50,0]
        mc.set_color(0, 50, 0)
        time.sleep(0.7)

Gripper control

from pymycobot import PI_PORT, PI_BAUD  # When using the Raspberry Pi version of mycobot, these two variables can be referenced to initialize MyCobot
from pymycobot.mycobot import MyCobot
import time
def gripper_test(mc):
    print("Start check IO part of api\n")
    # Check if the gripper is moving
    flag = mc.is_gripper_moving()
    print("Is gripper moving: {}".format(flag))
    time.sleep(1)

    # Set the current position to (2048).
    # Use it when you are sure you need it.
    # Gripper has been initialized for a long time. Generally, there
    # is no need to change the method.
    # mc.set_gripper_ini()
    # Set joint point 1 to rotate to the position of 2048
    mc.set_encoder(1, 2048)
    time.sleep(2)
    # Set six joint positions and let the robotic arm rotate to this position at a speed of 20

    mc.set_encoders([1024, 1024, 1024, 1024, 1024, 1024], 20)
    # mc.set_encoders([2048, 2900, 2048, 2048, 2048, 2048], 20)
    # mc.set_encoders([2048, 3000,3000, 3000, 2048, 2048], 50)
    time.sleep(3)
    # Get the position information of joint point 1
    print(mc.get_encoder(1))
    # Set the gripper to rotate to the position of 2048
    mc.set_encoder(7, 2048)
    time.sleep(3)
    # Set the gripper to rotate to the position of 1300
    mc.set_encoder(7, 1300)
    time.sleep(3)

    # Let the gripper reach the state of 2048 at a speed of 70, 2048 will report an error, so change it to 255
    mc.set_gripper_value(255, 70)
    time.sleep(3)
    # Let the gripper reach the state of 1500 at a speed of 70, 1500 will report an error, so change it to 255
    mc.set_gripper_value(255, 70)
    time.sleep(3)

    num=5
    while num>0:
        # Set the state of the gripper to quickly open the gripper at a speed of 70
        mc.set_gripper_state(0, 70)
        time.sleep(3)
        # Set the state of the gripper to quickly close the gripper at a speed of 70
        mc.set_gripper_state(1, 70)
        time.sleep(3)
        num-=1

    # Get the value of the gripper
    print("")
    print(mc.get_gripper_value())
    # mc.release_all_servos()

if __name__ == "__main__":
    # MyCobot class initialization requires two parameters:
    #   The first is the serial port string, such as:
    #       linux: "/dev/ttyUSB0"
    #       windows: "COM3"
    #   The second is the baud rate:
    #       M5 version is: 115200
    #
    #   Example:
    #       mycobot-M5:
    #           linux:
    #              mc = MyCobot("/dev/ttyUSB0", 115200)
    #           windows:
    #              mc = MyCobot("COM3", 115200)
    #       mycobot-raspi:
    #           mc = MyCobot(PI_PORT, PI_BAUD)
    #
    # Initialize a MyCobot object
    # Create object code for Raspberry Pi version below
    # mc = MyCobot(PI_PORT, PI_BAUD)
    # M5 version
    mc = MyCobot('COM3', 115200)
    # make it move to zero position

    mc.set_encoders([2048, 2048, 2048, 2048, 2048, 2048], 20)
    time.sleep(3)
    gripper_test(mc)

Adsorption pump control

from pymycobot.mycobot import MyCobot
from pymycobot import PI_PORT, PI_BAUD  # When using the Raspberry Pi version of mycobot, these two variables can be referenced to initialize MyCobot
import time

# MyCobot class initialization requires two parameters:
#   The first is the serial port string, such as:
#       linux: "/dev/ttyUSB0"
#       windows: "COM3"
#   The second is the baud rate:
#       M5 version is: 115200
#
#   Example:
#       mycobot-M5:
#           linux:
#              mc = MyCobot("/dev/ttyUSB0", 115200)
#           windows:
#              mc = MyCobot("COM3", 115200)
#       mycobot-raspi:
#           mc = MyCobot(PI_PORT, PI_BAUD)
#
# Initialize a MyCobot object
# Create object code here for M5 version
mc =MyCobot('COM3',115200)
# The position of the robot arm movement
angles = [
            [92.9, -10.1, -60, 5.8, -2.02, -37.7],
            [92.9, -53.7, -83.05, 50.09, -0.43, -38.75],
            [92.9, -10.1, -87.27, 5.8, -2.02, -37.7]
        ]


# Turn on the suction pump
def pump_on():
    # make position 2 work
    mc.set_basic_output(2, 0)
    # make position 5 work
    mc.set_basic_output(5, 0)

# stop the suction pump
def pump_off():
    # Stop position 2 from working
    mc.set_basic_output(2, 1)
    # Stop position 5 from working
    mc.set_basic_output(5, 1)


# Robotic arm recovery
mc.send_angles([0, 0, 0, 0, 0, 0], 30)
time.sleep(3)

#Turn on the suction pump
pump_on()
mc.send_angles(angles[2], 30)
time.sleep(2)

#absorb small blocks
mc.send_angles(angles[1], 30)
time.sleep(2)
mc.send_angles(angles[0], 30)
time.sleep(2)
mc.send_angles(angles[1], 30)
time.sleep(2)

#Turn off the suction pump
pump_off()
mc.send_angles(angles[0], 40)
time.sleep(1.5)
280-Pi version:

from pymycobot.mycobot import MyCobot
from pymycobot import PI_PORT, PI_BAUD  # When using the Raspberry Pi version of mycobot, these two variables can be referenced to initialize MyCobot
import RPi.GPIO as GPIO
import time

# MyCobot class initialization requires two parameters:
#   The first is the serial port string, such as:
#       linux: "/dev/ttyUSB0"
#       windows: "COM3"
#   The second is the baud rate:
#       M5 version is: 115200
#
#   Example:
#       mycobot-M5:
#           linux:
#              mc = MyCobot("/dev/ttyUSB0", 115200)
#           windows:
#              mc = MyCobot("COM3", 115200)
#       mycobot-raspi:
#           mc = MyCobot(PI_PORT, PI_BAUD)
#
# Initialize a MyCobot object
# Create object code here for Raspberry Pi version
mc = MyCobot(PI_PORT, PI_BAUD)

# The position of the robot arm movement
angles = [
            [92.9, -10.1, -60, 5.8, -2.02, -37.7],
            [92.9, -53.7, -83.05, 50.09, -0.43, -38.75],
            [92.9, -10.1, -87.27, 5.8, -2.02, -37.7]
        ]
# Turn on the suction pump
GPIO.setmode(GPIO.BCM)
GPIO.setup(20, GPIO.OUT)
GPIO.setup(21, GPIO.OUT)

# Turn on the suction pump
def pump_on():
    # make position 20 work
    GPIO.output(20,0)
    # make position 21 work
    GPIO.output(21,0)

# stop the suction pump
def pump_off():
    # make position 20 work
    GPIO.output(21,1)
    # make position 21 work
    GPIO.output(21,1)


# Robotic arm recovery
mc.send_angles([0, 0, 0, 0, 0, 0], 30)
time.sleep(3)

#Turn on the suction pump
pump_on()
mc.send_angles(angles[2], 30)
time.sleep(2)

#absorb small blocks
mc.send_angles(angles[1], 30)
time.sleep(2)
mc.send_angles(angles[0], 30)
time.sleep(2)
mc.send_angles(angles[1], 30)
time.sleep(2)

#Turn off the suction pump
pump_off()
mc.send_angles(angles[0], 40)
time.sleep(1.5)

C++

Environment building

Windows Environment Configuration

1 Downloading:
First download vs2019 from the official website.
2 Installation:
After installation is complete, the interface shown in the figure below will appear. "Universal Windows platform development, desktop development using C++, ASRNET and Web development" are mainly chosen (This is just a suggestion, you can choose according to your own needs. The installation time of vs2019 is long).

3 Environment variable configuration:
This Computer -> Right-click Properties -> Advanced System Settings -> Environment Variables -> Look at System Variables, click New -> Variable Name: VCINSTALLDIR variable value: Find the directory where Redist is located (eg: D:\vs2019\VC), for specific operation click here.

Installing qt5.12.10

1) Downloading:
Download qt5.12.10 and above versions. They are all available. For specific operation click here.
2) Installation:
First log into the qt account. if you haven't an qt account, register first. Next, the interface for selecting components will appear. You may select MinGW and MSVC on Windows, as shown in the following figure.

4 Environment variable configuration:
This Computer -> Right-click Properties -> Advanced System Settings -> Environment Variables -> Look at System Variables, click New -> Variable Name: QTDIR variable value: the directory where msvc2017_64 is located (eg: D:\qt5.12.10\5.12.10\msvc2017_64, it depends on your own computer installation path), for specific operation click here.

Installing qt plugin vsaddin

1) Downloading:
First select the vsaddin version corresponding to vs2019. For specific operation click here.
2) Installation: direct installation.
3) Configuration: vs2019 menu bar extension -> QT VS Tools -> QT Versions -> add new qtversion. For Path, select the path where msvc2017_64 is located (eg: D:\qt5.12.10\5.12.10\msvc2017_64). For specific operation click here.

Linux Environment Configuration

Installing qt5.12.10

1.Downloading:
The download address is the same as Windows. Select the installation package on Linux. For details, see the steps above.
2.Installation:
Command line installation: run ./"installation package name". If there is no execute permission, add execute permission: sudo chmod +x "installation package name", and then enter the graphical interface like Windows; graphical interface installation: the same as Windows.
It is recommended to install qt directly with ordinary user rights. After the installation is successful, you can execute qmake –version, and if the interface appears, installation is successful.
3.Configuration:
Open the configuration file, install qt: vi ~/.bashrc for ordinary users, and install qt: vi ~/.profile for root users. Add in the configuration file: export QTDIR="the directory where qt is located" (eg: export QTDIR=$HOME/Qt/5.12.10/gcc_64), click here to see details.

Compiling and running

Downloading

(1) Downloading source code
Download MycobotCpp on github.
(2) Dynamic library downloading
Dependency library downloading (Download the latest version, and pay attention to select Windows or Linux; the suffix.zip is the library required by Windows, and .tar.gz is the library required by Linux).

Running in Windows

1.Compiling

In vs2019, open MycobotCpp, select x64-Release to compile (which is next to the startup item. If there is no x64-Release, click the drop-down box -> Manage configuration to add it), at the same time select release in the configuration of cmake setting, and finally click Generate. Note: Be sure to select x64-Release to compile, click here to see details.

2.Running

Add library files: add .lib to myCobotCpp/lib. Add .lib and .dll to the directory of myCobotCppExample.exe, such as out/build/x64-Release/bin (The two files .lib and .dll are in the myCobotCpp-0.0.3-windows-msvc-x86_64.zip package). Running: Select the startup item (which is next to the green play button and also to the running button), drop down to select myCobotCppEXample.exe(bin\myCobotCppExample.exe), and click Run, click here to see details.

3.Common problems and solutions:

Run-time error:

Running in Linux

1.Compiling and building
1) mkdir build && cd build
2) cmake ..
3) cmake --build .
2.Run
1) copy all .so files to the lib directory
2) command line run: ./bin/myCobotCppExample (Here it is running in the build directory)

For example, running on Ubuntu20.04

  1. Compiling
    1) mkdir build && cd build
    2) cmake ..
    3) cmake –build .

  2. Run
    1) copy all .so files to the lib directory (Note: after downloading, unzip it. Do not unzip it in Windows, and then copy to Ubuntu. Unzip it directly in Ubuntu, for example: tar -xvf and then drag the file directly to the terminal)
    2) Soft-link libQt5SerialPort.so.5 (in the QT installation directory, such as: /home/"username"/Qt5.12.10/5.12.10/gcc_64/lib) to mycobotcpp/build/bin (Do not copy directly). The command is as follows (Be careful to choose your path): ln -s/home/"username"/Qt5.12.10/5.12.10/gcc_64/lib/libQt5SerialPort.so.5 /home/"username"/myCobotCpp/build/bin/libQt5SerialPort.so.5

  3. Common problems and solutions

Notice:If you don't use cmake to compile, for example, if use it directly in MFC, do configurations as shown in the figure below:

3) Use Cases
Joint control

int main(int argc, char* argv[])
try {
    QCoreApplication a(argc, argv);
    using namespace std::chrono_literals;
    if (!mycobot::MyCobot::I().IsControllerConnected()) {
        std::cerr << "Robot is not connected\n";
        exit(EXIT_FAILURE);
    }
    std::cout << "Robot is connected\n";
    mycobot::MyCobot::I().PowerOn();
    mycobot::MyCobot::I().StopRobot();
    std::cout << "Robot is moving: " << mycobot::MyCobot::I().IsMoving() << "\n";
    mycobot::Angles angles = mycobot::MyCobot::I().GetAngles();
    std::this_thread::sleep_for(200ms);
    mycobot::Coords coords = mycobot::MyCobot::I().GetCoords();
    angles = mycobot::MyCobot::I().GetAngles();
    std::cout << "[" << angles[mycobot::J1] << ", " << angles[mycobot::J2] << ", " << angles[mycobot::J3] << ", "
        << angles[mycobot::J4] << ", " << angles[mycobot::J5] << ", " << angles[mycobot::J6] << "]";
    mycobot::Angles goal_angles = { 5, 5, 5, 5, 5, 5 };
    mycobot::MyCobot::I().WriteAngles(goal_angles);
    while (!mycobot::MyCobot::I().IsInPosition(goal_angles, false)) {
        angles = mycobot::MyCobot::I().GetAngles();
        std::cout << "[" << angles[mycobot::J1] << ", " << angles[mycobot::J2] << ", "
            << angles[mycobot::J3] << ", " << angles[mycobot::J4] << ", "
            << angles[mycobot::J5] << ", " << angles[mycobot::J6] << "]" << std::flush;
        std::this_thread::sleep_for(200ms);
    }

    mycobot::MyCobot::I().JogAngle(mycobot::Joint::J1, 1, 5);
    std::this_thread::sleep_for(5000ms);
    mycobot::MyCobot::I().StopRobot();

    std::cout << "\n";
    exit(EXIT_SUCCESS);
} catch (std::error_code&) {
    std::cerr << "System error. Exiting.\n";
    exit(EXIT_FAILURE);
} catch (...) {
    std::cerr << "Unknown exception thrown. Exiting.\n";
    exit(EXIT_FAILURE);
}

Coordinate control

int main(int argc, char* argv[])
try {
    QCoreApplication a(argc, argv);
    using namespace std::chrono_literals;
    if (!mycobot::MyCobot::I().IsControllerConnected()) {
        std::cerr << "Robot is not connected\n";
        exit(EXIT_FAILURE);
    }
    std::cout << "Robot is connected\n";
    mycobot::MyCobot::I().PowerOn();
    mycobot::MyCobot::I().StopRobot();
    std::cout << "Robot is moving: " << mycobot::MyCobot::I().IsMoving() << "\n";
    mycobot::Angles angles = mycobot::MyCobot::I().GetAngles();
    std::this_thread::sleep_for(200ms);
    mycobot::Coords coords = mycobot::MyCobot::I().GetCoords();
    angles = mycobot::MyCobot::I().GetAngles();
    std::cout << "[" << angles[mycobot::J1] << ", " << angles[mycobot::J2] << ", " << angles[mycobot::J3] << ", "
        << angles[mycobot::J4] << ", " << angles[mycobot::J5] << ", " << angles[mycobot::J6] << "]";
    mycobot::Angles goal_angles = { 5, 5, 5, 5, 5, 5 };
    mycobot::MyCobot::I().WriteAngles(goal_angles);
    while (!mycobot::MyCobot::I().IsInPosition(goal_angles, false)) {
        angles = mycobot::MyCobot::I().GetAngles();
        std::cout << "[" << angles[mycobot::J1] << ", " << angles[mycobot::J2] << ", "
            << angles[mycobot::J3] << ", " << angles[mycobot::J4] << ", "
            << angles[mycobot::J5] << ", " << angles[mycobot::J6] << "]" << std::flush;
        std::this_thread::sleep_for(200ms);
    }

    mycobot::MyCobot::I().JogAngle(mycobot::Joint::J1, 1, 5);
    std::this_thread::sleep_for(5000ms);
    mycobot::MyCobot::I().StopRobot();

    std::cout << "\n";
    exit(EXIT_SUCCESS);
} catch (std::error_code&) {
    std::cerr << "System error. Exiting.\n";
    exit(EXIT_FAILURE);
} catch (...) {
    std::cerr << "Unknown exception thrown. Exiting.\n";
    exit(EXIT_FAILURE);
}

IO control

int main(int argc, char* argv[])
try {
QCoreApplication a(argc, argv);
using namespace std::chrono_literals;
if (!mycobot::MyCobot::I().IsControllerConnected()) {
    std::cerr << "Robot is not connected\n";
    exit(EXIT_FAILURE);
}
std::cout << "Robot is connected\n";
mycobot::MyCobot::I().PowerOn();

mycobot::MyCobot::I().SleepSecond(1);//Need to wait 1S for the previous motion to be done

//Set io output, 2, 5 and 26 are m5 output pins
mycobot::MyCobot::I().SetBasicOut(2, 1);
mycobot::MyCobot::I().SleepSecond(1);
mycobot::MyCobot::I().SetBasicOut(5, 1);
mycobot::MyCobot::I().SleepSecond(1);
mycobot::MyCobot::I().SetBasicOut(26, 1);
mycobot::MyCobot::I().SleepSecond(1);

//delay will occur on m5 input pins 35 and 36 for the first time
/*for (int i = 0; i < 2; i++) {
    std::cout << "35= " << mycobot::MyCobot::I().GetBasicIn(35) << std::endl;
    mycobot::MyCobot::I().SleepSecond(1);
    std::cout << "36= " << mycobot::MyCobot::I().GetBasicIn(36) << std::endl;
    mycobot::MyCobot::I().SleepSecond(1);
}*/

//atom output pins 23 and 33
/*mycobot::MyCobot::I().SetDigitalOut(23, 1);
mycobot::MyCobot::I().SleepSecond(1);
mycobot::MyCobot::I().SetDigitalOut(33, 1);
mycobot::MyCobot::I().SleepSecond(1);*/

//delay will occur on atom input pins 22 and 19 for the first time
/*for (int i = 0; i < 2; i++) {
    std::cout << "22= " << mycobot::MyCobot::I().GetDigitalIn(22) << std::endl;
    mycobot::MyCobot::I().SleepSecond(1);
    std::cout << "19= " << mycobot::MyCobot::I().GetDigitalIn(19) << std::endl;
    mycobot::MyCobot::I().SleepSecond(1);
}*/

//Adaptive gripper 1--open 0--close send twice due to first delay
/*for (int i = 0; i < 2; i++) {
    mycobot::MyCobot::I().SetGriper(1);
    mycobot::MyCobot::I().SleepSecond(3);
    mycobot::MyCobot::I().SetGriper(0);
    mycobot::MyCobot::I().SleepSecond(3);
}*/

//Electric gripper 1--open 0--close send twice due to first delay
/*for (int i = 0; i < 2; i++) {
    mycobot::MyCobot::I().SetElectricGriper(1);
    mycobot::MyCobot::I().SleepSecond(1);
    mycobot::MyCobot::I().SetElectricGriper(0);
    mycobot::MyCobot::I().SleepSecond(1);
}*/
/*mycobot::MyCobot::I().StopRobot();
std::cout << "Robot is moving: " << mycobot::MyCobot::I().IsMoving() << "\n";
mycobot::Angles angles = mycobot::MyCobot::I().GetAngles();
std::this_thread::sleep_for(200ms);
mycobot::Coords coords = mycobot::MyCobot::I().GetCoords();
angles = mycobot::MyCobot::I().GetAngles();
std::cout << "[" << angles[mycobot::J1] << ", " << angles[mycobot::J2] << ", " << angles[mycobot::J3] << ", "
    << angles[mycobot::J4] << ", " << angles[mycobot::J5] << ", " << angles[mycobot::J6] << "]";
mycobot::Angles goal_angles = { 1, 0, 0, 0, 0, 0 };
mycobot::MyCobot::I().WriteAngles(goal_angles,180);
while (!mycobot::MyCobot::I().IsInPosition(goal_angles, false)) {
    angles = mycobot::MyCobot::I().GetAngles();
    std::cout << "[" << angles[mycobot::J1] << ", " << angles[mycobot::J2] << ", "
        << angles[mycobot::J3] << ", " << angles[mycobot::J4] << ", "
        << angles[mycobot::J5] << ", " << angles[mycobot::J6] << "]" << std::flush;
    std::this_thread::sleep_for(200ms);
}

//mycobot::MyCobot::I().JogAngle(mycobot::Joint::J1, 1, 5);
std::this_thread::sleep_for(5000ms);
mycobot::MyCobot::I().StopRobot();*/

std::cout << "\n";
exit(EXIT_SUCCESS);
} catch (std::error_code&) {
std::cerr << "System error. Exiting.\n";
exit(EXIT_FAILURE);
} catch (...) {
std::cerr << "Unknown exception thrown. Exiting.\n";
exit(EXIT_FAILURE);
}

Gripper control

int main(int argc, char* argv[])
try {
QCoreApplication a(argc, argv);
using namespace std::chrono_literals;
if (!mycobot::MyCobot::I().IsControllerConnected()) {
    std::cerr << "Robot is not connected\n";
    exit(EXIT_FAILURE);
}
std::cout << "Robot is connected\n";
mycobot::MyCobot::I().PowerOn();

mycobot::MyCobot::I().SleepSecond(1);//Need to wait 1S for the previous motion to be done

//Set io output, 2, 5 and 26 are m5 output pins
mycobot::MyCobot::I().SetBasicOut(2, 1);
mycobot::MyCobot::I().SleepSecond(1);
mycobot::MyCobot::I().SetBasicOut(5, 1);
mycobot::MyCobot::I().SleepSecond(1);
mycobot::MyCobot::I().SetBasicOut(26, 1);
mycobot::MyCobot::I().SleepSecond(1);

//delay will occur on m5 input pins 35 and 36 for the first time
/*for (int i = 0; i < 2; i++) {
    std::cout << "35= " << mycobot::MyCobot::I().GetBasicIn(35) << std::endl;
    mycobot::MyCobot::I().SleepSecond(1);
    std::cout << "36= " << mycobot::MyCobot::I().GetBasicIn(36) << std::endl;
    mycobot::MyCobot::I().SleepSecond(1);
}*/

//atom output pins 23 and 33
/*mycobot::MyCobot::I().SetDigitalOut(23, 1);
mycobot::MyCobot::I().SleepSecond(1);
mycobot::MyCobot::I().SetDigitalOut(33, 1);
mycobot::MyCobot::I().SleepSecond(1);*/

//delay will occur on atom input pins 22 and 19 for the first time
/*for (int i = 0; i < 2; i++) {
    std::cout << "22= " << mycobot::MyCobot::I().GetDigitalIn(22) << std::endl;
    mycobot::MyCobot::I().SleepSecond(1);
    std::cout << "19= " << mycobot::MyCobot::I().GetDigitalIn(19) << std::endl;
    mycobot::MyCobot::I().SleepSecond(1);
}*/

//Adaptive gripper 1--open 0--close send twice due to first delay
for (int i = 0; i < 2; i++) {
    mycobot::MyCobot::I().SetGriper(1);
    mycobot::MyCobot::I().SleepSecond(3);
    mycobot::MyCobot::I().SetGriper(0);
    mycobot::MyCobot::I().SleepSecond(3);
}

//Electric gripper 1--open 0--close send twice due to first delay
/*for (int i = 0; i < 2; i++) {
    mycobot::MyCobot::I().SetElectricGriper(1);
    mycobot::MyCobot::I().SleepSecond(1);
    mycobot::MyCobot::I().SetElectricGriper(0);
    mycobot::MyCobot::I().SleepSecond(1);
}*/
/*mycobot::MyCobot::I().StopRobot();
std::cout << "Robot is moving: " << mycobot::MyCobot::I().IsMoving() << "\n";
mycobot::Angles angles = mycobot::MyCobot::I().GetAngles();
std::this_thread::sleep_for(200ms);
mycobot::Coords coords = mycobot::MyCobot::I().GetCoords();
angles = mycobot::MyCobot::I().GetAngles();
std::cout << "[" << angles[mycobot::J1] << ", " << angles[mycobot::J2] << ", " << angles[mycobot::J3] << ", "
    << angles[mycobot::J4] << ", " << angles[mycobot::J5] << ", " << angles[mycobot::J6] << "]";
mycobot::Angles goal_angles = { 1, 0, 0, 0, 0, 0 };
mycobot::MyCobot::I().WriteAngles(goal_angles,180);
while (!mycobot::MyCobot::I().IsInPosition(goal_angles, false)) {
    angles = mycobot::MyCobot::I().GetAngles();
    std::cout << "[" << angles[mycobot::J1] << ", " << angles[mycobot::J2] << ", "
        << angles[mycobot::J3] << ", " << angles[mycobot::J4] << ", "
        << angles[mycobot::J5] << ", " << angles[mycobot::J6] << "]" << std::flush;
    std::this_thread::sleep_for(200ms);
}

//mycobot::MyCobot::I().JogAngle(mycobot::Joint::J1, 1, 5);
std::this_thread::sleep_for(5000ms);
mycobot::MyCobot::I().StopRobot();*/

std::cout << "\n";
exit(EXIT_SUCCESS);
} catch (std::error_code&) {
std::cerr << "System error. Exiting.\n";
exit(EXIT_FAILURE);
} catch (...) {
std::cerr << "Unknown exception thrown. Exiting.\n";
exit(EXIT_FAILURE);
}

C#

1) Environment building
Windows Environment Configuration
Installing vs2019
(1) Downloading:
First download vs2019 from the official website.
(2) Installation:
After installation is complete, the interface shown in the figure below will appear. .NET desktop development is mainly chosen (This is just a suggestion, you can choose according to your own needs. The installation time of vs2019 is long).

Environment configuration of Raspberry Pi robot arm
1) Installing monodevelop
(1) Installation
Execute the following commands in order to install it. You may also view the instructions on the official website.
sudo apt install apt-transport-https dirmngr

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF echo "deb https://download.mono-project.com/repo/ubuntu vs-bionic main" | sudo tee /etc/apt/sources.list.d/mono-official-vs.list

sudo apt update

sudo apt-get install monodevelop
(2) Test
Test whether the installation is successful. Check this documentdocument.

2) Compiling and Running
Downloading
(1) Downloading source code
Download Mycobot.csharp from github.

(2) Downloading a dynamic library
To run the case, you need to use this dynamic library, which encapsulates the API to control the robot arm:
1.Select the latest version, as shown in the following figure:

2.The dynamic library is divided into two versions: Windows (Windows is divided into .net and .net framework. For the way to distinguish them, see running under Windows below) and Raspberry Pi system, as shown in the following figure.

Running in Windows
(1) Directly running the Mycobot.csharp case downloaded from github:
1.Double-click Mycobot.csharp.sln to open it (Make sure that vs2019 has been installed in the computer. If not, see Environment building)

2.Compile and run the project, and check the serial port number of the robot arm. If it is inconsistent with the example, modify the serial port number, as shown here.

(2) Calling a Mycobot.csharp dynamic library in your own project
1.Check the target frame of the project, and then download the corresponding dynamic library. If the target frame is .net core, download net core/Mycobot.csharp.dll, if it is .net framework, download net framework/Mycobot.csharp.dll). For specific steps click here.
2.Import Mycobot.csharp.dll into the project. For specific steps click here.
3.Add system.io.ports to .csproj (the project name, and the file is located in the directory of the project), as shown in the picture below: frame: .net core

frame: .net framework

(3) Problems
Problems that may be encountered during use:

1.Problem: System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies...
Solution: update your sdk(if .net core,update to 5.0 and choose,if .net framework update to 4.0 and choose 4.7.2), click here to view:

2.Problem: System.IO.FileNotFoundException:“Could not load file or assembly 'System.IO.Ports, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.
Solution: See the step 3 of calling dynamic library above.

Running in the Raspberry Pi robot arm
1.Create a C# console application;
2.Copy the program.cs and paste it to the application;
3.change the port number in program.cs to /dev/ttyAMA0(MyCobot mc = new MyCobot("/dev/ttyAMA0"));

4.Change the compilation method to Release;

5.Add the Mycobot.csharp.dll library file to the project, library: ReFerences–>Edit References–>.Net Assembly–>Browse(path for .dll), click here to view.
6.Run it. Note: compile and run it. For the whole operation process, click here.

3) Use Cases
Joint control
The program.cs in Mycobot.csharp source code is a complete use case program, which can be modified as needed on this basis.

using System;

namespace Mycobot.csharp
{
    class Test 
    {
        static void Main(string[] args)
        {
            MyCobot mc = new MyCobot("/dev/ttyUSB0");
            mc.Open();
            // int[] angles = new[] {100, 100, 100, 100, 100, 100};
            // mc.SendAngles(angles, 50);
            // Thread.Sleep(5000);
            // var recv = mc.GetAngles();
            // foreach (var v in recv)
            // {
                // Console.WriteLine(v);
            // }

            // int[] coords = new[] {160, 160, 160, 0, 0, 0};
            // mc.SendCoords(coords, 90, 1);
            // Thread.Sleep(5000);
            // var recv = mc.GetCoords();
            // foreach (var v in recv)
            // {
                // Console.WriteLine(v);
            // }

            mc.SendOneAngle(1, 100,70);

            // byte[] setColor = {0xfe, 0xfe, 0x05, 0x6a, 0xff, 0x00, 0x00, 0xfa};
            mc.Close();
        }
    }

Coordinate control

The program.cs in Mycobot.csharp source code is a complete use case program, which can be modified as needed on this basis.

using System;

namespace Mycobot.csharp
{
    class Test 
    {
        static void Main(string[] args)
        {
            MyCobot mc = new MyCobot("/dev/ttyUSB0");
            mc.Open();
            // int[] angles = new[] {100, 100, 100, 100, 100, 100};
            // mc.SendAngles(angles, 50);
            // Thread.Sleep(5000);
            // var recv = mc.GetAngles();
            // foreach (var v in recv)
            // {
                // Console.WriteLine(v);
            // }

            // int[] coords = new[] {160, 160, 160, 0, 0, 0};
            // mc.SendCoords(coords, 90, 1);
            // Thread.Sleep(5000);
            // var recv = mc.GetCoords();
            // foreach (var v in recv)
            // {
                // Console.WriteLine(v);
            // }

            mc.SendOneAngle(1, 100,70);

            // byte[] setColor = {0xfe, 0xfe, 0x05, 0x6a, 0xff, 0x00, 0x00, 0xfa};
            mc.Close();
        }
    }

IO control

The program.cs in Mycobot.csharp source code is a complete use case program, which can be modified as needed on this basis.

using System;
using System.Threading;

namespace Mycobot.csharp
{
    class Test
    {
        static void Main(string[] args)
        {
            MyCobot mc = new MyCobot("COM57");//Raspberry Pi robot arm serial port name:/dev/ttyAMA0
            mc.Open();
            Thread.Sleep(5000);//After windows open the serial port, you need to wait 5s, the bottom basic will restart when windows open the serial port

            //set basic output io
            /*mc.SetBasicOut(2, 1);
            Thread.Sleep(100);
            mc.SetBasicOut(5, 1);
            Thread.Sleep(100);
            mc.SetBasicOut(26, 1);
            Thread.Sleep(100);*/

            //get basic input io
            Console.WriteLine(mc.GetBasicIn(35));
            Thread.Sleep(100);
            Console.WriteLine(mc.GetBasicIn(36));
            Thread.Sleep(100);

            //set atom output io
            /*mc.SetDigitalOut(23, 0);
            Thread.Sleep(100);
            mc.SetDigitalOut(33, 0);
            Thread.Sleep(100);*/

            //get m5 input io
            /*Console.WriteLine(mc.GetDigitalIn(19));
            Thread.Sleep(100);
            Console.WriteLine(mc.GetDigitalIn(22));
            Thread.Sleep(100);*/

            mc.Close();
        }
    }
}

Gripper control

using System;
using System.Threading;

namespace Mycobot.csharp
{
    class Test
    {
        static void Main(string[] args)
        {
            MyCobot mc = new MyCobot("COM57");//Raspberry Pi robot arm serial port name:/dev/ttyAMA0
            mc.Open();
            Thread.Sleep(5000);//After windows open the serial port, you need to wait 5s, the bottom basic will restart when windows open the serial port

            //set gripper open or close 0--close 100-open max 0-100
            mc.setGripperValue(0, 10);
            Thread.Sleep(3000);
            mc.setGripperValue(50, 100);
            Thread.Sleep(3000);

            //set electric gripper
            mc.setEletricGripper(0);
            Thread.Sleep(100);
            mc.setEletricGripper(1);
            Thread.Sleep(100);

            //get gripper state 0--close 1--open
            Console.WriteLine(mc.getGripperValue());
            mc.Close();
        }
    }
}

JavaScript

1. Preparations before development

windows 32-bit downloading address
windows 64-site downloading address
macOs downloading address

1) Windows Node environment building

Step 1: After downloading is completed, double-click the downloaded installation package to start installing Node.js. Click the Next button

Step 2: Check the option in the lower left red box, and click Next

Step 3: Customize the installation directory

Step 4: Click the Next button (default)

Step 5: Click Install

Step 6: Click Finish to complete the installation

Step 7: Open and run with win+r, input cmd to a command indicator

Step 8: Input node -v to get the node version; when the version is displayed, its means that the installation is completed successfully.

2)MacOs node environment building

Step 1: After downloading is completed, double-click the downloaded installation package to start installing Node.js. Click the Next button, click Continue

Step 2: Click Continue again

Step 3: Click Agree to go to the next step

Step 4: Click Customize, choose the installation address, or click Install to continue the installation and input your password to install

Step 5: When successful installation is prompted, click Close to exit The installation process

Right-click on the desktop and select a punching terminal, enter the terminal and input node -v. If the node version number is displayed, it means that installation is done successfully

3)Linux node environment building

Step 1: The official Node website has changed the linux downloading version to a compiled version, so we can directly download and unzip it for use:

# wget https://nodejs.org/dist/v10.9.0/node-v10.9.0-linux-x64.tar.xz    // download
# tar xf  node-v10.9.0-linux-x64.tar.xz       // unzip
# cd node-v10.9.0-linux-x64/                  // enter the unzipping directory
# ./bin/node -v                               // execute node command, and check version
v10.9.0

Step 2: The bin directory of the unzipped file contains commands such as node, npm, etc. We can use the ln command to set up a soft connection:

ln -s /usr/software/nodejs/bin/npm   /usr/local/bin/ 
ln -s /usr/software/nodejs/bin/node   /usr/local/bin/

(4) Installing Node.js using Ubuntu source code Step 1: In the following part, we will introduce the installation of Node.js in Ubuntu Linux using source code. For other Linux systems, such as Centos, perform the installation steps below. Get Node.js source code from Github.

$ sudo git clone https://github.com/nodejs/node.git
Cloning into 'node'...

Step 2: Modify the permission of the directory.

$ sudo chmod -R 755 node

Step 3: Create a compiling file using ./configure according to the following code:

$ cd node
$ sudo ./configure
$ sudo make
$ sudo make install

Step 4: Check the node version

$ node --version
v0.10.25

2.Preparations for development

(1) Downloading a project file
Open the command prompt

git clone https://github.com/elephantrobotics/jsmycobot.git

(2) Initializing a development program
Note: Open the command prompt in the downloaded project file.

<!-- initialize the program, then install and run all plug-ins required therefor -->
npm i

(3) Initializing the program

<!-- Import the plug-in installed in step 1-1 -->
const mycobot = require("mycobot")

<!-- initialize the program,mycobot.connect(serial port number, serial baud rate) -->
const obj = mycobot.connect("COM15",115200)

<!-- write in the first command, power up the robot arm and keep its current posture -->
obj.write(mycobot.powerOn())

3.Using Case

IO Control

<!-- Initialize Program -->
const mycobot = require('mycobot')

const obj = mycobot.connect('COM15',115200)

<!-- Set ATOM indicator color, mycobot.setColor(redValue, greenValue, blueVaule)-->
<!-- Note: the three parameters should be within 0-255 -->
obj.write(mycobot.setColor(125,11,9))

<!-- Take the current angle and coordinates of the robot arm as the starting point -->
obj.write(mycobot.setGripperInit())

Single Joint Control

<!-- Initialize Program -->
const mycobot = require('mycobot')

const obj = mycobot.connect('COM15',115200)

<!-- Set angle of single-joint robot arm, mycobot.sendAngle(Robot arm ID, angle, speed)-->
<!-- Note: pay attention to the number of joints when adjusting angles. For 4-joints, input 1-4; for 6 joints, input 1-6, otherwise, error may occur -->
<!-- For 4-axis/6-axis robot arm angle setup, refer to chart 1-3-->
obj.write(mycobot.sendAngle(1,110,10))

<!-- Set coordinate of single-joint robot arm, mycobot.sendCoord(Robot arm ID, coordinate, speed)-->
obj.write(mycobot.sendCoord(1,20,10))

Multiple Joints Control

Note: Fill the corresponding parameters according to the number of joints when multiple joints are operated.

<!-- Initialize -->
const mycobot = require('mycobot')

const obj = mycobot.connect('COM15',115200)

<!-- Set angles of multi-joints robot arm, mycobot.sendAngles([joint 1 , joint 2, joint 3, joint 4, joint 5, joint 6], speed) -->
obj.write(mycobot.sendAngles([-110,23,-22,110],20))

<!-- Set coordinates of multi-joints robot arm, mycobot.sendCoords([joint 1 , joint 2, joint 3, joint 4, joint 5, joint 6], speed) -->
obj.write(mycobot.sendCoords([22.5,12,-22,45],20))
Joint ID Range
1 -170 to 170
2 -170 to 170
3 -170 to 170
4 -170 to 170
5 -170 to 170
6 Not limited

Gripper Control

<!-- Initialize Program -->
const mycobot = require('mycobot')

const obj = mycobot.connect('COM15',115200)

<!-- Set gripper state, mycobot.setGripperState(On/Off, speed)-->
<!-- Note: 0 for on, 1 for off. Speed range: 0-100 -->
obj.write(mycobot.setGripperState(0,10))

<!-- Set gripper angle, mycobot.setGripperValue(angle, speed)-->
<!-- Note: angle and speed values are both between 0-100 -->
obj.write(mycobot.setGripperValue(80,20)))

Sample Code 1

<!-- Initialize Program -->
const mycobot = require('mycobot')
const obj = mycobot.connect('COM15',115200)

<!-- If the device connected is a 4-axis robot arm -->
const name = "myPallizer"
<!-- If the device connected is a 6-axis robot arm -->
if(name == "myCobot"){
    <!-- Set angles of six joints -->
    obj.write(mycobot.sendAngles([-1.49,115,-153.45,30,-33.42,137.9],80))
    <!-- And judge if it reaches the coordinate -->
    if(obj.write(mycobot.isInPosition([-1.49,115,-153.45,30,-33.42,137.9],0)) == 1){
        <!-- Robot arm continues to move -->
        obj.write(mycobot.programResume())
        <!-- Wait 0.5 second -->
        settimeout(() =>{
            <!-- Robot arm stops -->
            obj.write(mycobot.programPause())
        },500)
    }
}else{
    <!-- Set angles of four joints -->
    obj.write(mycobot.sendAngles([-1.49,45,-23,30],80))
    <!-- Set ATOM indicator color -->
    obj.write(mycobot.setColor(0,0,50))
    <!-- Wait 0.7 second -->
    settimeout(() =>{
        <!-- Set angles of four joints again -->
        obj.write(mycobot.sendAngles([-1.49,60,11,30],80))
        <!-- Set ATOM indicator color -->
        obj.write(mycobot.setColor(0,50,0))
    },700)

}

Sample Code 2

<!-- Initialize Program -->
const mycobot = require('mycobot')
const obj = mycobot.connect('COM15',115200)

<!-- Read all joint angles -->
const botData = obj.write(mycobot.getAngles())
<!-- Output all joint angles -->
console.log(botdata)
<!-- Set all joint angles -->
obj.write(mycobot.sendAngles([0,0,0,0],50))
<!-- Print if the robot arm reaches the position currently -->
console.log(obj.write(mycobot.isInPosition([0,0,0,0,0,0],0)) == 1)

<!-- Wait 3 seconds -->
settimeout(() =>{
    <!-- Set the first joint angle -->
    obj.write(mycobot.sendAngle(1,90,50))
},3000)

<!-- Wait 2 seconds -->
settimeout(() =>{
    <!-- Set the second joint angle to 50 degrees -->
    obj.write(mycobot.sendAngle(2,50,50))
},2000)
<!-- Wait 1.5 seconds -->
settimeout(() =>{
    <!-- Set the third joint angle to 50 degrees -->
    obj.write(mycobot.sendAngle(3,-50,50))
},1500)
<!-- Wait 1.5 seconds -->
settimeout(() =>{
    <!-- Set all joint angles -->
    obj.write(mycobot.sendAngles([88.68, -138.51, 155.65, -128.05, -9.93, -15.29],50))
},1500)
<!-- Wait 2.5 seconds -->
settimeout(() =>{
    <!-- Set robot arm to free mode -->
    obj.write(mycobot.releaseAllServos())
},2500)

FAQ

For any questions, advice or cool ideas to share, please visit the DFRobot Forum.

Version Update Announcement

Performance Enhancement

1.Repeat Positioning Precision

The internal components of myCobot have been replaced with superior-quality and higher-precision parts, resulting in a remarkable improvement in the repeatability of myCobot 280 robotic arm, achieving an impressive ±0.5mm positioning accuracy. This significant enhancement in repeat positioning precision enables myCobot 280 to be suitable for a wider range of scenarios and enables it to perform more intricate tasks, making precise commercial applications a tangible reality!

2.Doubling of Lifespan

By incorporating material and structural advancements, subjecting it to rigorous testing, and ensuring cost-effectiveness, the 2023 edition of myCobot 280 is set to witness a 100% increase in its operational lifespan compared to its predecessors.

3.Self-interference detection

Following a comprehensive redesign of the motion algorithm for myCobot robotic arm, this latest update has equipped myCobot with the capability of self-interference detection.

4.The communication speed has been enhanced by a staggering fivefold

The communication speed refers to the time it takes for the robotic arm to receive instructions and provide feedback. The speed of communication greatly influences the efficiency of the arm's tasks, its learning capabilities, and user experience. In this latest update, through hardware enhancements, the communication speed of the myCobot 280 robotic arm has been boosted to 20ms, nearly five times faster than before.

5.An overall joint optimization

Through extensive testing using various materials and combinations, the most suitable configuration was ultimately selected, resulting in significant improvements in stability, durability, and precision for the 2023 version of myCobot 280. Within the robotic arm, all joint motors have been replaced with fully metallic motors, ensuring resilience even during repeated disassembly and assembly, thus enhancing the manipulator's versatility. Additionally, meticulous adjustments have been made to the arm joints, increasing the length of connecting components to achieve smoother arm movements.

6.The stiffness has been enhanced, rendering the overall structure less susceptible to damage

The casing has been reinforced with added ribs, while the proportion of polycarbonate in the material has been increased. As a result, the overall rigidity of the casing has been significantly enhanced, leading to a remarkable improvement in hardness and resistance to damage.

Introducing three new features

1.Creative Expression

The precision and stability of the robotic arm have been significantly enhanced, thanks to an upgraded kinematic algorithm. With this advancement, the arm can effortlessly produce fluent strokes, supporting both writing and simple drawing tasks. It opens up a world of artistic possibilities for users, allowing them greater freedom to unleash their creativity.

2.Mobile App Control

The addition of myCobot_Control App enables wireless control of the robot through a smartphone. Each degree of freedom of the robotic arm can be individually manipulated via a Bluetooth module installed on the main control board. The app also provides configurable buttons for creating various movements, granting users seamless control over the robot's actions.

3.Gamepad Control

Introducing myCobot_Gamepad, a wireless remote controller allowing users to operate the robot with ease. The gamepad control mode utilizes a receiver installed on the main control board to capture and interpret the control signals emitted by the gamepad. This efficient and user-friendly control mode simplifies the interaction with the robotic arm, enhancing the overall user experience.

More Documents

DFshopping_car1.png Get Raspberry Pi Six-axis Robotic Arm from DFRobot Store or DFRobot Distributor.

Turn to the Top