forked from rtv/Stage
/
p_bumper.cc.TODO
135 lines (110 loc) · 3.67 KB
/
p_bumper.cc.TODO
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
* Player - One Hell of a Robot Server
* Copyright (C) 2004, 2005 Richard Vaughan
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
/*
* Desc: A plugin driver for Player that gives access to Stage devices.
* Author: Richard Vaughan
* Date: 10 December 2004
* CVS: $Id$
*/
// DOCUMENTATION ------------------------------------------------------------
/** @addtogroup player
@par Bumper interface
- PLAYER_BUMPER_DATA_STATE
- PLAYER_BUMPER_GET_GEOM
*/
// CODE ----------------------------------------------------------------------
#include "p_driver.h"
//
// BUMPER INTERFACE
//
extern "C" {
int bumper_init( model_t* mod );
}
InterfaceBumper::InterfaceBumper( player_devaddr_t id,
StgDriver* driver,
ConfigFile* cf,
int section )
: InterfaceModel( id, driver, cf, section, bumper_init )
{
}
void InterfaceBumper::Publish( void )
{
size_t len = mod->data_len;
bumper_sample_t* sdata = (bumper_sample_t*)mod->data;
player_bumper_data_t pdata;
memset( &pdata, 0, sizeof(pdata) );
if( len > 0 )
{
size_t bcount = len / sizeof(bumper_sample_t);
// limit the number of samples to Player's maximum
if( bcount > PLAYER_BUMPER_MAX_SAMPLES )
bcount = PLAYER_BUMPER_MAX_SAMPLES;
pdata.bumpers_count = bcount;
for( int i=0; i<(int)bcount; i++ )
pdata.bumpers[i] = sdata[i].hit ? 1 : 0;
}
this->driver->Publish( this->addr, NULL,
PLAYER_MSGTYPE_DATA,
PLAYER_BUMPER_DATA_STATE,
&pdata, sizeof(pdata), NULL);
}
int InterfaceBumper::ProcessMessage( MessageQueue* resp_queue,
player_msghdr_t* hdr,
void* data )
{
if( Message::MatchMessage(hdr, PLAYER_MSGTYPE_REQ,
PLAYER_BUMPER_GET_GEOM,
this->addr) )
{
size_t cfglen = mod->cfg_len;
bumper_config_t* cfgs = (bumper_config_t*)mod->cfg;
assert( cfgs );
size_t bcount = cfglen / sizeof(bumper_config_t);
// convert the bumper data into Player-format bumper poses
player_bumper_geom_t pgeom;
memset( &pgeom, 0, sizeof(pgeom) );
// limit the number of samples to Player's maximum
if( bcount > PLAYER_BUMPER_MAX_SAMPLES )
bcount = PLAYER_BUMPER_MAX_SAMPLES;
pgeom.bumper_def_count = bcount;
for( int i=0; i<(int)bcount; i++ )
{
// fill in the geometry data formatted player-like
pgeom.bumper_def[i].pose.px = cfgs[i].pose.x;
pgeom.bumper_def[i].pose.py = cfgs[i].pose.y;
pgeom.bumper_def[i].pose.pa = cfgs[i].pose.a;
pgeom.bumper_def[i].length = cfgs[i].length;
pgeom.bumper_def[i].radius = 0;
}
this->driver->Publish( this->addr, resp_queue,
PLAYER_MSGTYPE_RESP_ACK,
PLAYER_BUMPER_GET_GEOM,
(void*)&pgeom, sizeof(pgeom), NULL );
return 0; // ok
}
else
{
// Don't know how to handle this message.
PRINT_WARN2( "bumper doesn't support msg with type/subtype %d/%d",
hdr->type, hdr->subtype);
return(-1);
}
}