Update of /cvsroot/playerstage/code/player/client_libs/libplayerc++
In directory 
sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22655/client_libs/libplayerc++

Modified Files:
        Makefile.am playerc++.h 
Added Files:
        rangerproxy.cc 
Log Message:
added geoffs ranger interface


--- NEW FILE: rangerproxy.cc ---
/*
 *  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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

#if HAVE_CONFIG_H
#include "config.h"
#endif

#include "playerc++.h"

using namespace PlayerCc;

RangerProxy::RangerProxy(PlayerClient *aPc, uint aIndex)
  : ClientProxy(aPc, aIndex),
  mDevice(NULL)
{
  Subscribe(aIndex);
  mInfo = &(mDevice->info);
}

RangerProxy::~RangerProxy()
{
  Unsubscribe();
}

void RangerProxy::Subscribe(uint 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::GetSensorPose(uint aIndex) const
{
  if (aIndex > mDevice->sensor_count)
    throw PlayerError("RangerProxy::GetSensorPose", "index out of bounds");
  return GetVar(mDevice->sensor_poses[aIndex]);
}

player_bbox3d_t RangerProxy::GetSensorSize(uint aIndex) const
{
  if (aIndex > mDevice->sensor_count)
    throw PlayerError("RangerProxy::GetSensorSize", "index out of bounds");
  return GetVar(mDevice->sensor_sizes[aIndex]);
}

double RangerProxy::GetRange(uint aIndex) const
{
  if (aIndex > mDevice->ranges_count)
    throw PlayerError("RangerProxy::GetRange", "index out of bounds");
  return GetVar(mDevice->ranges[aIndex]);
}

double RangerProxy::GetIntensity(uint 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");
}


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.GetSensorCount() > 0)
  {
    os << c.GetSensorCount() << " sensors:" << endl;
    for (uint ii = 0; ii < c.GetSensorCount(); ii++)
    {
      pose = c.GetSensorPose(ii);
      size = c.GetSensorSize(ii);
      os << "  Pose: (" << pose.px << ", " << pose.py << ", " << pose.pz << "), 
(" <<
         pose.proll << ", " << pose.ppitch << ", " << pose.pyaw << ")" << 
"\tSize: (" <<
         size.sw << ", " << size.sl << ", " << size.sh << ")" << endl;
    }
  }
  if (c.GetRangeCount() > 0)
  {
    os << c.GetRangeCount() << " range readings:" << endl << "  [";
    uint 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 << "  [";
    uint ii;
    for (ii = 0; ii < c.GetIntensityCount() - 1; ii++)
      os << c.GetIntensity(ii) << ", ";
    os << c.GetIntensity(ii) << "]" << endl;
  }

  return os;
}

Index: Makefile.am
===================================================================
RCS file: 
/cvsroot/playerstage/code/player/client_libs/libplayerc++/Makefile.am,v
retrieving revision 1.45
retrieving revision 1.46
diff -C2 -d -r1.45 -r1.46
*** Makefile.am 14 Mar 2007 16:41:51 -0000      1.45
--- Makefile.am 20 May 2007 00:30:14 -0000      1.46
***************
*** 57,60 ****
--- 57,61 ----
                                powerproxy.cc \
                                ptzproxy.cc \
+                               rangerproxy.cc \
                                rfidproxy.cc \
                                simulationproxy.cc \

Index: playerc++.h
===================================================================
RCS file: 
/cvsroot/playerstage/code/player/client_libs/libplayerc++/playerc++.h,v
retrieving revision 1.86
retrieving revision 1.87
diff -C2 -d -r1.86 -r1.87
*** playerc++.h 30 Apr 2007 23:52:12 -0000      1.86
--- playerc++.h 20 May 2007 00:30:14 -0000      1.87
***************
*** 2132,2135 ****
--- 2132,2190 ----
  
  /**
+ The @p RangerProxy class is used to control a @ref interface_ranger device. */
+ class RangerProxy : public ClientProxy
+ {
+   private:
+ 
+     void Subscribe(uint aIndex);
+     void Unsubscribe();
+ 
+     // libplayerc data structure
+     playerc_ranger_t *mDevice;
+ 
+   public:
+     /// constructor
+     RangerProxy(PlayerClient *aPc, uint aIndex=0);
+     /// destructor
+     ~RangerProxy();
+ 
+     /// Return the individual range sensor count
+     uint GetSensorCount() const { return GetVar(mDevice->sensor_count); };
+ 
+     /// Return the device pose
+     player_pose3d_t GetDevicePose() const { return 
GetVar(mDevice->device_pose); };
+     /// Return the device size
+     player_bbox3d_t GetDeviceSize() const { return 
GetVar(mDevice->device_size); };
+ 
+     /// Return the pose of an individual sensor
+     player_pose3d_t GetSensorPose(uint aIndex) const;
+     /// Return the size of an individual sensor
+     player_bbox3d_t GetSensorSize(uint aIndex) const;
+ 
+     /// Return the number of range readings
+     uint GetRangeCount() const { return GetVar(mDevice->ranges_count); };
+     /// Get a range reading
+     double GetRange(uint aIndex) const;
+     /// Operator to get a range reading
+     double operator[] (uint aIndex) const { return GetRange(aIndex); }
+ 
+     /// Return the number of intensity readings
+     uint GetIntensityCount() const { return 
GetVar(mDevice->intensities_count); } ;
+     /// Get an intensity reading
+     double GetIntensity(uint aIndex) const;
+ 
+     /// Turn the device power on or off.
+     /// Set @p state to true to enable, false to disable.
+     void SetPower(bool aEnable);
+ 
+     /// Turn intensity data on or off.
+     /// Set @p state to true to enable, false to disable.
+     void SetIntensityData(bool aEnable);
+ 
+     /// Request the ranger geometry.
+     void RequestGeom();
+ };
+ 
+ /**
  The @p RFIDProxy class is used to control a  @ref interface_rfid device. */
  class RFIDProxy : public ClientProxy
***************
*** 2509,2512 ****
--- 2564,2568 ----
    std::ostream& operator << (std::ostream& os, const PlayerCc::PowerProxy& c);
    std::ostream& operator << (std::ostream& os, const PlayerCc::PtzProxy& c);
+   std::ostream& operator << (std::ostream &os, const PlayerCc::RangerProxy 
&c);
    std::ostream& operator << (std::ostream& os, const 
PlayerCc::SimulationProxy& c);
    std::ostream& operator << (std::ostream& os, const PlayerCc::SonarProxy& c);


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to