14 #ifndef LIB_ALMATH_SCENEGRAPH_RIGIDBODYSYSTEMBUILDER_H
15 #define LIB_ALMATH_SCENEGRAPH_RIGIDBODYSYSTEMBUILDER_H
19 #include <Eigen/Geometry>
21 #include <boost/format.hpp>
25 namespace RigidBodySystemBuilder {
37 std::string
joint_name(
const std::string &body_name)
const {
45 typedef Eigen::Transform<T, 3, Eigen::AffineCompact, Eigen::DontAlign>
Pose;
68 typedef Eigen::Transform<T, 3, Eigen::AffineCompact, Eigen::DontAlign>
Pose;
96 virtual const Config &config()
const = 0;
97 virtual void addLink(Link link) = 0;
98 virtual void addStaticFrame(StaticFrame sframe) = 0;
101 void add(
const std::string &parent_body,
const std::string &new_body,
103 const BodyMass &mass,
const std::string &new_joint) {
104 addLink(
Link{parent_body, new_body, new_joint, H_parent_joint, joint_type,
107 void add(
const std::string &parent_body,
const std::string &new_body,
110 add(parent_body, new_body, H_parent_joint, joint_type, mass,
111 this->config().joint_name(new_body));
117 if (this->config().no_static_frame)
return;
123 const Pose &H_parent_new) {
124 add(parent_frame, new_static_frame, H_parent_new,
125 this->config().joint_name(new_static_frame));
129 #define TYPEDEF_Interface_TYPES \
130 typedef typename Interface<T>::Scalar Scalar; \
131 typedef typename Interface<T>::Link Link; \
132 typedef typename Interface<T>::BodyMass BodyMass; \
133 typedef typename Interface<T>::Vector3 Vector3; \
134 typedef typename Interface<T>::Matrix3 Matrix3; \
135 typedef typename Interface<T>::StaticFrame StaticFrame; \
136 typedef typename Interface<T>::Pose Pose
139 template <
typename T>
151 _builder.addStaticFrame(sframe);
158 template <
typename TD,
typename TB>
167 _builder.addLink(link.template cast<TB>());
171 _builder.addStaticFrame(sframe.template cast<TB>());
178 template <
typename T>
187 std::stringstream ss;
188 ss <<
"cannot add body \"" << link.
new_body
189 <<
"\": unknown parent body \"" << link.
parent_body <<
"\"";
190 throw std::runtime_error(ss.str());
193 std::stringstream ss;
194 ss <<
"cannot add body \"" << link.
new_body <<
"\":"
195 <<
" there is already a frame with this name";
196 throw std::runtime_error(ss.str());
199 std::stringstream ss;
200 ss <<
"cannot add joint \"" + link.
new_joint +
"\":"
201 <<
" there is already a transform with this name";
202 throw std::runtime_error(ss.str());
204 this->_builder.addLink(link);
205 _known_bodies.insert(link.
new_body);
211 throw std::runtime_error(
213 "\": unknown parent frame \"" + sframe.
parent_frame +
"\"");
217 throw std::runtime_error(
"cannot add static frame \"" +
219 "\": there is already a frame with this name");
222 throw std::runtime_error(
224 "\": there is already a transform with this name");
226 this->_builder.addStaticFrame(sframe);
233 std::set<std::string> _known_bodies =
234 std::set<std::string>({this->_builder.config().galilean_frame});
235 std::set<std::string> _known_joints;
236 std::set<std::string> _known_sframes;
237 std::set<std::string> _known_stransforms;
239 bool xIsKnownBody(
const std::string &
name)
const {
240 return _known_bodies.find(name) != _known_bodies.end();
244 bool xIsKnownFrame(
const std::string &name)
const {
245 return xIsKnownBody(name) ||
246 (_known_sframes.find(name) != _known_sframes.end());
249 bool xIsKnownJoint(
const std::string &name)
const {
250 return _known_joints.find(name) != _known_joints.end();
254 bool xIsKnownTransform(
const std::string &name)
const {
255 return xIsKnownJoint(name) ||
256 (_known_stransforms.find(name) != _known_stransforms.end());
260 template <
typename T>
267 this->_builder.addLink(link);
271 #undef TYPEDEF_Interface_TYPES
virtual void addStaticFrame(StaticFrameData< TD > sframe)
virtual void addLink(Link link)
std::string new_static_frame
BodyMass::Matrix3 Matrix3
BodyMass::Matrix3 Matrix3
const Config & config() const
const Config & config() const
BodyMass::Vector3 Vector3
Interface< T > & _builder
void add(const std::string &parent_body, const std::string &new_body, const Pose &H_parent_joint, JointType joint_type, const BodyMass &mass, const std::string &new_joint)
Eigen::Transform< T, 3, Eigen::AffineCompact, Eigen::DontAlign > Pose
std::string joint_name(const std::string &body_name) const
void add(const std::string &parent_body, const std::string &new_body, const Pose &H_parent_joint, JointType joint_type, const BodyMass &mass)
std::string joint_name_format
LinkData< S > cast() const
std::string name(const ptree &pt)
virtual void addLink(LinkData< TD > link)
void add(const std::string &parent_frame, const std::string &new_static_frame, const Pose &H_parent_new)
void addStaticFrame(StaticFrame sframe)
NamesChecker(Interface< T > &builder)
StaticFrameData< S > cast() const
Interface< TB > & _builder
virtual void addStaticFrame(StaticFrame sframe)
BodyMass::Vector3 Vector3
Eigen::Transform< T, 3, Eigen::AffineCompact, Eigen::DontAlign > Pose
Decorator(Interface< T > &builder)
StaticFrameData< Scalar > StaticFrame
Eigen::Matrix< Scalar, 3, 3, Eigen::DontAlign > Matrix3
Eigen::Matrix< Scalar, 3, 1, Eigen::DontAlign > Vector3
InertiaEraser(Interface< T > &builder)
std::string galilean_frame
void add(const std::string &parent_frame, const std::string &new_static_frame, const Pose &H_parent_new, const std::string &new_static_transform)
Adapter(Interface< TB > &builder)
Math::BodyMass< Scalar > BodyMass
Matrix3 rotational_inertia
std::string new_static_transform