Robot arm script

About advanced scenes, and the Thyme scripting language used in Algodoo.

Robot arm script

Postby Kilinich » Mon Dec 03, 2012 12:10 pm

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:

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.

Rating: rated 6.1
Filesize: 12.38 kB
Comments: 4
Ratings: 3
download


p.s. angles may need "-" sign depends on hinges geom0/geom1 order.
Dream of Algodoo as game development engine...
User avatar
Kilinich
[Best bug reporter 2010]
 
Posts: 2098
Joined: Mon Aug 31, 2009 8:27 pm
Location: South Russia

Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 3 guests