【发布时间】:2016-02-24 13:24:21
【问题描述】:
我有一个 2 段机械臂,它需要通过设置关节(角度)来到达特定点。
这里是设置图:
我的手臂位于草图的中间,所以我的原点是 (width/2,0)。 这些是我知道的价值观: 长度: 第一段 (L1):140 毫米。 第二段 (L2):180 毫米。 原点与目标点之间的距离。 (使用 dist() )。
这些长度形成一个三角形。因此,使用三角定律我可以找到三角形的角度,这些角度是我想用来定位我的手臂使其到达目标点的角度。
现在,我想使用处理环境在屏幕上绘制三角形进行模拟。我应用了一些变换来绘制三角形,但我没有得到正确的绘图。
这是我的代码:
void draw(){
background(100);
translate(width/2,0); // origin
// target
float penX = mouseX-width/2;
float penY = mouseY;
// draw points
ellipse(penX, penY, 20, 20);
ellipse(0,0,20,20);
line(0,0,penX,penY);
// distance from origin to target
float distance = dist(0,0,penX,penY);
// first angle (part of S1)
float b = asin(penY/distance);
arc(0,0,100,100,0,b);
// second angle (part of S1)
float a = acos((pow(L1,2)+pow(distance,2)-pow(L2,2))/(2*L1*distance));
// Angle representing first joint
S1 = a + b; // first joint angle
// Angle representing second joint
S2 = acos((pow(L1,2)+pow(L2,2)-pow(distance,2))/(2*L1*L2)); //second joint angle
//Drawing Triangle:
rotate(S1);
line(0,0,120,0);
translate(120,0);
rotate(-S2);
line(0,0,180,0);}
我希望我的文字清晰,如有任何混淆,我深表歉意。
【问题讨论】:
-
你有想过这个问题吗?
标签: java processing transformation angle inverse-kinematics