# Coordinate control

It is mainly used to realize intelligent route planning to make the robot arm move from one position to another specified position. It is divided into `[x, y, z, rx, ry, rz]`. Among them `[x,y,z]` represents the position of the robot arm head in space (The coordinate system is Cartesian coordinate system); `[rx,ry,rz]` represents the posture of such head at this point (The coordinate system is Euler coordinates). The realization of the algorithm and the representation of Euler coordinates require a certain degree of academic knowledge. We will not explain it too much here. We can use this function well as long as we understand the Cartesian coordinate system.

Note: When setting the coordinates, different series of manipulators have different joint structures. For the same set of coordinates, different series of manipulators will show different postures. ## 1 Single parameter coordinates

1.1 `send_coord(id,coord,speed)`

• Function: to send a single coordinate value to the robot arm to make it move.
• Description of parameters:
• `id`: represents the coordinates of the robotic arm. Six axis means that the robot arm has six joints, and four-axis means it has four joints. and there are specific representation methods therefor. The way to represent X coordinate:`Coord.X.value`. There is also a simple representation method. For example, you can fill in 1 for X-axis, 2 for Y-axis, and so on.
• `coord`: Input the coordinate value you want.
• `speed`: means the movement speed of the robot arm, ranging from 0 to 100.
• Return value: None

## 2 Multiple parameter coordinates

2.1 `get_coords()`

• Function: to obtain the current coordinate and posture.
• Return value: `list`: a list containing coordinates and postures.
• Six axes: The length is 6, and they are `[x, y, z, rx, ry, rz]` in order.
• Four axes: The length is 6, and they are `[x, y, z, rx]` in order.

2.2 `send_coords(coords, speed, mode)`

• Function: to send the overall coordinates and postures to move the robot arm head from the original point to the point you have specified.
• Description of parameters:
• `coords`:
• Six axes: The length of the coordinate value of ```[x, y, z, rx, ry, rz]``` is 6.
• Four axes: The length of the coordinate value of `[x,y,z,rx]` is 4.
• `speed`: means the movement speed of the robot arm, ranging from 0 to 100.
• `mode`: (`int` ): The value is limited to 0 and 1.
• 0 means that the movement path of the robot arm head is non-linear, i.e. the movement route is randomly planned just to make sure that the head moves to a specified point with a specified posture.
• 1 means that the movement path of the robot arm head is linear, i.e. the movement route is intelligently planned just to make sure that the head moves to a specified point with a specified posture in a linear manner.
• Return value: None

## 3 Cases

For more cases and running result videos, see 7.7 Use Cases.

``````from pymycobot.mycobot import MyCobot
from pymycobot.genre import Coord
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
import time

# MyCobot class initialization requires two parameters:
#   The first is the serial port string, such as:
#       linux:  "/dev/ttyUSB0"
#          or "/dev/ttyAMA0"
#       windows: "COM3"
#   The second is the baud rate::
#       M5 version is:  115200
#
#    Example:
#       mycobot-M5:
#           linux:
#              mc = MyCobot("/dev/ttyUSB0", 115200)
#          or mc = MyCobot("/dev/ttyAMA0", 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)

# Get the current coordinates and pose of the head
coords = mc.get_coords()
print(coords)

# Intelligently plan the route, let the head reach the coordinates of [57.0, -107.4, 316.3] in a linear manner, and maintain the attitude of [-93.81, -12.71, -163.49], the speed is 80mm/s
mc.send_coords([57.0, -107.4, 316.3, -93.81, -12.71, -163.49], 80, 1)

# Set the wait time to 1.5 seconds
time.sleep(1.5)

# Intelligently plan the route, let the head reach the coordinates of [-13.7, -107.5, 223.9] in a linear way, and maintain the attitude of [165.52, -75.41, -73.52], the speed is 80mm/s
mc.send_coords([-13.7, -107.5, 223.9, 165.52, -75.41, -73.52], 80, 1)

# Set the wait time to 1.5 seconds
time.sleep(1.5)

# To change only the x-coordinate of the head, set the x-coordinate of the head to -40. Let it plan the route intelligently and move the head to the changed position, with a speed of 70mm/s
mc.send_coord(Coord.X.value, -40, 70)
``````