Fawkes API
Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * NaoSensorInterface.cpp - Fawkes BlackBoard Interface - NaoSensorInterface 00004 * 00005 * Templated created: Thu Oct 12 10:49:19 2006 00006 * Copyright 2008 Tim Niemueller 00007 * 00008 ****************************************************************************/ 00009 00010 /* This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. A runtime exception applies to 00014 * this software (see LICENSE.GPL_WRE file mentioned below for details). 00015 * 00016 * This program is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Library General Public License for more details. 00020 * 00021 * Read the full text in the LICENSE.GPL_WRE file in the doc directory. 00022 */ 00023 00024 #include <interfaces/NaoSensorInterface.h> 00025 00026 #include <core/exceptions/software.h> 00027 00028 #include <cstring> 00029 #include <cstdlib> 00030 00031 namespace fawkes { 00032 00033 /** @class NaoSensorInterface <interfaces/NaoSensorInterface.h> 00034 * NaoSensorInterface Fawkes BlackBoard Interface. 00035 * 00036 This interface provides access to Nao sensors. 00037 00038 * @ingroup FawkesInterfaces 00039 */ 00040 00041 00042 00043 /** Constructor */ 00044 NaoSensorInterface::NaoSensorInterface() : Interface() 00045 { 00046 data_size = sizeof(NaoSensorInterface_data_t); 00047 data_ptr = malloc(data_size); 00048 data = (NaoSensorInterface_data_t *)data_ptr; 00049 data_ts = (interface_data_ts_t *)data_ptr; 00050 memset(data_ptr, 0, data_size); 00051 add_fieldinfo(IFT_FLOAT, "accel_x", 1, &data->accel_x); 00052 add_fieldinfo(IFT_FLOAT, "accel_y", 1, &data->accel_y); 00053 add_fieldinfo(IFT_FLOAT, "accel_z", 1, &data->accel_z); 00054 add_fieldinfo(IFT_FLOAT, "gyro_x", 1, &data->gyro_x); 00055 add_fieldinfo(IFT_FLOAT, "gyro_y", 1, &data->gyro_y); 00056 add_fieldinfo(IFT_FLOAT, "gyro_ref", 1, &data->gyro_ref); 00057 add_fieldinfo(IFT_FLOAT, "angle_x", 1, &data->angle_x); 00058 add_fieldinfo(IFT_FLOAT, "angle_y", 1, &data->angle_y); 00059 add_fieldinfo(IFT_FLOAT, "l_fsr_fl", 1, &data->l_fsr_fl); 00060 add_fieldinfo(IFT_FLOAT, "l_fsr_fr", 1, &data->l_fsr_fr); 00061 add_fieldinfo(IFT_FLOAT, "l_fsr_rl", 1, &data->l_fsr_rl); 00062 add_fieldinfo(IFT_FLOAT, "l_fsr_rr", 1, &data->l_fsr_rr); 00063 add_fieldinfo(IFT_FLOAT, "r_fsr_fl", 1, &data->r_fsr_fl); 00064 add_fieldinfo(IFT_FLOAT, "r_fsr_fr", 1, &data->r_fsr_fr); 00065 add_fieldinfo(IFT_FLOAT, "r_fsr_rl", 1, &data->r_fsr_rl); 00066 add_fieldinfo(IFT_FLOAT, "r_fsr_rr", 1, &data->r_fsr_rr); 00067 add_fieldinfo(IFT_FLOAT, "l_total_weight", 1, &data->l_total_weight); 00068 add_fieldinfo(IFT_FLOAT, "r_total_weight", 1, &data->r_total_weight); 00069 add_fieldinfo(IFT_FLOAT, "l_cop_x", 1, &data->l_cop_x); 00070 add_fieldinfo(IFT_FLOAT, "l_cop_y", 1, &data->l_cop_y); 00071 add_fieldinfo(IFT_FLOAT, "r_cop_x", 1, &data->r_cop_x); 00072 add_fieldinfo(IFT_FLOAT, "r_cop_y", 1, &data->r_cop_y); 00073 add_fieldinfo(IFT_FLOAT, "ultrasonic_distance_left", 4, &data->ultrasonic_distance_left); 00074 add_fieldinfo(IFT_FLOAT, "ultrasonic_distance_right", 4, &data->ultrasonic_distance_right); 00075 add_fieldinfo(IFT_ENUM, "ultrasonic_direction", 1, &data->ultrasonic_direction, "UltrasonicDirection"); 00076 add_fieldinfo(IFT_UINT8, "l_foot_bumper_l", 1, &data->l_foot_bumper_l); 00077 add_fieldinfo(IFT_UINT8, "l_foot_bumper_r", 1, &data->l_foot_bumper_r); 00078 add_fieldinfo(IFT_UINT8, "r_foot_bumper_l", 1, &data->r_foot_bumper_l); 00079 add_fieldinfo(IFT_UINT8, "r_foot_bumper_r", 1, &data->r_foot_bumper_r); 00080 add_fieldinfo(IFT_UINT8, "head_touch_front", 1, &data->head_touch_front); 00081 add_fieldinfo(IFT_UINT8, "head_touch_middle", 1, &data->head_touch_middle); 00082 add_fieldinfo(IFT_UINT8, "head_touch_rear", 1, &data->head_touch_rear); 00083 add_fieldinfo(IFT_UINT8, "chest_button", 1, &data->chest_button); 00084 add_fieldinfo(IFT_FLOAT, "battery_charge", 1, &data->battery_charge); 00085 add_messageinfo("EmitUltrasonicWaveMessage"); 00086 add_messageinfo("StartUltrasonicMessage"); 00087 add_messageinfo("StopUltrasonicMessage"); 00088 unsigned char tmp_hash[] = {0x41, 0x41, 0x54, 0x94, 0xca, 0xe8, 0x3d, 0x7a, 0xb8, 0xaa, 0xc2, 0x4e, 0x2c, 0xac, 0xcb, 0x15}; 00089 set_hash(tmp_hash); 00090 } 00091 00092 /** Destructor */ 00093 NaoSensorInterface::~NaoSensorInterface() 00094 { 00095 free(data_ptr); 00096 } 00097 /** Convert UltrasonicDirection constant to string. 00098 * @param value value to convert to string 00099 * @return constant value as string. 00100 */ 00101 const char * 00102 NaoSensorInterface::tostring_UltrasonicDirection(UltrasonicDirection value) const 00103 { 00104 switch (value) { 00105 case USD_NONE: return "USD_NONE"; 00106 case USD_LEFT_LEFT: return "USD_LEFT_LEFT"; 00107 case USD_LEFT_RIGHT: return "USD_LEFT_RIGHT"; 00108 case USD_RIGHT_RIGHT: return "USD_RIGHT_RIGHT"; 00109 case USD_RIGHT_LEFT: return "USD_RIGHT_LEFT"; 00110 case USD_BOTH_BOTH: return "USD_BOTH_BOTH"; 00111 default: return "UNKNOWN"; 00112 } 00113 } 00114 /* Methods */ 00115 /** Get accel_x value. 00116 * Accelerometer x 00117 * @return accel_x value 00118 */ 00119 float 00120 NaoSensorInterface::accel_x() const 00121 { 00122 return data->accel_x; 00123 } 00124 00125 /** Get maximum length of accel_x value. 00126 * @return length of accel_x value, can be length of the array or number of 00127 * maximum number of characters for a string 00128 */ 00129 size_t 00130 NaoSensorInterface::maxlenof_accel_x() const 00131 { 00132 return 1; 00133 } 00134 00135 /** Set accel_x value. 00136 * Accelerometer x 00137 * @param new_accel_x new accel_x value 00138 */ 00139 void 00140 NaoSensorInterface::set_accel_x(const float new_accel_x) 00141 { 00142 data->accel_x = new_accel_x; 00143 data_changed = true; 00144 } 00145 00146 /** Get accel_y value. 00147 * Accelerometer y 00148 * @return accel_y value 00149 */ 00150 float 00151 NaoSensorInterface::accel_y() const 00152 { 00153 return data->accel_y; 00154 } 00155 00156 /** Get maximum length of accel_y value. 00157 * @return length of accel_y value, can be length of the array or number of 00158 * maximum number of characters for a string 00159 */ 00160 size_t 00161 NaoSensorInterface::maxlenof_accel_y() const 00162 { 00163 return 1; 00164 } 00165 00166 /** Set accel_y value. 00167 * Accelerometer y 00168 * @param new_accel_y new accel_y value 00169 */ 00170 void 00171 NaoSensorInterface::set_accel_y(const float new_accel_y) 00172 { 00173 data->accel_y = new_accel_y; 00174 data_changed = true; 00175 } 00176 00177 /** Get accel_z value. 00178 * Accelerometer z 00179 * @return accel_z value 00180 */ 00181 float 00182 NaoSensorInterface::accel_z() const 00183 { 00184 return data->accel_z; 00185 } 00186 00187 /** Get maximum length of accel_z value. 00188 * @return length of accel_z value, can be length of the array or number of 00189 * maximum number of characters for a string 00190 */ 00191 size_t 00192 NaoSensorInterface::maxlenof_accel_z() const 00193 { 00194 return 1; 00195 } 00196 00197 /** Set accel_z value. 00198 * Accelerometer z 00199 * @param new_accel_z new accel_z value 00200 */ 00201 void 00202 NaoSensorInterface::set_accel_z(const float new_accel_z) 00203 { 00204 data->accel_z = new_accel_z; 00205 data_changed = true; 00206 } 00207 00208 /** Get gyro_x value. 00209 * Gyrometer x 00210 * @return gyro_x value 00211 */ 00212 float 00213 NaoSensorInterface::gyro_x() const 00214 { 00215 return data->gyro_x; 00216 } 00217 00218 /** Get maximum length of gyro_x value. 00219 * @return length of gyro_x value, can be length of the array or number of 00220 * maximum number of characters for a string 00221 */ 00222 size_t 00223 NaoSensorInterface::maxlenof_gyro_x() const 00224 { 00225 return 1; 00226 } 00227 00228 /** Set gyro_x value. 00229 * Gyrometer x 00230 * @param new_gyro_x new gyro_x value 00231 */ 00232 void 00233 NaoSensorInterface::set_gyro_x(const float new_gyro_x) 00234 { 00235 data->gyro_x = new_gyro_x; 00236 data_changed = true; 00237 } 00238 00239 /** Get gyro_y value. 00240 * Gyrometer y 00241 * @return gyro_y value 00242 */ 00243 float 00244 NaoSensorInterface::gyro_y() const 00245 { 00246 return data->gyro_y; 00247 } 00248 00249 /** Get maximum length of gyro_y value. 00250 * @return length of gyro_y value, can be length of the array or number of 00251 * maximum number of characters for a string 00252 */ 00253 size_t 00254 NaoSensorInterface::maxlenof_gyro_y() const 00255 { 00256 return 1; 00257 } 00258 00259 /** Set gyro_y value. 00260 * Gyrometer y 00261 * @param new_gyro_y new gyro_y value 00262 */ 00263 void 00264 NaoSensorInterface::set_gyro_y(const float new_gyro_y) 00265 { 00266 data->gyro_y = new_gyro_y; 00267 data_changed = true; 00268 } 00269 00270 /** Get gyro_ref value. 00271 * Gyrometer reference 00272 * @return gyro_ref value 00273 */ 00274 float 00275 NaoSensorInterface::gyro_ref() const 00276 { 00277 return data->gyro_ref; 00278 } 00279 00280 /** Get maximum length of gyro_ref value. 00281 * @return length of gyro_ref value, can be length of the array or number of 00282 * maximum number of characters for a string 00283 */ 00284 size_t 00285 NaoSensorInterface::maxlenof_gyro_ref() const 00286 { 00287 return 1; 00288 } 00289 00290 /** Set gyro_ref value. 00291 * Gyrometer reference 00292 * @param new_gyro_ref new gyro_ref value 00293 */ 00294 void 00295 NaoSensorInterface::set_gyro_ref(const float new_gyro_ref) 00296 { 00297 data->gyro_ref = new_gyro_ref; 00298 data_changed = true; 00299 } 00300 00301 /** Get angle_x value. 00302 * Angle x 00303 * @return angle_x value 00304 */ 00305 float 00306 NaoSensorInterface::angle_x() const 00307 { 00308 return data->angle_x; 00309 } 00310 00311 /** Get maximum length of angle_x value. 00312 * @return length of angle_x value, can be length of the array or number of 00313 * maximum number of characters for a string 00314 */ 00315 size_t 00316 NaoSensorInterface::maxlenof_angle_x() const 00317 { 00318 return 1; 00319 } 00320 00321 /** Set angle_x value. 00322 * Angle x 00323 * @param new_angle_x new angle_x value 00324 */ 00325 void 00326 NaoSensorInterface::set_angle_x(const float new_angle_x) 00327 { 00328 data->angle_x = new_angle_x; 00329 data_changed = true; 00330 } 00331 00332 /** Get angle_y value. 00333 * Angle y 00334 * @return angle_y value 00335 */ 00336 float 00337 NaoSensorInterface::angle_y() const 00338 { 00339 return data->angle_y; 00340 } 00341 00342 /** Get maximum length of angle_y value. 00343 * @return length of angle_y value, can be length of the array or number of 00344 * maximum number of characters for a string 00345 */ 00346 size_t 00347 NaoSensorInterface::maxlenof_angle_y() const 00348 { 00349 return 1; 00350 } 00351 00352 /** Set angle_y value. 00353 * Angle y 00354 * @param new_angle_y new angle_y value 00355 */ 00356 void 00357 NaoSensorInterface::set_angle_y(const float new_angle_y) 00358 { 00359 data->angle_y = new_angle_y; 00360 data_changed = true; 00361 } 00362 00363 /** Get l_fsr_fl value. 00364 * Left FSR front left 00365 * @return l_fsr_fl value 00366 */ 00367 float 00368 NaoSensorInterface::l_fsr_fl() const 00369 { 00370 return data->l_fsr_fl; 00371 } 00372 00373 /** Get maximum length of l_fsr_fl value. 00374 * @return length of l_fsr_fl value, can be length of the array or number of 00375 * maximum number of characters for a string 00376 */ 00377 size_t 00378 NaoSensorInterface::maxlenof_l_fsr_fl() const 00379 { 00380 return 1; 00381 } 00382 00383 /** Set l_fsr_fl value. 00384 * Left FSR front left 00385 * @param new_l_fsr_fl new l_fsr_fl value 00386 */ 00387 void 00388 NaoSensorInterface::set_l_fsr_fl(const float new_l_fsr_fl) 00389 { 00390 data->l_fsr_fl = new_l_fsr_fl; 00391 data_changed = true; 00392 } 00393 00394 /** Get l_fsr_fr value. 00395 * Left FSR front right 00396 * @return l_fsr_fr value 00397 */ 00398 float 00399 NaoSensorInterface::l_fsr_fr() const 00400 { 00401 return data->l_fsr_fr; 00402 } 00403 00404 /** Get maximum length of l_fsr_fr value. 00405 * @return length of l_fsr_fr value, can be length of the array or number of 00406 * maximum number of characters for a string 00407 */ 00408 size_t 00409 NaoSensorInterface::maxlenof_l_fsr_fr() const 00410 { 00411 return 1; 00412 } 00413 00414 /** Set l_fsr_fr value. 00415 * Left FSR front right 00416 * @param new_l_fsr_fr new l_fsr_fr value 00417 */ 00418 void 00419 NaoSensorInterface::set_l_fsr_fr(const float new_l_fsr_fr) 00420 { 00421 data->l_fsr_fr = new_l_fsr_fr; 00422 data_changed = true; 00423 } 00424 00425 /** Get l_fsr_rl value. 00426 * Left FSR rear left 00427 * @return l_fsr_rl value 00428 */ 00429 float 00430 NaoSensorInterface::l_fsr_rl() const 00431 { 00432 return data->l_fsr_rl; 00433 } 00434 00435 /** Get maximum length of l_fsr_rl value. 00436 * @return length of l_fsr_rl value, can be length of the array or number of 00437 * maximum number of characters for a string 00438 */ 00439 size_t 00440 NaoSensorInterface::maxlenof_l_fsr_rl() const 00441 { 00442 return 1; 00443 } 00444 00445 /** Set l_fsr_rl value. 00446 * Left FSR rear left 00447 * @param new_l_fsr_rl new l_fsr_rl value 00448 */ 00449 void 00450 NaoSensorInterface::set_l_fsr_rl(const float new_l_fsr_rl) 00451 { 00452 data->l_fsr_rl = new_l_fsr_rl; 00453 data_changed = true; 00454 } 00455 00456 /** Get l_fsr_rr value. 00457 * Left FSR rear right 00458 * @return l_fsr_rr value 00459 */ 00460 float 00461 NaoSensorInterface::l_fsr_rr() const 00462 { 00463 return data->l_fsr_rr; 00464 } 00465 00466 /** Get maximum length of l_fsr_rr value. 00467 * @return length of l_fsr_rr value, can be length of the array or number of 00468 * maximum number of characters for a string 00469 */ 00470 size_t 00471 NaoSensorInterface::maxlenof_l_fsr_rr() const 00472 { 00473 return 1; 00474 } 00475 00476 /** Set l_fsr_rr value. 00477 * Left FSR rear right 00478 * @param new_l_fsr_rr new l_fsr_rr value 00479 */ 00480 void 00481 NaoSensorInterface::set_l_fsr_rr(const float new_l_fsr_rr) 00482 { 00483 data->l_fsr_rr = new_l_fsr_rr; 00484 data_changed = true; 00485 } 00486 00487 /** Get r_fsr_fl value. 00488 * Right FSR front left 00489 * @return r_fsr_fl value 00490 */ 00491 float 00492 NaoSensorInterface::r_fsr_fl() const 00493 { 00494 return data->r_fsr_fl; 00495 } 00496 00497 /** Get maximum length of r_fsr_fl value. 00498 * @return length of r_fsr_fl value, can be length of the array or number of 00499 * maximum number of characters for a string 00500 */ 00501 size_t 00502 NaoSensorInterface::maxlenof_r_fsr_fl() const 00503 { 00504 return 1; 00505 } 00506 00507 /** Set r_fsr_fl value. 00508 * Right FSR front left 00509 * @param new_r_fsr_fl new r_fsr_fl value 00510 */ 00511 void 00512 NaoSensorInterface::set_r_fsr_fl(const float new_r_fsr_fl) 00513 { 00514 data->r_fsr_fl = new_r_fsr_fl; 00515 data_changed = true; 00516 } 00517 00518 /** Get r_fsr_fr value. 00519 * Right FSR front right 00520 * @return r_fsr_fr value 00521 */ 00522 float 00523 NaoSensorInterface::r_fsr_fr() const 00524 { 00525 return data->r_fsr_fr; 00526 } 00527 00528 /** Get maximum length of r_fsr_fr value. 00529 * @return length of r_fsr_fr value, can be length of the array or number of 00530 * maximum number of characters for a string 00531 */ 00532 size_t 00533 NaoSensorInterface::maxlenof_r_fsr_fr() const 00534 { 00535 return 1; 00536 } 00537 00538 /** Set r_fsr_fr value. 00539 * Right FSR front right 00540 * @param new_r_fsr_fr new r_fsr_fr value 00541 */ 00542 void 00543 NaoSensorInterface::set_r_fsr_fr(const float new_r_fsr_fr) 00544 { 00545 data->r_fsr_fr = new_r_fsr_fr; 00546 data_changed = true; 00547 } 00548 00549 /** Get r_fsr_rl value. 00550 * Right FSR rear left 00551 * @return r_fsr_rl value 00552 */ 00553 float 00554 NaoSensorInterface::r_fsr_rl() const 00555 { 00556 return data->r_fsr_rl; 00557 } 00558 00559 /** Get maximum length of r_fsr_rl value. 00560 * @return length of r_fsr_rl value, can be length of the array or number of 00561 * maximum number of characters for a string 00562 */ 00563 size_t 00564 NaoSensorInterface::maxlenof_r_fsr_rl() const 00565 { 00566 return 1; 00567 } 00568 00569 /** Set r_fsr_rl value. 00570 * Right FSR rear left 00571 * @param new_r_fsr_rl new r_fsr_rl value 00572 */ 00573 void 00574 NaoSensorInterface::set_r_fsr_rl(const float new_r_fsr_rl) 00575 { 00576 data->r_fsr_rl = new_r_fsr_rl; 00577 data_changed = true; 00578 } 00579 00580 /** Get r_fsr_rr value. 00581 * Right FSR rear right 00582 * @return r_fsr_rr value 00583 */ 00584 float 00585 NaoSensorInterface::r_fsr_rr() const 00586 { 00587 return data->r_fsr_rr; 00588 } 00589 00590 /** Get maximum length of r_fsr_rr value. 00591 * @return length of r_fsr_rr value, can be length of the array or number of 00592 * maximum number of characters for a string 00593 */ 00594 size_t 00595 NaoSensorInterface::maxlenof_r_fsr_rr() const 00596 { 00597 return 1; 00598 } 00599 00600 /** Set r_fsr_rr value. 00601 * Right FSR rear right 00602 * @param new_r_fsr_rr new r_fsr_rr value 00603 */ 00604 void 00605 NaoSensorInterface::set_r_fsr_rr(const float new_r_fsr_rr) 00606 { 00607 data->r_fsr_rr = new_r_fsr_rr; 00608 data_changed = true; 00609 } 00610 00611 /** Get l_total_weight value. 00612 * Total weight on left foot 00613 * @return l_total_weight value 00614 */ 00615 float 00616 NaoSensorInterface::l_total_weight() const 00617 { 00618 return data->l_total_weight; 00619 } 00620 00621 /** Get maximum length of l_total_weight value. 00622 * @return length of l_total_weight value, can be length of the array or number of 00623 * maximum number of characters for a string 00624 */ 00625 size_t 00626 NaoSensorInterface::maxlenof_l_total_weight() const 00627 { 00628 return 1; 00629 } 00630 00631 /** Set l_total_weight value. 00632 * Total weight on left foot 00633 * @param new_l_total_weight new l_total_weight value 00634 */ 00635 void 00636 NaoSensorInterface::set_l_total_weight(const float new_l_total_weight) 00637 { 00638 data->l_total_weight = new_l_total_weight; 00639 data_changed = true; 00640 } 00641 00642 /** Get r_total_weight value. 00643 * Total weight on right foot 00644 * @return r_total_weight value 00645 */ 00646 float 00647 NaoSensorInterface::r_total_weight() const 00648 { 00649 return data->r_total_weight; 00650 } 00651 00652 /** Get maximum length of r_total_weight value. 00653 * @return length of r_total_weight value, can be length of the array or number of 00654 * maximum number of characters for a string 00655 */ 00656 size_t 00657 NaoSensorInterface::maxlenof_r_total_weight() const 00658 { 00659 return 1; 00660 } 00661 00662 /** Set r_total_weight value. 00663 * Total weight on right foot 00664 * @param new_r_total_weight new r_total_weight value 00665 */ 00666 void 00667 NaoSensorInterface::set_r_total_weight(const float new_r_total_weight) 00668 { 00669 data->r_total_weight = new_r_total_weight; 00670 data_changed = true; 00671 } 00672 00673 /** Get l_cop_x value. 00674 * Center of pressure X for left foot. 00675 * @return l_cop_x value 00676 */ 00677 float 00678 NaoSensorInterface::l_cop_x() const 00679 { 00680 return data->l_cop_x; 00681 } 00682 00683 /** Get maximum length of l_cop_x value. 00684 * @return length of l_cop_x value, can be length of the array or number of 00685 * maximum number of characters for a string 00686 */ 00687 size_t 00688 NaoSensorInterface::maxlenof_l_cop_x() const 00689 { 00690 return 1; 00691 } 00692 00693 /** Set l_cop_x value. 00694 * Center of pressure X for left foot. 00695 * @param new_l_cop_x new l_cop_x value 00696 */ 00697 void 00698 NaoSensorInterface::set_l_cop_x(const float new_l_cop_x) 00699 { 00700 data->l_cop_x = new_l_cop_x; 00701 data_changed = true; 00702 } 00703 00704 /** Get l_cop_y value. 00705 * Center of pressure Y for left foot. 00706 * @return l_cop_y value 00707 */ 00708 float 00709 NaoSensorInterface::l_cop_y() const 00710 { 00711 return data->l_cop_y; 00712 } 00713 00714 /** Get maximum length of l_cop_y value. 00715 * @return length of l_cop_y value, can be length of the array or number of 00716 * maximum number of characters for a string 00717 */ 00718 size_t 00719 NaoSensorInterface::maxlenof_l_cop_y() const 00720 { 00721 return 1; 00722 } 00723 00724 /** Set l_cop_y value. 00725 * Center of pressure Y for left foot. 00726 * @param new_l_cop_y new l_cop_y value 00727 */ 00728 void 00729 NaoSensorInterface::set_l_cop_y(const float new_l_cop_y) 00730 { 00731 data->l_cop_y = new_l_cop_y; 00732 data_changed = true; 00733 } 00734 00735 /** Get r_cop_x value. 00736 * Center of pressure X for right foot. 00737 * @return r_cop_x value 00738 */ 00739 float 00740 NaoSensorInterface::r_cop_x() const 00741 { 00742 return data->r_cop_x; 00743 } 00744 00745 /** Get maximum length of r_cop_x value. 00746 * @return length of r_cop_x value, can be length of the array or number of 00747 * maximum number of characters for a string 00748 */ 00749 size_t 00750 NaoSensorInterface::maxlenof_r_cop_x() const 00751 { 00752 return 1; 00753 } 00754 00755 /** Set r_cop_x value. 00756 * Center of pressure X for right foot. 00757 * @param new_r_cop_x new r_cop_x value 00758 */ 00759 void 00760 NaoSensorInterface::set_r_cop_x(const float new_r_cop_x) 00761 { 00762 data->r_cop_x = new_r_cop_x; 00763 data_changed = true; 00764 } 00765 00766 /** Get r_cop_y value. 00767 * Center of pressure Y for right foot. 00768 * @return r_cop_y value 00769 */ 00770 float 00771 NaoSensorInterface::r_cop_y() const 00772 { 00773 return data->r_cop_y; 00774 } 00775 00776 /** Get maximum length of r_cop_y value. 00777 * @return length of r_cop_y value, can be length of the array or number of 00778 * maximum number of characters for a string 00779 */ 00780 size_t 00781 NaoSensorInterface::maxlenof_r_cop_y() const 00782 { 00783 return 1; 00784 } 00785 00786 /** Set r_cop_y value. 00787 * Center of pressure Y for right foot. 00788 * @param new_r_cop_y new r_cop_y value 00789 */ 00790 void 00791 NaoSensorInterface::set_r_cop_y(const float new_r_cop_y) 00792 { 00793 data->r_cop_y = new_r_cop_y; 00794 data_changed = true; 00795 } 00796 00797 /** Get ultrasonic_distance_left value. 00798 * 00799 First four ultrasonic sensor readings from left receiver. Distance 00800 to detected object is in meters. 00801 00802 * @return ultrasonic_distance_left value 00803 */ 00804 float * 00805 NaoSensorInterface::ultrasonic_distance_left() const 00806 { 00807 return data->ultrasonic_distance_left; 00808 } 00809 00810 /** Get ultrasonic_distance_left value at given index. 00811 * 00812 First four ultrasonic sensor readings from left receiver. Distance 00813 to detected object is in meters. 00814 00815 * @param index index of value 00816 * @return ultrasonic_distance_left value 00817 * @exception Exception thrown if index is out of bounds 00818 */ 00819 float 00820 NaoSensorInterface::ultrasonic_distance_left(unsigned int index) const 00821 { 00822 if (index > 4) { 00823 throw Exception("Index value %u out of bounds (0..4)", index); 00824 } 00825 return data->ultrasonic_distance_left[index]; 00826 } 00827 00828 /** Get maximum length of ultrasonic_distance_left value. 00829 * @return length of ultrasonic_distance_left value, can be length of the array or number of 00830 * maximum number of characters for a string 00831 */ 00832 size_t 00833 NaoSensorInterface::maxlenof_ultrasonic_distance_left() const 00834 { 00835 return 4; 00836 } 00837 00838 /** Set ultrasonic_distance_left value. 00839 * 00840 First four ultrasonic sensor readings from left receiver. Distance 00841 to detected object is in meters. 00842 00843 * @param new_ultrasonic_distance_left new ultrasonic_distance_left value 00844 */ 00845 void 00846 NaoSensorInterface::set_ultrasonic_distance_left(const float * new_ultrasonic_distance_left) 00847 { 00848 memcpy(data->ultrasonic_distance_left, new_ultrasonic_distance_left, sizeof(float) * 4); 00849 data_changed = true; 00850 } 00851 00852 /** Set ultrasonic_distance_left value at given index. 00853 * 00854 First four ultrasonic sensor readings from left receiver. Distance 00855 to detected object is in meters. 00856 00857 * @param new_ultrasonic_distance_left new ultrasonic_distance_left value 00858 * @param index index for of the value 00859 */ 00860 void 00861 NaoSensorInterface::set_ultrasonic_distance_left(unsigned int index, const float new_ultrasonic_distance_left) 00862 { 00863 if (index > 4) { 00864 throw Exception("Index value %u out of bounds (0..4)", index); 00865 } 00866 data->ultrasonic_distance_left[index] = new_ultrasonic_distance_left; 00867 data_changed = true; 00868 } 00869 /** Get ultrasonic_distance_right value. 00870 * 00871 First four ultrasonic sensor readings from right receiver. Distance 00872 to detected object is in meters. 00873 00874 * @return ultrasonic_distance_right value 00875 */ 00876 float * 00877 NaoSensorInterface::ultrasonic_distance_right() const 00878 { 00879 return data->ultrasonic_distance_right; 00880 } 00881 00882 /** Get ultrasonic_distance_right value at given index. 00883 * 00884 First four ultrasonic sensor readings from right receiver. Distance 00885 to detected object is in meters. 00886 00887 * @param index index of value 00888 * @return ultrasonic_distance_right value 00889 * @exception Exception thrown if index is out of bounds 00890 */ 00891 float 00892 NaoSensorInterface::ultrasonic_distance_right(unsigned int index) const 00893 { 00894 if (index > 4) { 00895 throw Exception("Index value %u out of bounds (0..4)", index); 00896 } 00897 return data->ultrasonic_distance_right[index]; 00898 } 00899 00900 /** Get maximum length of ultrasonic_distance_right value. 00901 * @return length of ultrasonic_distance_right value, can be length of the array or number of 00902 * maximum number of characters for a string 00903 */ 00904 size_t 00905 NaoSensorInterface::maxlenof_ultrasonic_distance_right() const 00906 { 00907 return 4; 00908 } 00909 00910 /** Set ultrasonic_distance_right value. 00911 * 00912 First four ultrasonic sensor readings from right receiver. Distance 00913 to detected object is in meters. 00914 00915 * @param new_ultrasonic_distance_right new ultrasonic_distance_right value 00916 */ 00917 void 00918 NaoSensorInterface::set_ultrasonic_distance_right(const float * new_ultrasonic_distance_right) 00919 { 00920 memcpy(data->ultrasonic_distance_right, new_ultrasonic_distance_right, sizeof(float) * 4); 00921 data_changed = true; 00922 } 00923 00924 /** Set ultrasonic_distance_right value at given index. 00925 * 00926 First four ultrasonic sensor readings from right receiver. Distance 00927 to detected object is in meters. 00928 00929 * @param new_ultrasonic_distance_right new ultrasonic_distance_right value 00930 * @param index index for of the value 00931 */ 00932 void 00933 NaoSensorInterface::set_ultrasonic_distance_right(unsigned int index, const float new_ultrasonic_distance_right) 00934 { 00935 if (index > 4) { 00936 throw Exception("Index value %u out of bounds (0..4)", index); 00937 } 00938 data->ultrasonic_distance_right[index] = new_ultrasonic_distance_right; 00939 data_changed = true; 00940 } 00941 /** Get ultrasonic_direction value. 00942 * 00943 Direction that was used to gather the ultrasonic readings. 00944 00945 * @return ultrasonic_direction value 00946 */ 00947 NaoSensorInterface::UltrasonicDirection 00948 NaoSensorInterface::ultrasonic_direction() const 00949 { 00950 return (NaoSensorInterface::UltrasonicDirection)data->ultrasonic_direction; 00951 } 00952 00953 /** Get maximum length of ultrasonic_direction value. 00954 * @return length of ultrasonic_direction value, can be length of the array or number of 00955 * maximum number of characters for a string 00956 */ 00957 size_t 00958 NaoSensorInterface::maxlenof_ultrasonic_direction() const 00959 { 00960 return 1; 00961 } 00962 00963 /** Set ultrasonic_direction value. 00964 * 00965 Direction that was used to gather the ultrasonic readings. 00966 00967 * @param new_ultrasonic_direction new ultrasonic_direction value 00968 */ 00969 void 00970 NaoSensorInterface::set_ultrasonic_direction(const UltrasonicDirection new_ultrasonic_direction) 00971 { 00972 data->ultrasonic_direction = new_ultrasonic_direction; 00973 data_changed = true; 00974 } 00975 00976 /** Get l_foot_bumper_l value. 00977 * Left foot bumper left side 00978 * @return l_foot_bumper_l value 00979 */ 00980 uint8_t 00981 NaoSensorInterface::l_foot_bumper_l() const 00982 { 00983 return data->l_foot_bumper_l; 00984 } 00985 00986 /** Get maximum length of l_foot_bumper_l value. 00987 * @return length of l_foot_bumper_l value, can be length of the array or number of 00988 * maximum number of characters for a string 00989 */ 00990 size_t 00991 NaoSensorInterface::maxlenof_l_foot_bumper_l() const 00992 { 00993 return 1; 00994 } 00995 00996 /** Set l_foot_bumper_l value. 00997 * Left foot bumper left side 00998 * @param new_l_foot_bumper_l new l_foot_bumper_l value 00999 */ 01000 void 01001 NaoSensorInterface::set_l_foot_bumper_l(const uint8_t new_l_foot_bumper_l) 01002 { 01003 data->l_foot_bumper_l = new_l_foot_bumper_l; 01004 data_changed = true; 01005 } 01006 01007 /** Get l_foot_bumper_r value. 01008 * Left foot bumper right side 01009 * @return l_foot_bumper_r value 01010 */ 01011 uint8_t 01012 NaoSensorInterface::l_foot_bumper_r() const 01013 { 01014 return data->l_foot_bumper_r; 01015 } 01016 01017 /** Get maximum length of l_foot_bumper_r value. 01018 * @return length of l_foot_bumper_r value, can be length of the array or number of 01019 * maximum number of characters for a string 01020 */ 01021 size_t 01022 NaoSensorInterface::maxlenof_l_foot_bumper_r() const 01023 { 01024 return 1; 01025 } 01026 01027 /** Set l_foot_bumper_r value. 01028 * Left foot bumper right side 01029 * @param new_l_foot_bumper_r new l_foot_bumper_r value 01030 */ 01031 void 01032 NaoSensorInterface::set_l_foot_bumper_r(const uint8_t new_l_foot_bumper_r) 01033 { 01034 data->l_foot_bumper_r = new_l_foot_bumper_r; 01035 data_changed = true; 01036 } 01037 01038 /** Get r_foot_bumper_l value. 01039 * Right foot bumper left side 01040 * @return r_foot_bumper_l value 01041 */ 01042 uint8_t 01043 NaoSensorInterface::r_foot_bumper_l() const 01044 { 01045 return data->r_foot_bumper_l; 01046 } 01047 01048 /** Get maximum length of r_foot_bumper_l value. 01049 * @return length of r_foot_bumper_l value, can be length of the array or number of 01050 * maximum number of characters for a string 01051 */ 01052 size_t 01053 NaoSensorInterface::maxlenof_r_foot_bumper_l() const 01054 { 01055 return 1; 01056 } 01057 01058 /** Set r_foot_bumper_l value. 01059 * Right foot bumper left side 01060 * @param new_r_foot_bumper_l new r_foot_bumper_l value 01061 */ 01062 void 01063 NaoSensorInterface::set_r_foot_bumper_l(const uint8_t new_r_foot_bumper_l) 01064 { 01065 data->r_foot_bumper_l = new_r_foot_bumper_l; 01066 data_changed = true; 01067 } 01068 01069 /** Get r_foot_bumper_r value. 01070 * Right foot bumper right side 01071 * @return r_foot_bumper_r value 01072 */ 01073 uint8_t 01074 NaoSensorInterface::r_foot_bumper_r() const 01075 { 01076 return data->r_foot_bumper_r; 01077 } 01078 01079 /** Get maximum length of r_foot_bumper_r value. 01080 * @return length of r_foot_bumper_r value, can be length of the array or number of 01081 * maximum number of characters for a string 01082 */ 01083 size_t 01084 NaoSensorInterface::maxlenof_r_foot_bumper_r() const 01085 { 01086 return 1; 01087 } 01088 01089 /** Set r_foot_bumper_r value. 01090 * Right foot bumper right side 01091 * @param new_r_foot_bumper_r new r_foot_bumper_r value 01092 */ 01093 void 01094 NaoSensorInterface::set_r_foot_bumper_r(const uint8_t new_r_foot_bumper_r) 01095 { 01096 data->r_foot_bumper_r = new_r_foot_bumper_r; 01097 data_changed = true; 01098 } 01099 01100 /** Get head_touch_front value. 01101 * Front part of head touch sensor (only Academics robot) 01102 * @return head_touch_front value 01103 */ 01104 uint8_t 01105 NaoSensorInterface::head_touch_front() const 01106 { 01107 return data->head_touch_front; 01108 } 01109 01110 /** Get maximum length of head_touch_front value. 01111 * @return length of head_touch_front value, can be length of the array or number of 01112 * maximum number of characters for a string 01113 */ 01114 size_t 01115 NaoSensorInterface::maxlenof_head_touch_front() const 01116 { 01117 return 1; 01118 } 01119 01120 /** Set head_touch_front value. 01121 * Front part of head touch sensor (only Academics robot) 01122 * @param new_head_touch_front new head_touch_front value 01123 */ 01124 void 01125 NaoSensorInterface::set_head_touch_front(const uint8_t new_head_touch_front) 01126 { 01127 data->head_touch_front = new_head_touch_front; 01128 data_changed = true; 01129 } 01130 01131 /** Get head_touch_middle value. 01132 * Middle part of head touch sensor (only Academics robot) 01133 * @return head_touch_middle value 01134 */ 01135 uint8_t 01136 NaoSensorInterface::head_touch_middle() const 01137 { 01138 return data->head_touch_middle; 01139 } 01140 01141 /** Get maximum length of head_touch_middle value. 01142 * @return length of head_touch_middle value, can be length of the array or number of 01143 * maximum number of characters for a string 01144 */ 01145 size_t 01146 NaoSensorInterface::maxlenof_head_touch_middle() const 01147 { 01148 return 1; 01149 } 01150 01151 /** Set head_touch_middle value. 01152 * Middle part of head touch sensor (only Academics robot) 01153 * @param new_head_touch_middle new head_touch_middle value 01154 */ 01155 void 01156 NaoSensorInterface::set_head_touch_middle(const uint8_t new_head_touch_middle) 01157 { 01158 data->head_touch_middle = new_head_touch_middle; 01159 data_changed = true; 01160 } 01161 01162 /** Get head_touch_rear value. 01163 * Rear part of head touch sensor (only Academics robot) 01164 * @return head_touch_rear value 01165 */ 01166 uint8_t 01167 NaoSensorInterface::head_touch_rear() const 01168 { 01169 return data->head_touch_rear; 01170 } 01171 01172 /** Get maximum length of head_touch_rear value. 01173 * @return length of head_touch_rear value, can be length of the array or number of 01174 * maximum number of characters for a string 01175 */ 01176 size_t 01177 NaoSensorInterface::maxlenof_head_touch_rear() const 01178 { 01179 return 1; 01180 } 01181 01182 /** Set head_touch_rear value. 01183 * Rear part of head touch sensor (only Academics robot) 01184 * @param new_head_touch_rear new head_touch_rear value 01185 */ 01186 void 01187 NaoSensorInterface::set_head_touch_rear(const uint8_t new_head_touch_rear) 01188 { 01189 data->head_touch_rear = new_head_touch_rear; 01190 data_changed = true; 01191 } 01192 01193 /** Get chest_button value. 01194 * Chest button state 01195 * @return chest_button value 01196 */ 01197 uint8_t 01198 NaoSensorInterface::chest_button() const 01199 { 01200 return data->chest_button; 01201 } 01202 01203 /** Get maximum length of chest_button value. 01204 * @return length of chest_button value, can be length of the array or number of 01205 * maximum number of characters for a string 01206 */ 01207 size_t 01208 NaoSensorInterface::maxlenof_chest_button() const 01209 { 01210 return 1; 01211 } 01212 01213 /** Set chest_button value. 01214 * Chest button state 01215 * @param new_chest_button new chest_button value 01216 */ 01217 void 01218 NaoSensorInterface::set_chest_button(const uint8_t new_chest_button) 01219 { 01220 data->chest_button = new_chest_button; 01221 data_changed = true; 01222 } 01223 01224 /** Get battery_charge value. 01225 * Battery charge 01226 * @return battery_charge value 01227 */ 01228 float 01229 NaoSensorInterface::battery_charge() const 01230 { 01231 return data->battery_charge; 01232 } 01233 01234 /** Get maximum length of battery_charge value. 01235 * @return length of battery_charge value, can be length of the array or number of 01236 * maximum number of characters for a string 01237 */ 01238 size_t 01239 NaoSensorInterface::maxlenof_battery_charge() const 01240 { 01241 return 1; 01242 } 01243 01244 /** Set battery_charge value. 01245 * Battery charge 01246 * @param new_battery_charge new battery_charge value 01247 */ 01248 void 01249 NaoSensorInterface::set_battery_charge(const float new_battery_charge) 01250 { 01251 data->battery_charge = new_battery_charge; 01252 data_changed = true; 01253 } 01254 01255 /* =========== message create =========== */ 01256 Message * 01257 NaoSensorInterface::create_message(const char *type) const 01258 { 01259 if ( strncmp("EmitUltrasonicWaveMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) { 01260 return new EmitUltrasonicWaveMessage(); 01261 } else if ( strncmp("StartUltrasonicMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) { 01262 return new StartUltrasonicMessage(); 01263 } else if ( strncmp("StopUltrasonicMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) { 01264 return new StopUltrasonicMessage(); 01265 } else { 01266 throw UnknownTypeException("The given type '%s' does not match any known " 01267 "message type for this interface type.", type); 01268 } 01269 } 01270 01271 01272 /** Copy values from other interface. 01273 * @param other other interface to copy values from 01274 */ 01275 void 01276 NaoSensorInterface::copy_values(const Interface *other) 01277 { 01278 const NaoSensorInterface *oi = dynamic_cast<const NaoSensorInterface *>(other); 01279 if (oi == NULL) { 01280 throw TypeMismatchException("Can only copy values from interface of same type (%s vs. %s)", 01281 type(), other->type()); 01282 } 01283 memcpy(data, oi->data, sizeof(NaoSensorInterface_data_t)); 01284 } 01285 01286 const char * 01287 NaoSensorInterface::enum_tostring(const char *enumtype, int val) const 01288 { 01289 if (strcmp(enumtype, "UltrasonicDirection") == 0) { 01290 return tostring_UltrasonicDirection((UltrasonicDirection)val); 01291 } 01292 throw UnknownTypeException("Unknown enum type %s", enumtype); 01293 } 01294 01295 /* =========== messages =========== */ 01296 /** @class NaoSensorInterface::EmitUltrasonicWaveMessage <interfaces/NaoSensorInterface.h> 01297 * EmitUltrasonicWaveMessage Fawkes BlackBoard Interface Message. 01298 * 01299 01300 */ 01301 01302 01303 /** Constructor with initial values. 01304 * @param ini_ultrasonic_direction initial value for ultrasonic_direction 01305 */ 01306 NaoSensorInterface::EmitUltrasonicWaveMessage::EmitUltrasonicWaveMessage(const UltrasonicDirection ini_ultrasonic_direction) : Message("EmitUltrasonicWaveMessage") 01307 { 01308 data_size = sizeof(EmitUltrasonicWaveMessage_data_t); 01309 data_ptr = malloc(data_size); 01310 memset(data_ptr, 0, data_size); 01311 data = (EmitUltrasonicWaveMessage_data_t *)data_ptr; 01312 data_ts = (message_data_ts_t *)data_ptr; 01313 data->ultrasonic_direction = ini_ultrasonic_direction; 01314 add_fieldinfo(IFT_ENUM, "ultrasonic_direction", 1, &data->ultrasonic_direction, "UltrasonicDirection"); 01315 } 01316 /** Constructor */ 01317 NaoSensorInterface::EmitUltrasonicWaveMessage::EmitUltrasonicWaveMessage() : Message("EmitUltrasonicWaveMessage") 01318 { 01319 data_size = sizeof(EmitUltrasonicWaveMessage_data_t); 01320 data_ptr = malloc(data_size); 01321 memset(data_ptr, 0, data_size); 01322 data = (EmitUltrasonicWaveMessage_data_t *)data_ptr; 01323 data_ts = (message_data_ts_t *)data_ptr; 01324 add_fieldinfo(IFT_ENUM, "ultrasonic_direction", 1, &data->ultrasonic_direction, "UltrasonicDirection"); 01325 } 01326 01327 /** Destructor */ 01328 NaoSensorInterface::EmitUltrasonicWaveMessage::~EmitUltrasonicWaveMessage() 01329 { 01330 free(data_ptr); 01331 } 01332 01333 /** Copy constructor. 01334 * @param m message to copy from 01335 */ 01336 NaoSensorInterface::EmitUltrasonicWaveMessage::EmitUltrasonicWaveMessage(const EmitUltrasonicWaveMessage *m) : Message("EmitUltrasonicWaveMessage") 01337 { 01338 data_size = m->data_size; 01339 data_ptr = malloc(data_size); 01340 memcpy(data_ptr, m->data_ptr, data_size); 01341 data = (EmitUltrasonicWaveMessage_data_t *)data_ptr; 01342 data_ts = (message_data_ts_t *)data_ptr; 01343 } 01344 01345 /* Methods */ 01346 /** Get ultrasonic_direction value. 01347 * 01348 Direction that was used to gather the ultrasonic readings. 01349 01350 * @return ultrasonic_direction value 01351 */ 01352 NaoSensorInterface::UltrasonicDirection 01353 NaoSensorInterface::EmitUltrasonicWaveMessage::ultrasonic_direction() const 01354 { 01355 return (NaoSensorInterface::UltrasonicDirection)data->ultrasonic_direction; 01356 } 01357 01358 /** Get maximum length of ultrasonic_direction value. 01359 * @return length of ultrasonic_direction value, can be length of the array or number of 01360 * maximum number of characters for a string 01361 */ 01362 size_t 01363 NaoSensorInterface::EmitUltrasonicWaveMessage::maxlenof_ultrasonic_direction() const 01364 { 01365 return 1; 01366 } 01367 01368 /** Set ultrasonic_direction value. 01369 * 01370 Direction that was used to gather the ultrasonic readings. 01371 01372 * @param new_ultrasonic_direction new ultrasonic_direction value 01373 */ 01374 void 01375 NaoSensorInterface::EmitUltrasonicWaveMessage::set_ultrasonic_direction(const UltrasonicDirection new_ultrasonic_direction) 01376 { 01377 data->ultrasonic_direction = new_ultrasonic_direction; 01378 } 01379 01380 /** Clone this message. 01381 * Produces a message of the same type as this message and copies the 01382 * data to the new message. 01383 * @return clone of this message 01384 */ 01385 Message * 01386 NaoSensorInterface::EmitUltrasonicWaveMessage::clone() const 01387 { 01388 return new NaoSensorInterface::EmitUltrasonicWaveMessage(this); 01389 } 01390 /** @class NaoSensorInterface::StartUltrasonicMessage <interfaces/NaoSensorInterface.h> 01391 * StartUltrasonicMessage Fawkes BlackBoard Interface Message. 01392 * 01393 01394 */ 01395 01396 01397 /** Constructor with initial values. 01398 * @param ini_ultrasonic_direction initial value for ultrasonic_direction 01399 */ 01400 NaoSensorInterface::StartUltrasonicMessage::StartUltrasonicMessage(const UltrasonicDirection ini_ultrasonic_direction) : Message("StartUltrasonicMessage") 01401 { 01402 data_size = sizeof(StartUltrasonicMessage_data_t); 01403 data_ptr = malloc(data_size); 01404 memset(data_ptr, 0, data_size); 01405 data = (StartUltrasonicMessage_data_t *)data_ptr; 01406 data_ts = (message_data_ts_t *)data_ptr; 01407 data->ultrasonic_direction = ini_ultrasonic_direction; 01408 add_fieldinfo(IFT_ENUM, "ultrasonic_direction", 1, &data->ultrasonic_direction, "UltrasonicDirection"); 01409 } 01410 /** Constructor */ 01411 NaoSensorInterface::StartUltrasonicMessage::StartUltrasonicMessage() : Message("StartUltrasonicMessage") 01412 { 01413 data_size = sizeof(StartUltrasonicMessage_data_t); 01414 data_ptr = malloc(data_size); 01415 memset(data_ptr, 0, data_size); 01416 data = (StartUltrasonicMessage_data_t *)data_ptr; 01417 data_ts = (message_data_ts_t *)data_ptr; 01418 add_fieldinfo(IFT_ENUM, "ultrasonic_direction", 1, &data->ultrasonic_direction, "UltrasonicDirection"); 01419 } 01420 01421 /** Destructor */ 01422 NaoSensorInterface::StartUltrasonicMessage::~StartUltrasonicMessage() 01423 { 01424 free(data_ptr); 01425 } 01426 01427 /** Copy constructor. 01428 * @param m message to copy from 01429 */ 01430 NaoSensorInterface::StartUltrasonicMessage::StartUltrasonicMessage(const StartUltrasonicMessage *m) : Message("StartUltrasonicMessage") 01431 { 01432 data_size = m->data_size; 01433 data_ptr = malloc(data_size); 01434 memcpy(data_ptr, m->data_ptr, data_size); 01435 data = (StartUltrasonicMessage_data_t *)data_ptr; 01436 data_ts = (message_data_ts_t *)data_ptr; 01437 } 01438 01439 /* Methods */ 01440 /** Get ultrasonic_direction value. 01441 * 01442 Direction that was used to gather the ultrasonic readings. 01443 01444 * @return ultrasonic_direction value 01445 */ 01446 NaoSensorInterface::UltrasonicDirection 01447 NaoSensorInterface::StartUltrasonicMessage::ultrasonic_direction() const 01448 { 01449 return (NaoSensorInterface::UltrasonicDirection)data->ultrasonic_direction; 01450 } 01451 01452 /** Get maximum length of ultrasonic_direction value. 01453 * @return length of ultrasonic_direction value, can be length of the array or number of 01454 * maximum number of characters for a string 01455 */ 01456 size_t 01457 NaoSensorInterface::StartUltrasonicMessage::maxlenof_ultrasonic_direction() const 01458 { 01459 return 1; 01460 } 01461 01462 /** Set ultrasonic_direction value. 01463 * 01464 Direction that was used to gather the ultrasonic readings. 01465 01466 * @param new_ultrasonic_direction new ultrasonic_direction value 01467 */ 01468 void 01469 NaoSensorInterface::StartUltrasonicMessage::set_ultrasonic_direction(const UltrasonicDirection new_ultrasonic_direction) 01470 { 01471 data->ultrasonic_direction = new_ultrasonic_direction; 01472 } 01473 01474 /** Clone this message. 01475 * Produces a message of the same type as this message and copies the 01476 * data to the new message. 01477 * @return clone of this message 01478 */ 01479 Message * 01480 NaoSensorInterface::StartUltrasonicMessage::clone() const 01481 { 01482 return new NaoSensorInterface::StartUltrasonicMessage(this); 01483 } 01484 /** @class NaoSensorInterface::StopUltrasonicMessage <interfaces/NaoSensorInterface.h> 01485 * StopUltrasonicMessage Fawkes BlackBoard Interface Message. 01486 * 01487 01488 */ 01489 01490 01491 /** Constructor */ 01492 NaoSensorInterface::StopUltrasonicMessage::StopUltrasonicMessage() : Message("StopUltrasonicMessage") 01493 { 01494 data_size = sizeof(StopUltrasonicMessage_data_t); 01495 data_ptr = malloc(data_size); 01496 memset(data_ptr, 0, data_size); 01497 data = (StopUltrasonicMessage_data_t *)data_ptr; 01498 data_ts = (message_data_ts_t *)data_ptr; 01499 } 01500 01501 /** Destructor */ 01502 NaoSensorInterface::StopUltrasonicMessage::~StopUltrasonicMessage() 01503 { 01504 free(data_ptr); 01505 } 01506 01507 /** Copy constructor. 01508 * @param m message to copy from 01509 */ 01510 NaoSensorInterface::StopUltrasonicMessage::StopUltrasonicMessage(const StopUltrasonicMessage *m) : Message("StopUltrasonicMessage") 01511 { 01512 data_size = m->data_size; 01513 data_ptr = malloc(data_size); 01514 memcpy(data_ptr, m->data_ptr, data_size); 01515 data = (StopUltrasonicMessage_data_t *)data_ptr; 01516 data_ts = (message_data_ts_t *)data_ptr; 01517 } 01518 01519 /* Methods */ 01520 /** Clone this message. 01521 * Produces a message of the same type as this message and copies the 01522 * data to the new message. 01523 * @return clone of this message 01524 */ 01525 Message * 01526 NaoSensorInterface::StopUltrasonicMessage::clone() const 01527 { 01528 return new NaoSensorInterface::StopUltrasonicMessage(this); 01529 } 01530 /** Check if message is valid and can be enqueued. 01531 * @param message Message to check 01532 * @return true if the message is valid, false otherwise. 01533 */ 01534 bool 01535 NaoSensorInterface::message_valid(const Message *message) const 01536 { 01537 const EmitUltrasonicWaveMessage *m0 = dynamic_cast<const EmitUltrasonicWaveMessage *>(message); 01538 if ( m0 != NULL ) { 01539 return true; 01540 } 01541 const StartUltrasonicMessage *m1 = dynamic_cast<const StartUltrasonicMessage *>(message); 01542 if ( m1 != NULL ) { 01543 return true; 01544 } 01545 const StopUltrasonicMessage *m2 = dynamic_cast<const StopUltrasonicMessage *>(message); 01546 if ( m2 != NULL ) { 01547 return true; 01548 } 01549 return false; 01550 } 01551 01552 /// @cond INTERNALS 01553 EXPORT_INTERFACE(NaoSensorInterface) 01554 /// @endcond 01555 01556 01557 } // end namespace fawkes