GaitGeneration by Graph Search
読み取り中…
検索中…
一致する文字列を見つけられません
gait_pattern_generator_revaluation.cpp
[詳解]
1
3
4// Copyright(c) 2023-2025 Design Engineering Laboratory, Saitama University
5// Released under the MIT license
6// https://opensource.org/licenses/mit-license.php
7
9
10#include <utility>
11
12#include "cassert_define.h"
13#include "cmdio_util.h"
15#include "graph_search_const.h"
16#include "map_state.h"
17
18
19namespace designlab
20{
21
23 std::unique_ptr<IGaitPatternGenerator>&& gait_pattern_generator_ptr,
24 std::unique_ptr<IGaitPatternGenerator>&& gait_pattern_generator_revaluation_ptr,
25 const std::shared_ptr<const IHexapodCoordinateConverter>& converter_ptr,
26 const std::shared_ptr<const IHexapodJointCalculator>& joint_calculator_ptr) :
27 gpg_ptr_(std::move(gait_pattern_generator_ptr)),
28 gpg_revaluation_ptr_(std::move(gait_pattern_generator_revaluation_ptr)),
29 converter_ptr_(converter_ptr),
30 joint_calculator_ptr_(joint_calculator_ptr),
31 interpolated_node_creator_{ converter_ptr }
32{
33 // gpg_ptr_ は nullptrでない.
34 assert(gpg_ptr_ != nullptr);
35
36 // gpg_revaluation_ptr_ は nullptrでない.
37 assert(gpg_revaluation_ptr_ != nullptr);
38
39 // converter_ptr_ は nullptrでない.
40 assert(converter_ptr_ != nullptr);
41
42 // joint_calculator_ptr_ は nullptrでない.
43 assert(joint_calculator_ptr_ != nullptr);
44}
45
47 const RobotStateNode& current_node,
48 const MapState& map_state,
49 const RobotOperation& operation,
50 RobotStateNode* output_node)
51{
52 assert(output_node != nullptr); // output_nodeは nullptrでない
53
54 const GraphSearchResult result =
55 gpg_ptr_->GetNextNodeByGraphSearch(
56 current_node, map_state, operation, output_node);
57
58 if (result.result != enums::Result::kSuccess)
59 {
60 // グラフ探索に失敗した場合は終了.
61 return result;
62 }
63
64 // 成功した場合は,逆運動学計算で脚軌道生成が可能であるか確認する.
65 if (IsValidNode(current_node, *output_node))
66 {
67 // 有効なノードである場合は,そのまま終了.
68 return result;
69 }
70
71 // 逆運動学計算で脚軌道生成が不可能な場合は,再評価を行う.
72 return gpg_revaluation_ptr_->GetNextNodeByGraphSearch(
73 current_node, map_state, operation, output_node);
74}
75
76bool GaitPatternGeneratorRevaluation::IsValidNode(
77 const RobotStateNode& current_node,
78 const RobotStateNode& next_node) const
79{
80 // まず,next_nodeが有効なノードであるかを確認する.
81 const auto joint = joint_calculator_ptr_->CalculateAllJointState(next_node);
82
83 if (!joint_calculator_ptr_->IsValidAllJointState(next_node, joint))
84 {
85 // 逆運動学計算に失敗した場合は無効なノードとする.
86 return false;
87 }
88
89 // 次に補間ノードを生成する.
90 const std::vector<RobotStateNode> interpolated_node =
91 interpolated_node_creator_.CreateInterpolatedNode(current_node, next_node);
92
93 for (const auto& node : interpolated_node)
94 {
95 const auto joint_interpolated =
96 joint_calculator_ptr_->CalculateAllJointState(node);
97
98 if (!joint_calculator_ptr_->IsValidAllJointState(node, joint_interpolated))
99 {
100 // 逆運動学計算に失敗した場合は無効なノードとする.
101 return false;
102 }
103 }
104
105 return true;
106}
107
108} // namespace designlab
GraphSearchResult GetNextNodeByGraphSearch(const RobotStateNode &current_node, const MapState &map, const RobotOperation &operation, RobotStateNode *output_node) override
グラフ探索を行い,次の動作として最適なノードを返す.
GaitPatternGeneratorRevaluation(std::unique_ptr< IGaitPatternGenerator > &&gpg_ptr, std::unique_ptr< IGaitPatternGenerator > &&gpg_revaluation_ptr, const std::shared_ptr< const IHexapodCoordinateConverter > &converter_ptr, const std::shared_ptr< const IHexapodJointCalculator > &joint_calculator_ptr)
std::vector< RobotStateNode > CreateInterpolatedNode(const RobotStateNode &node, const RobotStateNode &next_node) const
ノード間を補間する.
マップを表すクラス.
Definition map_state.h:32
Definition com_type.h:24
グラフ探索の結果を表す構造体.
enums::Result result
成功か失敗か.
探索において目標となる座標や角度,評価する値についてまとめた構造体.
グラフ構造のためのノード(頂点).旧名 LNODE