以 3D 形式表示机器人的肘部角度

发布于 2024-08-31 19:24:13 字数 3368 浏览 4 评论 0原文

我得到了 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;
}

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

请让我知道您的想法!非常感谢任何帮助...

I am given coordinates of two points in 3-D viz. shoulder point and object point(to which I am supposed to reach). I am also given the length from my shoulder-to-elbow arm and the length of my forearm. I am trying to solve for the unknown position(the position of the joint elbow). I am using cosine rule to find out the elbow angle. Here is my code -

#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;
}

However, this solution makes sense only in 2-D. Because clockwise and counter-clockwise are meaningless without an axis and direction of rotation. Returning only an angle is technically correct but it leaves a lot of work for the client of this function to use the result in meaningful way. How can I make the changes to get the axis and direction of rotation ? Also, I want to know how many possible solution could be there for this problem.

Please let me know your thoughts ! Any help is highly appreciated ...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雪花飘飘的天空 2024-09-07 19:24:13

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

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

The basic problem is that you're solving (necessarily) the angle between the two arm parts on a plane, but the plane itself is unspecified. The solution will involve either constraining the plane itself or constraining the location of the elbow to some state like "the lowest possible position" (and the two of these will likely have identical solutions).

So, define the plane, and locate the three ends on that plane.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文