The use of python robot library (robotics-toolbox-python)

The use of python robot library (robotics-toolbox-python)

Using the Python Robotics Library



foreword

After searching for a long time, I found that there is very little information about the python robot library on the Internet, and at present, my project needs to use related things, and I will summarize it after querying the official website.

1. Related Summary

This toolbox brings robotics-specific functionality to Python and takes advantage of Python's portability, generality, and supportability, as well as open source for linear algebra (numpy, scipy), graphics (matplotlib, three.js, WebGL) Ecosystem capabilities, interactive development (jupyter, jupyterlab, mybinder.org) and documentation (sphinx).

Toolbox provides tools for representing the kinematics and dynamics of serially linked robots - you can easily create your own in Denavit-Hartenberg form, import URDF files, or use over 30 provided tools from Franka-Emika Well-known contemporary robot models, Kinova, Universal Robotics, Rethink and classic robots such as Puma 560 and Stanford arm.

The toolbox will also support models with robot motion (unicycle, bicycle), path planning algorithms (bug, distance transform, D*, PRM), motion dynamics planning (lattice, RRT), localization (EKF, particle filter) Mobile robots with functions such as map building (EKF) and simultaneous localization and mapping (EKF).

Toolbox provides:

Mature code that provides a point of comparison for other implementations of the same algorithm;
routines are often written in a straightforward manner that is easy to understand, but may come at the expense of computational efficiency;
source code for learning and teaching reading;
compatible with Robotics Toolbox Backward Compatibility for MATLAB
This toolbox leverages Python's spatial math toolbox to provide support for data types such as SO(n) and SE(n) matrices, quaternions, warps, and spatial vectors

Second, the installation of the necessary libraries

  1. Requires Python >= 3.6
  2. spatialmath-python
  3. numpy
  4. numpy-stl
  5. vpython (I really don't know how to install this library, but if it can't be installed, it will not affect the follow-up. If you know it, you can communicate with it)
  6. python robot toolbox
 % git clone https://github.com/petercorke/robotics-toolbox-python.git
 % cd robotics-toolbox-python
 % pip install -e .

1. Create a robotic arm model

Step 1 : Create a file named 'MYROBOT.py' in the model library, where MYROBOT is the descriptive name of the robot, which is a valid file name and Python class name.
E:\pyproject\defecate\robotics-toolbox-python\roboticstoolbox\models\DH\MYROBOT.py This is my address

Step 2 : Load the library

from math import pi
import numpy as np
from roboticstoolbox import DHRobot, RevoluteDH, PrismaticDH, RevoluteMDH, PrismaticMDH

The last line is important, it defines the possibilities of all possible classes. Not all of them will be used, to keep things tidy, you can delete the ones you don't use. This is their purpose;

'RevoluteDH' for revolute joints using standard DH parameters

'PrismaticDH' for mobile joints using standard DH parameters

'RevoluteMDH' for revolute joints using MDH parameters

'PrismaticMDH' for moving joints using MDH parameters

Step 3 : Describe the robotic arm, record the units used, DH parameters, and references to the source of the model.

class MYROBOT(DHRobot):
    """
    Create model of MYROBOT manipulator
    KR5()是一个用标准DH约定对Kuka KR5机器人建模并描述其运动学特征的类。
       .
       定义的关节构型为:
       qk1,公称工作位置1
       qk2,公称工作位置2
       qk3,公称工作位置3.

    :notes:
       .使用国际计量单位米
       .包括一个11.5厘米的工具在z方向
       .

    :references:
       .
       .
       .

    """

Step Four : In ' init_ ', define a set of link variables by creating an instance of the appropriate link class

def __init__(self):

        deg = pi/180

        L0 = RevoluteDH(
            d=0,          # link length (Dennavit-Hartenberg notation)
            a=0,          # link offset (Dennavit-Hartenberg notation)
            alpha=pi/2,   # link twist (Dennavit-Hartenberg notation)
            I=[0, 0.35, 0, 0, 0, 0],  # inertia tensor of link with respect to
                                      # center of mass I = [L_xx, L_yy, L_zz,
                                      # L_xy, L_yz, L_xz]
            r=[0, 0, 0],  # distance of ith origin to center of mass [x,y,z]
                          # in link reference frame
            m=0,          # mass of link
            Jm=200e-6,    # actuator inertia
            G=-62.6111,   # gear ratio
            B=1.48e-3,    # actuator viscous friction coefficient (measured
                          # at the motor)
            Tc=[0.395, -0.435],  # actuator Coulomb friction coefficient for
                                 # direction [-,+] (measured at the motor)
            qlim=[-160*deg, 160*deg])    # minimum and maximum joint angle

        L1 = RevoluteDH(
            d=0, a=0.4318, alpha=0,
            qlim=[-45*deg, 225*deg])

            .
            .
            .   

It includes four DH parameters and some dynamic parameters. Generally, if only the dynamic parameters are considered, only the DH parameters need to be connected, and some joint limits qlim() can also be added.
We provide as many parameters as possible. The above definition of L0 includes kinematic parameters and dynamic parameters, while L1 has only kinematic parameters. The minimal requirements are the kinematic parameters, you don't even need to know the joint limits, they just need some toolbox functions. For a robot with N joints, you must define N joint instances. Next, we call the super function to do the heavy lifting.

super().__init__(
    [L0, L1, L2, L3, L4, L5],
    name="MYROBOT",
    manufacturer="COMPANY THAT BUILDS MYROBOTs")

Step 5 : Create instance attributes, prepare two poses, and prepare for the verification of subsequent forward and reverse movements

# 零角度,L形姿势
        self._MYCONFIG = np.array([1, 2, 3, 4, 5, 6])  # 创建实例属性
        self.addconfiguration("qz", np.array([0,0,0,0,0,0 ]))  # 零角度,L形姿势
        self.addconfiguration("qr", np.array([0.610865,1.047198,0.785398,1.134464,0.628319,0 ]))

'MYCONFIG' is the name of this particular configuration. It must be a NumPy array with N elements. Then define a property that returns that property.

@property
def MYCONFIG(self):
    return self._MYCONFIG

Step 6 : There should be a main function at the bottom

if __name__ == '__main__':

    robot = MYROBOT()
    print(robot)
    print(robot._MYCONFIG)

Step 7 : Add the created model to the toolbox and edit the file ' init.py ' in this folder . Add a line as follows, and add the model name to _all []

from roboticstoolbox.models.DH.MYROBOT import MYROBOT

insert image description here

2. Realization of forward and reverse motion

Step 1; Load the library

import roboticstoolbox as rtb
import numpy as np
from math import pi

Step 2: Verify that the parameters of the robotic arm can be correctly called

robot = rtb.models.DH.MYROBOT()
#机械臂信息
print(robot)

output content
Robot arm information

Step 3: Model Validation
Use matplotlib graphics to display the robot as lines. matplotlib is the most ubiquitous graphics library for Python and runs on all platforms.

  import roboticstoolbox as rtb
  robot = rtb.models.DH.MYROBOT()
  qt = rtb.tools.trajectory.jtraj(robot.qz, robot.qr, 50)
  robot.plot(qt.q)

insert image description here
I haven't figured it out here. I checked it, and the Internet said that it may be a problem with the robot toolbox itself. If there is a solution, you can communicate with each other.
Verify that I verified by simulation through matlab

clc
clear

%        theta   d          a             alpha  sigma
L1=Link([  0     0.044      0             pi/2      0   ],'standard');
L2=Link([  0     0          0.14             0   0   ],'standard');
L3=Link([  0     0          0.0455      pi/2      0   ],'standard');
L4=Link([  0     0.1311     0      -pi/2      0   ],'standard');
L5=Link([  0     0          0.04945      pi/2  0   ],'standard');
L6=Link([  0     0.05585          0      0  0   ],'standard');
L2.offset = pi/2
L5.offset = -pi/2
%%取名
robot = SerialLink([L1 L2 L3 L4 L5 L6],'name','standard DH');
%读取角度信息
filename = '.\数据.txt';
[theta1, theta2,theta3, theta4, theta5 ,theta6] = textread(filename , '%f %f %f %f %f %f', 1);
theta = [theta1, theta2,theta3, theta4, theta5 theta6];
% theta = [0.523599 1.047189  1.047189  0.523599  1.5070796 ] 
% theta1 = theta(1);
% theta2 = theta(2);
% theta3 = theta(3);
% theta4 = theta(4);
% theta5 = theta(5);
du=pi/180;
ra=180/pi;

% -2.5946    0.0224    1.5707   -1.5930    2.5946
%定义关节范围
% L(1).qlim =[-170, 170]*du;
% L(2).qlim =[60-70, 60+70]*du;%-10,130
% L(3).qlim =[-70-70,-70+70]*du;%-140,0
% L(4).qlim =[-70,70]*du;
% L(5).qlim =[-170, 170]*du;
L1.qlim =[-180, 180]*du;
L2.qlim =[-180, 180]*du;
L3.qlim =[-180, 180]*du;
L4.qlim =[-180, 180]*du;
L5.qlim =[-180, 180]*du;
L6.qlim =[-180, 180]*du;
robot.teach()

insert image description here

Step 4 : Positive motion (known joint angle, solve end pose)

#正向运动
T = robot.fkine(robot.qr)

The qr here is one of the two attitude settings in the established manipulator model, qz and qr, respectively, qz is a zero-angle attitude, and qr is an arbitrary attitude
. Forward kinematics (FK) is The pose of the end effector for the given joint coordinates. It can be calculated for robots like DHRobot or ERobot.
Positive kinematics: In general, it is the positional relationship between the end pose and the base target, which is represented by a matrix. This positional relationship is transmitted through joint coordinates. T = T01 T12 T23 T34 T45* T56, and this T matrix is ​​represented by the DH parameter. The specific operation will be discussed in the next article. Here, I will briefly talk about it. Readers can also write their own.
The result is as follows:
insert image description here
This is a matrix of the position of the end pose relative to the polar coordinates, the fourth column represents the X, Y, and Z coordinates, and the three rows and three columns in the middle represent the deflection angle, pitch angle, and roller angle. So far, the movement is positive. Learn to calculate.

Step 5 : Inverse Kinematics
Inverse Kinematics (IK) is the joint coordinates required to achieve a given end effector pose. Features are not unique and there may be no workarounds. (Know the end pose to solve the joint angle)
Here are some differences between the python version and the matlab version of the robot toolbox
insert image description here
I choose ikine_LMS()

TT = robot.ikine_LMS(T)
print(TT)

insert image description here
It can be seen that the difference between the obtained angle and the previously set qr angle is very small. The inverse motion is successful. You can also write the inverse motion yourself. I use the numerical solution and write it together with the positive motion next time.

DH parameters

  1. 1 Establish a coordinate system

    1) Determine the Zi axis

    As the drive axis of the i+1th joint, its direction is the same as that of the joint axis. For example, Z0 is the drive axis of the first joint, and Z1 is the drive axis of the second joint. It may seem a little confusing, but it is in accordance with the rules, which guarantees: when joint i is driven, link i and the coordinate system OiXiYiZi connected to it will experience a corresponding motion.

    In addition, the direction of the Zi axis conforms to the right-hand rule, pay attention to correspond to the rotation direction of the joint!

    2) Determine the base coordinate system

    From the previous discussion, it can be seen that the coordinate transformation that satisfies the DH modeling constraints can be used as

    Four parameters to get!
    The choice of the base coordinate system is almost arbitrary , we can choose to place the origin Oo of the base coordinate system at any point on the Z0 axis. The X0 and Y0 axes can then be selected in any convenient manner. But when establishing a 0 coordinate system, make the final DH parameters as simple as possible.

    3) Determine the Xi direction

    a. Axis Zi-1 and axis Zi are not coplanar

    Then the common perpendicular of the axis Zi-1 and the axis Zi defines the Xi axis, and its intersection with the axis Zi is the origin Oi.

    b. Axis Zi-1 is parallel to axis Zi

    In this case, there are infinitely many common normals between the axis Zi-1 and the axis Zi. The normal passing through the origin Oi-1 is chosen as the Xi axis, and Oi is the intersection of this normal and the Zi axis.

    c. Axis Zi-1 intersects with axis Zi

    Choose Xi to be perpendicular to the plane composed of Zi-1 and Zi. The origin Oi is generally set as the intersection of Zi-1 and Zi. However, any point on the axis Zi can be chosen as the origin.

    4) Determine the coordinate system N

    The above three steps apply to coordinate system 0,...N-1. The final coordinate system is often referred to as the end effector or tool coordinate system. Most commonly, the origin Oi is arranged symmetrically in the middle of the fixture, and the direction of the Zi axis is along the movement direction of the end (the direction in which the last joint expands and contracts). The direction of the Xi axis is along the vertical opening and closing direction of the clamp.

    Because there are many cases where the direction of the Xi axis of the coordinate system can be chosen arbitrarily, this leads to different DH parameters. In order to standardize the DH modeling method, some rules for "making DH parameters simple" are summarized.

    1. When determining the direction of the Xi axis, if there are many choices, choose the same direction as Xi-1 as much as possible

    2. When the coordinate system 0 is determined, the value of the joint variable 1 is set to zero. If it is a rotary joint, the joint variable is d; if it is a translational joint, the joint variable is
    d

insert image description here
After the coordinate system is determined, the DH parameters are determined through the above picture. The parameters of the
insert image description here
matrix in the standard DH are used to determine the relationship between the two adjacent joints.

3. Summary

It mainly introduces the application of the python robot toolbox, and the DH parameters are recorded by the way.

Guess you like

Origin blog.csdn.net/qq_43874696/article/details/123528275