omni_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 #include <cmath>
00026 #include <iostream>
00027 #include <models/relative_position/omni_relative.h>
00028
00029
00030
00031
00032
00033
00034
00035
00036 OmniRelative::OmniRelative(MirrorModel *mirror_model)
00037 {
00038 this->mirror_model = mirror_model;
00039
00040 avg_x = avg_y = avg_x_sum = avg_y_sum = 0.f;
00041 avg_x_num = avg_y_num = 0;
00042
00043 ball_x = ball_y = bearing = slope = distance_ball_motor = distance_ball_cam = 0.f;
00044
00045
00046 slope = 0;
00047
00048 DEFAULT_X_VARIANCE = 36.f;
00049 DEFAULT_Y_VARIANCE = 25.f;
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066 }
00067
00068
00069 float
00070 OmniRelative::get_distance() const
00071 {
00072 return distance_ball_motor;
00073 }
00074
00075
00076 float
00077 OmniRelative::get_bearing(void) const
00078 {
00079 return bearing;
00080 }
00081
00082
00083 float
00084 OmniRelative::get_slope() const
00085 {
00086 return slope;
00087 }
00088
00089
00090 float
00091 OmniRelative::get_y(void) const
00092 {
00093 return ball_y;
00094 }
00095
00096
00097 float
00098 OmniRelative::get_x(void) const
00099 {
00100 return ball_x;
00101 }
00102
00103
00104 void
00105 OmniRelative::set_center(float x, float y)
00106 {
00107 image_x = (unsigned int)roundf(x);
00108 image_y = (unsigned int)roundf(y);
00109 }
00110
00111
00112 void
00113 OmniRelative::set_center(const center_in_roi_t& c)
00114 {
00115 }
00116
00117
00118 void
00119 OmniRelative::set_radius(float r)
00120 {
00121 }
00122
00123
00124
00125
00126
00127 float
00128 OmniRelative::get_radius() const
00129 {
00130 return 0;
00131 }
00132
00133
00134 void
00135 OmniRelative::set_pan_tilt(float pan, float tilt)
00136 {
00137 }
00138
00139
00140 void
00141 OmniRelative::get_pan_tilt(float *pan, float *tilt) const
00142 {
00143 }
00144
00145
00146 const char *
00147 OmniRelative::get_name() const
00148 {
00149 return "OmniRelative";
00150 }
00151
00152
00153 void
00154 OmniRelative::reset()
00155 {
00156 last_available = false;
00157
00158 }
00159
00160
00161 void
00162 OmniRelative::calc()
00163 {
00164
00165 if ( mirror_model->isValidPoint( image_x, image_y ) ) {
00166 fawkes::polar_coord_2d_t rel_pos = mirror_model->getWorldPointRelative( image_x, image_y );
00167
00168 distance_ball_cam = rel_pos.r;
00169 bearing = rel_pos.phi;
00170
00171
00172 ball_x = cos( bearing ) * distance_ball_cam;
00173 ball_y = sin( bearing ) * distance_ball_cam;
00174
00175
00176
00177 distance_ball_motor = sqrt( ball_x * ball_x + ball_y * ball_y );
00178 }
00179 }
00180
00181
00182 bool
00183 OmniRelative::is_pos_valid() const
00184 {
00185 return mirror_model->isValidPoint( image_x, image_y );
00186 }
00187
00188
00189 void
00190 OmniRelative::calc_unfiltered()
00191 {
00192
00193 fawkes::polar_coord_2d_t rel_pos = mirror_model->getWorldPointRelative( image_x, image_y );
00194
00195 distance_ball_cam = rel_pos.r;
00196 bearing = rel_pos.phi;
00197
00198
00199 slope = 0;
00200
00201
00202 ball_x = cos( bearing ) * distance_ball_cam;
00203 ball_y = sin( bearing ) * distance_ball_cam;
00204
00205 distance_ball_motor = sqrt( ball_x * ball_x + ball_y * ball_y );
00206 }
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251