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
00026
00027
00028
00029
00030
00040
00041
00042
00043
00044
00045
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
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
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
00105
00106
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
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
00138 player_fiducial_id_t* incoming = (player_fiducial_id_t*)data;
00139
00140
00141 int id = incoming->id;
00142
00143 mod->SetFiducialReturn( id );
00144
00145 player_fiducial_id_t pid;
00146 pid.id = id;
00147
00148
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);
00159 }
00160 }
00161 else if(Message::MatchMessage(hdr, PLAYER_MSGTYPE_REQ,
00162 PLAYER_FIDUCIAL_REQ_GET_ID,
00163 this->addr))
00164 {
00165
00166
00167 player_fiducial_id_t pid;
00168 pid.id = mod->GetFiducialReturn();
00169
00170
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
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223 else
00224 {
00225
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