Skip to content

Commit bd581f3

Browse files
author
Shota Aoki
authored
解析的にIKを解くSciurus17用のサンプルを追加 (#15)
* S17のサンプルを追加。IKの計算は正しくない * 右腕のIKを修正 * S17 IKサンプルの骨組みを作成 * S17 picking IKの骨組みを作成 * S17の右腕ピッキングIKを実装 * コメントの文言を修正 * コメントの文言を修正 * S17ピッキングIKを修正 * cpplint v1.6.0からinclude_subdirのエラーを検出するようになったため除外する * q_listにはサーボIDではなくリンクIDをセットするため、修正 * 目標角度がNaNになる場合の処理とテストを追加 * S17 IKサンプルの完成 * S17 IKサンプルの説明をREADMEに追記 * sciurus17_3groups.yamlを削除 * IKの条件分岐を修正。手先姿勢をFKから求める * ファイル名からinverse_kinematicsからrt_manipulators_ikに変更 * インクルードガードを修正
1 parent 28bfc76 commit bd581f3

11 files changed

+796
-273
lines changed

.tools/cpplint.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ SAMPLES02_DIR=$SCRIPT_DIR/../samples/samples02
99
SAMPLES03_DIR=$SCRIPT_DIR/../samples/samples03
1010

1111
function cpplint_check () {
12-
cpplint --filter=-build/c++11,-runtime/reference --linelength=100 --extensions=hpp,cpp $1/include/* $1/src/* $1/test/*
12+
cpplint --filter=-build/c++11,-runtime/reference,-build/include_subdir --linelength=100 --extensions=hpp,cpp $1/include/* $1/src/* $1/test/*
1313
}
1414

1515
echo "cpplintを実行し、コードフォーマットをチェックします"

samples/samples03/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin)
1515
# サンプルのビルド
1616
set(list_samples
1717
x7_3dof_inverse_kinematics
18+
s17_3dof_inverse_kinematics
1819
)
1920
foreach(sample IN LISTS list_samples)
2021
message("${sample}")
2122
add_executable(${sample}
2223
src/${sample}.cpp
23-
src/inverse_kinematics.cpp
24+
src/rt_manipulators_ik.cpp
2425
)
2526
target_include_directories(${sample} PUBLIC
2627
include

samples/samples03/README.md

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,16 @@ $ ./build_samples.bash
3333

3434
次のコマンドを実行します。
3535
CRANE-X7では、手先が0.3m前方の5点に向かって移動します。
36+
Sciurus17では、右手先が0.4m前方の4点に向かって移動します。
3637

3738
***安全のためロボットの周りに物や人を近づけないでください。***
3839

3940
```sh
4041
# CRANE-X7の場合
4142
$ cd bin/
4243
$ ./x7_3dof_inverse_kinematics
44+
# Sciurus17の場合
45+
$ ./s17_3dof_inverse_kinematics
4346
```
4447

4548
実行結果(CRANE-X7の場合)
@@ -75,10 +78,10 @@ IKに成功しました
7578
### 解説
7679

7780
解析的に逆運動学を解く関数を使用する場合、
78-
`samples03/include/inverse_kinematics.hpp`をincludeします。
81+
`samples03/include/rt_manipulators_ik.hpp`をincludeします。
7982

8083
```cpp
81-
#include "inverse_kinematics.hpp"
84+
#include "rt_manipulators_ik.hpp"
8285
```
8386

8487
CRANE-X7向けの逆運動学計算関数として、
@@ -126,3 +129,49 @@ for (const auto & [target_id, q_value] : q_list) {
126129
hardware.set_position(links[target_id].dxl_id, q_value);
127130
}
128131
```
132+
133+
Sciurus17向けの逆運動学計算関数には、
134+
`samples03::s17_3dof_right_arm_inverse_kinematics(links, target_p, q_list)`
135+
`samples03::s17_3dof_right_arm_picking_inverse_kinematics(links, target_p, q_list)`
136+
を用意しています。
137+
引数にはリンク構成と、目標位置(`Eigen::Vector3d`)、
138+
関節角度の格納先(`std::map<unsigned int, double>` または `kinematics_utils::q_list_t`)を入力します。
139+
140+
`samples03::s17_3dof_right_arm_inverse_kinematics(links, target_p, q_list)`
141+
は、右腕の第6リンクの原点を目標位置(`target_p`)として受け取り、
142+
右腕の第1、2、4関節の目標角度を出力する関数です。
143+
144+
`samples03::s17_3dof_right_arm_picking_inverse_kinematics(links, target_p, q_list)`
145+
は、右ハンドの先端を目標位置(`target_p`)として受け取り、
146+
右腕の第1、2、4関節と、第5、6、7関節の目標角度を出力する関数です。
147+
手先が地面(-Z)方向を向くように逆運動学を解きます。
148+
149+
```cpp
150+
Eigen::Vector3d target_p;
151+
kinematics_utils::q_list_t q_list;
152+
153+
// 右手目標位置(X方向に0.2m、Y方向に-0.3m、Z方向に0.2m)
154+
target_p << 0.2, -0.3, 0.2;
155+
156+
// 逆運動学を解き、関節角度を取得する
157+
samples03::s17_3dof_right_arm_inverse_kinematics(links, target_p, q_list);
158+
// 関節角度をサーボモータへ設定する
159+
for (const auto & [target_id, q_value] : q_list) {
160+
hardware.set_position(links[target_id].dxl_id, q_value);
161+
}
162+
```
163+
164+
```cpp
165+
Eigen::Vector3d target_p;
166+
kinematics_utils::q_list_t q_list;
167+
// ピッキング姿勢の逆運動学
168+
// 手先の目標位置(X方向に0.2m、Y方向に-0.3m、Z方向に0.0m)
169+
target_p << 0.2, -0.3, 0.0;
170+
171+
// 逆運動学を解き、関節角度を取得する
172+
samples03::s17_3dof_right_arm_picking_inverse_kinematics(links, target_p, q_list);
173+
// 関節角度をサーボモータへ設定する
174+
for (const auto & [target_id, q_value] : q_list) {
175+
hardware.set_position(links[target_id].dxl_id, q_value);
176+
}
177+
```

samples/samples03/include/inverse_kinematics.hpp renamed to samples/samples03/include/rt_manipulators_ik.hpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#ifndef SAMPLES_SAMPLES03_INCLUDE_INVERSE_KINEMATICS_HPP_
16-
#define SAMPLES_SAMPLES03_INCLUDE_INVERSE_KINEMATICS_HPP_
15+
#ifndef SAMPLES_SAMPLES03_INCLUDE_RT_MANIPULATORS_IK_HPP_
16+
#define SAMPLES_SAMPLES03_INCLUDE_RT_MANIPULATORS_IK_HPP_
1717

1818
#include "rt_manipulators_cpp/kinematics_utils.hpp"
1919

@@ -25,7 +25,13 @@ bool x7_3dof_inverse_kinematics(const kinematics_utils::links_t & links,
2525
bool x7_3dof_picking_inverse_kinematics(const kinematics_utils::links_t & links,
2626
const Eigen::Vector3d & target_p,
2727
kinematics_utils::q_list_t & q_list);
28+
bool s17_3dof_right_arm_inverse_kinematics(const kinematics_utils::links_t & links,
29+
const Eigen::Vector3d & target_p,
30+
kinematics_utils::q_list_t & q_list);
31+
bool s17_3dof_right_arm_picking_inverse_kinematics(const kinematics_utils::links_t & links,
32+
const Eigen::Vector3d & target_p,
33+
kinematics_utils::q_list_t & q_list);
2834

2935
} // namespace samples03
3036

31-
#endif // SAMPLES_SAMPLES03_INCLUDE_INVERSE_KINEMATICS_HPP_
37+
#endif // SAMPLES_SAMPLES03_INCLUDE_RT_MANIPULATORS_IK_HPP_

samples/samples03/src/inverse_kinematics.cpp

Lines changed: 0 additions & 130 deletions
This file was deleted.

0 commit comments

Comments
 (0)