omni_global.cpp

00001
00002 /***************************************************************************
00003  *  omni_relative.cpp - Implementation of the relative ball model
00004  *                      for the omni cam
00005  *
00006  *  Created: Thu Mar 23 22:00:15 2006
00007  *  Copyright  2006-2008  Tim Niemueller [www.niemueller.de]
00008  *
00009  ****************************************************************************/
00010
00011 /*  This program is free software; you can redistribute it and/or modify
00012  *  it under the terms of the GNU General Public License as published by
00013  *  the Free Software Foundation; either version 2 of the License, or
00014  *  (at your option) any later version. A runtime exception applies to
00015  *  this software (see LICENSE.GPL_WRE file mentioned below for details).
00016  *
00017  *  This program is distributed in the hope that it will be useful,
00018  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020  *  GNU Library General Public License for more details.
00021  *
00022  *  Read the full text in the LICENSE.GPL_WRE file in the doc directory.
00023  */
00024
00025 #include <models/global_position/omni_global.h>
00026 #include <models/mirror/mirrormodel.h>
00027 
00028 /** @class OmniGlobal <models/global_position/omni_global.h>
00029  * Omni vision global position model.
00030  */
00031 
00032 /** Constructor.
00033  * @param mirror_model mirror model
00034  */
00035 OmniGlobal::OmniGlobal(MirrorModel *mirror_model)
00036 {
00037   this->mirror_model = mirror_model;
00038
00039   ball_x = ball_y = 0.f;
00040 }
00041
00042
00043 void
00044 OmniGlobal::set_position_in_image(unsigned int x, unsigned int y)
00045 {
00046   image_x = x;
00047   image_y = y;
00048 }
00049
00050
00051 void
00052 OmniGlobal::set_robot_position(float x, float y, float ori)
00053 {
00054   pose_x   = x;
00055   pose_y   = y;
00056   pose_ori = ori;
00057 }
00058
00059
00060 float
00061 OmniGlobal::get_y(void) const
00062 {
00063   return ball_y;
00064 }
00065
00066
00067 float
00068 OmniGlobal::get_x(void) const
00069 {
00070   return ball_x;
00071 }
00072
00073
00074 void
00075 OmniGlobal::calc()
00076 {
00077   if ( mirror_model->isValidPoint( image_x, image_y ) ) {
00078
00079     fawkes::cart_coord_2d_t glob_pos = mirror_model->getWorldPointGlobal( image_x,
00080                                                                           image_y,
00081                                                                           pose_x,
00082                                                                           pose_y,
00083                                                                           pose_ori);
00084
00085     ball_x = glob_pos.x;
00086     ball_y = glob_pos.y;
00087   }
00088 }
00089
00090
00091 bool
00092 OmniGlobal::is_pos_valid() const
00093 {
00094   return mirror_model->isValidPoint( image_x, image_y );
00095 }