且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

逆向运动学CCD算法的工作

更新时间:2023-02-02 14:03:29

在我开始使用一些更高级的方法之前,我是这样做的:

Before I started use some more advanced approaches I did it like this:

pe=desired_new_position;

for (i=0;i<number_of_actuators;i++)
 {
 // choose better direction
                   p=direct_kinematics(); d =|p-pe|; // actual step
 actuator(i)--;  p=direct_kinematics(); d0=|p-pe|; // previous step
 actuator(i)+=2; p=direct_kinematics(); d1=|p-pe|; // next step
 actuator(i)--;  dir=0; d0=d;
      if ((d0<d)&&(d0<d1)) dir=-1;
 else if ((d1<d)&&(d1<d0)) dir=+1;
 else continue;

 for (;;)
  {
  actuator(i)+=dir; p=direct_kinematics(); d =|p-pe|;
  if (d>d0) { actuator(i)-=dir; break; }
  if (actuator(i) on the edge limit) break;
  }

 }

[注释]

  1. 您可以通过一些步骤而不是 1 将其修改为 inc/dec 执行器位置

  1. you can modify it to inc/dec actuator position by some step instead of 1

如果差异过零则停止然后以较小的步长重新开始直到 step == 1 这将提高性能但对于大多数应用程序来说 step=1 就足够了,因为新位置是通常接近最后一个.

stop if difference crossed zero then start again with smaller step until step == 1 This will improve performance but for most application is step=1 enough because new position is usually near the last one.

注意这可能会卡在局部最小值/最大值

beware that this can get stuck in local min/max

如果输出卡住(效应器位置不变),则随机化执行器并重试.这种情况的发生取决于运动学复杂性和您要使用的路径类型

if the output get stuck (effector position is unchanged) then randomize the actuators and try again. Occurrence of this depend on the kinematics complexity and on the kind of path you want to use

如果手臂更多地在顶部而不是在底部

if the arms are driven more on the top then on the bottom

然后尝试反转 i-for 循环

then try reverse the i-for loop

如果你要控制效应器正常

if you have to control the effector normal

那么你必须从CCD中排除它的旋转轴并在CCD之前设置它

then you have to exclude its rotation axises from CCD and set it before CCD