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)
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.
At this time, the model is directly associated with the model file and cannot be moved and modified
Solution:
method one:
Right click "Prefab" → "Unpack" to unlock it
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
Method 2:
Generate a prefab, drag the model directly into the Project window folder,
Prompt to create a prefab, select the "Original Prefab" original prefab to generate a new prefab.
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.
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)
(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
(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
Joint two example:
(1) Same as joint 1, create components and joint 2
(2) Adjust the rotation center to the second joint rotation axis
adjusted
(3) Grouping, the immobile part is placed in the component, and the moving part is placed in joint 2
(4) Rotation test is normal
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
Then hang the script on the robotic arm model RobotControl.cs
, and add joints 1 and 2 to Joints in order
test:
Simulate motion in test motion script
Effect