Skip to content

逆運動学ライブラリとX7のサンプルを追加 #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 39 commits into from
Dec 21, 2021

Conversation

ShotaAk
Copy link

@ShotaAk ShotaAk commented Dec 15, 2021

What does this implement/fix?

kinematicsライブラリに逆運動学を解く関数inverse_kinematics_LM()を追加します。
この関数には、 杉原 知道. Levenberg-Marquardt法による可解性を問わない逆運動学. 日本ロボット学会誌 Vol.29, 2011 に記載されたアルゴリズムを実装しています。

また、この関数を用いたCRANE-X7用のサンプル(x7_inverse_kinematics)を追加しています。

逆運動学関数とサンプルを追加するために、下記の変更を実施しています。

hardware関係

  • サーボモータの関節可動範囲を取得するための関数を追加します
    • get_min_position_limit()get_max_position_limit()

kinematics

  • 逆運動学を計算するinverse_kinematics_LM()を追加します

kinematics_utils

  • 下記の関数を追加します
    • rotation_to_omega():回転行列から等価各軸ベクトルへ変換する
    • find_route():目標リンクから根本リンク(ベースリンクは除く)までの経路をを抽出する
    • get_q_list():リンク構成から指定されたIDの関節位置qを抽出する
    • set_q_list():指定されたIDの関節位置qをリンク構成に書き込む
    • calc_error_R():回転行列の差を求める
    • calc_error_p():位置の差を求める
    • calc_error():目標位置・姿勢と、リンクの位置・姿勢の差を求める
    • calc_basic_jacobian():基礎ヤコビ行列を求める
  • parse_link_config_file()でリンクパラメータファイルからDynamixelのIDを取得しdxl_idにセットします
    • 関節可動範囲はハードウェアから取得するため、パラメータファイルからは取得しません

linkクラス

  • 対応するサーボモータのIDを格納するdxl_idを追加します
  • 関節可動範囲を格納するmin_qmax_qを追加します

テスト関連

  • IKのテストを実施するために、CRANE-X7のリンクパラメータファイルを追加します
  • FK、IKのテストを実施するtest_kinematics.cppを追加します
    • FKのテストは、手計算した数値でチェックしやすいように、テスト用のリンクパラメータtest_links.csvを使用します
    • IKのテストは、実際のロボットが動く範囲でIKが解けるか確認できるように、X7のリンクパラメータを使用します
    • X7の後側、上側のIKに失敗するためコメントアウトしています
      • IKに失敗する原因が分かり次第、別PRで対応します
  • kinematics_utilsに追加した関数のテストを追加します

サンプル関連

  • READMEを更新します
  • x7_inverse_kinematicsサンプルを追加します

Does this close any currently open issues?

いいえ

How has this been tested?

Lintチェック、ユニットテストが通ることをGitHub Actionsで確認しています。

https://github.com/rt-net/rt_manipulators_cpp/actions/runs/1591540120

Ubuntu 20.04 環境で、x7_inverse_kinematicsサンプルが動作することを確認しています。

Any other comments?

Sciurus17のサンプルは、このPRがマージされたあとに作成します。

Sciurus17のハードウェアに対応するため(例、腰軸を除いてIKを解く)、
IK関数や、関連する関数を加工する可能性があります。どう実装するかは検討中です。

Checklists

  • I have read the CONTRIBUTING guidelines.
  • I have checked to ensure there aren't other open Pull Requests for the same change.

@ShotaAk ShotaAk changed the title 逆運動学ライブラリとサンプルを追加 逆運動学ライブラリとX7のサンプルを追加 Dec 17, 2021
@ShotaAk ShotaAk added the Type: Feature New Feature label Dec 17, 2021
@ShotaAk ShotaAk marked this pull request as ready for review December 17, 2021 09:34
Copy link
Contributor

@knjinki knjinki left a comment

Choose a reason for hiding this comment

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

レビューして動作確認しました。解の収束性に関わるコメントをいくつかしました。ただそれらを変更してもコメントアウト部分は通るようになっていませんが、現状のテストはそのまま通って実機でも動作することを確認しています。

error = kinematics_utils::calc_error(target_p, target_R, calc_links[target_id]);

// 誤差が小さければ終了
if (error.norm() < 1.0E-6) {
Copy link
Contributor

Choose a reason for hiding this comment

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

epsilon = 1.0E-6とかでhpp側に定義してもよさそう。

Copy link
Author

@ShotaAk ShotaAk Dec 21, 2021

Choose a reason for hiding this comment

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

どこまでの値をライブラリ外部から調整できるようにするか悩ましいところですが、
今回は全パラメータ変更できないようにしたいです(今の実装がそうなってます)。

ただ、数字を直接書くと意味が伝わりにくいので、変数にします。

Copy link
Author

Choose a reason for hiding this comment

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

be4bedb
にて、定数error_toleranceとして定義しました。


// 減衰因子の計算
auto E = 0.5 * error.transpose() * We * error;
double omega = 0.001; // 0.1 ~ 0.001 * 代表リンク長の2乗
Copy link
Contributor

Choose a reason for hiding this comment

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

代表リンク長l=0.1としたときに、0.1*l^2の値を使っているので、0.1 ~ 0.001の端の値(0.1側)と考えると数値の安定性としてはもしかしたら不安定よりかもしれない。安定性の高い手法とはいえ、安定性が理論的に保証されているわけではなく(文献中、大域的収束性云々のところ)、経験則的に0.1 ~ 0.001の範囲で十分というようなパラメータなので、0.1 ~ 0.001の間の0.01くらいを選択してもいいかもしれない。それでもテストのコメントアウト部分は通るようになりませんでしたが。

Copy link
Author

Choose a reason for hiding this comment

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

ありがとうございます。
0.01に変更します。

Copy link
Author

Choose a reason for hiding this comment

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

7434dab
にて0.01に変更しました。

Comment on lines 271 to 276
`kinematics::inverse_kinematics_LM()`には、
[杉原 知道.
Levenberg-Marquardt法による可解性を問わない逆運動学.
日本ロボット学会誌 Vol.29, 2011](
https://www.jstage.jst.go.jp/article/jrsj/29/3/29_3_269/_pdf)
に記載されたアルゴリズムを実装しています。
Copy link
Contributor

Choose a reason for hiding this comment

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

実装について検証しきれてないという判断であれば、ここは一旦明記せずに保留してもいいかもしれません。
例えば注意書きとして、下記のようなものを書くなど。
kinematics::inverse_kinematics_LM()には数値解法による逆運動学の計算アルゴリズムが実装されています。任意の位置姿勢に対してロボットを動かしたい場合は、ロボットを動かす前に逆運動学の解が発散しないか等十分に検証して使用してください。

Copy link
Author

Choose a reason for hiding this comment

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

承知しました。文言を変更します。

Copy link
Author

Choose a reason for hiding this comment

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

9b0890c
にて対応しました。


// qを0にリセットする
for (auto q_i = q_list.begin(); q_i != q_list.end(); ++q_i) {
q_i->second = 0;
Copy link
Contributor

@knjinki knjinki Dec 21, 2021

Choose a reason for hiding this comment

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

Suggested change
q_i->second = 0;
q_i->second = -M_PI/4; // 特異点でない可動範囲内の適当な関節角

初期値0が特異姿勢なので数値解法の初期値としてあまり良くないため、これを適当な特異姿勢でない値に変更するのはありだと思います。数値解法として比較的安定した手法といっても、かなり不利な条件のスタートだと思います。
この値でも現状のテストは通りました。コメントアウト部分は通りませんでした。

Copy link
Author

Choose a reason for hiding this comment

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

たしかに、不利な状況から始める理由は無いですね。初期値を変更します。

Shota Aoki and others added 10 commits December 21, 2021 15:27
Co-authored-by: kenjiinukai <36922159+kenjiinukai@users.noreply.github.com>
Co-authored-by: kenjiinukai <36922159+kenjiinukai@users.noreply.github.com>
Co-authored-by: kenjiinukai <36922159+kenjiinukai@users.noreply.github.com>
Co-authored-by: kenjiinukai <36922159+kenjiinukai@users.noreply.github.com>
@knjinki
Copy link
Contributor

knjinki commented Dec 21, 2021

初期値については私の確認ミスでした。動作確認したのでマージします。

@knjinki knjinki merged commit fe52522 into main Dec 21, 2021
@knjinki knjinki deleted the inverse_kinematics branch December 21, 2021 10:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Feature New Feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants