00001
00008 #ifndef PTUDRIVER_H_
00009 #define PTUDRIVER_H_
00010
00011 #include <string.h>
00012 #include <math.h>
00013 #include "ros/ros.h"
00014 #include <limits>
00015 #include "PTUFree.h"
00016
00017
00018
00019
00020
00021 #define STOPPED_THRESHOLD 0.1
00022
00023
00024 #ifdef __PTU_FREE_INCLUDED__
00025 #define PAN 0
00026 #define TILT 1
00027 #define RESOLUTION 2
00028 #define POSITION_LIMITS_MODE 3
00029 #define OFF_MODE 4
00030 #define BASE 5
00031 #define ABSOLUTE 6
00032 #define UPPER_SPEED_LIMIT 7
00033 #define SPEED 8
00034 #define ACCELERATION 9
00035 #define HOLD_POWER_LEVEL 10
00036 #define MOVE_POWER_LEVEL 11
00037 #define MINIMUM_POSITION 12
00038 #define MAXIMUM_POSITION 13
00039 #define LOWER_SPEED_LIMIT 14
00040 #define POSITION 15
00041 #define PTU_LOW_POWER 16
00042 #define PTU_REG_POWER 17
00043 #define PTU_HI_POWER 18
00044 #define PTU_PURE_VELOCITY_SPEED_CONTROL_MODE 19
00045 #define PTU_OFF_POWER 20
00046 #define SPEED_CONTROL_MODE 21
00047 #define PTU_INDEPENDENT_SPEED_CONTROL_MODE 22
00048 #define PTU_OK 23
00049 #define PTU_NOT_OK 24
00050 #endif
00051
00052
00053
00054
00055 namespace asr_flir_ptu_driver {
00056 #define HOLZ
00057
00058 class PTUDriver {
00059 #define HOLZ
00060 public:
00067 PTUDriver(const char* port, int baud, bool speed_control);
00071 PTUDriver();
00072
00076 ~PTUDriver();
00077
00078
00083 bool virtual isConnected();
00084
00100 void virtual setSettings(int pan_base, int tilt_base, int pan_speed, int tilt_speed, int pan_upper, int tilt_upper,
00101 int pan_accel, int tilt_accel, int pan_hold, int tilt_hold, int pan_move, int tilt_move);
00102
00103
00111 void virtual setLimitAngles(double pan_min, double pan_max, double tilt_min, double tilt_max);
00112
00118 void virtual setAbsoluteAngleSpeeds(double pan_speed, double tilt_speed);
00119
00125 void virtual setAbsoluteAngleSpeeds(signed short pan_speed, signed short tilt_speed);
00126
00135 bool virtual setAbsoluteAngles(double pan_angle, double tilt_angle, bool no_forbidden_area_check);
00136
00144 bool virtual setValuesOutOfLimitsButWithinMarginToLimit(double * pan, double * tilt, double margin);
00145
00152 bool virtual isWithinPanTiltLimits(double pan, double tilt);
00153
00157 void virtual setLimitAnglesToHardwareConstraints();
00158
00163 void virtual setForbiddenAreas(std::vector< std::map< std::string, double> > forbidden_areas);
00164
00169 void virtual setSpeedControlMode(bool speed_control_mode);
00170
00175 bool virtual isInSpeedControlMode();
00176
00182 double virtual getCurrentAngle(char type);
00183
00189 double virtual getDesiredAngle(char type);
00190
00196 double virtual getAngleSpeed(char type);
00197
00204 bool virtual isInForbiddenArea(double pan_angle, double tilt_angle);
00205
00210 void virtual setComputationTolerance(double computation_tolerance);
00211
00217 void virtual setDistanceFactor(long distance_factor);
00218
00220
00221
00228 long virtual getLimitAngle(char pan_or_tilt, char upper_or_lower);
00229
00234 bool virtual hasHaltedAndReachedGoal();
00235
00240 bool virtual hasHalted();
00241
00246 bool virtual reachedGoal();
00247
00254 std::vector<double> virtual determineLegitEndPoint(double end_point_pan_candidate, double end_point_tilt_candidate);
00255
00256
00257
00258 protected:
00259
00260 std::string virtual getErrorString(char status_code);
00261 std::vector< std::map< std::string, double> > forbidden_areas;
00262 long pan_min, pan_max;
00263 long tilt_min, tilt_max;
00264
00265 long prefetched_pan_current_base;
00266 long prefetched_pan_desired_acceleration;
00267 long prefetched_pan_desired_speed;
00268 long prefetched_tilt_current_base;
00269 long prefetched_tilt_desired_acceleration;
00270 long prefetched_tilt_desired_speed;
00271 long prefetched_pan_current_position;
00272 long prefetched_tilt_current_position;
00273 double pan_resolution, tilt_resolution;
00274 private:
00275 void setValuesToBackupValues(int & pan_base, int & tilt_base, int & pan_speed, int & tilt_speed,
00276 int & pan_upper, int & tilt_upper, int & pan_accel, int & tilt_accel,
00277 int & pan_hold, int & tilt_hold, int & pan_move, int & tilt_move);
00278 void createSettingsBackup();
00279 bool checkReturnCode(char return_code);
00280 void restoreSettingsFromBackup();
00281 void prefetchValues();
00282
00283 double double_computation_tolerance;
00284 bool speed_control;
00285 static short int POW_VAL_MOVE[3];
00286 static short int POW_VAL_HOLD[3];
00287 std::map<std::string,int> backup_settings;
00288 long convertPanFromAngleToPosition(double angle);
00289 double convertPanFromPositionToAngle(long position);
00290 long convertTiltFromAngleToPosition(double angle);
00291 double convertTiltFromPositionToAngle(long position);
00292 double pan_acceleration_time;
00293 double pan_slew_speed_time;
00294 double tilt_acceleration_time;
00295 double tilt_slew_speed_time;
00296 std::vector<std::vector<double> > forbidden_area_first_line_coordinate_forms;
00297 std::vector<std::vector<double> > forbidden_area_second_line_coordinate_forms;
00298 std::vector<std::vector<double> > forbidden_area_third_line_coordinate_forms;
00299 std::vector<std::vector<double> > forbidden_area_fourth_line_coordinate_forms;
00300
00301 std::vector<std::vector<double> > max_pan_max_tilt_points;
00302 std::vector<std::vector<double> > max_pan_min_tilt_points;
00303 std::vector<std::vector<double> > min_pan_max_tilt_points;
00304 std::vector<std::vector<double> > min_pan_min_tilt_points;
00305
00306 long backup_pan_base;
00307 long backup_pan_upper;
00308 long backup_pan_speed;
00309 long backup_pan_accel;
00310 long backup_pan_hold;
00311 long backup_pan_move;
00312 long backup_tilt_base;
00313 long backup_tilt_upper;
00314 long backup_tilt_speed;
00315 long backup_tilt_accel;
00316 long backup_tilt_hold;
00317 long backup_tilt_move;
00318
00319
00320 std::vector<double> solveSecondDegreePolynomial(double a, double b, double c);
00321 std::vector<double> getAccelerationTimeAndSlewSpeedTime(double distance_in_steps, double base_speed, double acceleration, double slew_speed);
00322 std::vector<double> predictPositionInTime(std::vector<double> start_point, std::vector<double> end_point, double point_in_time);
00323 double calculateCoveredDistance(double acceleration_time, double slew_speed_time, double decceleration_time, bool is_pan);
00324 std::vector<double> calculatePointOfIntersectionWithForbiddenAreas(std::vector<double> start_point, std::vector<double> end_point);
00325 std::vector<double> calculateIntersectionPoint(std::vector<double> first_line_coordiante_form, std::vector<double> second_line_coordiante_form);
00326 bool isOnLineSegmentBetweenTwoPoints(std::vector<double> start_point, std::vector<double> end_point, std::vector<double> line_coordinate_form, std::vector<double> point_to_check, double tolerance);
00327 std::vector<double> calculateCoordinateForm(std::vector<double> start_point, std::vector<double> end_point);
00328 double getVectorLength(std::vector<double> input_vector);
00329 double getVectorLength(std::vector<double> start_point, std::vector<double> end_point);
00330 std::vector<double> checkForPossibleKollision(double new_pan_angle, double new_tilt_angle);
00331 double distance_factor;
00332 void precalculateForbiddenAreaCoodinateForms();
00333
00334 #ifndef __PTU_FREE_INCLUDED__
00335 portstream_fd COMstream;
00336 #endif
00337
00338 #ifdef __PTU_FREE_INCLUDED__
00339 long get_current(char pan_or_tilt, char what);
00340 char set_desired(char pan_or_tilt, char what, short int * value, char type);
00341 long get_desired(char pan_or_tilt, char what);
00342 char set_mode(char mode_type, char mode);
00343 ptu_free::PTUFree free_ptu;
00344 #endif
00345
00346
00347
00348
00349 };
00350
00351 }
00352
00353 #endif