Unity3d digital kanban-multi-joint robot motion control

Special: robot multi-joint following motion

The motion control of the manipulator is mainly the rotation of the joints. By controlling the angles of multiple joints, the synchronous control of the manipulator is realized.

The motion control of the manipulator can be decomposed into the movement of multiple joints. The next joint follows the movement of the previous joint. When processing the model, the next joint is hung under the previous joint as a sub-object, and by controlling the angles of multiple joints , to achieve the movement synchronization of the manipulator.

The model example is as follows (the model is downloaded from the Internet)

insert image description here

model processing

1. Model unlock

If the initial model is not processed like the following, the joint control cannot be performed, and the model sub-object needs to be processed.

insert image description here

At this time, the model is directly associated with the model file and cannot be moved and modified

Children of a Prefab instance cannot be deleted or moved, nor can components be reordered A Prefab instance can be unpacked to remove its Prefab connection

Solution:

method one:

Right click "Prefab" → "Unpack" to unlock it

insert image description here

After unlocking, the model name turns gray and can be modified directly. After the modification is completed, the model can be pulled into the Project view to generate a prefab
insert image description here

Method 2:

Generate a prefab, drag the model directly into the Project window folder,

insert image description here

Prompt to create a prefab, select the "Original Prefab" original prefab to generate a new prefab.

insert image description here

A .prefab file is generated in the folder, which is the prefab file. At this time, you can double-click the file or click the arrow on the right side of the model to enter the prefab file to modify the model.

insert image description here

2. Joint Treatment

Joint one example:

(1) Create two objects under the robotic arm, one is the component and the other is the joint 1 (the joint currently processed by the joint N is modified)

(2) Adjust the rotation center of joint 1 to the correct position of the rotation (very important)

insert image description here

insert image description here

(3) Put the sub-objects under the components and joints respectively

Components are used to place parts that do not move together with the joint, and the joint is the joint department and its sub-joint parts.

As shown in the figure, the base does not follow the movement of joint one, and the rest follow it, so put the base in the component, and put the others in joint one

insert image description here

insert image description here

(4) Rotation test

Select joint 1, drag the rotation line in the figure to test whether there is any problem with the grouping, and if there is no problem, you can proceed to the next joint

insert image description here

Joint two example:

(1) Same as joint 1, create components and joint 2
insert image description here

(2) Adjust the rotation center to the second joint rotation axis

insert image description here

adjusted
insert image description here

(3) Grouping, the immobile part is placed in the component, and the moving part is placed in joint 2

insert image description here

(4) Rotation test is normal

insert image description here

Other joints are treated similarly as above

3. Multi-joint unified control

Unified movement of multiple joints through RobotControl script

public class RobotControl : MonoBehaviour
{
    
    
    /// <summary>
    /// 关节组
    /// </summary>
    public MoveBase[] Joints;

    /// <summary>
    /// 关节数据
    /// </summary>
    public static float[] DataAngles;

    // Start is called before the first frame update
    void Start()
    {
    
    
        DataAngles=new float[2];
    }

    // Update is called once per frame
    void Update()
    {
    
    

        for (int i = 0; i < Joints.Length; i++)
        {
    
    
            Joints[i].SetDataPos(DataAngles[i]);
        }

    }
}

Hang the corresponding motion script according to the joint rotation attribute, the following joint 1 uses the Y direction rotation script YRotate, and joint 2 is the X direction rotation scriptXRotate

insert image description here

insert image description here

Then hang the script on the robotic arm model RobotControl.cs, and add joints 1 and 2 to Joints in order

insert image description here

test:

Simulate motion in test motion script

insert image description here

Effect

insert image description here

Guess you like

Origin blog.csdn.net/qq_39427511/article/details/130353894