File: InterfaceModel.hh

package info (click to toggle)
sdformat 12.3.0%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 7,980 kB
  • sloc: cpp: 54,706; python: 3,729; javascript: 704; ruby: 366; sh: 97; ansic: 30; makefile: 16
file content (140 lines) | stat: -rw-r--r-- 5,131 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
 * Copyright 2021 Open Source Robotics Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

#ifndef SDF_INTERFACE_MODEL_HH_
#define SDF_INTERFACE_MODEL_HH_

#include <functional>
#include <string>
#include <memory>
#include <vector>

#include <ignition/math/Pose3.hh>
#include <ignition/utils/ImplPtr.hh>

#include "sdf/InterfaceFrame.hh"
#include "sdf/InterfaceJoint.hh"
#include "sdf/InterfaceLink.hh"
#include "sdf/InterfaceModelPoseGraph.hh"
#include "sdf/Types.hh"

#include "sdf/sdf_config.h"
#include "sdf/system_util.hh"

namespace sdf
{
inline namespace SDF_VERSION_NAMESPACE
{
class InterfaceModel;
class Model;
struct PoseRelativeToGraph;
template <typename T>
class ScopedGraph;
class World;

using InterfaceModelPtr = std::shared_ptr<InterfaceModel>;
using InterfaceModelConstPtr = std::shared_ptr<const InterfaceModel>;

/// \brief Function signature for the reposture callback function
using RepostureFunction =
    std::function<void(const sdf::InterfaceModelPoseGraph &)>;

/// \brief Interface element representing a Model
class SDFORMAT_VISIBLE InterfaceModel
{
  /// \brief Constructor
  /// \param[in] name The *local* name (no nesting, e.g. "::").  If this name
  /// contains "::", an error will be raised.
  /// \param[in] _static Whether the model is static
  /// \param[in] _canonicalLinkName The canonical link's name. This is the
  /// resolved name of the canonical link, therefore, it cannot be an empty
  /// string. The link must be added to the model. If the canonical link is
  /// nested in a child model, this should be the relative name (using the "::"
  /// delimiter) of the canonical link in the scope of this model.
  /// \param[in] _poseInParentFrame Model frame pose relative to the parent
  /// frame. Defaults to identity.
  /// \note This will not be used if //include/pose is specified.
  public: InterfaceModel(const std::string &_name,
              const sdf::RepostureFunction &_repostureFunction,
              bool _static,
              const std::string &_canonicalLinkName,
              const ignition::math::Pose3d &_poseInParentFrame = {});

  /// \brief Get the name of the model.
  /// \return Local name of the model.
  public: const std::string &Name() const;

  /// \brief Get whether the model is static.
  /// \return Whether the model is static.
  public: bool Static() const;

  /// \brief Get the canonical link name.
  /// \remark Unlike Model::CanonicalLinkName which simply returns
  /// the value of //model/@canonical_link without resolving to an actual link,
  /// this function returns the resolved canonical link name.
  /// \return Canonical link name of the model.
  public: const std::string &CanonicalLinkName() const;

  /// \brief Get the pose of this model in the parent frame.
  /// \return Pose of this model in the parent model frame.
  public: const ignition::math::Pose3d &ModelFramePoseInParentFrame() const;

  /// \brief Provided so that hierarchy can still be leveraged from SDFormat.
  /// \param[in] _nestedModel A child interface model.
  public: void AddNestedModel(sdf::InterfaceModelConstPtr _nestedModel);

  /// \brief Gets registered nested models.
  public: const std::vector<sdf::InterfaceModelConstPtr> &NestedModels() const;

  /// \brief Add an interface frame. Provided so that the including SDFormat
  /// model can still interface with the declared frames.
  /// \param[in] _frame A child interface frame.
  public: void AddFrame(sdf::InterfaceFrame _frame);

  /// \brief Gets registered frames.
  public: const std::vector<sdf::InterfaceFrame> &Frames() const;

  /// \brief Add an interface joint. Provided so that the including SDFormat
  /// model can still interface with the declared joints.
  /// \param[in] _joint A child interface joint.
  public: void AddJoint(sdf::InterfaceJoint _joint);

  /// \brief Gets registered joints.
  public: const std::vector<sdf::InterfaceJoint> &Joints() const;

  /// \brief Add an interface link. Provided so that the including SDFormat
  /// model can still interface with the declared links.
  /// \param[in] _link A child interface link.
  public: void AddLink(sdf::InterfaceLink _link);

  /// \brief Gets registered links.
  public: const std::vector<sdf::InterfaceLink> &Links() const;

  /// \brief Recursively invoke the reposture callback if a the callback is set.
  /// \param[in] _poseGraph Object used for resolving poses.
  private: void InvokeRespostureFunction(
      sdf::ScopedGraph<PoseRelativeToGraph> _graph) const;

  friend World;
  friend Model;
  /// \brief Private data pointer.
  IGN_UTILS_IMPL_PTR(dataPtr)
};
}
}

#endif