globfromrel.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 <core/exception.h>
00026 #include <cmath>
00027 #include <models/velocity/globfromrel.h>
00028 #include <utils/time/time.h>
00029
00030
00031
00032
00033 using namespace std;
00034 using namespace fawkes;
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 VelocityGlobalFromRelative::VelocityGlobalFromRelative(VelocityModel *rel_velo_model,
00045 RelativePositionModel *rel_pos_model)
00046 {
00047 this->relative_velocity = rel_velo_model;
00048 this->relative_position = rel_pos_model;
00049
00050 if ( rel_velo_model->getCoordinateSystem() != COORDSYS_ROBOT_CART ) {
00051
00052
00053
00054
00055
00056 throw Exception("Given velocity model does not return robot-centric cartesian coordinates. WILL NOT WORK!");
00057 }
00058
00059 robot_ori = robot_poseage = 0.f;
00060
00061 velocity_x = velocity_y = 0.f;
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083 }
00084
00085
00086
00087 VelocityGlobalFromRelative::~VelocityGlobalFromRelative()
00088 {
00089 }
00090
00091
00092 void
00093 VelocityGlobalFromRelative::setPanTilt(float pan, float tilt)
00094 {
00095 }
00096
00097
00098 void
00099 VelocityGlobalFromRelative::setRobotPosition(float x, float y, float ori, timeval t)
00100 {
00101 timeval now;
00102 gettimeofday(&now, NULL);
00103 robot_ori = ori;
00104 robot_poseage = time_diff_sec(now, t);
00105 }
00106
00107
00108 void
00109 VelocityGlobalFromRelative::setRobotVelocity(float rel_vel_x, float rel_vel_y, timeval t)
00110 {
00111 }
00112
00113 void
00114 VelocityGlobalFromRelative::setTime(timeval t)
00115 {
00116 }
00117
00118
00119 void
00120 VelocityGlobalFromRelative::setTimeNow()
00121 {
00122 }
00123
00124
00125 void
00126 VelocityGlobalFromRelative::getTime(long int *sec, long int *usec)
00127 {
00128 *sec = 0;
00129 *usec = 0;
00130 }
00131
00132
00133 void
00134 VelocityGlobalFromRelative::getVelocity(float *vel_x, float *vel_y)
00135 {
00136 if (vel_x != NULL) {
00137 *vel_x = velocity_x;
00138 }
00139 if (vel_y != NULL) {
00140 *vel_y = velocity_y;
00141 }
00142 }
00143
00144
00145 float
00146 VelocityGlobalFromRelative::getVelocityX()
00147 {
00148 return velocity_x;
00149 }
00150
00151
00152 float
00153 VelocityGlobalFromRelative::getVelocityY()
00154 {
00155 return velocity_y;
00156 }
00157
00158
00159
00160 void
00161 VelocityGlobalFromRelative::calc()
00162 {
00163
00164 relative_velocity->getVelocity( &rel_vel_x, &rel_vel_y );
00165 sin_ori = sin( robot_ori );
00166 cos_ori = cos( robot_ori );
00167 rel_dist = relative_position->get_distance();
00168
00169 velocity_x = rel_vel_x * cos_ori - rel_vel_y * sin_ori;
00170 velocity_y = rel_vel_x * sin_ori + rel_vel_y * cos_ori;
00171
00172
00173
00174 }
00175
00176
00177 void
00178 VelocityGlobalFromRelative::reset()
00179 {
00180
00181 avg_vx_sum = 0.f;
00182 avg_vx_num = 0;
00183 avg_vy_sum = 0.f;
00184 avg_vy_num = 0;
00185 velocity_x = 0.f;
00186 velocity_y = 0.f;
00187 }
00188
00189
00190 const char *
00191 VelocityGlobalFromRelative::getName() const
00192 {
00193 return "VelocityModel::VelocityGlobalFromRelative";
00194 }
00195
00196
00197 coordsys_type_t
00198 VelocityGlobalFromRelative::getCoordinateSystem()
00199 {
00200 return COORDSYS_WORLD_CART;
00201 }
00202
00203
00204
00205
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