Army ant simulation
RobotController.h
Go to the documentation of this file.
1 
11 #ifndef ROBOTCONTROLLER_H_
12 #define ROBOTCONTROLLER_H_
13 
14 #include "Robot.h"
15 
17 public:
19  RobotController(config::sController controllerParam, config::sRobot robotParam, b2Body* terrain, double m_to_px = 0);
20  virtual ~RobotController();
21 
28  void addRobot(Robot* robot);
29 
35  bool checkGrabbed(Robot& robot);
36 
37  void create(config::sController controllerParam, config::sRobot robotParam, b2Body* terrain, double m_to_px = 0);
38 
45  void createGripRobots(Robot& robot);
46 
56  bool createRobot(b2World* world, int delay, double posX, double posY, double angle = 0);
57 
63  void destroyJoints(Robot& robot, side s);
64 
70  void drawRobots(sf::RenderWindow& window, double m_to_px);
71 
81  void findContactRobots(b2Contact* contact);
82 
88  double getDissolutionTime();
89 
95  int getNbActiveRobots();
96 
102  int getNbRobots(e_state s);
103 
108  int getNbRobotsBlocked();
109 
115  Robot* getRobot(int pos_id);
116 
121  Robot* getRobotWithId(int id);
122 
130  double getStabilizationTime();
131 
137  void invertMovingWheel(Robot& robot);
138 
143  bool isBridgeDissolved();
144 
151  bool isBridgeStable();
152 
159  void removeRobot();
160 
168  void robotOut(double end_x, int id);
169 
180  bool robotPushing(Robot& r);
181 
190  bool robotStacking(Robot* r, float posX);
191 
197  void setBridgeStability(bool stable);
198 
204  void setNbRobots(int nb_robots);
205 
212  void setRobotState(Robot& robot, e_state robotState);
213 
219  void setScale(double m_to_px);
220 
227  void step(double end_x);
228 
236  void wait_delay(Robot& robot);
237 
243  bool m_bridgeEntry = false;
244 
245 
246 private:
247 
248  std::vector<Robot*> m_robotVector; // Vector containing a pointer on every robot object attached to this robot controller
249  std::vector<int> m_robotToDestroy; // Vector containing the id of all the robot that have to be destroyed during the next simulation step
250  int m_nbRobots = 0; // Number of robot attached to this robot controller
251  int m_currentIt = 0; // Current iteration
252  int m_idLastRobot = 0; // id of the last robot that entered the bridge state
253  int m_nbRobInBridge = 0; // Number of robot in the bridge state
254  double m_stableTime = 0; // Time to reach stable bridge (real time)
255  bool m_isStable = false; // Flag to indicate bridge stability
256  bool m_isDissolved = false; // Flag to indicate if the bridge dissolved
257  double m_dissolutionTime = 0; // Time to reach bridge dissolution (real time)
258 
264  double m_angle_min= PI/8;
265 
266  b2Body* m_terrainBody=nullptr; //Pointer on the terrain Box2D body
267 
268  config::sController m_controllerParam; //Structure containing the controller parameters. The structure is defined in the Config.h file
269  config::sRobot m_robotParam; //Structure containing the robot parameters. The structure is defined in the Config.h file
270 
271  int m_M_TO_PX; //Copy of the scale to do the conversion from real dimensions (m) to simulated ones (pixels)
272 };
273 
274 #endif /* ROBOTCONTROLLER_H_ */
side
Definition: Robot.h:30
bool robotStacking(Robot *r, float posX)
void robotOut(double end_x, int id)
void findContactRobots(b2Contact *contact)
double getDissolutionTime()
Implement the Robot class and define enum linked to a robot object: e_state and side.
int getNbRobots(e_state s)
Robot * getRobotWithId(int id)
void setBridgeStability(bool stable)
bool checkGrabbed(Robot &robot)
void setNbRobots(int nb_robots)
e_state
Definition: Robot.h:26
void drawRobots(sf::RenderWindow &window, double m_to_px)
Robot * getRobot(int pos_id)
void addRobot(Robot *robot)
bool createRobot(b2World *world, int delay, double posX, double posY, double angle=0)
void wait_delay(Robot &robot)
Definition: Robot.h:40
void setRobotState(Robot &robot, e_state robotState)
void destroyJoints(Robot &robot, side s)
void invertMovingWheel(Robot &robot)
void step(double end_x)
void setScale(double m_to_px)
double getStabilizationTime()
bool robotPushing(Robot &r)
void createGripRobots(Robot &robot)