【问题标题】:Arm swing with ridged humanoid带有脊状人形机器人的手臂摆动
【发布时间】: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;
    }
'''

【问题讨论】:

    标签: c# unity3d rotation


    【解决方案1】:

    根据您的代码,它是能够让手臂做不同的事情。你现在如何拥有它,你正在硬编码使用哪种方法

    int method = 4;
    

    使其他方法过时。

    如果您特别询问为什么不同的方法会产生不同的结束位置,那是由于每个选项中的代码。方法一一般使用角度来设置位置。它不关心角度的分量。

    所有其他方法都设置角度的每个轴(或者它可以设置设置角度的 xyz 位置。我只能根据名称猜测),但它们使用不同的函数来确定该值。您可以看到每个方法都在一个值中广告,以将最后一个方法的值乘以。 (他们在method2之后为每个方法添加了一些值)

    this.ShoulderR.transform.localEulerAngles = angle;
    

    然后使用给定的角度移动手臂。

    如果您仍然不确定它为什么会这样做,那么在 3-d 坐标系中查找有关角度的信息会很有帮助。具体看一下笛卡尔坐标系,因为这是我所看到的代码所使用的。物理教科书的介绍应该有一些有用的信息。如果没有,请检查中级书籍。我不记得我们什么时候开始的,因为我拥有应用心理学学位,但我不是教授。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-10-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-03
      • 2013-06-23
      • 1970-01-01
      相关资源
      最近更新 更多