PTUDriverMock.cpp
Go to the documentation of this file.
1 #include "driver/PTUDriverMock.h"
2 #include "ros/ros.h"
3 
4 #define STEPS_UNTIL_GOAL_REACHED 20
5 
6 namespace asr_flir_ptu_driver {
7  PTUDriverMock::PTUDriverMock(const char* port, int baud, bool speedControl):
9  {
10  ROS_DEBUG("port: %s, baud: %d, speeControl: %d", port, baud, speedControl);
11  is_stopped_count = 0;
12  pan_angle = 0;
13  tilt_angle = 0;
14  pan_speed = 0;
15  tilt_speed = 0;
17  }
18 
20  {
21  return true;
22  }
23 
25  int pan_speed, int tilt_speed,
26  int pan_upper, int tilt_upper,
27  int pan_accel, int tilt_accel,
28  int pan_hold, int tilt_hold,
29  int pan_move, int tilt_move)
30  {
31  this->pan_speed = pan_speed;
32  this->tilt_speed = tilt_speed;
33  this->pan_base = pan_base;
34  this->tilt_base = tilt_base;
35  this->pan_acceleration = pan_accel;
36  this->tilt_acceleration = tilt_accel;
37  ROS_DEBUG("setSettings");
38  //this->forbiddenAreas = forbiddenAreas;
39 
40  }
41  void PTUDriverMock::setLimitAngles(double pan_min, double pan_max, double tilt_min, double tilt_max) {
42  ROS_DEBUG("setLimitAngles");
43  ROS_DEBUG("double panMin:%f, double panMax:%f", pan_min, pan_max);
44  ROS_DEBUG("double tiltMin:%f, double tiltMax:%f", tilt_min, tilt_max);
45  this->pan_min_limit = pan_min;
46  this->pan_max_limit = pan_max;
47  this->tilt_min_limit = tilt_min;
48  this->tilt_max_limit = tilt_max;
49  }
50 
52  ROS_DEBUG("setAbsoluteAngleSpeeds");
53  ROS_DEBUG("double pan_speed:%f, double tilt_speed:%f", pan_speed, tilt_speed);
54  this->pan_speed = pan_speed;
55  this->tilt_speed = tilt_speed;
56 
57  }
58 
59  void PTUDriverMock::setAbsoluteAngleSpeeds(signed short pan_speed, signed short tilt_speed) {
60  ROS_ERROR("This mock function should not be used");
61  }
62 
63  bool PTUDriverMock::setAbsoluteAngles(double pan_angle, double tilt_angle, bool no_forbidden_area_check) {
64  if (isInForbiddenArea(pan_angle, tilt_angle)) {
65  ROS_ERROR("PAN and TILT lie within forbidden area");
66  return false;
67  }
68  if (!isWithinPanTiltLimits(pan_angle, tilt_angle)){
69  ROS_ERROR("PAN/TILT out of pan/tilt bounds");
70  return false;
71  }
72  ROS_DEBUG("setAbsoluteAngles");
73  ROS_DEBUG("double pan_angle:%f, double tilt_angle:%f", pan_angle, tilt_angle);
74  this->pan_distance = pan_angle - this->pan_angle;
75  this->tilt_distance = tilt_angle - this->tilt_angle;
76  this->pan_angle = pan_angle;
77  this->tilt_angle = tilt_angle;
79 
80  ROS_INFO("Successfull set Pan and Tilt. PAN: %f, TILT: %f\n", pan_angle, tilt_angle);
81  return true;
82  }
83  void PTUDriverMock::setSpeedControlMode(bool speed_control_mode) {
84  ROS_DEBUG("setSpeedControlMode");
85  }
87  return false;
88  }
89  /*
90  bool PTUDriverMock::isStopped() {
91  isStoppedCount++;
92  if (isStoppedCount % 50 == 0) {
93  isStoppedCount = 1;
94  ROS_DEBUG("is NOT stopped");
95  return true;
96  }
97  return false;
98  }
99  */
100 
101  bool PTUDriverMock::isWithinPanTiltLimits(double pan, double tilt){
102  if ((pan < pan_min_limit)
103  || (pan > pan_max_limit)
104  || (tilt < tilt_min_limit)
105  || (tilt > tilt_max_limit)){
106  return false;
107  }
108  else {
109  return true;
110  }
111  }
112 
114  if(is_stopped_count != 0) {
116  }
118  is_stopped_count = 0;
119  return true;
120  }
121  else {
122  return false;
123  }
124  }
125 
128  return true;
129  }
130  else {
131  return false;
132  }
133  }
134 
136  return hasHalted() && reachedGoal();
137  }
138 
139 
140  double PTUDriverMock::getCurrentAngle(char type) {
141  if (type == PAN) {
142  return pan_angle - (((STEPS_UNTIL_GOAL_REACHED - is_stopped_count) % STEPS_UNTIL_GOAL_REACHED)/STEPS_UNTIL_GOAL_REACHED * pan_distance);
143  }
145  }
146 
147  double PTUDriverMock::getDesiredAngle(char type) {
148  if (type == PAN) {
149  return pan_angle;
150  }
151  return tilt_angle;
152  }
153 
154  //WARNING: IN PTUDriver this returns the current angle speed. In MOCK this is not possible (no real movement, simulation would take a lot of time etc.)
155  //Therefore the desired speed is returned if the ptu is "in movment" and 0 is returned otherwise
156  double PTUDriverMock::getAngleSpeed(char type) {
157  if (type == PAN) {
159  return 0.0;
160  }
161  else {
162  return pan_speed;
163  }
164  }
166  return 0.0;
167  }
168  else {
169  return tilt_speed;
170  }
171  }
172 
173 
174 
175 
177  ros::NodeHandle n("~");
179  n.getParam("mock_pan_min_hardware_limit", pan_min_limit);
180  n.getParam("mock_pan_max_hardware_limit", pan_max_limit);
181  n.getParam("mock_tilt_min_hardware_limit", tilt_min_limit);
182  n.getParam("mock_tilt_max_hardware_limit", tilt_max_limit);
183 
184  this->pan_min_limit = pan_min_limit;
185  this->pan_max_limit = pan_max_limit;
186  this->tilt_min_limit = tilt_min_limit;
187  this->tilt_max_limit = tilt_max_limit;
188 
189  ROS_DEBUG("pan_min_limit: %f, pan_max_limit: %f, tilt_min_limit: %f, tilt_max_limit: %f", pan_min_limit, pan_max_limit, tilt_min_limit, tilt_max_limit);
190 
191  }
192 
193  //DO NOT USE, NOT INTENDED TO USE WITH PTU DRIVER MOCK
194  std::vector<double> PTUDriverMock::determineLegitEndPoint(double end_point_pan_candidate, double end_point_tilt_candidate) {
195  ROS_ERROR("DO NOT USE determineLegitEndPoint WITH PTU DRIVER MOCK");
196  ROS_ERROR("Maybe you enabled path_prediction in one of the launch files you use. Path prediction is not intended to be used with the mock launch files");
197  std::vector<double> dummy;
198  dummy.push_back(end_point_pan_candidate);
199  dummy.push_back(end_point_tilt_candidate);
200  return dummy;
201  }
202 
203  bool PTUDriverMock::setValuesOutOfLimitsButWithinMarginToLimit(double * pan, double * tilt, double margin) {
204  ROS_DEBUG("PAN: %f, TILT: %f\n", *pan, *tilt);
205  if(((pan_max_limit - pan_min_limit) <= margin) || ((tilt_max_limit - tilt_min_limit) <= margin)) {
206  ROS_ERROR("Margin Degree: %f is too big. Bigger than distance between TILT max and TILT min (%f Degree) or PAN max and PAN min (%f Degree)",margin, (tilt_max_limit - tilt_min_limit), (pan_max_limit - pan_min_limit));
207  return false;
208  }
209  double pan_initial = *pan;
210  double tilt_initial = *tilt;
211  if((pan_initial < pan_min_limit) && (pan_initial >= (pan_min_limit - margin))) {
212  *pan = pan_min_limit;
213  ROS_WARN("PAN was out of limits, but within margin, so instead of the initial value %f the value %f is used", pan_initial, *pan);
214  }
215  else if ((pan_initial > pan_max_limit) && (pan_initial <= (pan_max_limit + margin))) {
216  *pan = pan_max_limit;
217  ROS_WARN("PAN was out of limits, but within margin, so instead of the initial value %f the value %f is used", pan_initial, *pan);
218  }
219  if((tilt_initial < tilt_min_limit) && (tilt_initial >= (tilt_min_limit - margin))) {
220  *tilt = tilt_min_limit;
221  ROS_WARN("TILT was out of limits, but within margin, so instead of the initial value %f the value %f is used", tilt_initial, *tilt);
222  }
223  else if((tilt_initial > tilt_max_limit) && (tilt_initial <= (tilt_max_limit + margin))) {
224  *tilt = tilt_max_limit;
225  ROS_WARN("TILT was out of limits, but within margin, so instead of the initial value %f the value %f is used", tilt_initial, *tilt);
226  }
227 
228  if(isWithinPanTiltLimits(*pan, *tilt)) {
229  ROS_DEBUG("PAN: %f, TILT: %f\n", *pan, *tilt);
230  return true;
231  }
232  else {
233  return false;
234  }
235  }
236 
237 
238 
239  long PTUDriverMock::getLimitAngle(char pan_or_tilt, char upper_or_lower) {
240  if(pan_or_tilt == 'p') {
241  if (upper_or_lower == 'l') {
242  return pan_min_limit;
243  }
244  else if (upper_or_lower == 'u') {
245  return pan_max_limit;
246  }
247  else {
248  return std::numeric_limits<double>::max();
249  }
250  }
251  else if (pan_or_tilt == 't') {
252  if (upper_or_lower == 'l') {
253  return tilt_min_limit;
254  }
255  else if (upper_or_lower == 'u') {
256  return tilt_max_limit;
257  }
258  else {
259  return std::numeric_limits<double>::max();
260  }
261  }
262  else {
263  return std::numeric_limits<double>::max();
264  }
265  }
266 }
virtual double getAngleSpeed(char type)
getAngleSpeed Method to get the current angle speed of an axisa (deg/s)
virtual bool hasHaltedAndReachedGoal()
hasHaltedAndReachedGoal Method to determine if the PTU has halted and reached its goal ...
#define STEPS_UNTIL_GOAL_REACHED
virtual void setAbsoluteAngleSpeeds(double pan_speed, double tilt_speed)
setAbsoluteAngleSpeeds Method to set desired speed for pan/tilt movement absolute in deg/s ...
virtual void setSettings(int pan_base, int tilt_base, int pan_speed, int tilt_speed, int pan_upper, int tilt_upper, int pan_accel, int tilt_accel, int pan_hold, int tilt_hold, int pan_move, int tilt_move)
setSettings Method to configure various settings of the ptu
virtual void setSpeedControlMode(bool speed_control_mode)
setSpeedControlMode Method to set and disable pure speed control mode
PTUDriverMock(const char *port, int baud, bool speed_control)
#define ROS_WARN(...)
bool isConnected()
isConnected Method to check if ptu is connected.
virtual bool isWithinPanTiltLimits(double pan, double tilt)
isWithinPanTiltLimits Method that checks if pan and tilt value are within the chosen pan and tilt lim...
virtual bool hasHalted()
hasHalted Method to determine if PTU movement has stopped
virtual bool setAbsoluteAngles(double pan_angle, double tilt_angle, bool no_forbidden_area_check)
setAbsoluteAngles Method to set pan and tilt angle for the PTU
virtual bool reachedGoal()
reachedGoal Method to determine if the PTU has reached its goal.
virtual double getDesiredAngle(char type)
getDesiredAngle Method to get the desired pan/tilt angle (where the ptu moves to) ...
#define ROS_INFO(...)
virtual void setLimitAngles(double pan_min, double pan_max, double tilt_min, double tilt_max)
setSettings Method to configure limits for pan and tilt
virtual void setLimitAnglesToHardwareConstraints()
setLimitAnglesToHardwareConstraints Method that sets the pan and tilt limits to the maximum values th...
virtual bool setValuesOutOfLimitsButWithinMarginToLimit(double *pan, double *tilt, double margin)
setValuesOutOfLimitsButWithinMarginToLimit This method is used to set pan/tilt values that are slighl...
virtual long getLimitAngle(char pan_or_tilt, char upper_or_lower)
!!!!!!!!!Müssen nachfolgende public sein? Nach erstellen von mock überprüfen!!!!!!!!!!! ...
bool getParam(const std::string &key, std::string &s) const
virtual bool isInSpeedControlMode()
isInSpeedControlMode Method to determine if ptu is in pure speed control mode
virtual bool isInForbiddenArea(double pan_angle, double tilt_angle)
isInForbiddenArea method to determine if a pan + tilt value pair lies within a forbidden area...
Definition: PTUDriver.cpp:362
virtual double getCurrentAngle(char type)
getCurrentAngle Method to get the current pan/tilt angle
virtual std::vector< double > determineLegitEndPoint(double end_point_pan_candidate, double end_point_tilt_candidate)
determineLegitEndPoint DO NOT USE, NOT SUPPORTED IN MOCK
#define ROS_ERROR(...)
#define PAN
Definition: PTUDriver.h:25
#define ROS_DEBUG(...)


asr_flir_ptu_driver
Author(s): Valerij Wittenbeck, Joachim Gehrung, Pascal Meißner, Patrick Schlosser
autogenerated on Mon Dec 2 2019 03:15:17