Skip to content

MasterYip/IKFast_wrapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

IKFast warpper for c++ & python

Usage

NOTE:

  1. C++ lib generation support multiple files, but python binding generation only support one file once a time.
  2. Temporarily this repo only support 3D translation. You can modify the interface to support more.

After uploading your single leg URDF, links and indices will be displayed:

name            index parents
------------------------------
BASE            0
RF_HIP          1     BASE
RF_THIGH        2     RF_HIP
RF_SHANK        3     RF_THIGH
RF_FOOT         4     RF_SHANK
RF_KFE_CollBall 5     RF_THIGH
RF_HFE_CollBall 6     RF_HIP
------------------------------

Filling the blanks:

alt text

Warning

The third row should be filled with the index of the JOINT that will not change during the IK calculation, which is called Free Joint in IKFast. In this case, the joint between RF_SHANK and RF_FOOT is the Free Joint, so the index should be 3. More details can be found in the IKFast documentation.

Examples of IKFast generation can be found in folder cpp_demos_for_generation.

C++ lib generation

  1. Use IKFast Generator to generate your IK algorithm

    Note: for 3DTranslation there should be an intermediate link and joint between root link BASE and the arm (unknown reason)

  2. Add your generated files to /src

    For example:

    src
    ├── ikfast_leg1.cpp
    ├── ikfast_leg2.cpp
    └── ikfast_leg3.cpp

    Note: the namespace will follow the file name

  3. Rename lib in CMakeLists.txt

     project(IKFast_warpper)
     # change this to your library name
     set(LIB_NAME <your-lib-name>)
    

    Note: lib name should be different from source file name

  4. Generate your ikfast lib

    cd ikfast_gen_cpp
    bash ./build.sh
  5. Get your lib in ./lib/<your-lib-name> and enjoy it using different namespace

    Note: example is generated as test.cpp

Note: if you want change the interface, you can modify ikfast_interface.h, ikfast_interface.cpp, ikfast_interface_gen.h.in in template folder.

Python binding generation

Prerequisite: pybind11 should be installed.

pip install pybind11
sudo apt install pybind11-dev
  1. Use IKFast Generator to generate your IK algorithm

    Note: for 3DTranslation there should be an intermediate link and joint between root link BASE and the arm (unknown reason)

  2. Replace ikfast_gen.cpp with your file

  3. Rename your module in CMakeLists.txt

    ## Settings
    set(PYBIND_NAME <replace with your favored name>) # Change this to the name of your python module
    
  4. Complie it.

    mkdir build
    cd build
    cmake ..
    make

    or specifying python exec path

    mkdir build
    cd build
    cmake .. -DPYTHON_EXECUTABLE=$(which python3)
    make

    or use build.sh

    sh build.sh

    Note: DO NOT use conda python, it may cause some problems.

  5. Get your cpython module in build and use it like:

    from .pyikfast import pyikfast_el_mini as ik
    from .pyikfast import pyikfast_el_mini_back as ik_back

Examples

ElSpider2

Leg config is axial symmetry.

rot_mat = [0, np.pi/3*2, np.pi/3, -np.pi/3, -np.pi, -np.pi/3*2]
th_2 = self.rot_mat[foot_index]/2
m = pin.XYZQUATToSE3([0, 0, 0, 0, 0, np.sin(th_2), np.cos(th_2)])
pos = m.actInv(target)
sol = ik.IKFast_trans3D(list(pos))

ElSpider Air

               head
  (leg3)LF ------------- RF(leg0)
           |           |
           |     x     |
  (leg4)LM |  y__|     | RM(leg1)
           |           |
           |           |
  (leg5)LB ------------- RB(leg2)

Robot foot positions under config q0 = [0]*18:

leg0: [ 0.35350208 -0.22998902 -0.1360558 ]
leg1: [ 0.05350208 -0.28998902 -0.1360558 ]
leg2: [-0.35349792 -0.22998928 -0.1360562 ]
leg3: [ 0.35350208  0.2299882  -0.1360569 ]
leg4: [ 0.05350208  0.2899882  -0.1360569 ]
leg5: [-0.35350133  0.22998794 -0.13605704]

Detailed python example can be found in ikfast_gen_py/test_ik.py.

About

IKFast wrapper for c++ & python

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages