front_ball.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
00027 #include <cmath>
00028 #include <iostream>
00029 #include <models/relative_position/front_ball.h>
00030 #include <utils/math/angle.h>
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 FrontBallRelativePos::FrontBallRelativePos(unsigned int image_width,
00051 unsigned int image_height,
00052 float camera_height,
00053 float camera_offset_x,
00054 float camera_offset_y,
00055 float camera_ori,
00056 float horizontal_angle,
00057 float vertical_angle,
00058 float ball_circumference
00059 )
00060 {
00061
00062 this->image_width = image_width;
00063 this->image_height = image_height;
00064 this->ball_circumference = ball_circumference;
00065 this->horizontal_angle = deg2rad( horizontal_angle );
00066 this->vertical_angle = deg2rad( vertical_angle );
00067 this->camera_orientation = deg2rad( camera_ori );
00068 this->camera_height = camera_height;
00069 this->camera_offset_x = camera_offset_x;
00070 this->camera_offset_y = camera_offset_y;
00071
00072 m_fRadius = 0.0f;
00073 m_cirtCenter.x = 0.0f;
00074 m_cirtCenter.y = 0.0f;
00075 m_fPan = 0.0f;
00076 m_fTilt = 0.0f;
00077
00078 avg_x = avg_y = avg_x_sum = avg_y_sum = 0.f;
00079 avg_x_num = avg_y_num = 0;
00080
00081 m_fPanRadPerPixel = this->horizontal_angle / this->image_width;
00082 m_fTiltRadPerPixel = this->vertical_angle / this->image_height;
00083 m_fBallRadius = this->ball_circumference / ( 2 * M_PI );
00084
00085 ball_x = ball_y = bearing = slope = distance_ball_motor = distance_ball_cam = 0.f;
00086
00087 DEFAULT_X_VARIANCE = 1500.f;
00088 DEFAULT_Y_VARIANCE = 1000.f;
00089
00090 var_proc_x = 1500;
00091 var_proc_y = 1000;
00092 var_meas_x = 1500;
00093 var_meas_y = 1000;
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109 }
00110
00111
00112 float
00113 FrontBallRelativePos::get_distance() const
00114 {
00115 return distance_ball_motor;
00116 }
00117
00118
00119 float
00120 FrontBallRelativePos::get_bearing(void) const
00121 {
00122 return bearing;
00123 }
00124
00125
00126 float
00127 FrontBallRelativePos::get_slope() const
00128 {
00129 return slope;
00130 }
00131
00132
00133 float
00134 FrontBallRelativePos::get_y(void) const
00135 {
00136 return ball_y;
00137 }
00138
00139
00140 float
00141 FrontBallRelativePos::get_x(void) const
00142 {
00143 return ball_x;
00144 }
00145
00146
00147 void
00148 FrontBallRelativePos::set_center(float x, float y)
00149 {
00150 m_cirtCenter.x = x;
00151 m_cirtCenter.y = y;
00152 }
00153
00154
00155 void
00156 FrontBallRelativePos::set_center(const center_in_roi_t& c)
00157 {
00158 m_cirtCenter.x = c.x;
00159 m_cirtCenter.y = c.y;
00160 }
00161
00162
00163 void
00164 FrontBallRelativePos::set_radius(float r)
00165 {
00166 m_fRadius = r;
00167 }
00168
00169
00170
00171
00172
00173 float
00174 FrontBallRelativePos::get_radius() const
00175 {
00176 return m_fRadius;
00177 }
00178
00179
00180 void
00181 FrontBallRelativePos::set_pan_tilt(float pan, float tilt)
00182 {
00183 m_fPan = pan;
00184 m_fTilt = tilt;
00185 }
00186
00187
00188 void
00189 FrontBallRelativePos::get_pan_tilt(float *pan, float *tilt) const
00190 {
00191 *pan = m_fPan;
00192 *tilt = m_fTilt;
00193 }
00194
00195
00196 const char *
00197 FrontBallRelativePos::get_name() const
00198 {
00199 return "FrontBallRelativePos";
00200 }
00201
00202
00203
00204
00205
00206 void
00207 FrontBallRelativePos::set_horizontal_angle(float angle_deg)
00208 {
00209 horizontal_angle = deg2rad( angle_deg );
00210 }
00211
00212
00213
00214
00215
00216 void
00217 FrontBallRelativePos::set_vertical_angle(float angle_deg)
00218 {
00219 vertical_angle = deg2rad( angle_deg );
00220 }
00221
00222
00223 void
00224 FrontBallRelativePos::reset()
00225 {
00226 last_available = false;
00227
00228 }
00229
00230 void
00231 FrontBallRelativePos::calc()
00232 {
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249 float tmp = m_fBallRadius / sin(m_fRadius * m_fPanRadPerPixel);
00250
00251
00252 distance_ball_cam = sqrt( tmp * tmp -
00253 (camera_height - m_fBallRadius) * (camera_height - m_fBallRadius) );
00254
00255
00256 #ifdef OLD_COORD_SYS
00257
00258 bearing = (((m_cirtCenter.x - image_width/2) * m_fPanRadPerPixel + m_fPan + camera_orientation));
00259 #else
00260
00261 bearing = - (((m_cirtCenter.x - image_width/2) * m_fPanRadPerPixel + m_fPan + camera_orientation));
00262 #endif
00263
00264
00265 slope = - ((m_cirtCenter.y - image_height / 2) * m_fTiltRadPerPixel - m_fTilt);
00266
00267 ball_x = cos( bearing ) * distance_ball_cam + camera_offset_x;
00268 ball_y = sin( bearing ) * distance_ball_cam + camera_offset_y;
00269
00270
00271
00272 distance_ball_motor = sqrt( ball_x * ball_x + ball_y * ball_y );
00273
00274 }
00275
00276
00277 bool
00278 FrontBallRelativePos::is_pos_valid() const
00279 {
00280 return true;
00281 }
00282
00283
00284 void
00285 FrontBallRelativePos::calc_unfiltered()
00286 {
00287 float tmp = m_fBallRadius / sin(m_fRadius * m_fPanRadPerPixel);
00288
00289
00290
00291 distance_ball_cam = sqrt( tmp * tmp -
00292 (camera_height - m_fBallRadius) * (camera_height - m_fBallRadius) );
00293
00294
00295 #ifdef OLD_COORD_SYS
00296
00297 bearing = (((m_cirtCenter.x - image_width/2) * m_fPanRadPerPixel + m_fPan + camera_orientation));
00298 #else
00299
00300 bearing = - (((m_cirtCenter.x - image_width/2) * m_fPanRadPerPixel + m_fPan + camera_orientation));
00301 #endif
00302
00303
00304 slope = - ((m_cirtCenter.y - image_height / 2) * m_fTiltRadPerPixel - m_fTilt);
00305
00306
00307 ball_x = cos( bearing ) * distance_ball_cam + camera_offset_x;
00308 ball_y = sin( bearing ) * distance_ball_cam + camera_offset_y;
00309
00310 distance_ball_motor = sqrt( ball_x * ball_x + ball_y * ball_y );
00311
00312 }
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342