runCoordinate.cpp

00001 /*
00002   自己位置取得コマンド実装
00003   Satofumi KAMIMURA
00004   $Id$
00005 */
00006 
00007 #include "runCtrl.h"
00008 
00009 
00010 VXV::Position3D RunCtrl::getLocalPosition(void) {
00011   int x, y;
00012   long div16;
00013   if (recvGetPosition(&x, &y, &div16) < 0) {
00014     throw RunCtrl_Exception("Transmit fail: in recvGetPosition()");
00015   }
00016 
00017   crd_ticks = getModuleTicks(updateTicksDiff(tbl->sec * 1000 + tbl->msec));
00018   crd_position =
00019     VXV::Position(x, y, VXV::Direction::rad(2.0*M_PI* div16 / 0x10000));
00020   convertWithAngle(crd_position, crd_position, local_offset);
00021 
00022   return crd_position;
00023 }
00024 
00025 
00026 VXV::Position RunCtrl::getRunPosition(const CoordinateCtrl* crd) {
00027   return getCrdPosition(crd, getLocalPosition());
00028 }
00029 
00030 
00031 void RunCtrl::adjustRunPosition(const VXV::Position& position,
00032                                 const CoordinateCtrl* crd) {
00033 
00034   local_offset = VXV::Position();
00035   VXV::Position actual = getRunPosition();
00036   local_offset = position - actual;
00037 
00038   if (crd_auto) {
00039     VXV::Position send_offset = getCrdPosition(crd, local_offset);
00040     sendUpdatedPosition(this, send_offset);
00041   }
00042 }
00043 
00044 
00045 void RunCtrl::coordinateUpdateDetect(bool on) {
00046   crd_auto = on;
00047 }
00048 
00049 
00050 void RunCtrl::sendUpdatedPosition(const CoordinateCtrl* crd,
00051                                   const VXV::Position& position) {
00052   VXV::Position run_pos = getCrdPosition(crd, position);
00053   if (sendChangeCoordinateOffset(run_pos.x, run_pos.y,
00054                                  static_cast<int>(0x10000 * run_pos.zt.to_rad()
00055                                                   / (2.0 * M_PI))) < 0) {
00056     throw RunCtrl_Exception("Transmit fail: in sendChangeCoordinateOffset()");
00057   }
00058 }
00059 

Generated on Mon Apr 13 22:52:04 2009 by  doxygen 1.5.7.1