Example 9: Visualization of the positive solution of kinematics of a quadruped robot in plane RR single leg

Example 9: Single-leg visualization of forward kinematics of a quadruped robot

Purpose

  1. Through hands-on practice, build the legs of the mini pupper quadruped robot and master the single-leg structure of the robot.
  2. Through theoretical study, you will become familiar with the use of geometric methods and rotation matrix methods in the forward solution of kinematics (FK).
  3. Through programming practice, become familiar with the method of visually simplifying a single leg of a robot.

Experimental requirements

Through Python programming, in the simplified mini pupper plane two-link model, the user is allowed to input joint angles. Based on the joint angles and basic information of the joints, the coordinates of each joint relative to the base coordinate system are calculated and output visually.

experimental knowledge

1. What is Forward Kinematics?

In the actual movement operation of the mini pupper, it is necessary to consider the static geometric problem of calculating the position and posture relationship of the lower leg end relative to the body base coordinate system. To put it simply, given a set of joint angle values, calculate the pose of the calf end coordinate system relative to the base coordinate system.
The problem of forward kinematics exploration can be seen as joint space (θ 1, θ 2, ⋅ ⋅ ⋅ ⋅, θ n) (\theta_1,\theta_2,····,\theta_n)( i1,i2,⋅⋅⋅⋅,in) described to Cartesian Space Cartesian Space( W orld P ) (^{World}P)W or l d P)describes the position representation.
Exploring the representation relationship of this position is forward kinematics. For robots, it uses the joint variables of the operating arm as independent variables to describe the functional relationship between the posture of the end effector of the operating arm and the base coordinate system.

2. How to describe a leg of a robot?

Since we need to consider the calculation of the position and attitude relationship of the lower leg end relative to the body base coordinate system during the actual movement of the mini pupper, there should be corresponding qualitative and quantitative descriptions and representations to enable the calculation.
In robotics, the operating arm is composed of links . The links are regarded as rigid bodies. Adjacent links are connected by joints . The joints can relatively rotate (revolute) or move (prismatic) . The axis of rotation is called Axis .
This description of the operating arm corresponds to the human body and can be regarded as a simplified human arm. The "big arm" is a connecting rod, connected to another connecting rod "small arm" through the "elbow joint", and the mini pupper is also Same reason.

The rotation and movement of joints lead to two mathematical quantities. For rotating joints, the relative angle change between adjacent members is called joint angle , while for moving joints, the relative displacement change between adjacent members is called joint deflection . Shift amount .

For the manipulator, the number of degrees of freedom is the number of independent position variables. Common industrial robots are mostly open kinematic chains. Each joint position is defined by a unique variable, so the number of joints is often equal to the number of degrees of freedom. quantity.

The end of the operating arm is called the end effector, such as a fixture, a welding gun, etc. The operating arm is usually described by the relative relationship between the tool coordinate system Frame_Tool set on the end effector and the reference base coordinate system Frame_Base of the fixed base of the operating arm. position and posture.

3. How to describe the relationship between the parts between the legs?

In order to describe the relationship between adjacent connecting rods, four variables are introduced to describe the spatial relationship of the connecting rods.

name symbol meaning Comment
Connecting rod length a i − 1 a_{i-1} ai1 The length of the common perpendicular between two adjacent joint axes The length of the connecting rod is along X ^ i − 1 \hat X_{i-1}X^i1direction, Z ^ i − 1 \hat Z_{i-1}Z^i1 Z ^ i \hat Z_{i} Z^iThe length of the common perpendicular line between. Because ai − 1 a_{i-1}ai1is the distance, so there is always ai − 1 ≥ 0 a_{i-1}\geq0ai10
Connecting rod torsion angle α i − 1 \alpha_{i-1} ai1 Alongside ai − 1 a_{i-1}ai1The angle between the two joint axes in the projection plane of the direction The connecting rod torsion angle is along X ^ i − 1 \hat X_{i-1}X^i1Z ^ i − 1 \hat Z_{i-1} in the two-dimensional plane formed by looking in the directionZ^i1 Z ^ i \hat Z_{i} Z^iThe angle between , according to the right-hand method from Z ^ i − 1 \hat Z_{i-1}Z^i1扭向 Z ^ i \hat Z_{i} Z^iTake plus or minus.
Connecting rod offset d i d_{i} di The distance along the common axis of two adjacent links. Alongside Z ^ i \hat Z_{i}Z^iLooking in the direction, for X ^ i − 1 \hat X_{i-1}X^i1 Z ^ i \hat Z_{i} Z^iThe intersection point of the straight line and X ^ i \hat X_{i}X^i Z ^ i \hat Z_{i} Z^iThe intersection point of the straight lines and the distance between the two intersection points.
joint angle θ i \theta_{i} ii The angle of rotation of two adjacent links about a common axis. Alongside Z ^ i \hat Z_{i}Z^iLooking in the direction, X ^ i − 1 \hat X_{i-1} in the two-dimensional planeX^i1 X ^ i \hat X_{i} X^iThe angle between , the direction is X ^ i − 1 \hat X_{i-1}X^i1扭向 X ^ i \hat X_{i} X^i

The connecting rod torsion angle and connecting rod length define the relationship between the two joint axes of the same member, and the joint angle and connecting rod offset define how the connecting rods are connected. X ^ i \hat X_{i}
mentioned in the comments aboveX^i Y ^ i \hat Y_{i} Y^i Z ^ i \hat Z_{i} Z^iIt will be mentioned later in conjunction with the connecting rod coordinate system and can be understood in conjunction.

4.Denavit-Hartenberg expression

Abbreviated as DH expression method, the version is Craig version. DH method is a rule that uses four connecting rod parameters to describe the motion relationship of the mechanism. Two parameters are used to describe the connecting rod itself, and the other two parameters are used to describe the relationship between the connecting rods. connection relationship. These four parameters are the connecting rod torsion angle α i − 1 \alpha_{i-1}
mentioned beforeai1, connecting rod length ai − 1 a_{i-1}ai1, the angle θ i \theta_{i}ii, connecting rod offset di d_{i}di.
Generally speaking, for a rotating joint, the joint variable is the joint angle θ i \theta_{i}ii, for moving joints, the joint variable is the connecting rod offset di d_{i}di.
For this type of joint, except for the joint variables, the other three link parameters are fixed hardware attribute parameters.

5. Connecting rod coordinate system

In order to describe the relationship between connecting rods, a coordinate system is introduced, so a connecting rod coordinate system needs to be established on each connecting rod. For connecting rod i − 1 {i-1}i1 , on which there is a connecting rod coordinate system{ i − 1 } \{i-1\}{ i1 } , in Craig's improved DH method, the origin of the link coordinate system is usually specified at the joint axisA xis (i − 1) Axis_{(i-1)}Axis(i1)superior.
According to the provisions of this coordinate system, the orthogonal axes of the fixed link coordinate system are as follows:

axis or point definition
origin Public service line ai a_iaiwith joint axis A xisi Axis_iAxisiintersection point
Z ^ i \hat Z_i Z^i with joint axis A xisi Axis_iAxisicoincide
X ^ i \hat X_i X^i along the common perpendicular ai a_iaiby joint jointi joint_ijointiPoint to joint jointi + 1 joint_{i+1}jointi+1direction. When the common vertical line ai = 0 a_i=0ai=0时, X ^ i \hat X_i X^iPerpendicular to Z ^ i \hat Z_iZ^i Z ^ i + 1 \hat Z_{i+1} Z^i+1The formed plane can have two directions, which can be selected according to convenience.
Y ^ i \hat Y_i Y^i Determined according to the right-hand rule, the thumb is known to be X ^ i \hat X_iX^i, the index finger is Y ^ i \hat Y_iY^i, it is known that the middle finger is Z ^ i \hat Z_iZ^i
Special existence in the connecting rod coordinate system
First end connecting rod

The first link is called the ground rod, and the coordinate system on the fixed base of the robot is { 0 } \{0\}{ 0 } is often used as a reference coordinate system. Z ^ 0 \hat Z_0Z^0Direction and Z^1 \hat Z_1Z^1The same, and when the coordinate system { 1 } \{1\} The joint variableθ i \theta_{i} of { 1 }iidi d_{i}diWhen is 0, make the coordinate system { 0 } \{0\}{ 0 } and coordinate system{ 1 } \{1\}{ 1 } overlap to simplify calculations.

Revolute joint α 0 = 0 a 0 = 0 d 1 = 0 θ 1 = ? (F rame coincides with 0) \text {Revolute joint} \quad \alpha_0=0 \quad a_0=0 \quad d_1=0 \quad\theta_1=? (When it is 0, the Frame overlaps)Revolute jointa0=0a0=0d1=0i1=? ( F r am e coincides when it is 0 ) Moving
joint Prismatic joint α 0 = 0 a 0 = 0 θ 1 = 0 d 1 = ? (Frame overlaps when it is 0) \text {Mobile joint Prismatic joint} \quad \alpha_0=0 \quad a_0=0 \quad \theta_1=0 \quad d_1=? (Frame overlaps when it is 0)Moving jointPrismatic jointa0=0a0=0i1=0d1=? ( F r am e coincides when it is 0 )

end link

The end rod has no next rod, so it needs to be related to the previous rod.
For a rotating joint, X ^ n \hat X_nX^nDirection and X ^ n − 1 \hat X_{n-1}X^n1Same, then choose to set the origin so that dn = 0 d_n=0dn=0For
moving joints, choose the settingX ^ n \hat X_nX^nThe direction is such that θ n = 0 \theta_n=0in=0 , whendn = 0 d_n=0dn=When 0 , the origin is located at joint axisnnn andX ^ n − 1 \hat X_{n-1}X^n1intersection

After learning the connecting rod coordinate system, the connecting rod parameters can be understood more simply:

name symbol meaning
Connecting rod torsion angle α i − 1 \alpha_{i-1} ai1 The connecting rod torsion angle is around X ^ i − 1 \hat X_{i-1}X^i1轴, Z ^ i − 1 \hat Z_{i-1} Z^i1Rotate to Z ^ i \hat Z_{i}Z^ithe angle of
Connecting rod length a i − 1 a_{i-1} ai1 The length of the connecting rod is along X ^ i − 1 \hat X_{i-1}X^i1轴, Z ^ i − 1 \hat Z_{i-1} Z^i1Move to Z ^ i \hat Z_{i}Z^iThe length of the common perpendicular
joint angle θ i \theta_{i} ii Z ^ i \hat Z_{i} Z^i轴, X ^ i − 1 \hat X_{i-1} X^i1Rotate to X ^ i \hat X_{i}X^ithe angle of
Connecting rod offset d i d_{i} di Alongside Z ^ i \hat Z_{i}Z^i轴, X ^ i − 1 \hat X_{i-1} X^i1Move to X ^ i \hat X_{i}X^idistance
Establish connecting rod coordinate system and DH table
  1. Find the joint axes.
    Analyze the motion status and find the axes of joint translation or rotation (joint axes).
  2. Z ^ i \hat Z_{i}Z^i
    Z ^ i \hat Z_{i} Z^iThe positive direction is the axis direction of rotation or movement
  3. Find X ^ i \hat X_{i}X^i
    X ^ i \hat X_{i} X^iThe positive direction of is on the common vertical line between the two joint axes, pointing to the direction of the next joint axis
    ( ai = 0 a_i=0ai=0 , that is, when the two joint axes intersect,XXX sumZ i Z_iZiSum Z i + 1 Z_{i+1}Zi+1The direction is vertical, whatever is convenient for the direction at this time)
  4. Determine the origin.
    The origin is Z ^ i \hat Z_{i}Z^i X ^ i \hat X_{i} X^iintersection point
  5. Y ^ i \hat Y_{i }Y^i
    According to the right-hand rule, the thumb is X ^ i \hat X_iX^i, the index finger is Y ^ i \hat Y_iY^i, the middle finger is Z ^ i \hat Z_iZ^i
  6. Process the first link
    and treat it as Frame 1 Frame_1Frame1The joint variable θ i \theta_{i}iidi d_{i}diWhen 0, make Frame 0 Frame_0Frame0 F r a m e 1 Frame_1 Frame1overlap to simplify calculations.
  7. When dealing with the end connecting rod,
    try to make the connecting rod parameters equal to 0 to simplify the calculation.

Based on the results of the above steps, the DH parameter table can be obtained

The DH parameter table is the relationship between Frames. Each i represents the relationship between a pair of axes.
1 in the table is the base coordinate system Frame 0 Frame_0Frame0Coordinate system with the first axis Frame 1 Frame_1Frame1The relationship
3 in the table is the relationship between the end link and the last axis that can (rotate, translate)

i α i − 1 \alpha_{i-1} ai1 a i − 1 a_{i-1} ai1 θ i \theta_i ii d i d_i di
1 0 0 θ 1 \theta_1 i1 0
2 0 L 1 L_1L1 θ 2 \theta_2 i2 0
3 0 L 2 L_2L2 θ 3 \theta_3 i3 0

6. Conversion between connecting rod coordinate systems

Frame_{i-1 }Framei1、 Essentially A xisi − 1 Axis_{i-1}Axisi1 A x i s i Axis_{i} Axisi.
First, complete the equation from Z ^ i − 1 \hat Z_{i-1}Z^i1 Z ^ i \hat Z_{i} Z^iRotation α i − 1 \alpha_{i-1}ai1Peace transition ai − 1 a_{i-1}ai1distance.

Then, rotate and translate A xisi − 1 Axis_{i-1}Axisi1Rotation θ i \theta_{i}ii, and along Z ^ i \hat Z_{i}Z^iDirection translation di d_{i}didistance.
After a total of four operations, we finally get
i − 1 P = ii − 1 T i P ^{i-1}P=^{i-1}_iT^{i}Pi 1 P=ii1TiP
i i − 1 T ^{i-1}_iT ii1Given the equivalence of T
, the equivalent equation is: ii − 1 T = [ C os θ i − S in θ i 0 ai − 1 S in θ i C os α i − 1 C os θ i C os α i − 1 − S in α i − 1 − S in α i − 1 di S in θ i S in α i − 1 C os θ i C in α i − 1 C os α i − 1 C os α i − 1 di 0 0 0 1 ] ^{i-1}_iT= \left[ \begin{matrix} Cos\theta_i & -Sin\theta_i & 0 & a_{i-1} \\ Sin\theta_iCos\alpha_{i- 1} & Cos\theta_iCos\alpha_{i-1} & -Sin\alpha_{i-1} &-Sin\alpha_{i-1}d_i\\ Sin\theta_iSin\alpha_{i-1} & Cos\theta_iSin \alpha_{i-1} & Cos\alpha_{i-1} &Cos\alpha_{i-1}d_i\\\0&0&0&1\end{matrix}\right]ii1T= CosθiSinθiC os αi1SinθiS in αi10SinθiCosθiC os αi1CosθiS in αi100S in αi1C os αi10ai1S in αi1diC os αi1di 1
Using this transformation matrix multiple times can obtain the transformation relationship between non-adjacent joints.

7.Simplified kinematic structure of mini pupper

The single leg of the mini pupper can be simplified as a typical three-link non-planar operating arm. The three-degree-of-freedom design allows it to theoretically reach any position within the space limit range.
When we further simplify and do not consider the lateral hip joint motion, the legs of the mini pupper can be simplified to a planar two-link mechanism RR model, and the geometric solution can be used at the known θ 1 \theta_1i1Sum θ 2 \theta_2i2Find 0 P ^0P in the case ofThe coordinates of 0 Pcomplete the positive solution of kinematics.
For the intersection of the big arm and the small armQQQ
x q = l 1 C o s θ 1 x_q=l_1Cos\theta_1 xq=l1Cosθ1
yq = l 1 S in θ 1 y_q=l_1Sin\theta_1yq=l1Sinθ1

Default function:
xp = l 1 C os θ 1 + l 2 C os ( θ 1 + θ 2 ) x_p=l_1Cos\theta_1+l_2Cos(\theta_1+\theta_2) .xp=l1Cosθ1+l2Cos ( i _1+i2)
yp = l 1 S in θ 1 + l 2 S in ( θ 1 + θ 2 ) y_p=l_1Sin\theta_1+l_2Sin(\theta_1+\theta_2);yp=l1Sinθ1+l2S in ( i1+i2)

Picture: Planar two-link mechanism RR model
Insert image description here

Experimental steps

1. Write Python code rr_FK.py

#!/usr/bin/python
# coding:utf-8
# rr_FK.py
# mini pupper的简化单腿,可视作同一平面的RR类机械臂,可视化该机械臂,由给定角度计算末端点位置
import matplotlib.pyplot as plt  # 引入matplotlib
import numpy as np  # 引入numpy
from math import degrees, radians, sin, cos


# 几何法:关节角转端点坐标
def theta_2_position_rr(l1, l2, theta1, theta2):
    """
    运动学正解 将输入的关节角转化为对应的端点坐标
    :param l1: 大臂长
    :param l2: 小臂长
    :param theta1: 大臂关节角
    :param theta2: 小臂关节角
    :return: 端点1坐标 端点2坐标
    """
    point_1 = [l1*cos(radians(theta1)), l1*sin(radians(theta1))]
    point_2 = [l1*cos(radians(theta1))+l2*cos(radians(theta1+theta2)),
               l1*sin(radians(theta1))+l2*sin(radians(theta1+theta2))]
    print(point_1)
    print(point_2)
    return point_1, point_2


def preprocess_drawing_data(points):
    """
    处理点坐标数据转化为matplotlib适应的绘图格式
    :param points: 点数据
    :return: 绘图数据x坐标list和对应的y坐标list
    """
    xs = [0]
    ys = [0]
    xs.append(points[0][0])
    xs.append(points[1][0])
    ys.append(points[0][1])
    ys.append(points[1][1])
    return xs, ys


def annotate_angle(x0, y0, rad1, rad2, name, inverse=False):
    """
    为两条直线绘制角度
    :param x0: 圆心x坐标
    :param y0: 圆心x坐标
    :param rad1: 起始角
    :param rad2: 终止角
    :param name: 角名
    :param inverse: 用于解决点1的重叠问题
    :return: 无
    """
    theta = np.linspace(rad1, rad2, 100)  # 0~rad
    r = 0.3  # circle radius
    x1 = r * np.cos(theta) + x0
    y1 = r * np.sin(theta) + y0
    plt.plot(x1, y1, color='red')
    plt.scatter(x0, y0, color='blue')
    degree = degrees((rad2 - rad1))
    if inverse:
        plt.annotate("%s=%.1f°" % (name, degree), [x0, y0], [x0 - r / 1.5, y0 - r / 1.5])
    else:
        plt.annotate("%s=%.1f°" % (name, degree), [x0, y0], [x0 + r / 1.5, y0 + r / 1.5])


# 关节信息
# 大臂长度:5 cm 小臂长度:6 cm
link_length = [5, 6]  # in cm

# 关节角初始化
joints_angle_origin = [-150, 90]
joints_angle = [0, 0]
print("关节角初始状态 theta1=%d°, theta2=%d°" % (joints_angle_origin[0], joints_angle_origin[1]))

# 输入连杆参数:各关节角
for i in range(1, 3):
    joints_angle[i-1] = int(input("请输入腿部舵机[%d]要转动的的角度:" % i))
    print("腿部舵机[{0}]将转动{1}°".format(i, joints_angle[i-1]))

# 计算并预处理绘图数据
points_origin = theta_2_position_rr(link_length[0], link_length[1], joints_angle_origin[0], joints_angle_origin[1])
points_after = theta_2_position_rr(link_length[0], link_length[1], joints_angle[0], joints_angle[1])
data_origin = preprocess_drawing_data(points_origin)
data_after = preprocess_drawing_data(points_after)

# 绘图
fig, ax = plt.subplots()  # 建立图像
plt.plot(data_origin[0], data_origin[1], color='black', label='original')
plt.scatter(data_origin[0], data_origin[1], color='black')
plt.plot(data_after[0], data_after[1], color='red', label='after')
plt.scatter(data_after[0], data_after[1], color='blue')
ax.set(xlabel='X', ylabel='Y', title='mini pupper FK RR model')
ax.grid()
plt.axis("equal")
plt.legend(loc=2)

# 标注
annotate_angle(data_origin[0][0], data_origin[1][0],
               0, radians(joints_angle_origin[0]), "theta1_original", inverse=True)
annotate_angle(data_origin[0][1], data_origin[1][1], radians(joints_angle_origin[0]),
               radians(joints_angle_origin[0]+joints_angle_origin[1]), "theta2_original", inverse=True)
annotate_angle(data_after[0][0], data_after[1][0],
               0, radians(joints_angle[0]), "theta1_after")
annotate_angle(data_after[0][1], data_after[1][1], radians(joints_angle[0]),
               radians(joints_angle[0]+joints_angle[1]), "theta2_after")
plt.show()

2. Run the program and observe the effect

Execute the following commands in the directory of rr_FK.py:

sudo python rr_FK.py

At this point the visual coordinates calculated from the joint angles should be observed.
Insert image description here

Experiment summary

After studying and experimenting with this knowledge point, you should be able to reach the following levels:

Knowledge points content learn familiar master
hardware Construction of mini pupper single-leg structure
Kinesiology Correct kinematics solution of planar RR type manipulator
Kinesiology Non-planar RRR type robotic arm
Kinesiology Geometric method completes the correct solution of kinematics
Kinesiology Basic knowledge of correct solutions of kinematics
Visualization Visualizing kinematics in Python

Copyright information: The teaching materials are not yet complete. Copyright information processing methods are reserved here.
Mini pupper related content can be accessed: https://github.com/mangdangroboticsclub

Guess you like

Origin blog.csdn.net/m0_56661101/article/details/129124983