p_fiducial.cc
Go to the documentation of this file.
00001 /*
00002  *  Player - One Hell of a Robot Server
00003  *  Copyright (C) 2004, 2005 Richard Vaughan
00004  *
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  */
00021 
00022 /*
00023  * Desc: A plugin driver for Player that gives access to Stage devices.
00024  * Author: Richard Vaughan
00025  * Date: 10 December 2004
00026  * CVS: $Id$
00027  */
00028 
00029 // DOCUMENTATION
00030 
00040 /* TODO
00041         - PLAYER_FIDUCIAL_REQ_SET_FOV
00042         - PLAYER_FIDUCIAL_REQ_GET_FOV
00043 */
00044 
00045 // CODE
00046 
00047 #include "p_driver.h"
00048 using namespace Stg;
00049 
00050 
00051 InterfaceFiducial::InterfaceFiducial(  player_devaddr_t addr,
00052                                                                                                         StgDriver* driver,
00053                                                                                                         ConfigFile* cf,
00054                                                                                                         int section )
00055   : InterfaceModel( addr, driver, cf, section, "fiducial" )
00056 {
00057 }
00058 
00059 void InterfaceFiducial::Publish( void )
00060 {
00061   player_fiducial_data_t pdata;
00062   memset( &pdata, 0, sizeof(pdata) );
00063   
00064         std::vector<ModelFiducial::Fiducial>& fids = 
00065                 ((ModelFiducial*)mod)->GetFiducials();  
00066         
00067         pdata.fiducials_count = fids.size();
00068 
00069         if( pdata.fiducials_count > 0 )
00070     {
00071                         pdata.fiducials = new player_fiducial_item_t[pdata.fiducials_count];
00072                         
00073       for( unsigned int i=0; i<pdata.fiducials_count; i++ )
00074                                 {
00075                                         pdata.fiducials[i].id = fids[i].id;                                     
00076 
00077                                         // 2D x,y only
00078                                         double xpos = fids[i].range * cos(fids[i].bearing);
00079                                         double ypos = fids[i].range * sin(fids[i].bearing);
00080                                         
00081                                         pdata.fiducials[i].pose.px = xpos;
00082                                         pdata.fiducials[i].pose.py = ypos;
00083                                         pdata.fiducials[i].pose.pz = 0.0;
00084                                         pdata.fiducials[i].pose.proll = 0.0;
00085                                         pdata.fiducials[i].pose.ppitch = 0.0;
00086                                         pdata.fiducials[i].pose.pyaw = fids[i].geom.a;
00087                                 }
00088     }
00089         
00090   // publish this data
00091   this->driver->Publish( this->addr,
00092                                                                                                  PLAYER_MSGTYPE_DATA,
00093                                                                                                  PLAYER_FIDUCIAL_DATA_SCAN,
00094                                                                                                  &pdata, sizeof(pdata), NULL);
00095         
00096   if ( pdata.fiducials )
00097                 delete [] pdata.fiducials;
00098 }
00099 
00100 int InterfaceFiducial::ProcessMessage(QueuePointer& resp_queue,
00101                                                                                                   player_msghdr_t* hdr,
00102                                                                                                   void* data )
00103 {
00104   //printf("got fiducial request\n");
00105 
00106   // Is it a request to get the geometry?
00107   if(Message::MatchMessage(hdr, PLAYER_MSGTYPE_REQ,
00108                            PLAYER_FIDUCIAL_REQ_GET_GEOM,
00109                            this->addr))
00110     {
00111       Geom geom = mod->GetGeom();
00112       Pose pose = mod->GetPose();
00113 
00114       // fill in the geometry data formatted player-like
00115       player_laser_geom_t pgeom;
00116       pgeom.pose.px = pose.x;
00117       pgeom.pose.py = pose.y;
00118       pgeom.pose.pz = pose.z;
00119       pgeom.pose.proll = 0.0;
00120       pgeom.pose.ppitch = 0.0;
00121       pgeom.pose.pyaw = pose.a;
00122       pgeom.size.sl = geom.size.x;
00123       pgeom.size.sw = geom.size.y;
00124 
00125       this->driver->Publish(this->addr, resp_queue,
00126                                                                          PLAYER_MSGTYPE_RESP_ACK,
00127                                                                          PLAYER_FIDUCIAL_REQ_GET_GEOM,
00128                                                                          (void*)&pgeom, sizeof(pgeom), NULL);
00129       return(0);
00130     }
00131   else if(Message::MatchMessage(hdr, PLAYER_MSGTYPE_REQ,
00132                                                                                   PLAYER_FIDUCIAL_REQ_SET_ID,
00133                                                                                   this->addr))
00134     {
00135       if( hdr->size == sizeof(player_fiducial_id_t) )
00136                   {
00137                          // copy the new ID
00138                          player_fiducial_id_t* incoming = (player_fiducial_id_t*)data;
00139 
00140                          // Stage uses a simple int for IDs.
00141                          int id = incoming->id;
00142 
00143                          mod->SetFiducialReturn( id );
00144 
00145                          player_fiducial_id_t pid;
00146                          pid.id = id;
00147 
00148                          // acknowledge, including the new ID
00149                          this->driver->Publish(this->addr, resp_queue,
00150                                                                                   PLAYER_MSGTYPE_RESP_ACK,
00151                                                                                   PLAYER_FIDUCIAL_REQ_SET_ID,
00152                                                                                   (void*)&pid, sizeof(pid) );
00153                   }
00154       else
00155                   {
00156                          PRINT_ERR2("Incorrect packet size setting fiducial ID (%d/%d)",
00157                                                         (int)hdr->size, (int)sizeof(player_fiducial_id_t) );
00158                          return(-1); // error - NACK is sent automatically
00159                   }
00160     }
00161   else if(Message::MatchMessage(hdr, PLAYER_MSGTYPE_REQ,
00162                                                                                   PLAYER_FIDUCIAL_REQ_GET_ID,
00163                                                                                   this->addr))
00164     {
00165       // fill in the data formatted player-like
00166 
00167       player_fiducial_id_t pid;
00168                 pid.id = mod->GetFiducialReturn();
00169                 
00170       // acknowledge, including the new ID
00171       this->driver->Publish(this->addr, resp_queue,
00172                                                                          PLAYER_MSGTYPE_RESP_ACK,
00173                                                                          PLAYER_FIDUCIAL_REQ_GET_ID,
00174                                                                          (void*)&pid, sizeof(pid) );
00175     }
00176   /*    case PLAYER_FIDUCIAL_SET_FOV:
00177 
00178                   if( len == sizeof(player_fiducial_fov_t) )
00179                   {
00180                   player_fiducial_fov_t* pfov = (player_fiducial_fov_t*)src;
00181 
00182                   // convert from player to stage FOV packets
00183                   fiducial_config_t setcfg;
00184                   memset( &setcfg, 0, sizeof(setcfg) );
00185                   setcfg.min_range = (uint16_t)ntohs(pfov->min_range) / 1000.0;
00186                   setcfg.max_range_id = (uint16_t)ntohs(pfov->max_range) / 1000.0;
00187                   setcfg.max_range_anon = setcfg.max_range_id;
00188                   setcfg.fov = DTOR((uint16_t)ntohs(pfov->view_angle));
00189 
00190                   //printf( "setting fiducial FOV to min %f max %f fov %f\n",
00191                   //  setcfg.min_range, setcfg.max_range_anon, setcfg.fov );
00192 
00193                   //model_set_config( this->mod, &setcfg, sizeof(setcfg));
00194                   model_set_property( this->mod, "fiducial_cfg",
00195                   &setcfg, sizeof(setcfg));
00196                   }
00197                   else
00198                   PRINT_ERR2("Incorrect packet size setting fiducial FOV (%d/%d)",
00199                   (int)len, (int)sizeof(player_fiducial_fov_t) );
00200 
00201                   // deliberate no-break - SET_FOV needs the current FOV as a reply
00202 
00203                   case PLAYER_FIDUCIAL_GET_FOV:
00204                   {
00205                   fiducial_config_t *cfg = (fiducial_config_t*)
00206                   model_get_property_fixed( this->mod, "fiducial_cfg", sizeof(fiducial_config_t));
00207                   assert(cfg);
00208 
00209                   // fill in the geometry data formatted player-like
00210                   player_fiducial_fov_t pfov;
00211                   pfov.min_range = htons((uint16_t)(1000.0 * cfg->min_range));
00212                   pfov.max_range = htons((uint16_t)(1000.0 * cfg->max_range_anon));
00213                   pfov.view_angle = htons((uint16_t)RTOD(cfg->fov));
00214 
00215                   if( this->driver->PutReply(  this->id, client, PLAYER_MSGTYPE_RESP_ACK,
00216                   &pfov, sizeof(pfov), NULL ) != 0 )
00217                   DRIVER_ERROR("PutReply() failed for "
00218                   "PLAYER_FIDUCIAL_GET_FOV or PLAYER_FIDUCIAL_SET_FOV");
00219                   }
00220                   break;
00221   */
00222 
00223   else
00224     {
00225       // Don't know how to handle this message.
00226       PRINT_WARN2( "fiducial doesn't support msg with type/subtype %d/%d",
00227                                                  hdr->type, hdr->subtype);
00228       return(-1);
00229     }
00230 
00231   return 0;
00232 }
00233 


stage
Author(s): Richard Vaughan , Brian Gerkey , Reed Hedges , Andrew Howard , Toby Collett , Pooya Karimian , Jeremy Asher , Alex Couture-Beil , Geoff Biggs , Rich Mattes , Abbas Sadat
autogenerated on Thu Aug 27 2015 15:20:57