Flatland
model.h
1 /*
2  * ______ __ __ __
3  * /\ _ \ __ /\ \/\ \ /\ \__
4  * \ \ \L\ \ __ __ /\_\ \_\ \ \ \____ ___\ \ ,_\ ____
5  * \ \ __ \/\ \/\ \\/\ \ /'_` \ \ '__`\ / __`\ \ \/ /',__\
6  * \ \ \/\ \ \ \_/ |\ \ \/\ \L\ \ \ \L\ \/\ \L\ \ \ \_/\__, `\
7  * \ \_\ \_\ \___/ \ \_\ \___,_\ \_,__/\ \____/\ \__\/\____/
8  * \/_/\/_/\/__/ \/_/\/__,_ /\/___/ \/___/ \/__/\/___/
9  * @copyright Copyright 2017 Avidbots Corp.
10  * @name model.h
11  * @brief Defines flatland Model
12  * @author Chunshang Li
13  *
14  * Software License Agreement (BSD License)
15  *
16  * Copyright (c) 2017, Avidbots Corp.
17  * All rights reserved.
18  *
19  * Redistribution and use in source and binary forms, with or without
20  * modification, are permitted provided that the following conditions
21  * are met:
22  *
23  * * Redistributions of source code must retain the above copyright
24  * notice, this list of conditions and the following disclaimer.
25  * * Redistributions in binary form must reproduce the above
26  * copyright notice, this list of conditions and the following
27  * disclaimer in the documentation and/or other materials provided
28  * with the distribution.
29  * * Neither the name of the Avidbots Corp. nor the names of its
30  * contributors may be used to endorse or promote products derived
31  * from this software without specific prior written permission.
32  *
33  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
34  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
35  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
36  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
37  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
38  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
39  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
40  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
41  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
42  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
43  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
44  * POSSIBILITY OF SUCH DAMAGE.
45  */
46 
47 #ifndef FLATLAND_SERVER_MODEL_H
48 #define FLATLAND_SERVER_MODEL_H
49 
50 #include <flatland_server/collision_filter_registry.h>
51 #include <flatland_server/entity.h>
52 #include <flatland_server/joint.h>
53 #include <flatland_server/model_body.h>
54 #include <flatland_server/yaml_reader.h>
55 #include <yaml-cpp/yaml.h>
56 #include <boost/filesystem.hpp>
57 
58 namespace flatland_server {
59 
60 class ModelBody;
61 class Joint;
62 
67 class Model : public Entity {
68  public:
69  std::string namespace_;
70  std::vector<ModelBody *> bodies_;
71  std::vector<Joint *> joints_;
74  std::string viz_name_;
75 
82  Model(b2World *physics_world, CollisionFilterRegistry *cfr,
83  const std::string &ns, const std::string &name);
84 
88  ~Model();
89 
94  EntityType Type() const { return EntityType::MODEL; }
95 
100  void LoadBodies(YamlReader &bodies_reader);
101 
106  void LoadJoints(YamlReader &joints_reader);
107 
113  ModelBody *GetBody(const std::string &name);
114 
120  Joint *GetJoint(const std::string &name);
121 
125  const std::vector<ModelBody *> &GetBodies();
126 
130  const std::vector<Joint *> &GetJoints();
131 
135  const std::string &GetNameSpace() const;
136 
140  std::string NameSpaceTF(const std::string &frame_id) const;
141 
145  std::string NameSpaceTopic(const std::string &topic) const;
146 
150  const std::string &GetName() const;
151 
155  const CollisionFilterRegistry *GetCfr() const;
156 
160  void DebugVisualize() const override;
161 
165  void DebugOutput() const override;
166 
170  void DumpBox2D() const;
171 
176  void TransformAll(const Pose &pose_delta);
177 
182  void SetPose(const Pose &pose);
183 
193  static Model *MakeModel(b2World *physics_world, CollisionFilterRegistry *cfr,
194  const std::string &model_yaml_path,
195  const std::string &ns, const std::string &name);
196 };
197 }; // namespace flatland_server
198 #endif // FLATLAND_SERVER_MODEL_H
EntityType
Defines the type of entity.
Definition: entity.h:64
Definition: collision_filter_registry.h:63
void SetPose(const Pose &pose)
Explicitly set the model pose in world coordinates.
Definition: model.cpp:212
~Model()
Destructor for the layer class.
Definition: model.cpp:61
Model(b2World *physics_world, CollisionFilterRegistry *cfr, const std::string &ns, const std::string &name)
Constructor for the model.
Definition: model.cpp:54
Definition: entity.h:61
std::vector< ModelBody * > bodies_
list of bodies in the model
Definition: model.h:70
Definition: body.h:55
void LoadJoints(YamlReader &joints_reader)
load joints to this model, throws exceptions upon failure
Definition: model.cpp:131
Definition: model_body.h:65
Definition: model.h:67
void DebugVisualize() const override
Publish debug visualizations for model.
Definition: model.cpp:253
CollisionFilterRegistry * cfr_
Collision filter registry.
Definition: model.h:73
Definition: joint.h:63
std::string NameSpaceTF(const std::string &frame_id) const
Definition: model.cpp:180
std::string NameSpaceTopic(const std::string &topic) const
Definition: model.cpp:194
const std::string & GetName() const
Definition: model.cpp:208
ModelBody * GetBody(const std::string &name)
Get a body in the model using its name.
Definition: model.cpp:156
void DebugOutput() const override
log debug messages for the layer
Definition: model.cpp:269
Definition: types.h:84
std::string namespace_
namespace of the model
Definition: model.h:69
void DumpBox2D() const
Dump box2d data for debugging.
Definition: model.cpp:285
void TransformAll(const Pose &pose_delta)
transform all bodies in the model
Definition: model.cpp:231
Joint * GetJoint(const std::string &name)
Get a body in the model using its name.
Definition: model.cpp:165
EntityType Type() const
Return the type of entity.
Definition: model.h:94
const CollisionFilterRegistry * GetCfr() const
Definition: model.cpp:210
static Model * MakeModel(b2World *physics_world, CollisionFilterRegistry *cfr, const std::string &model_yaml_path, const std::string &ns, const std::string &name)
Create a model, throws exceptions upon failure.
Definition: model.cpp:77
const std::vector< Joint * > & GetJoints()
Definition: model.cpp:176
void LoadBodies(YamlReader &bodies_reader)
load bodies to this model, throws exceptions upon failure
Definition: model.cpp:102
std::string viz_name_
used for visualization
Definition: model.h:74
Definition: yaml_reader.h:76
const std::string & GetNameSpace() const
Definition: model.cpp:178
std::vector< Joint * > joints_
list of joints in the model
Definition: model.h:71
YamlReader plugins_reader_
for storing plugins when paring YAML
Definition: model.h:72
const std::vector< ModelBody * > & GetBodies()
Definition: model.cpp:174