Flatland
world_modifier.h
1 /*
2  * ______ __ __ __
3  * /\ _ \ __ /\ \/\ \ /\ \__
4  * \ \ \L\ \ __ __ /\_\ \_\ \ \ \____ ___\ \ ,_\ ____
5  * \ \ __ \/\ \/\ \\/\ \ /'_` \ \ '__`\ / __`\ \ \/ /',__\
6  * \ \ \/\ \ \ \_/ |\ \ \/\ \L\ \ \ \L\ \/\ \L\ \ \ \_/\__, `\
7  * \ \_\ \_\ \___/ \ \_\ \___,_\ \_,__/\ \____/\ \__\/\____/
8  * \/_/\/_/\/__/ \/_/\/__,_ /\/___/ \/___/ \/__/\/___/
9  * @copyright Copyright 2017 Avidbots Corp.
10  * @name world_modifier.h
11  * @brief Provide general functions to modify the world
12  * @author Yi Ren
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 #ifndef WORLD_MODIFIER_H
47 #define WORLD_MODIFIER_H
48 
49 #include <Box2D/Box2D.h>
50 #include <flatland_server/types.h>
51 #include <flatland_server/world.h>
52 #include <flatland_server/yaml_reader.h>
53 #include <ros/ros.h>
54 #include <yaml-cpp/yaml.h>
55 #include <map>
56 #include <string>
57 #include <vector>
58 using namespace flatland_server;
59 
60 namespace flatland_plugins {
61 
62 // sub class for loading laser Param
63 struct LaserRead {
64  std::string name_; // name of the laser
65  b2Vec2 location_; // location of the laser in local frame
66  double range_; // range of the laser
67  double min_angle_;
68  double max_angle_;
69  double increment_;
70  LaserRead(std::string name, b2Vec2 location, double range, double min_angle,
71  double max_angle, double increment)
72  : name_(name),
73  location_(location),
74  range_(range),
75  min_angle_(min_angle),
76  max_angle_(max_angle),
77  increment_(increment) {}
78 };
79 
80 struct RayTrace : public b2RayCastCallback {
81  bool is_hit_;
82  float fraction_;
83  uint16_t category_bits_;
84  RayTrace(uint16_t category_bits)
85  : is_hit_(false), category_bits_(category_bits) {}
86  float ReportFixture(b2Fixture *fixture, const b2Vec2 &point,
87  const b2Vec2 &normal, float fraction) override;
88 };
89 
90 struct WorldModifier {
91  // private members
92  World *world_; // the world we are modifying
93  std::string layer_name_;
94  double wall_wall_dist_;
95  bool double_wall_;
96  Pose robot_ini_pose_;
97 
98  /*
99  * @brief based on the info regard old wall and d, calculate new obstacle's
100  * vertices
101  * @param[in] double d, the sign of this value determine which side of the wall
102  * will the new obstacle be added
103  * @param[in] b2Vec2 vertex1, old wall's vertex1
104  * @param[in] b2Vec2 vertex2, old wall's vertex2
105  * @param[out] b2EdgeShape new_wall, reference passed in to set the vertices
106  */
107  void CalculateNewWall(double d, b2Vec2 vertex1, b2Vec2 vertex2,
108  b2EdgeShape &new_wall);
109 
110  /*
111  * @brief add the new wall into the world
112  * @param[in] new_wall, the wall that's going to be added
113  */
114  void AddWall(b2EdgeShape &new_wall);
115 
116  /*
117  * @brief add two side walls to make it a full obstacle
118  * @param[in] old_wall, the old wall where new wall is added on top to
119  * @param[in] new_wall, the new wall got added
120  */
121  void AddSideWall(b2EdgeShape &old_wall, b2EdgeShape &new_wall);
122 
123  /*
124  * @brief constructor for WorldModifier
125  * @param[in] world, the world that we are adding walls to
126  * @param[in] layer_name, which layer is the obstacle going to be added
127  * @param[in] wall_wall_dist, how thick is the obstacle
128  * @param[in] double_wall, whether add obstacle on both side or not
129  * @param[in] robot_ini_pose, the initial pose of the robot
130  */
131  WorldModifier(flatland_server::World *world, std::string layer_name,
132  double wall_wall_dist, bool double_wall, Pose robot_ini_pose);
133 
134  /*
135  * @brief make a new wall in front of the old wall, also add two side walls to
136  * make a full object
137  * @param[in] b2EdgeShape *wall, old wall where new wall will be added on top
138  * to
139  */
140  void AddFullWall(b2EdgeShape *wall);
141 
142 }; // class WorldModifier
143 }; // namespace flatland_server
144 #endif // WORLD_MODIFIER_H
Definition: world_modifier.h:80
Definition: dummy_model_plugin.h:59
Definition: world_modifier.h:90
Definition: body.h:55
Definition: types.h:84
Definition: world_modifier.h:63
Definition: world.h:69