box_relative.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include <cmath>
00027 #include <models/relative_position/box_relative.h>
00028 #include <utils/math/angle.h>
00029
00030 #include <iostream>
00031
00032 using namespace std;
00033 using namespace fawkes;
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 BoxRelative::BoxRelative(unsigned int image_width,
00051 unsigned int image_height,
00052 float camera_height,
00053 float camera_offset_x, float camera_offset_y,
00054 float camera_ori,
00055 float horizontal_angle, float vertical_angle
00056 )
00057 {
00058
00059 this->image_width = image_width;
00060 this->image_height = image_height;
00061 this->horizontal_angle = deg2rad( horizontal_angle );
00062 this->vertical_angle = deg2rad( vertical_angle );
00063 this->camera_orientation = deg2rad( camera_ori );
00064 this->camera_height = camera_height;
00065 this->camera_offset_x = camera_offset_x;
00066 this->camera_offset_y = camera_offset_y;
00067
00068 center.x = center.y = 0.f;
00069 pan = 0.0f;
00070 tilt = 0.0f;
00071
00072 pan_rad_per_pixel = this->horizontal_angle / this->image_width;
00073 tilt_rad_per_pixel = this->vertical_angle / this->image_height;
00074
00075 box_x = box_y = bearing = slope = distance_box_motor = distance_box_cam = 0.f;
00076
00077 DEFAULT_X_VARIANCE = 1500.f;
00078 DEFAULT_Y_VARIANCE = 1000.f;
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099 }
00100
00101
00102
00103
00104
00105
00106 float
00107 BoxRelative::get_distance() const
00108 {
00109 return distance_box_motor;
00110 }
00111
00112
00113 float
00114 BoxRelative::get_bearing(void) const
00115 {
00116 return bearing;
00117 }
00118
00119
00120 float
00121 BoxRelative::get_slope() const
00122 {
00123 return slope;
00124 }
00125
00126
00127
00128
00129
00130
00131 float
00132 BoxRelative::get_y(void) const
00133 {
00134 return box_y;
00135 }
00136
00137
00138
00139
00140
00141
00142 float
00143 BoxRelative::get_x(void) const
00144 {
00145 return box_x;
00146 }
00147
00148 void
00149 BoxRelative::set_radius(float r)
00150 {
00151 }
00152
00153
00154 void
00155 BoxRelative::set_center(float x, float y)
00156 {
00157 center.x = x;
00158 center.y = y;
00159 }
00160
00161
00162 void
00163 BoxRelative::set_center(const center_in_roi_t& c)
00164 {
00165 center.x = c.x;
00166 center.y = c.y;
00167 }
00168
00169
00170 void
00171 BoxRelative::set_pan_tilt(float pan, float tilt)
00172 {
00173 this->pan = pan;
00174 this->tilt = tilt;
00175 }
00176
00177
00178 void
00179 BoxRelative::get_pan_tilt(float *pan, float *tilt) const
00180 {
00181 *pan = this->pan;
00182 *tilt = this->tilt;
00183 }
00184
00185
00186 const char *
00187 BoxRelative::get_name() const
00188 {
00189 return "BoxRelative";
00190 }
00191
00192
00193
00194
00195
00196 void
00197 BoxRelative::set_horizontal_angle(float angle_deg)
00198 {
00199 horizontal_angle = deg2rad( angle_deg );
00200 }
00201
00202
00203
00204
00205
00206 void
00207 BoxRelative::set_vertical_angle(float angle_deg)
00208 {
00209 vertical_angle = deg2rad( angle_deg );
00210 }
00211
00212
00213 void
00214 BoxRelative::reset()
00215 {
00216 last_available = false;
00217
00218 }
00219
00220 void
00221 BoxRelative::calc()
00222 {
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240 calc_unfiltered();
00241
00242
00243 }
00244
00245
00246 bool
00247 BoxRelative::is_pos_valid() const
00248 {
00249 return true;
00250 }
00251
00252
00253 void
00254 BoxRelative::calc_unfiltered()
00255 {
00256
00257
00258 bearing = ((center.x - image_width/2) * pan_rad_per_pixel + pan + camera_orientation);
00259
00260
00261 slope = -((center.y - image_height / 2) * tilt_rad_per_pixel - tilt);
00262
00263 distance_box_cam = camera_height * tan(M_PI / 2 + slope);
00264 distance_box_motor = distance_box_cam - camera_offset_x;
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274 box_x = cos( bearing ) * distance_box_cam + camera_offset_x;
00275 box_y = sin( bearing ) * distance_box_cam + camera_offset_y;
00276 }
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306