Skip to content

Commit a482ba0

Browse files
Shota Aokiknjinki
andauthored
運動学ライブラリの追加 (#8)
* 空のkinematicsライブラリを実装 * link.hpp 追加 * リンク情報リファレンスを解析する * eigen3のinclude方法を修正 * parse_link_config_file関数を実装 * forward_kinematicsを実装 * X7 forward kinematicsサンプル実装 * S17_forwad_kinematicsサンプル追加 * READMEの追加と、サンプルの微修正 * サンプルに目次を追加 * mother表記をparent表記に変更 * 歪対称行列のコメント修正 * googletest環境を追加 * Add test steps to github workflow * googletestのインストール方法を修正 * テスト失敗時に詳細を表示する * jointクラスの初期化テストを追加 * testディレクトリにもcpplintを適用する * linkはunistdの予約語だったため、manipulators_linkに変更する * kinematics_utilsのテストを追加 * Lintエラーを修正 * CIでEigen3をインストールする * kinematics_utilsにrotation_from_eulerを追加 * コンフリクト修正 * 回転軸方向に合わせて重心座標を回転させる * 回転軸方向に合わせて慣性テンソルを回転させる * Link.a のテストを追加 * 重心位置と慣性テンソルの読み込みをコメントアウト。実際に使用する際に再実装する * READMEの更新 * 重心位置、慣性テンソルの読み込みは未実装であることをREADMEに追記 * skew_symmetric_matrixのテストを実装 * rodriguesのテストを追加 * rotation_to_euler_ZYXのテストを追加 * Update samples/samples02/README.md Co-authored-by: kenjiinukai <36922159+kenjiinukai@users.noreply.github.com> * skew_symmetric_matrix_for_cross_productに改名 * rotation_to_euler_XYZに機能変更 * rotation_from_euler_XYZに改名 * rotation_from_euler_ZYXに修正 * rotation_to_euler_ZYXに修正 * サンプルの姿勢の表示順番を変更 * rotation_to_euler_ZYXのテストを更新 * Update samples/samples02/README.md Co-authored-by: kenjiinukai <36922159+kenjiinukai@users.noreply.github.com> * Update rt_manipulators_lib/src/kinematics_utils.cpp Co-authored-by: kenjiinukai <36922159+kenjiinukai@users.noreply.github.com> * rotation_from_euler_ZYXのロールピッチヨー表記をzyx表記に変更 * Update samples/samples02/src/x7_forward_kinematics.cpp Co-authored-by: kenjiinukai <36922159+kenjiinukai@users.noreply.github.com> * Update samples/samples02/src/s17_forward_kinematics.cpp Co-authored-by: kenjiinukai <36922159+kenjiinukai@users.noreply.github.com> Co-authored-by: kenjiinukai <36922159+kenjiinukai@users.noreply.github.com>
1 parent d94f8e1 commit a482ba0

23 files changed

+1406
-13
lines changed

.github/workflows/build_test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
cmake ..
3737
sudo make install
3838
- name: Install dependencies
39-
run: sudo apt install libyaml-cpp-dev
39+
run: sudo apt install libyaml-cpp-dev libeigen3-dev
4040
- uses: actions/checkout@v2
4141
- name: Build and insall library
4242
run: ./rt_manipulators_lib/build_install_library.bash

.tools/cpplint.bash

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ set -e
55
SCRIPT_DIR=$(dirname $0)
66
LIB_DIR=$SCRIPT_DIR/../rt_manipulators_lib
77
SAMPLES01_DIR=$SCRIPT_DIR/../samples/samples01
8+
SAMPLES02_DIR=$SCRIPT_DIR/../samples/samples02
89

910
function cpplint_check () {
1011
cpplint --filter=-build/c++11,-runtime/reference --linelength=100 --extensions=hpp,cpp $1/include/* $1/src/* $1/test/*
@@ -14,4 +15,5 @@ echo "cpplintを実行し、コードフォーマットをチェックします"
1415

1516
cpplint_check $LIB_DIR
1617
cpplint_check $SAMPLES01_DIR
18+
cpplint_check $SAMPLES02_DIR
1719

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
- g++ (>= 7.5.0)
1515
- [DYNAMIXEL SDK](https://github.com/ROBOTIS-GIT/DynamixelSDK) (linux64向けにビルド&インストール)
1616
- [yaml-cpp](https://github.com/jbeder/yaml-cpp)
17+
- Eigen (>= 3.3.4)
1718
- Linux OS
1819
- Ubuntu 18.04
1920
- Ubuntu 20.04
@@ -42,7 +43,7 @@ $ sudo make install
4243
次のコマンドを実行します。
4344

4445
```sh
45-
$ sudo apt install libyaml-cpp-dev
46+
$ sudo apt install libyaml-cpp-dev libeigen3-dev
4647
```
4748

4849
### RTマニピュレータC++ライブラリのビルド&インストール
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2021 RT Corporation
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef RT_MANIPULATORS_LIB_INCLUDE_KINEMATICS_HPP_
16+
#define RT_MANIPULATORS_LIB_INCLUDE_KINEMATICS_HPP_
17+
18+
#include <vector>
19+
20+
#include "link.hpp"
21+
22+
namespace kinematics {
23+
24+
void forward_kinematics(std::vector<manipulators_link::Link> & links, const int & start_id);
25+
26+
} // namespace kinematics
27+
28+
#endif // RT_MANIPULATORS_LIB_INCLUDE_KINEMATICS_HPP_
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2021 RT Corporation
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef RT_MANIPULATORS_LIB_INCLUDE_KINEMATICS_UTILS_HPP_
16+
#define RT_MANIPULATORS_LIB_INCLUDE_KINEMATICS_UTILS_HPP_
17+
18+
#include <eigen3/Eigen/Dense>
19+
#include <string>
20+
#include <vector>
21+
22+
#include "link.hpp"
23+
24+
namespace kinematics_utils {
25+
26+
std::vector<manipulators_link::Link> parse_link_config_file(const std::string & file_path);
27+
void print_links(const std::vector<manipulators_link::Link> & links, const int & start_id);
28+
Eigen::Matrix3d skew_symmetric_matrix_for_cross_product(const Eigen::Vector3d & v);
29+
Eigen::Matrix3d rodrigues(const Eigen::Vector3d & a, const double theta);
30+
Eigen::Vector3d rotation_to_euler_ZYX(const Eigen::Matrix3d & mat);
31+
Eigen::Matrix3d rotation_from_euler_ZYX(
32+
const double & z, const double & y, const double & x);
33+
34+
} // namespace kinematics_utils
35+
36+
#endif // RT_MANIPULATORS_LIB_INCLUDE_KINEMATICS_UTILS_HPP_
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Copyright 2021 RT Corporation
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef RT_MANIPULATORS_LIB_INCLUDE_LINK_HPP_
16+
#define RT_MANIPULATORS_LIB_INCLUDE_LINK_HPP_
17+
18+
#include <eigen3/Eigen/Dense>
19+
#include <string>
20+
21+
namespace manipulators_link {
22+
23+
// Linkクラスの参考情報:
24+
// 梶田秀司 編著, ヒューマノイドロボット 改訂2版, オーム社, 2020
25+
class Link{
26+
public:
27+
Link():
28+
name("ダミーリンク"), sibling(0), child(0), parent(0), q(0), dq(0), ddq(0), m(0) {
29+
// 0ベクトル、単位行列で初期化
30+
p.setZero();
31+
R.setIdentity();
32+
v.setZero();
33+
w.setZero();
34+
a.setZero();
35+
b.setZero();
36+
c.setZero();
37+
I.setIdentity();
38+
}
39+
std::string name; // リンク名
40+
int sibling; // 姉妹兄弟リンクID
41+
int child; // 子リンクID
42+
int parent; // 親リンクID
43+
Eigen::Vector3d p; // ワールド座標系での位置
44+
Eigen::Matrix3d R; // ワールド座標系での姿勢
45+
Eigen::Vector3d v; // ワールド座標系での速度
46+
Eigen::Vector3d w; // ワールド座標系での角速度ベクトル
47+
double q; // 関節位置
48+
double dq; // 関節速度
49+
double ddq; // 関節加速度
50+
Eigen::Vector3d a; // 親リンクに対する関節軸ベクトル
51+
Eigen::Vector3d b; // 親リンクに対する相対位置
52+
double m; // 質量
53+
Eigen::Vector3d c; // 自リンクに対する重心位置
54+
Eigen::Matrix3d I; // 自リンクに対する慣性テンソル
55+
};
56+
57+
} // namespace manipulators_link
58+
59+
#endif // RT_MANIPULATORS_LIB_INCLUDE_LINK_HPP_

rt_manipulators_lib/src/CMakeLists.txt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,27 @@ add_library(${library_name}
99
joint.cpp
1010
hardware_joints.cpp
1111
hardware_communicator.cpp
12+
kinematics.cpp
13+
kinematics_utils.cpp
1214
)
1315
set_target_properties(${library_name} PROPERTIES VERSION 1.0.0 SOVERSION 1)
1416

15-
target_include_directories(${library_name}
16-
PUBLIC ${PROJECT_SOURCE_DIR}/include
17+
target_include_directories(${library_name} PUBLIC
18+
${PROJECT_SOURCE_DIR}/include
1719
)
20+
message("${CMAKE_THREAD_LIBS_INIT}")
1821
target_link_libraries(${library_name} PUBLIC
1922
${YAML_CPP_LIBRARIES}
2023
${CMAKE_THREAD_LIBS_INIT}
2124
dxl_x64_cpp
2225
)
2326

2427
install(TARGETS ${library_name}
25-
LIBRARY DESTINATION lib)
28+
EXPORT ${library_name}-export
29+
LIBRARY DESTINATION lib
30+
INCLUDES DESTINATION include
31+
PUBLIC_HEADER DESTINATION include/${library_name}
32+
)
2633

2734
install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/
2835
DESTINATION include/${CMAKE_PROJECT_NAME})
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright 2021 RT Corporation
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include <iostream>
16+
17+
#include "kinematics.hpp"
18+
#include "kinematics_utils.hpp"
19+
20+
namespace kinematics {
21+
22+
namespace utils = kinematics_utils;
23+
24+
void forward_kinematics(std::vector<manipulators_link::Link> & links, const int & start_id) {
25+
// 指定されたリンクIDからchild、siblingに向かって逐次的に順運動学を解き、
26+
// リンクの位置・姿勢を更新する
27+
if (start_id == 0) {
28+
return;
29+
}
30+
31+
if (start_id >= links.size()) {
32+
std::cerr << "引数start_idには引数linksの要素数より小さい数字を入力して下さい" << std::endl;
33+
return;
34+
}
35+
36+
if (start_id != 1) {
37+
auto parent_id = links[start_id].parent;
38+
links[start_id].p = links[parent_id].R * links[start_id].b + links[parent_id].p;
39+
links[start_id].R = links[parent_id].R *
40+
utils::rodrigues(links[start_id].a, links[start_id].q);
41+
}
42+
43+
forward_kinematics(links, links[start_id].sibling);
44+
forward_kinematics(links, links[start_id].child);
45+
}
46+
47+
} // namespace kinematics

0 commit comments

Comments
 (0)