【问题标题】:Representing robot's elbow angle in 3-D以 3-D 形式表示机器人的肘部角度
【发布时间】:2010-05-07 01:55:50
【问题描述】:

我得到了 3-D 中两点的坐标。肩点和目标点(我应该达到的)。我还得到了肩到肘臂的长度和前臂的长度。我正在尝试解决未知位置(关节肘的位置)。我正在使用余弦规则来找出肘部角度。这是我的代码 -

#include <stdio.h>
#include <math.h>
#include <stdlib.h>

struct point {
     double x, y, z;
};

struct angles {
     double clock_wise;
     double counter_clock_wise;
};

double max(double a, double b) {
     return (a > b) ? a : b;
}
/*
 * Check if the combination can make a triangle by considering the fact that sum
 * of any two sides of a triangle is greater than the remaining side. The
 * overlapping condition of links is handled separately in main().
 */
int valid_triangle(struct point p0, double l0, struct point p1, double l1) {
     double dist = sqrt(pow((fabs(p1.z - p0.z)), 2) + pow((fabs(p1.y - p0.y)), 2) + pow((fabs(p1.x - p0.x)), 2));
     if((max(dist, l0) == dist) && max(dist, l1) == dist) {
          return (dist < (l0 + l1));
     }
     else if((max(dist, l0) == l0) && (max(l0, l1) == l0)) {
          return (l0 < (dist + l1));
     }
     else {
          return (l1 < (dist + l0));
     }
}
/* 
 * Cosine rule is used to find the elbow angle. Positive value indicates a
 * counter clockwise angle while negative value indicates a clockwise angle.
 * Since this problem has at max 2 solutions for any given position of P0 and
 * P1, I am returning a structure of angles which can be used to consider angles
 * from both direction viz. clockwise-negative and counter-clockwise-positive
 */
void return_config(struct point p0, double l0, struct point p1, double l1, struct angles *a) {
     double dist = sqrt(pow((fabs(p1.z - p0.z)), 2) + pow((fabs(p1.y - p0.y)), 2) + pow((fabs(p1.x - p0.x)), 2));
     double degrees = (double) acos((l0 * l0 + l1 * l1 - dist * dist) / (2 * l0 * l1)) * (180.0f / 3.1415f);
     a->clock_wise = -degrees;
     a->counter_clock_wise = degrees;
}
int main() {

     struct point p0, p1;
     struct angles a;
     p0.x = 15, p0.y = 4, p0.z = 0;
     p1.x = 20, p1.y = 4, p1.z = 0;
     double l0 = 5, l1 = 8;

     if(valid_triangle(p0, l0, p1, l1)) {
          printf("Three lengths can make a valid configuration \n");
          return_config(p0, l0, p1, l1, &a);
          printf("Angle of the elbow point (clockwise) = %lf, (counter clockwise) = %lf \n", a.clock_wise, a.counter_clock_wise);
     }
     else {
          double dist = sqrt(pow((fabs(p1.z - p0.z)), 2) + pow((fabs(p1.y - p0.y)), 2) + pow((fabs(p1.x - p0.x)), 2));

          if((dist <= (l0 + l1)) && (dist > l0)) {
               a.clock_wise = -180.0f;
               a.counter_clock_wise = 180.0f;
               printf("Angle of the elbow point (clockwise) = %lf, (counter clockwise) = %lf \n", a.clock_wise, a.counter_clock_wise);
          }
          else if((dist <= fabs(l0 - l1)) && (dist < l0)){
               a.clock_wise = -0.0f;
               a.counter_clock_wise = 0.0f;
               printf("Angle of the elbow point (clockwise) = %lf, (counter clockwise) = %lf \n", a.clock_wise, a.counter_clock_wise);
          }
          else
               printf("Given combination cannot make a valid configuration\n");
     }
     return 0;
}

但是,此解决方案仅适用于二维。因为没有轴和旋转方向,顺时针和逆时针是没有意义的。只返回一个角度在技术上是正确的,但它给这个函数的客户端留下了很多工作来以有意义的方式使用结果。如何进行更改以获得旋转轴和方向?另外,我想知道这个问题有多少可能的解决方案。

请告诉我你的想法!任何帮助都非常感谢...

【问题讨论】:

    标签: 3d robotics kinematics inverse-kinematics


    【解决方案1】:

    基本问题是您(必须)解决平面上两个臂部件之间的角度,但平面本身未指定。该解决方案将涉及约束平面本身或将肘部的位置约束到某种状态,例如“可能的最低位置”(并且这两个可能具有相同的解决方案)。

    因此,定义平面,并在该平面上定位三个端点。

    【讨论】:

    • dash-tom-bang,除了两个点和长度没有给出其他信息。我找到了一个参考 - eng.utah.edu/~cs5310/chapter5.pdf theta2 = 2 * atan(sqrt((pow(l0 + l1, 2) - (dist * dist)) / ((dist * dist) - pow(l0 - l1, 2))) ); phi = atan2(p1.y, p1.x); psi = atan2(l1 * sin(theta2), (l0 + l1 * cos(theta2))); theta1 = phi - psi;因此,return_config 将返回 theta2 作为“肘角”,返回 theta1 作为与旋转轴的角度。我还应该返回旋转方向。请问,如果我在正确的轨道上,任何人都可以评论吗?
    • 是的,您只需要提供您没有的信息。换句话说,选择一些看起来合理的东西并尝试一下。 ;)
    猜你喜欢
    • 1970-01-01
    • 2014-08-15
    • 2012-06-12
    • 2018-11-09
    • 2017-11-05
    • 2011-05-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多