Difference between revisions of "Custom IKFast for your Baxter"

From sdk-wiki
Jump to: navigation, search
(Clone the custom_baxter_ikfast Repository)
(Clone the custom_baxter_ikfast Repository)
Line 16: Line 16:
=== Clone the custom_baxter_ikfast Repository ===
=== Clone the custom_baxter_ikfast Repository ===
Clone this <code>custom_baxter_ikfast</code> repo anywhere, but make sure you are initialized inside a [[RSDK_Shell | initialized baxter.sh shell]] for commands later on.
Clone this <code>custom_baxter_ikfast</code> repo anywhere, but make sure you are inside a [[RSDK_Shell | initialized baxter.sh shell]] for commands later on.
<source lang="bash">
<source lang="bash">
$ git clone https://github.com/RethinkRobotics/custom_baxter_ikfast.git
$ git clone https://github.com/RethinkRobotics/custom_baxter_ikfast.git

Revision as of 21:52, 17 June 2015


Every Baxter's URDF is slightly different. This tutorial will show you how to generate IKFast for use with MoveIt specific to your Baxter. This is a fairly involved process, requiring many steps. For additional background information on the algorithm behind IKFast, please see Rosen Diankov's Doctoral thesis.

What is IKFast?

#ikfast IKFast provides analytical closed-form solutions for manipulator inverse kinematics. Part of the OpenRAVE robot architecture/software framework, IKFast has been used to provide closed-form solutions for Baxter's inverse kinematics. Advantages include order of magnitude faster IK solutions and the ability explore the manipulator's null space!

Using Baxter's MoveIt! IKFast plugins

Please see MoveIt_Tutorial#IKFast for the exact commands required to enable IKFast in your baxter_moveit_config package.

Generating Custom IKFast for Baxter

Install OpenRAVE

As of this writing, the instructions for adding the openrave PPA and installing openrave debians does not work on Ubuntu Trusty since the latest release was created in 2012 for Precise. That leaves building from source as the only option. Please clone the OpenRAVE repo and follow this tutorial for building from source:

 git clone --branch latest_stable https://github.com/rdiankov/openrave.git

If you encounter any issues in building this repo, please let the developers know in the issues tab of their repo.

Clone the custom_baxter_ikfast Repository

Clone this custom_baxter_ikfast repo anywhere, but make sure you are inside a initialized baxter.sh shell for commands later on.

$ git clone https://github.com/RethinkRobotics/custom_baxter_ikfast.git

Navigate inside this cloned folder for the rest of this tutorial:

$ cd custom_baxter_ikfast

Extracting the Mount Joint Transform

The left and right arm mount joint's in Baxter's torso are hand-welded at manufacture time. These joints are carefully measured and the transforms are stored in your Baxter's torso joint board. Fortunately, we can see the transforms in your robot's URDF located in the /robot_description parameter on the param server. After a fresh boot (to ensure the custom URDF has not been overwritten), from a properly initialized Baxter environment, export the URDF from the /robot_description parameter on the ROS parameter server where it is stored, to a file of your choice (ex: baxter_urdf.xml):

$ rosparam get -p /robot_description | tail -n +2 > baxter_urdf.xml

The -p outputs the parameter using pretty print. The output urdf is piped through the tail command first to remove a dummy first line - an artifact of the pretty print.

Open baxter_urdf.xml in your favorite text editor, and search for torso_arm_mount to find the only joints that differ from Baxter to Baxter. This is an example of what you should expect if the robot description contains Baxter's custom joints:

<joint name="left_torso_arm_mount" type="fixed">
    <origin xyz="0.0229088 0.220982 0.106714" rpy="-0.0179406 0.0117677 0.786034" />
    <axis xyz="0 0 0" />
    <parent link="torso" />
    <child link="left_arm_mount" />


<joint name="right_torso_arm_mount" type="fixed">
    <origin xyz="0.0245182 -0.218624 0.10866" rpy="-0.00321838 -0.00564277 -0.78571" />
    <axis xyz="0 0 0" />
    <parent link="torso" />
    <child link="right_arm_mount" />

Save these snippits of URDF for the next steps.

  • Note: If you see the following joint values, then you are using the generic URDF provided in baxter_description of the SDK. This can happen if the generic URDF is loaded to the param server via a roslaunch script (such as the one with MoveIt). Reboot your robot to clear the robot_description and try again:
    <joint name="left_torso_arm_mount" type="fixed">
        <origin rpy="0 0 0.7854" xyz="0.024645 0.219645 0.118588"/>
        <parent link="torso"/>
        <child link="left_arm_mount"/>
    <joint name="right_torso_arm_mount" type="fixed">
        <origin rpy="0 0 -0.7854" xyz="0.024645 -0.219645 0.118588"/>
        <parent link="torso"/>
        <child link="right_arm_mount"/>

Modify Simplified URDFs with your robot's joints

The baxter_arm.accurate.<side>.urdf was extracted from Baxter's original urdf to separate out the left and right arms. Inside the custom_baxter_ikfast folder, edit both baxter_arm.accurate.left.urdf and baxter_arm.accurate.right.urdf with your favorite text editor.

 <joint name="left_torso_arm_mount" type="fixed">
   <origin rpy="0 0 0.7854" xyz="0.024645 0.219645 0.118588"/>
   <parent link="base"/>
   <child link="left_arm_mount"/>

with your custom joint copied from above. Save, quit, and repeat for the other arm's urdf.

Create DAEs for Each Arm

Create our DAEs for each arm:

sudo apt-get install ros-indigo-robot-model
  • Note: Please use the a simplified version of the urdf to only contain each manipulators links/joints modified with your robot's arm mount joint extracted above
rosrun collada_urdf urdf_to_collada baxter_arm.accurate.left.urdf baxter_arm.left.dae
  • The resulting DAE also needs some hand tuning - specifically the rotational portions of the description. Round values logically (ie. 119.9999999999999 to 120.0)

Please take note of the link indices using the following command:

$ openrave0.9-robot.py baxter_arm.left.dae --info links
name                 index parents             
base                 0                         
right_arm_mount      1     base                
right_upper_shoulder 2     right_arm_mount     
right_lower_shoulder 3     right_upper_shoulder
right_upper_elbow    4     right_lower_shoulder
right_lower_elbow    5     right_upper_elbow   
right_upper_forearm  6     right_lower_elbow   
right_lower_forearm  7     right_upper_forearm 
right_wrist          8     right_lower_forearm 
right_hand           9     right_wrist         
right_gripper        10    right_hand          
name                 index parents   

Likewise with the joints:

$ openrave0.9-robot.py baxter_arm.left.dae --info joints
name                  joint_index dof_index parent_link          child_link           mimic
right_s0              0           0         right_arm_mount      right_upper_shoulder      
right_s1              1           1         right_upper_shoulder right_lower_shoulder      
right_e0              2           2         right_lower_shoulder right_upper_elbow         
right_e1              3           3         right_upper_elbow    right_lower_elbow         
right_w0              4           4         right_lower_elbow    right_upper_forearm       
right_w1              5           5         right_upper_forearm  right_lower_forearm       
right_w2              6           6         right_lower_forearm  right_wrist               
right_torso_arm_mount -1          -1        base                 right_arm_mount           
right_hand            -1          -1        right_wrist          right_hand                
right_endpoint        -1          -1        right_hand           right_gripper             
name                  joint_index dof_index parent_link          child_link           mimic

Choose IK Type

Choose your IK Type (ex: Transform6D, Rotation3d, Translation3D, etc.)
For most applications it makes sense to use transform6D - Baxter's end effector reaches desired 6D transformation

Generate the IKFast Solver

Building the solver using the collada mesh, chosen iktype, base, and end effector links created and found in the previous steps.

$ python /usr/lib/python2.7/dist-packages/openravepy/_openravepy_0_9/ikfast.py --robot=baxter_arm.left.dae --iktype=transform6d --baselink=1 --eelink=10 --freeindex=5 --savefile=baxter_ikfast.w1.left.cpp

Completion time should ~24 minutes.
Compile executable:

g++ -lstdc++ -o baxter_ik baxter_ikfast.w1.left.cpp -llapack

Customizing the IKFastDemo

Open up the ikfastdemo.cpp source file in your favorite text editor.
Modify the following lines at the top of the file:

#define IK_VERSION 61
#include "baxter_ikfast.w1.left.cpp"

Then compile your IKFastDemo:

g++ ikfastdemo.cpp -lstdc++ -llapack -o compute -lrt