Robot arm script
1 post • Page 1 of 1
Robot arm script
I think it might be useful. Since hinges with bend=true can maintain target angle, it's easy to make 2-segments robot arm.
Script for hinges angle:
apos - endpoint position related to arm base
a - far segment length
b - near segment length
Result is a list [joint1angle, joint2angle] so you can put it into scene.my. variable and apply on hinges.
Don't forget to adjust apos, and joint1angle according to base geom pos and angle.
p.s. angles may need "-" sign depends on hinges geom0/geom1 order.
Script for hinges angle:
- Code: Select all
Scene.my.arm = (apos, a, b) => {
c2 := apos(0)*apos(0)+apos(1)*apos(1); c := c2^0.5;
m := math.atan(apos(1)/apos(0)) + (apos(0) > 0 ? 0: math.pi);
j1 :=0; j2 :=0;
c > a+b ? {j1 = m; j2 = 0} : {
(a > b) && (c < a-b) ? {j1 = m + math.pi; j2 = math.pi} : {
(b > a) && (c < b-a) ? {j1 = m; j2 = math.pi} : {
j1 = m + math.acos((b*b+c2-a*a)/(2*b*c));
j2 = math.pi + math.acos((a*a+b*b-c2)/(2*a*b))
}
}
}; [j1,j2]
}
apos - endpoint position related to arm base
a - far segment length
b - near segment length
Result is a list [joint1angle, joint2angle] so you can put it into scene.my. variable and apply on hinges.
Don't forget to adjust apos, and joint1angle according to base geom pos and angle.
p.s. angles may need "-" sign depends on hinges geom0/geom1 order.
Dream of Algodoo as game development engine...
-

Kilinich - [Best bug reporter 2010]
- Posts: 2098
- Joined: Mon Aug 31, 2009 8:27 pm
- Location: South Russia
1 post • Page 1 of 1
Who is online
Users browsing this forum: No registered users and 3 guests




