How to define a joint at a singular point during IK

Typically: "How do I... ", "How can I... " questions
Post Reply
Ruediger
Posts: 12
Joined: 03 Aug 2013, 07:25

How to define a joint at a singular point during IK

Post by Ruediger » 09 Aug 2013, 11:24

Hello,
I like to change the middle joint of a scara type robot from one side to the other.

The tip of the scara follows a path in a loop with
simHandlePath(_path, simGetSimulationTimeStep())
the path reaches a point were the middle joint is straight,
but from this point on, it looks like random which direction
the middle joint uses afterwards.

Can I define the behavior?

Or is it possible to stop at a point just before the straight position,
setting the joint TargetPosition to the desired values (how to?)
and then continue with the loop?

Thanks
Ruediger

coppelia
Site Admin
Posts: 7123
Joined: 14 Dec 2012, 00:25

Re: How to define a joint at a singular point during IK

Post by coppelia » 09 Aug 2013, 16:13

Hello Ruediger,

Yes, you can do this, and there are probably several possibilities. The easiest would be to add a second IK group, with following characteristics:
  • it should be damped (i.e. DLS resolution method)
  • it should be executed before the regular IK group (i.e. before the IK group that solves the main IK task)
  • it should contain a tip-target dummy pair, where the tip is located after the second joint, and the target before the second joint. The kinematic chain of that IK group should include just the second joint (make sure to specify as base an object after the first joint, and before the second joint)
  • the target dummy should be initially set so that the joint 2 will always try to keep a small angle
What will effectively happen is following:
  • The second IK group is executed. The result is a small angle in joint 2
  • Immediately after, the first (and original) IK group is executed, which will solve the IK task for the scara robot. Since the IK group 2 already set a small angle in joint 2, joint2 will tend to make the least movement and keep its sign.
Finally, when you know that you will have a singular configuration at some point, always use damped resolution methods (in your case for the 2 IK groups), otherwise your manipulator might be unstable in the singular configuration.

Cheers

Ruediger
Posts: 12
Joined: 03 Aug 2013, 07:25

Re: How to define a joint at a singular point during IK

Post by Ruediger » 13 Aug 2013, 14:07

Hello Admin,
I have my IK groups made ​​exactly according to your instructions, but the behavior is unstable.
I think the problem is that the intial small angle of the tip-target around joint 2 does not remains small if the joint is far away of the singular configuration. This is the case for other positions on the path.
Playing with differnt dumping values for the IK groups helps, but I can not yield a good result.
How to set the secont tip-target pair (around joint 2), that the delta remains small, even if the joint has huge angle value, as needed to solve the scara IK group.

Regards,
Ruediger

coppelia
Site Admin
Posts: 7123
Joined: 14 Dec 2012, 00:25

Re: How to define a joint at a singular point during IK

Post by coppelia » 13 Aug 2013, 14:56

Ruediger,

please send us the scene, or upload it to a free storage service that we can access. Then we can have a quick look at the scene.

Cheers

Ruediger
Posts: 12
Joined: 03 Aug 2013, 07:25

Re: How to define a joint at a singular point during IK

Post by Ruediger » 13 Aug 2013, 16:12

I have found a solution, which looks more simple to me:
Insite the simHandlePath() loop I check for the straight elbow (joint 2 is near 0)
and then I limit the JointInterval to the right or left angle range
(M2 is the handle for the joint 2)

Code: Select all

length = simGetPathLength(_path)
while (simGetPathPosition(_path) < length) do
	simHandlePath(_path, simGetSimulationTimeStep())
	if (math.abs(simGetJointTargetPosition(M2)) < 5*math.pi/180) then
		simAddStatusbarMessage("< 5 grad")
		if (Elbow_right) then
			simSetJointInterval(M2, false, {0, M2_range/2})
		else
			simSetJointInterval(M2, false, {-M2_range/2, M2_range/2})
		end
	end
	simSwitchThread()
end
The "if simGetJointTargetPosition() less then" looks not "clean".
Any other way to trigger the "if"?
e.g. at a path point.
In my case I know the path poit number, where the singular configuration is.

Regards,
Ruediger

coppelia
Site Admin
Posts: 7123
Joined: 14 Dec 2012, 00:25

Re: How to define a joint at a singular point during IK

Post by coppelia » 13 Aug 2013, 16:56

Not sure if I understand the code...

try maybe simGetJointPosition instead of simGetJointTargetPosition.

Your solution doesn't seem very elegant since your loop will force your joint to a given range when its angle is small, which will effectively instantaneously change it.

I would go with a manipulator path that never comes too close of a singularity.

Another possibility that I see: execute the IK calculations for your manipulator explicitely in a non-threaded child script. If after execution you see that the angle is not what you want, set it to its inverse value (or possibly a little bit larger than that) and execute the calculation directly again, similar to:

Code: Select all

if (simGetScriptExecutionCount()==0) then
	ikGroup=simGetIkGroupHandle('ikGroupName')
	joint2Handle=simGetObjectHandle('joint2Name')
end

simHandleIkGroup(ikGroup)
if (simGetJointPosition(joint2Handle)<0) then
	simSetJointPosition(joint2Handle,-simGetJointPosition(joint2Handle))
	simHandleIkGroup(ikGroup)
end
just make sure your Ik group is explicitely flagged (in the Ik dialog, check Explicit handling for that Ik group).

Cheers

Ruediger
Posts: 12
Joined: 03 Aug 2013, 07:25

Re: How to define a joint at a singular point during IK

Post by Ruediger » 14 Aug 2013, 07:35

Your code defines the Joint_2 position to stay positive or negative. This does not solve my problem.
Let me explain:
A scara can reach tip positions in an area limited by an outer circle. All tip positions on this circle have Joint_2 set to 0.
For that reason all tip positions inside this circle can be reached with a positive or negative values of Joint_2. Both is possible for each tip position!
Positive values of Joint_2 have the elbow right of the tip position, negative values have the elbow left of the tip position.
In my case the left tip position is close to a left boundary. Therfore the elbow must be right of the tip.
I have defined Joint_2 positive (and Joint_1 according) to yield a possible start point for the path.
The other tip position (the end point of the path) is in right direction close to a right boundary. At this tip position the elbow *must be left* of the tip position, because the boundary makes it impossible for the elbow to be right of the tip position.
The only possible path from start to end must include a tip position on the outer circle because the Joint_2 has to move from positive values to negative values during the path move.
I will define this path and the IK algorithm should change the Joint_2 freedom degree exactly at this point of the path.
Regards
Ruediger

coppelia
Site Admin
Posts: 7123
Joined: 14 Dec 2012, 00:25

Re: How to define a joint at a singular point during IK

Post by coppelia » 14 Aug 2013, 17:41

Ruediger,

the example I mentioned should work for your case too. You could theoretically recompute the IK for a given position from many different start configurations, and keep the result you like. Only in the second phase will the joint positions be applied to the dynamic part.
The easiest would be to post your simulation scene, or to send it to us.

Cheers

Post Reply