【发布时间】:2020-06-04 18:20:19
【问题描述】:
在一个装配好的类人机器人上,我正在测试通过操纵肩关节的旋转来摆动右臂。
在我的代码中,您会看到 4 种方法给出不同的手臂末端位置。谁能解释一下为什么?
当我选择 method=1 时:手臂从正确的最终位置快速移动到最终位置。然而,最终的位置是完全错误的。
Method=2:再一步到达最终位置。最终位置现在正确
Method=3:手臂慢慢摆动到最终位置,误差很小(约1度)
Method=4:手臂快速摆动到末端位置,误差较大(几度)
void Start()
{
shoulderR_AngleBegin = new Vector3(37.418f, 7.976f, -17.495f);
shoulderR_AngleEnd = new Vector3(-6.643f, -30.957f, -80.09f);
angle = shoulderR_AngleBegin;
}
// Update is called once per frame
void Update()
{
int method = 4;
float x, y, z;
x = this.shoulderR_AngleBegin.x;
y = this.shoulderR_AngleBegin.y;
z = this.shoulderR_AngleBegin.z;
if(angle.x > this.shoulderR_AngleEnd.x || angle.y > this.shoulderR_AngleEnd.y || angle.z > this.shoulderR_AngleEnd.z)
{
if(method==1)
{
this.angle = this.angle + (this.shoulderR_AngleEnd - this.shoulderR_AngleBegin);
}
else if(method==2)
{
this.angle.x = this.angle.x + (this.shoulderR_AngleEnd.x - this.shoulderR_AngleBegin.x);
this.angle.y = this.angle.y + (this.shoulderR_AngleEnd.y - this.shoulderR_AngleBegin.y);
this.angle.z = this.angle.z + (this.shoulderR_AngleEnd.z - this.shoulderR_AngleBegin.z);
}
else if(method==3)
{
this.angle.x = this.angle.x + (this.shoulderR_AngleEnd.x - this.shoulderR_AngleBegin.x) * Time.deltaTime;
this.angle.y = this.angle.y + (this.shoulderR_AngleEnd.y - this.shoulderR_AngleBegin.y) * Time.deltaTime;
this.angle.z = this.angle.z + (this.shoulderR_AngleEnd.z - this.shoulderR_AngleBegin.z) * Time.deltaTime;
}
else if (method==4)
{
this.angle.x = this.angle.x + (this.shoulderR_AngleEnd.x - this.shoulderR_AngleBegin.x) * Time.deltaTime * 8.0f;
this.angle.y = this.angle.y + (this.shoulderR_AngleEnd.y - this.shoulderR_AngleBegin.y) * Time.deltaTime * 8.0f;
this.angle.z = this.angle.z + (this.shoulderR_AngleEnd.z - this.shoulderR_AngleBegin.z) * Time.deltaTime * 8.0f;
}
}
this.ShoulderR.transform.localEulerAngles = angle;
}
'''
【问题讨论】: