[r9122]: code / player / trunk / client_libs / libplayerc++ / rangerproxy.cc Maximize Restore History

Download this file

rangerproxy.cc    208 lines (184 with data), 7.2 kB

  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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/*
* Player - One Hell of a Robot Server
* Copyright (C) 2000-2003
* Brian Gerkey, Kasper Stoy, Richard Vaughan, & Andrew Howard
*
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
/********************************************************************
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
********************************************************************/
#include "config.h"
#include "playerc++.h"
using namespace PlayerCc;
RangerProxy::RangerProxy(PlayerClient *aPc, uint32_t aIndex)
: ClientProxy(aPc, aIndex),
mDevice(NULL)
{
Subscribe(aIndex);
mInfo = &(mDevice->info);
try {
RequestConfigure();
RequestGeom();
}
catch(PlayerCc::PlayerError & e){
}
}
RangerProxy::~RangerProxy()
{
Unsubscribe();
}
void RangerProxy::Subscribe(uint32_t aIndex)
{
scoped_lock_t lock(mPc->mMutex);
mDevice = playerc_ranger_create(mClient, aIndex);
if (mDevice == NULL)
throw PlayerError("RangerProxy::RangerProxy()", "could not create");
if (playerc_ranger_subscribe(mDevice, PLAYER_OPEN_MODE) != 0)
throw PlayerError("RangerProxy::RangerProxy()", "could not subscribe");
}
void RangerProxy::Unsubscribe()
{
assert(mDevice != NULL);
scoped_lock_t lock(mPc->mMutex);
playerc_ranger_unsubscribe(mDevice);
playerc_ranger_destroy(mDevice);
mDevice = NULL;
}
player_pose3d_t RangerProxy::GetElementPose(uint32_t aIndex) const
{
if (aIndex >= mDevice->element_count)
throw PlayerError("RangerProxy::GetSensorPose", "index out of bounds");
return GetVar(mDevice->element_poses[aIndex]);
}
player_bbox3d_t RangerProxy::GetElementSize(uint32_t aIndex) const
{
if (aIndex >= mDevice->element_count)
throw PlayerError("RangerProxy::GetSensorSize", "index out of bounds");
return GetVar(mDevice->element_sizes[aIndex]);
}
double RangerProxy::GetRange(uint32_t aIndex) const
{
if (aIndex >= mDevice->ranges_count)
throw PlayerError("RangerProxy::GetRange", "index out of bounds");
return GetVar(mDevice->ranges[aIndex]);
}
player_point_3d_t RangerProxy::GetPoint(uint32_t aIndex) const
{
if (aIndex >= mDevice->points_count)
throw PlayerError("RangerProxy::GetPoint", "index out of bounds");
return GetVar(mDevice->points[aIndex]);
}
double RangerProxy::GetIntensity(uint32_t aIndex) const
{
if (aIndex >= mDevice->intensities_count)
throw PlayerError("RangerProxy::GetIntensity", "index out of bounds");
return GetVar(mDevice->intensities[aIndex]);
}
void RangerProxy::SetPower(bool aEnable)
{
scoped_lock_t lock(mPc->mMutex);
if (playerc_ranger_power_config(mDevice, aEnable ? 1 : 0) != 0)
throw PlayerError("RangerProxy::SetPower()", "error setting power");
}
void RangerProxy::SetIntensityData(bool aEnable)
{
scoped_lock_t lock(mPc->mMutex);
if (playerc_ranger_intns_config(mDevice, aEnable ? 1 : 0) != 0)
throw PlayerError("RangerProxy::SetIntensityData()", "error setting power");
}
void RangerProxy::RequestGeom()
{
scoped_lock_t lock(mPc->mMutex);
if (playerc_ranger_get_geom(mDevice) != 0)
throw PlayerError("RangerProxy::RequestGeom()", "error requesting geometry");
}
void RangerProxy::Configure(double aMinAngle, double aMaxAngle, double aAngularRes,
double aMinRange, double aMaxRange, double aRangeRes,
double aFrequency)
{
scoped_lock_t lock(mPc->mMutex);
if (0 != playerc_ranger_set_config(mDevice, aMinAngle, aMaxAngle, aAngularRes,
aMinRange, aMaxRange, aRangeRes, aFrequency))
throw PlayerError("RangerProxy::Configure()", "error setting config");
}
void RangerProxy::RequestConfigure()
{
scoped_lock_t lock(mPc->mMutex);
if (0 != playerc_ranger_get_config(mDevice, NULL, NULL, NULL, NULL, NULL, NULL, NULL))
throw PlayerError("RangerProxy::RequestConfigure()", "error getting config");
}
std::ostream& std::operator << (std::ostream &os, const PlayerCc::RangerProxy &c)
{
player_pose3d_t pose;
player_bbox3d_t size;
os << "#Ranger (" << c.GetInterface() << ":" << c.GetIndex() << ")" << std::endl;
pose = c.GetDevicePose ();
os << "Device pose: (" << pose.px << ", " << pose.py << ", " << pose.pz << "), (" <<
pose.proll << ", " << pose.ppitch << ", " << pose.pyaw << ")" << endl;
size = c.GetDeviceSize ();
os << "Device size: (" << size.sw << ", " << size.sl << ", " << size.sh << ")" << endl;
if (c.GetElementCount() > 0)
{
os << c.GetElementCount() << " sensors:" << endl;
for (uint32_t ii = 0; ii < c.GetElementCount(); ii++)
{
pose = c.GetElementPose(ii);
size = c.GetElementSize(ii);
os << " Pose: (" << pose.px << ", " << pose.py << ", " << pose.pz << "), (" <<
pose.proll << ", " << pose.ppitch << ", " << pose.pyaw << ")" << "\tSize: (" <<
size.sw << ", " << size.sl << ", " << size.sh << ")" << endl;
}
}
os << "Configuration: " << endl;
os << "Minimum angle: " << c.GetMinAngle () << "\tMaximum angle: " << c.GetMaxAngle () <<
"\tAngular resolution: " << c.GetAngularRes () << endl;
os << "Minimum range: " << c.GetMinRange () << "\tMaximum range: " << c.GetMaxRange () <<
"\tRange resolution: " << c.GetRangeRes () << endl;
os << "Scanning frequency: " << c.GetFrequency () << endl;
if (c.GetRangeCount() > 0)
{
os << c.GetRangeCount() << " range readings:" << endl << " [";
uint32_t ii;
for (ii = 0; ii < c.GetRangeCount() - 1; ii++)
os << c.GetRange(ii) << ", ";
os << c.GetRange(ii) << "]" << endl;
}
if (c.GetIntensityCount() > 0)
{
os << c.GetIntensityCount() << " intensity readings:" << endl << " [";
uint32_t ii;
for (ii = 0; ii < c.GetIntensityCount() - 1; ii++)
os << c.GetIntensity(ii) << ", ";
os << c.GetIntensity(ii) << "]" << endl;
}
return os;
}