Algorithms for Robot Manipulator Control
To reach a broader audience, this article has been translated from Japanese.
You can find the original version here.
Algorithms for Robot Manipulator Control
#Mamezou Engineering Solutions Division, Takahiro Ishii
1. Introduction
#At Mamezou, we develop various robotics technologies. We often develop applied technologies that meet client demands using robots from other companies, but we also develop industrial robots with 6-axis or 7-axis arms, known as robot arms or manipulators, from scratch. Through this development, we generate various applied technologies and proposals. I would like to share the knowledge gained here with the readers. In this explanation, I will explain various mechanisms for controlling a 6-axis industrial vertical articulated manipulator, especially introducing fundamental algorithms and related mathematics. Understanding the technical background of ROS (Robot Operating System) will also be helpful for applying and improving robots. This time, I will explain the most basic trajectory generation process.
2. What is a Robot Manipulator?
#Main Body Structure
#First, I would like to explain what the hardware to be controlled is. The figure below is a typical industrial manipulator. Modeled after a human arm, it has 5 links (bones) at the end of 6 rotary joint axes and can reproduce various hand movements. The axes are, from the bottom up,
- Ws axis (Waist)
- Sh axis (Shoulder)
- Eb axis (Elbow)
- Rt axis (Wrist Rotation)
- Bn axis (Wrist Bending)
- Tr axis (Wrist Turning)
They are called. (Others are called [S axis, L axis, U axis, R axis, B axis, T axis] or simply [J1 axis, J2 axis, J3 axis, ..., J6 axis].)
A tool (hand) is attached to the end of the Tr axis. For example, depending on the work purpose, it can be replaced with a welding machine, laser device, grinder, driver, drill, suction machine, gripper, camera, etc.
Each axis has an AC servo motor, a reducer, and a mechanical brake, which rotate to control the precise position and posture of the hand in three dimensions. By controlling the presence or absence of power, the mechanical brake can be actively released or applied. In the event of a sudden interruption of power or communication, the mechanical brake automatically applies, preventing the arm from free-falling due to its own weight.
Main Peripheral Devices
#<Motor Driver>
It is a computer that controls the electric current to the motor so that it reaches a specified angle, specified angular velocity, or specified torque. It is designed for quick and smooth motor operation through feedback control using the rotary angle sensor in the servo motor and various signal filters. Normally, one motor driver is connected to each motor, and a total of six motor drivers are required for body control.
Each motor is connected by a communication cable for the rotary angle sensor and a power cable. The motor is powered and its own calculations are powered by a power unit.
<Robot Controller>
It is the main computer that comprehensively issues commands to the six motor drivers. It is also a computing device that performs various numerical calculations for the control described in this article, and is a communication I/O device such as EtherCAT, LAN, and Serial I/O. It is connected to six motor drivers via communication standards such as EtherCAT and CAN, synchronizes multiple motors, sends command values to each motor driver, and receives the actual values reached.
It also receives commands from human user interfaces (HUI) such as pendants, interprets and executes robot programs, configures environments, and records data. Furthermore, when devices for tool control are added to the robot, it also controls I/O with them and controls synchronized with robot operation.
<Pendant>
It is a controller that serves as an HUI. It is equipped with JOG operation buttons for instructing forward/reverse rotation for each axis and for moving and changing the posture of the hand in 3D in a straight line/circular shape. It also has functions to display, edit, and execute programs for giving complex operation instructions to the robot.
<Power Unit>
It distributes power to various devices from the AC power source. It transforms and becomes the AC power source for servo motors and the DC power source for peripheral devices. Since it handles large currents, it is often equipped with mechanical switches such as relays.
Mechanism of Main Body Operation
#With the above configuration, the arm can be moved by repeating the following processes.
- The robot controller calculates the joint angles required for the operation for all six axes.
- Send each angle value of the element to the corresponding motor driver and execute the command.
- The servo motors rotate and each joint moves until each commanded angle value of is reached.
- The robot controller obtains the actual angles reached by each motor driver.
Here, is a vector representing the joint axis angles between links, consisting of six elements
The cycle T in which the above repetition can be performed varies depending on the mechanical performance and the processing performance of the motor driver, but it is a fixed value of about 1-2 milliseconds (ms). In practice, buffering is performed, that is, multiple samples of are created in advance, and sent to the motor driver all at once as asynchronous I/O. For example, if T=1[ms] and N=100 unit times, the time series is sent all at once, and the actual arm operation time becomes exactly 100[ms]=0.1 second(s). If the next 100 samples of have been calculated and sent by this 0.1(s), continuous operation of the arm is possible without interruption. The figure below is an example of a processing sequence that realizes this.
In the next chapter, I will explain how to control the manipulator with software using this mechanism.
3. Basic Control Algorithms
#Structural Definition of the Manipulator
#Generally, the geometric structure representing the positional relationship of the manipulator's links and tools is expressed in the form of DH parameters. An XYZ orthogonal coordinate system is superimposed on the joint rotation axis, and the relative state of the next joint is expressed with two distances and two angles. The table below shows the DH parameters for a PUMA-type manipulator.
When illustrated, the figure below is obtained. All coordinate systems mentioned in this explanation are right-handed systems.
DH parameters start from the XYZ coordinate system of the base and proceed to the end by repeating
- Move in the Z-axis direction
- Rotate around the Z-axis
- Move in the X-axis direction
- Rotate around the X-axis
This defines attached to each rotary axis. is the origin of . is the coordinate system of the tool. Furthermore, if i=7 is added, the coordinate system of the tool tip (hand tip) can be represented. Among these, , , are robot design values and constants. On the other hand, is the joint axis angle, so it is a variable controlled by the servo motor.
Forward Kinematics Calculation
#What is the position and posture of the tool tip seen from the base coordinates when is given? Let's consider how to calculate and .
First, the affine transformation from to is expressed as a 4x4 matrix using DH parameters as follows.
For example, in the case of
The direction of the XYZ coordinate axes and the position of the origin of seen from are calculated as
Therefore, when the coordinate system of the tool tip is ,
should be calculated. Here,
If so, the upper left 3x3 submatrix (orthonormal system) represents the posture/direction of the coordinate system seen from the base coordinate system , and the fourth column represents the position of the origin. That is, the direction of the 3 axes of the i-th XYZ coordinate system is
and the position is
It can be represented.
Here, the direction of the three axes at the tool tip is referred to as "posture", but it is cumbersome to represent it with 9 numbers, so it is represented with 3 ZYX Euler angles . If it is rotated around the Z-axis by , around the Y-axis by , and around the X-axis by , then
Here, represents the 3x3 rotation matrix around the X-axis, around the Y-axis, and around the Z-axis. Solving this gives
It can be calculated. (※atan2(y,x) is a C language function that calculates ArcTan(y/x).)
Above, the calculation to derive the position and posture of the tool tip from is called forward kinematics.
Inverse Kinematics Calculation
#One of the most important functions of a robot manipulator is to move the tool tip to a specified location with a specified posture. Therefore, contrary to the calculation of forward kinematics, it is necessary to reverse-calculate the axis angles that make the position and posture of the tool tip stand and use them as command values for the motor driver. This calculation is called inverse kinematics calculation (IK).
Represent the coordinate system of the tool tip specified by and with the 4x4 homogeneous matrix and set
For simplicity, multiply the constant matrix from the right on both sides and set
In principle, it is sufficient to solve these 12 valid elements for 6 s. However, these are non-independent and non-linear simultaneous equations, so it is necessary to use a time-consuming algorithm such as the steepest descent method. In particular, in the case of a convergence calculation method, the number of repetitions until convergence cannot be predicted, so the calculation time becomes unstable. Therefore, IK can become a bottleneck and hinder system operation. Unlike this, analytical solution methods are known for special types of manipulators or axes. In any case, these simultaneous equations cannot be solved uniquely, and it is known that there are up to 8 combinations of solutions.
Fortunately, there is an analytical method for the 6-axis PUMA-type manipulator in this example. This is a method based on well-known methods using geometry. However, in terms of geometry, it becomes three types of two choices (ARM Forward/Backward, ELBOW Above/Below, WRIST Up/Down (see figure below)), and as a combination, there are up to possibilities of solutions.
Therefore, it is necessary to have some rational selection method, such as specifying the form, choosing the combination closest to the current value of , etc. Below is the core part of the IK code we actually implemented (※1) for reference.
※1. Note that this is not practical as is because details of exception handling and inspection processing are omitted.
///////////////////////////////////////////////////////////
/// @brief Find joint axis angle with inverse kinematics (IK) (holding mode setting)
///////////////////////////////////////////////////////////
int Kinematics::CalcJointAngles6ByIKwithMode(
const Matrix4x4& T6,
const JAngles6& prev_theta,
JAngles6& theta,
int mode[3],
double& diff_average,
bool bCheckRange) const
{
JAngles6& th=theta; // angle
JAngles6 dth; // difference between angle and prev_angle
int ndif=0;
diff_average=1.0e+10;
const double &ux = T6.At(0,0), &vx = T6.At(0,1), &wx = T6.At(0,2), &qx = T6.At(0,3);
const double &uy = T6.At(1,0), &vy = T6.At(1,1), &wy = T6.At(1,2), &qy = T6.At(1,3);
const double &uz = T6.At(2,0), &vz = T6.At(2,1), &wz = T6.At(2,2), &qz = T6.At(2,3);
const double &d1 = m_d1, &d4=m_d4, &d6=m_d6;
const double &a1 = m_a1, &a2=m_a2, &a3=m_a3;
const int mode_arm = mode[0]; //Forward+/Backward-
const int mode_elbow = mode[1]; //Above+/Below-
const int mode_wrist = mode[2]; //Up+/Down-
//---------------------------------------------------
// th[1]
//---------------------------------------------------
//P Position = O4 / O5 @ WC
double px = qx-d6*wx;
double py = qy-d6*wy;
double pz = qz-d6*wz;
int iret=0;
double karm;
//check Arm mode
if(mode_arm>0){ //Arm Forward
karm = 1.0;
}else{ //Arm Backward
karm = -1.0;
}
th[1] = atan2(karm*py, karm*px);
iret=EvaluateAxisTheta(1, prev_theta, th, dth, bCheckRange);
if(iret<0) return iret;
ndif++;
//---------------------------------------------------
// th[3]
//---------------------------------------------------
double C1=cos(th[1]);
double S1=sin(th[1]);
// k1*S3 + k2*C3 =k3 Solve
double k1 = 2.0*a2*d4;
double k2 = 2.0*a2*a3;
double k3 = px*px +py*py +pz*pz +a1*a1 -a2*a2 -a3*a3
+d1*d1 -d4*d4 -2.0*( a1*(px*C1+py*S1) + d1*pz );
double denom1 =k2+k3;
double t=0.0;
// Normal solution
// (k2+k3)*t^2 -2*k1*t +(k3-k2) =0 Solve
double D = k1*k1 + k2*k2 - k3*k3;
double rootD = sqrt(D);
/// Elbow Mode: Above(+1)/Below(-1)
if(mode_elbow>0){ //Above(+1)
t = (k1-rootD)/denom1;
}else{ //Below(-,1){ //Below(-1)
t = (k1+rootD)/denom1;
}
th[3] = 2.0*atan(t);
iret = EvaluateAxisTheta(3, prev_theta, th, dth, bCheckRange);
if(iret<0) return iret;
ndif++;
//---------------------------------------------------
// th[2]
//---------------------------------------------------
double C3=cos(th[3]);
double S3=sin(th[3]);
//----------------------
// myu1*C2 + nyu1*S2=gamma1
// myu2*C2 + nyu2*S2=gamma2 Solve
double myu1 = a3*C3 +d4*S3 +a2;
double nyu1 = d4*C3 -a3*S3;
double gamma1 = px*C1 +py*S1 -a1;
double myu2 = -nyu1;
double nyu2 = myu1;
double gamma2 = -d1+pz;
double denom2 = -myu1*myu1-nyu1*nyu1;
double C2 = (gamma2*nyu1-gamma1*nyu2)/denom2;
double S2 = -(gamma2*myu1-gamma1*myu2)/denom2;
th[2] = atan2(S2,C2);
iret=EvaluateAxisTheta(2, prev_theta, th, dth, bCheckRange);
if(iret<0) return iret;
ndif++;
//---------------------------------------------------
// th[5]
//---------------------------------------------------
const double th23 = th[2]+th[3];
const double C23 = cos(th23);
const double S23 = sin(th23);
double C5 = -wz*C23+(wx*C1+wy*S1)*S23;
const double th5 = acos(C5);
double S5 = sqrt(1.0-C5*C5);
/// Wrist Mode: Up(+1)/Down(-1)
if(mode_wrist>0){
th[5] = th5; //Wrist Up
}else{
th[5] = -th5; //Wrist Down
S5 = -S5;
}
iret=EvaluateAxisTheta(5, prev_theta, th, dth, bCheckRange);
if(iret<0) return iret;
ndif++;
//---------------------------------------------------
// th[4],th[6]
//---------------------------------------------------
const double C4 = (wx*C1*C23+wy*C23*S1+wz*S23)/S5;
const double S4 = (-wy*C1+wx*S1)/S5;
th[4] = atan2(S4,C4);
iret=EvaluateAxisTheta(4, prev_theta, th, dth, bCheckRange);
if(iret<0) return iret;
ndif++;
const double C6 = ( uz*C23-(ux*C1+uy*S1)*S23)/S5;
const double S6 = (-vz*C23+(vx*C1+vy*S1)*S23)/S5;
th[6] = atan2(S6,C6);
iret=EvaluateAxisTheta(6, prev_theta, th, dth, bCheckRange);
if(iret<0) return iret;
ndif++;
//--------------------------------
// Average angle calculation
double d_sum=0.0;
double d;
for(int i=1;i<=6;i++){
d = dth[i]/(m_theta_upper[i] - m_theta_lower[i]);// Normalize in the operating range.
d_sum += d*d;
}
diff_average = d_sum;
return 0;
}
Velocity Forward/Inverse Kinematics Calculation
#Let be the position of the tool tip, then the following 6x6 matrix, which is the velocity transformation Jacobian matrix, can be calculated. Here " " denotes the vector product, and the superscript T denotes the transpose of the matrix.
Using this Jacobian matrix, the translational and rotational velocities of the tool tip can be calculated from the joint axis velocities as follows.
Here {i=1,2,...,6} are the angular velocities of each axis, is the 3D translational velocity vector of the tool tip, and is the 3D rotational velocity vector.
Generally, since the inverse matrix of can be uniquely determined,
Thus, it is also possible to determine the angular velocities of the six axes from the translational and rotational velocities of the tool tip.
These transformation formulas are often used to display the state of the robot, analyze its operation, perform mechanical calculations, and other special controls.
Trajectory Generation
#PTP Control and CP Control
Using the basic mathematics and algorithms described above,
- PTP (Point to Point) control = Control to move the joints by calculating the time series that can smoothly move from the current state to the specified .
- CP (Continuous Path) control = Control to move the joints by first calculating the time series so that the tool tip smoothly reaches the specified points or specified postures along a certain 3D shape (straight line, arc, etc.), and then calculating using IK.
is performed. (Here, indicates an equidistant time series with a sample period T=1[ms] given to the motor driver.)
The generation of such time series samples is called trajectory generation. In the case of PTP, generating a time series of is referred to, and in the case of CP, generating a time series of is referred to. It is important to note that this time series must be an equal-time interval series with period T. In either case, the starting point, the endpoint, and the operating speed in between are required.
In the actual UI for specifying the trajectory, for example, in a robot program, the following specification method is used. The starting point is the current state of the robot posture, and only the endpoint is specified for each command.
20: JOINT 90,0,0,0,0,0 maxvr=30.0
21: LINE_MOVE -400, 200, 200 maxvc=150
22: CIRCLE_MOVE 500, 300, 200 maxvc=150
These points are called KP (Key Points). In a PTP command like the JOINT command, assuming that each axis rotates straight between the starting and ending KPs, the angular velocity profile for each axis is determined so that the maximum angular velocity maxvr is reached, and the samples of are calculated. On the other hand, in CP commands such as LINE_MOVE and CIRCLE_MOVE, the shape of the tool tip trajectory (straight line, arc, respectively) connecting the KPs and the speed profile so that the tool tip speed reaches the maximum speed maxvc are determined, and the sample points are first calculated. Finally, the samples of are calculated by IK.
Note that while the maximum speed is often specified for setting the speed profile, the travel time from the start KP to the end KP is also sometimes specified.
Method of Determining the Speed Profile
The figure below shows an example of a speed profile during CP control, showing a trapezoidal speed profile. The travel distance S between KPs is calculated from the trajectory shape. Also, , are predetermined as system settings, and the maximum speed is specified by the user. Since the time integral of the speed (i.e., the area) becomes the travel distance, the shape of the trapezoid can be determined by adjusting it so that S becomes equal to the trapezoidal area.
This profile is exactly trapezoidal, and at points such as BOA, EOD, EOA, and BOD, the acceleration (the first derivative of the profile) changes suddenly. Therefore, when actually moving the joints with this, mechanical shocks and vibrations often occur in the vicinity. To operate smoothly without vibrations, this area is often connected with a smooth curve using higher-order functions or trigonometric functions to smooth it out. At this time, care is taken to ensure that the area is the same as the trapezoidal area S.
Trajectory Sampling
The shape of the trajectory specified for CP control can be analytically determined using geometry. That is, it can be concretely calculated as a series of {k=0,1,2...} with an appropriate parameter . However, the series is clearly different from the required equal-time sampling series . How should this difference be corrected to sample the correct time series?
This difference arises from the difference between the parameters and . The figure below shows the graph obtained by integrating the speed profile, with the vertical axis being the travel distance . It is a monotonically increasing curve as time progresses.
On the other hand, the travel distance samples can be geometrically calculated from , which is also a monotonically increasing function with respect to . In this case, it is a function independent of time. If the trajectory shape is complex, it may be a curve, but it is still a monotonically increasing function. Ultimately, both and are one-to-one relationships with respect to the parameter. Therefore, it is possible to correspond the parameters and via the travel distance . That is, the following processing is possible.
- Calculate the value of .
- Reverse the table ⇒ and view it as a table ⇒ . From this table, interpolate the value to obtain the value (linear interpolation is sufficient).
- Calculate . Set this as .
Repeat the above for until the end KP is reached, and if the time series can be generated, the trajectory generation is completed. In the case of PTP control, the same processing can be performed using a representative (※2) instead of S. Also, in the case of CP control, the obtained can be converted by IK to obtain the joint angle series necessary for motor control.
※2. For example, the one that performs the largest operation among the six s.
4. Conclusion
#Starting from the structure of the manipulator, after introducing the basic ideas and mathematics required for its control, I explained the method of trajectory generation for actually operating it. However, the following regarding CP control was not described in detail in the above explanation.
- What is the specific method for geometrically sampling the trajectory? For example, how are commonly used straight trajectory, circular trajectory, and spline trajectory calculated using ?
- How is the change in posture (rotation) of the tool tip sampled?
- There are special postures of the arm, or combinations of , called "singular points", which become problems in control. What are they, and how should they be avoided?
I would like to explain these in the next session.
References
#- Shigeki Toyama, "Robotics (Mechatronics Textbook Series)", Corona Publishing (1994)
- R.P. Paul, "Robot Manipulators", translated by Tsuneo Yoshikawa, Corona Publishing (1984)
End