Skip to content
This repository has been archived by the owner on Aug 3, 2020. It is now read-only.

Add recursive mimic joint #177

Merged
merged 15 commits into from
Mar 17, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,18 @@ class JointStatePublisher():
parent = param['parent']
factor = param.get('factor', 1)
offset = param.get('offset', 0)
# Handle recursive mimic chain
recursive_mimic_chain_joints = [name]
while parent in self.dependent_joints:
if parent in recursive_mimic_chain_joints:
error_message = "Found an infinite recursive mimic chain"
rospy.logerr("%s: [%s, %s]", error_message, ', '.join(recursive_mimic_chain_joints), parent)
sys.exit(-1)
recursive_mimic_chain_joints.append(parent)
param = self.dependent_joints[parent]
parent = param['parent']
factor *= param.get('factor', 1)
# the offset is relative only to the first parent
offset = factor*offset + param.get('offset', 0)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi thank you for thew changes,

I think the correct math is:

offset += factor * param.get('offset', 0)
factor *= param.get('factor', 1)

(in that order)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the recursive formula is correct

J_k = f_k * J_k-1 + o_k
    = f_k * f_k-1 * ... * f_2 * f_1 * J_0 +
      + f_k * (f_k-1 * (... * (f_2 * o_1 + o_2) + ...) + o_k-1) + o_k

It should be:

  • factor = factor_new * factor_old
  • offset = factor_new * offset_old + offset_new

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your code does not match your math.

Here is your math:

factor = factor_new * factor_old
offset = factor_new * offset_old + offset_new

Here is what I think your code does:

factor = factor_new * factor_old
offset = factor_new * factor_old * offset_old + offset_new

I also think you're looking at the mimic chain from the wrong side. (hence the math is wrong).

Let consider the former example again:

 <joint name="Jc" type="continuous">
 </joint>
 <joint name="Jb" type="continuous">
     <mimic joint="Jc" multiplier="x" offset="y"/>
 </joint>
 <joint name="Ja" type="continuous">
    <mimic joint="Jb" multiplier="x'" offset="y'"/>
 </joint>

Let do the algorithm step by step, with my modification.
At first you have

name == Ja
factor = x'
offset = y'
parent = Jb

parent in self.dependent_joints == True
parent = Jc
offset += factor * y
offset == y' + x'*y
factor *= x
factor == x'*x

parent in self.dependent_joints == False

hence:
offset == y' + x'*y
factor == x'*x

we're back on equation (3).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right I'm sorry, I completely forget about factor_old already computed inside factor_new when doing factor_new * offset_old.

joint = self.free_joints[parent]

if has_position and 'position' in joint:
Expand Down