GAMS  1.4.0
VREPBase.h
Go to the documentation of this file.
1 
54 #ifndef _GAMS_PLATFORM_VREP_BASE_H_
55 #define _GAMS_PLATFORM_VREP_BASE_H_
56 
57 #include "gams/variables/Self.h"
58 #include "gams/variables/Sensor.h"
61 #include "madara/knowledge/KnowledgeBase.h"
63 #include "gams/pose/Position.h"
64 #include "gams/pose/Orientation.h"
65 #include "gams/pose/GPSFrame.h"
66 #include "madara/threads/Threader.h"
67 #include "madara/threads/BaseThread.h"
68 #include "madara/LockType.h"
69 #include "madara/knowledge/containers/Integer.h"
70 
72 
73 #ifdef __GNUC__
74 #pragma GCC diagnostic push
75 #pragma GCC diagnostic ignored "-Wpedantic"
76 #pragma GCC diagnostic ignored "-Wunused-but-set-variable"
77 #pragma GCC diagnostic ignored "-Wunused-parameter"
78 #endif
79 
80 extern "C" {
81 #include "extApi.h"
82 }
83 
84 #ifdef __GNUC__
85 #pragma GCC diagnostic pop
86 #endif
87 
88 #ifdef _GAMS_VREP_
89 
90 namespace gams
91 {
92  namespace platforms
93  {
97  class GAMS_EXPORT VREPBase : public BasePlatform
98  {
99  public:
109  VREPBase(
110  std::string model_file,
111  simxUChar is_client_side,
112  madara::knowledge::KnowledgeBase * knowledge,
113  variables::Sensors * sensors,
114  variables::Self * self);
115 
119  virtual ~VREPBase();
120 
125  void operator=(const VREPBase & rhs);
126 
131  virtual int sense(void) override;
132 
137  virtual int analyze(void) override;
138 
143  virtual double get_accuracy() const override;
144 
148  virtual double get_move_speed() const override;
149 
154  virtual int land(void) override;
155 
162  int move(const pose::Position & location,
163  const PositionBounds &bounds) override;
164 
165  using BasePlatform::move;
166 
173  int orient(const pose::Orientation & location,
174  const OrientationBounds &bounds) override;
175 
176  using BasePlatform::orient;
177 
182  virtual void set_move_speed(const double& speed) override;
183 
188  virtual int takeoff(void) override;
189 
194  virtual const pose::ReferenceFrame & get_frame(void) const override;
195 
196  const pose::ReferenceFrame & get_vrep_frame(void) const;
197 
198  protected:
202  virtual void add_model_to_environment(const std::string& file,
203  const simxUChar client_side) = 0;
204 
209  bool get_ready(void);
210 
214  virtual void get_target_handle() = 0;
215 
219  virtual void set_initial_position();
220 
225  virtual double get_initial_z() const;
226 
230  bool sim_is_running(void);
231 
235  bool vrep_is_ready(void);
236 
240  bool agent_is_ready(void);
241 
243  bool airborne_;
244 
246  simxInt client_id_;
247 
249  double move_speed_;
250 
252  simxInt node_id_;
253 
255  simxInt node_target_;
256 
258  pose::Pose sw_pose_;
259 
263  pose::ReferenceFrame vrep_frame_;
264 
265  madara::knowledge::containers::Double thread_rate_;
266 
267  madara::knowledge::containers::Double thread_move_speed_;
268 
269  madara::knowledge::containers::Double max_delta_;
270 
271  madara::knowledge::containers::Double max_orient_delta_;
272 
274  const static std::string MOVE_THREAD_NAME;
275 
279  class TargetMover : public madara::threads::BaseThread
280  {
281  public:
286  TargetMover(VREPBase &base);
287 
291  void run();
292 
293  static const std::string NAME;
294  private:
295  VREPBase &base_;
296  };
297 
298  friend class TargetMover;
299 
301  TargetMover *mover_;
302 
304  madara::threads::Threader threader_;
305 
306  mutable MADARA_LOCK_TYPE vrep_mutex_;
307 
308  private:
309 
313  void create_ready_conditions(void);
314 
316  bool agent_is_ready_;
317 
319  bool vrep_is_ready_;
320 
322  bool sim_is_running_;
323 
327  std::string model_file_;
328 
332  simxUChar is_client_side_;
333 
335  madara::knowledge::containers::Integer begin_sim_;
336 
338  madara::knowledge::containers::Integer vrep_ready_;
339 
341  madara::knowledge::containers::Integer agent_ready_;
342 
343  pose::Pose get_sw_pose(const pose::ReferenceFrame &frame);
344 
345  int do_move(const pose::Position & target,
346  const pose::Position & current, double max_delta);
347 
348  int do_orient(pose::Orientation target,
349  const pose::Orientation & current, double max_delta);
350  }; // class VREPBase
351  } // namespace platform
352 } // namespace gams
353 
354 #include "VREPBase.inl"
355 
356 #endif // _GAMS_VREP_
357 
358 #endif // _GAMS_PLATFORM_VREP_BASE_H_
Copyright(c) 2014 Carnegie Mellon University.
#define GAMS_EXPORT
Definition: GamsExport.h:20
Copyright(c) 2014 Carnegie Mellon University.
Copyright(c) 2014 Carnegie Mellon University.
Copyright(c) 2014 Carnegie Mellon University.
virtual int orient(const pose::Orientation &target)
Rotates the platform to match a given angle.
Definition: BasePlatform.h:258
virtual int move(const pose::Position &target)
Moves the platform to a location.
Definition: BasePlatform.h:230
gams::pose::Orientation Orientation
Represents a orientation or orientation within a reference frame.
Definition: Orientation.h:94
gams::pose::ReferenceFrame ReferenceFrame
Base class for Reference Frames.
gams::pose::Pose Pose
Represents a combination of Location and Orientation within a single reference frame.
Definition: Pose.h:79
std::map< std::string, Sensor * > Sensors
a map of sensor names to the sensor information
Definition: Sensor.h:238
Contains all GAMS-related tools, classes and code.
Copyright (c) 2015 Carnegie Mellon University.
Copyright (c) 2015 Carnegie Mellon University.
Copyright (c) 2015 Carnegie Mellon University.
Copyright (c) 2015-2018 Carnegie Mellon University.