Announcements

Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.

Need help with tricky IK chain

andrij.byelyayev
Participant
Participant

Need help with tricky IK chain

andrij.byelyayev
Participant
Participant

I am trying to build a rig described on the scheme:

I want the IK solution to conform automatically to settings of both slider manipulators (path constraints) and to the movement of the part to the left (to which joints 1 and 6 are linked / constrained).

Part I'm having problems with is highlighted in red.

My approach was to have such a hierarchy: one HD IK chain from joint 1 to 4 (1-2-3-4) and another one  from 2 to 6 (2-5-6).

But I don't know:
a. How to incorporate the path which joint 3 should follow.
b. How to make bone 2-3 stretchy only to adjust joint 3 to it's desired position on the path and not to stretch because of the IK solution.
c. How to make angle between bones 2-5 and 2-3 change  only to adjust joint 3 to it's desired position on the path and not to change because of the IK solution.
d. How to make joints 3, 4 and 6 to strictly "sit" in their positions and not to deviate from their positions. When I link IK end effectors to dummies and add position constraints everything becomes a mess(((...

question.png

 

 

 

0 Likes
Reply
Accepted solutions (1)
1,548 Views
19 Replies
Replies (19)

andrij.byelyayev
Participant
Participant

Open image and then right-klick "view image in new tab" to see readable size

0 Likes

leeminardi
Mentor
Mentor

I downloaded the image and the text was too difficult to read.  Please make  make multiple more legible copies of the images.

 

Here's a solution I posted for a mechanism that needed to follow a straight slot like in your design.  I used a transform script.  Also check out this thread where I found it necessary to write my own primitive solver for a mechanism via a transform script.

 

Please also post a Max file containing the key elements of the rig. 

A few questions.

  1. Are points 1 and 6 fixed relative to the peach object?
  2. Are 2 and 5 fixed relative to the pink object?
  3. Pink can move.
  4. Green is fixed.
  5. What make the angle 3-2-5 change when peach is moved? 

 

 

lee.minardi

andrij.byelyayev
Participant
Participant

Here are the images:

0 Likes

andrij.byelyayev
Participant
Participant
  1. Are points 1 and 6 fixed relative to the peach object?
    > yes (rotating joints)
  2. Are 2 and 5 fixed relative to the pink object?
    > Yes (rotating joint) path for joint 3 is also cut in the pink object
  3. Pink can move.
    > Yes. Its position is to be solved by IK while its rotation is always parallel to 1-6
  4. Green is fixed.
    > Yes
  5. What make the angle 3-2-5 change when peach is moved? 
    > 3-2-5 should not change by the IK solution. It should only change when joint 3 is adjusted by sliding manipulator on the path
0 Likes

andrij.byelyayev
Participant
Participant

Here's a solution I posted for a mechanism that needed to follow a straight slot like in your design.

> It is different in my case. In my case joint 3 does NOT slide along the pink object. Its position on the pink object's path should be defined by the slider manipulator and this will change the position of pink object in relation to peach and green objects.

0 Likes

domo.spaji
Advisor
Advisor

It would be best if you tell us what kind of hierarchy/animation you want to achieve - some real-world example...

 

From what you described here only points 1, 2 and path of point 3 are part of hierarchy  really  needed to satisfy your conditions. 

 

E.g. Point 4 (and it's path) have no role whatsoever in this.

0 Likes

leeminardi
Mentor
Mentor

@andrij.byelyayev I am trying to understand the kinematic action of your mechanism before trying to determine appropriate rigging.  Are you familiar with Gruebler's Equation?  It can be used to determine the degrees of freedom given the number of links and joints.   The simple form is

3* (L - 1) - 2 * J = degrees of freedom.  

  where, L = number of links and J = number of joints.

For example, A 4-bar linkage (3 *(4-1)-2*4 =1 ) has 1 DoF while a truss (L=3, J = 3) = 0 DoF (a structure not a mechanism).

 

For your mechanism, you choose a location for point #4 so we can consider it fixed (grounded). Point #3 is fixed relative to the pink object for a specific configuration.  In this case we have 6 links and 6 joints or 3 degrees of freedom. Since pink cannot rotate (is this true?) then we can subtract 1 DoF yielding 2 DoF. Link 4-3 angle of rotation is 1 DoF .  The link chain 1 - 2 -5 -6 is a four bar linkage with 1 DoF but none of its links are grounded.  Since the translation and rotation of 1-2 in constrained by it path the result is 1 DoF.

To be clear, you want to move the object contain 1-2 along a path.  Its position on the path determines its location AND  rotation.

 

In the attached file I created a crude model of the linkage.  It does not do what you want but you can rotate the crank link (arrow) and the parallelogram linkage will articulate  to an orientation you want. Then move the rectangle to a where you want and the rest of the linkage will follow. To effect the change caused by moving 3 in its slot just move the IK goal relative to the rectangle. The change of the position for 4 is achieved by changing the position of Bone001.

leeminardi_0-1648513819279.png

 

The position of pink is a function of the position and rotation of peach.  I think this is best controlled via an expression or transform script controller.  

 

I would write a transform script to control the location of the pink object based on the position and rotation of the Moving Part with a feature to move the location of point 3 based on a slider position.

I will not be able to give this any time for a couple of days but let me know if this is what you seek to do. 

 

 

 

 

lee.minardi
0 Likes

andrij.byelyayev
Participant
Participant

@domo.spaji @leeminardi, Thank You!

Unfortunately, I'm recreating a machine from photos, and can't find any video of it's work.
Leaving aside the movement of the "moving part" and possibility to adjust joints 4 position (let's say they are grounded), I want to build a system, where "pink part" will be automatically positioned in right place, when I change the position of joint 3 in relation to it (in relation to bar 2-5).

The right place would be when 2 rules are met:
1. Joints 2 and 5 in new position will have same distance from joints 1 and 6 respectively (r1) so that:
1a. Bar 2-5 will stay parallel to 1-6;
2. Distance between joints 3 and 4 in new position will stay the same (r2)

I'm new to scripting or expressions, so I do knot know for now how to write this "system of equations" to work in 3DS MAX... 

The fact that I can't solve it with IK is pretty disappointing(..

 

question3.png

0 Likes

domo.spaji
Advisor
Advisor
  1. Remove all constraints and links...
  2. Link obj. 2 to obj. 1
  3. With obj. 2 selected go to Hierarchy tab ->Link Info and uncheck Inherit - Rotate X,Y,Z
  4. Link your main obj. (pink one I guess) to obj. 2

Animate obj. 1 rotation...

Objects 5 and 6 are just pos. offset of 1, 2...   so, obj. 5 rotation = obj. 1 rotation... 

obj. 6 doesn't even have to be separate obj.

 

Obj. 3 looks like limiter of "pink one" movement, have (possible) same radius circular motion path like  2 and "pink"

Obj. 4 - although looks like in reality controlling obj. 3  in animation can be it's child - 99,9% ignore till finished animation

 

 

So why didn't you show some pictures?

0 Likes

andrij.byelyayev
Participant
Participant

@domo.spaji @leeminardi 
Hope this image will finally make everything clear.

Left and right columns represent moving (peach) part extreme positions.
Rows represent the correct position of the tricky (pink) part for four extreme positions of joints 3 and 4 on their paths (which I want to have the ability to control by sliding manipulators)

I've drawn this in CAD, so I'm sure such system (mechanism) is possible.
Still can't recreate it in MAX(...
question5.png

0 Likes

domo.spaji
Advisor
Advisor

Yes, here is perfectly clear that point 3 is child of point 4 and its motion path is R2 (from pic. before).

You are insisting in controlling animation with 2 "path constraints" ctrls and if you look at first 4 (new) pictures

you could see that for same points 3, 4 positions you have different transforms of other objects.

What you earlier said it's path of point 3 is actually Pink obj. path.

 

After all, all we need for most complicated animation is set of "extreme" poses and mechanical rigging/animation is simplest kind.

0 Likes

andrij.byelyayev
Participant
Participant

@domo.spaji @leeminardi 

I'm almost there, but not at all still.

I've set up an IK chain with two perpendicular bones (3A and A5) instead of one bone 3-5
to easily control 5 position relative to 3 by changing bone A-5 X.POS with upper slider manipulator.
Bone A-5 rotational joints are OFF, so that it stays perpendicular to 3-A


Bone 4-3 (root bone) is linked to a dummy that is path constrained and controlled by lower slider manipulator.

The problem is: I can't make IK solver keep bone A-3 parallel to 1-6 (as it should) and search for a solution (position of joints 3, A and 5) within this limitation.

If only I could do so, the problem would be solved.

I also understand that from the mathematical point of view I need to find two vector angles:
<1-6-5 (between 1-6 and 5-6) and <3-4-6 (between 3-4 and 6-4) for which vector sum (4-3)+(3-5)+(5-6)=(4-6),
which is possible to solve as I know because all the lengths of vectors are known and angle of vector (5-3) is also known.

Maybe, @leeminardi you can give some advice on how to write this with MAXScript, or, maybe, a tutorial on how to do so...

question6.png

0 Likes

leeminardi
Mentor
Mentor

@andrij.byelyayev   I've been on the road the past few days and away from my CAD PC but have given your task some thought. In essence you have a 4-bar linkage as show in your last image.  Links 6-5, 5-3, 3-4 and ground.  HOWEVER, you have a further constraint that 1-2 must be parallel to 6-5 via the parallelogram linkage. You could maintain this constraint in several ways including the addition of a wire parameter that ties the rotation of "Tricky Part" to the rotation of "Moving part" and then use a LookAt constraint to control link 1-2.

 

I would like to pursue creating a transform script that calculates the position of joint 3 based on the angle of link 6-5.  The computed position of 3 and its distance from 4 is then compared to the actual length of link 3-4 and the angle of 6-5 is adjusted accordingly   until the 2 distances are the same (within tolerance).  This is effectively a custom solver.  I understand that the location of 3 relative to 2-5 and the location of 4 can change but the script should allow for that.  I assume that the location of 3 and 4 are "locked" when the mechanism is animated but can be adjusted for slightly different action.  True?

 

I hope to look into this later today.  I have some other things I need to do before tackling this interesting challenge.  What is your timeline for a solution?

lee.minardi

andrij.byelyayev
Participant
Participant

Thank you so much for your time and effort, @leeminardi !

I have no deadline, as this is a personal project/

> I assume that the location of 3 and 4 are "locked" when the mechanism is animated but can be adjusted for slightly different action.  True?

Yes. I want to be able so set all the 4 controllers of this machine (2 of which already done and other 2 being discussed here) and then control the animation by choosing from several patterns (graphs) for the moving part. Mechanism should work correctly for all possible combinations of settings of the controllers.

What I thought of was a script that will find a proper place for vector 5-3 in space (all I actually need is a correct position of either 5 or 3), given it's length and orientation are known as well as distance from  6 to 5 and from 4 to 3 and vector 6-4 (both length and orientation). I believe, math is pretty simple, question is: how to code it and where...

0 Likes

leeminardi
Mentor
Mentor
Accepted solution

@andrij.byelyayev   I think I have a solution!

To review, given the following:

leeminardi_0-1648859103888.png

 

you would like to move and/or rotate Moving Part  and have Tricky Part move and rotate accordingly. The rig should also work if the location of joint 3 on Tricky Part and joint 4 on Fixed Part are moved.  In addition, Link 1-2, Tricky Part (2-5),  link 5-6 and Moving Part (1-6) form a parallelogram linkage that ensures that the rotation of Tricky Part is the same as Moving Part.

 Assuming that Joint 3 and 4 are temporarily fixed, we know that we can determine the location of joint3 if we know the angle that line 5-6 forms with a horizontal reference line.  A valid solution will place joint3 a distance from joint4 that is equal to the length of line 3-4.   I created a numerical method solution (i.e., a solver) to determine the angle of link 5-6.

 

The transform script for Tricky Part is:

leeminardi_1-1648859881546.png

The complete code is:

 

-- Calculate position and orientation of Tricky Part
-- that will have Joint3 a disatnce L34 from Joint4.

L56 = 228.35
L34 = 220
g1 = 0  -- lower limit angle guess L34 from Joint #4
g2 = 90  -- upper limit angle guess
gm = (g1 + g2)/2.  -- mid angle guess
pt4 = Joint4pos * FixedPartT  -- pivot point of link 3_4

m = copy MPT -- make independent copy of Moving Part's transform
 for i = 1 to 10 do  -- take 10 steps to converge to a solution
(
-- find the location of pivot point #3 for the 3 guesses
p1 = Joint8Pos * MPT + L56 * [cos(g1), 0 , sin(g1)]
p2 = Joint8Pos * MPT + L56 * [cos(g2), 0 , sin(g2)]
pm = Joint8Pos * MPT + L56 * [cos(gm), 0 , sin(gm)]
m.pos = p1
local v1 = Joint3Pos * m
m.pos = p2
v2 = Joint3Pos * m
m.pos = pm
vm = Joint3Pos * m
-- computer distances for the 3 guesses
 d1 = length(pt4 - v1)
 d2 = length(pt4 - v2)
 dm = length(pt4 - vm)

if dm > L34 then -- determine which 2 guesses bracket solution
( g2 = gm
)
else
( g1 = gm
)
gm = (g1 + g2)/2.  -- compute new middle guess value

i = i + 1
)-- end for ------

m.pos = pm
m  -- position Trick Part to new location

 

The code works as follow. After the length of links 3-4 and 5-6 are defined, three initial guesses are made for the angle of link 5-6.  They are g1 = 0Β°, g2 = 90Β° and midway guess gm = (g1 + g2)/2 = 45Β°.

The distance from joint 3 to joint4 for the three cases is then compared to the goal distance, the length of link 3-4. If the distance for angle gm is greater than link 3-4 (L34) then the upper bound is changed to gm (g2 = gm). if not, the lower bound is changed to gm (g1 = gm) and gm is redefine as the midway angle between the new set of g1 and g2.  The process can be repeated until a desired level of precision is found.  For now, I just limited the search to 10 iterations which works fairly well (I ran out of energy). I can adjust this later.

 

Once we know the location of Joint3 a LookAt contrainst is used to rotate link 3-4 and link 1-22 to their correct angles.

 

Note that joints 3 and 4 can be moved within their slots by simply changing to the local coordinate system and then moving these joints in the desired direction.  Their position could of course be controlled by a Slider Manipulator. 

 

There were many challenges in getting this solution.

  1. The original geometry behaved badly!  I don't know why but my only solution was to rebuild the major parts.
  2. The were too many constraints already applied to objects.  It's best to start with clean, unconstrained objects (e.g., no basic or inherit locks), IK constraints, etc.
  3. Poor choices for pivots.  With links it is best to have a local principal axis that is in the direction of the link.
  4. I had the statement

 

m = MPT​

 in my code where MPT is the Transform matrix for Moving Part.  Later in the code I modify the matrix m not realizing that in doing so MPT is also modified!  I had assumed that, as with most other programming languages, modifying m does not affect MPT.  I was wrong and discovered that m in this case was essentially an instance of MPT.  This problem was fixed with the statement

m = copy MPT​

 

Very simple once you know what to look for!

 

To see the action move and or rotate Moving Part in the attached file.  The object could be linked to a path with follow checked and the part would move and rotate as the percent-along value is changed thus meeting your original goal.  As noted, you can move joints 3 and 4.

 

lee.minardi

andrij.byelyayev
Participant
Participant

Thank you once again, @leeminardi !

 

Looks like learning MaxScript will be my new hobby;)!

 

Sincerely wish You all the best and good luck!

0 Likes

andrij.byelyayev
Participant
Participant

@leeminardi 
Everything under control and working perfectly!
(video attached)

 

0 Likes

leeminardi
Mentor
Mentor

I'm glad I could help.  Let me know if you have any questions about this script or writing scripts in general.  I have several youtube tutorials on writing 3ds Max scripts.

 

The mechanism is very interesting although the purpose of all those links (the ones in your original post and some others) is not clear.  The basic action is the simple rocking of a 4-bar linkage. Are those other links for some springs/shocks to provide dampening?

lee.minardi
0 Likes

andrij.byelyayev
Participant
Participant

@leeminardi, everything is clear so far, except the different local coordinate systems for different objects was a bit confusing. But I'm sure, there will be more questions as I'll tackle new challenges.

 

What I was trying to do (and did with your great help) was to make this machine work absolutely realistically, so that I can adjust it as in real life and it will work correctly  whichever rocking pattern I choose.

 

As you can see, there are four "manipulators", which change the way rocking motion is translated to other parts.
question7.png

0 Likes