|
From: <gb...@us...> - 2008-08-08 02:50:55
|
Revision: 301
http://gearbox.svn.sourceforge.net/gearbox/?rev=301&view=rev
Author: gbiggs
Date: 2008-08-08 02:51:04 +0000 (Fri, 08 Aug 2008)
Log Message:
-----------
Added Python bindings for hokuyo_aist. Small change to the API to resolve some ambiguity in overloads.
Modified Paths:
--------------
gearbox/trunk/src/hokuyo_aist/CMakeLists.txt
gearbox/trunk/src/hokuyo_aist/hokuyo_aist.cpp
gearbox/trunk/src/hokuyo_aist/hokuyo_aist.h
gearbox/trunk/src/hokuyo_aist/test/example.cpp
Added Paths:
-----------
gearbox/trunk/src/hokuyo_aist/python/
gearbox/trunk/src/hokuyo_aist/python/CMakeLists.txt
gearbox/trunk/src/hokuyo_aist/python/hokuyo_aist.cpp
gearbox/trunk/src/hokuyo_aist/python/test/
gearbox/trunk/src/hokuyo_aist/python/test/CMakeLists.txt
gearbox/trunk/src/hokuyo_aist/python/test/hokuyo_aist_example.py
Modified: gearbox/trunk/src/hokuyo_aist/CMakeLists.txt
===================================================================
--- gearbox/trunk/src/hokuyo_aist/CMakeLists.txt 2008-08-06 00:37:42 UTC (rev 300)
+++ gearbox/trunk/src/hokuyo_aist/CMakeLists.txt 2008-08-08 02:51:04 UTC (rev 301)
@@ -26,4 +26,9 @@
IF (GBX_BUILD_TESTS)
ADD_SUBDIRECTORY (test)
ENDIF (GBX_BUILD_TESTS)
-ENDIF( build )
+
+ OPTION (HOKUYO_AIST_BUILD_BINDINGS "Build the Python bindings for Hokuyo_aist" ON)
+ IF (HOKUYO_AIST_BUILD_BINDINGS)
+ ADD_SUBDIRECTORY (python)
+ ENDIF (HOKUYO_AIST_BUILD_BINDINGS)
+ENDIF (build)
Modified: gearbox/trunk/src/hokuyo_aist/hokuyo_aist.cpp
===================================================================
--- gearbox/trunk/src/hokuyo_aist/hokuyo_aist.cpp 2008-08-06 00:37:42 UTC (rev 300)
+++ gearbox/trunk/src/hokuyo_aist/hokuyo_aist.cpp 2008-08-08 02:51:04 UTC (rev 301)
@@ -1434,7 +1434,7 @@
return data->_length;
}
-unsigned int HokuyoLaser::GetRanges (HokuyoData *data, double startAngle,
+unsigned int HokuyoLaser::GetRangesByAngle (HokuyoData *data, double startAngle,
double endAngle, unsigned int clusterCount)
{
if (data == NULL)
@@ -1549,7 +1549,7 @@
return data->_length;
}
-unsigned int HokuyoLaser::GetNewRanges (HokuyoData *data, double startAngle, double endAngle,
+unsigned int HokuyoLaser::GetNewRangesByAngle (HokuyoData *data, double startAngle, double endAngle,
unsigned int clusterCount)
{
if (data == NULL)
@@ -1670,7 +1670,7 @@
return data->_length;
}
-unsigned int HokuyoLaser::GetNewRangesAndIntensities (HokuyoData *data, double startAngle,
+unsigned int HokuyoLaser::GetNewRangesAndIntensitiesByAngle (HokuyoData *data, double startAngle,
double endAngle, unsigned int clusterCount)
{
if (data == NULL)
Modified: gearbox/trunk/src/hokuyo_aist/hokuyo_aist.h
===================================================================
--- gearbox/trunk/src/hokuyo_aist/hokuyo_aist.h 2008-08-06 00:37:42 UTC (rev 300)
+++ gearbox/trunk/src/hokuyo_aist/hokuyo_aist.h 2008-08-08 02:51:04 UTC (rev 301)
@@ -252,7 +252,7 @@
/// @brief Get the number of samples in the data.
unsigned int Length (void) const { return _length; }
/** @brief Indicates if one or more steps had an error.
-
+
A step's value will be less than 20 if it had an error. Use @ref ErrorCodeToString to get
a textual representation of the error. */
bool GetErrorStatus (void) const { return _error; }
@@ -273,7 +273,7 @@
/// @brief Force the data to clean up.
void CleanUp (void);
- private:
+ protected:
uint32_t *_ranges;
uint32_t *_intensities;
unsigned int _length;
@@ -330,7 +330,7 @@
(startup) value. Values between 1 and 10 specify a ratio of the default speed. The speeds in
revolutions per minute that these correspond to will depend on the scanner model. For
example, for a URG-04LX, they are (from 1 to 10) 594, 588, 576, 570, 564, 558, 552, 546, and
- 540 rpm.
+ 540 rpm.
Not available with the SCIP v1 protocol. */
void SetMotorSpeed (unsigned int speed);
@@ -381,7 +381,7 @@
@param clusterCount The number of readings to cluster together into a single reading. The
minimum value from a cluster is returned as the range for that cluster.
@return The number of range readings read into @ref data. */
- unsigned int GetRanges (HokuyoData *data, double startAngle, double endAngle,
+ unsigned int GetRangesByAngle (HokuyoData *data, double startAngle, double endAngle,
unsigned int clusterCount = 1);
/** @brief Get a new scan from the scanner.
@@ -390,7 +390,7 @@
will request a new scan. This means it will wait while the scanner performs the scan, which
means the rate at which scans can be retrieved using this function is less than with @ref
GetRanges. Otherwise behaves identicallty to @ref GetRanges.
-
+
Not available with the SCIP v1 protocol.
@note The command used to retrieve a fresh scan is also used for the continuous scanning
@@ -420,7 +420,7 @@
@param clusterCount The number of readings to cluster together into a single reading. The
minimum value from a cluster is returned as the range for that cluster.
@return The number of range readings read into @ref data. */
- unsigned int GetNewRanges (HokuyoData *data, double startAngle, double endAngle,
+ unsigned int GetNewRangesByAngle (HokuyoData *data, double startAngle, double endAngle,
unsigned int clusterCount = 1);
/** @brief Get a new scan from the scanner with intensity data.
@@ -458,7 +458,7 @@
@param clusterCount The number of readings to cluster together into a single reading. The
minimum value from a cluster is returned as the range for that cluster.
@return The number of range readings read into @ref data. */
- unsigned int GetNewRangesAndIntensities (HokuyoData *data, double startAngle,
+ unsigned int GetNewRangesAndIntensitiesByAngle (HokuyoData *data, double startAngle,
double endAngle, unsigned int clusterCount = 1);
/// @brief Return the major version of the SCIP protocol in use.
Added: gearbox/trunk/src/hokuyo_aist/python/CMakeLists.txt
===================================================================
--- gearbox/trunk/src/hokuyo_aist/python/CMakeLists.txt (rev 0)
+++ gearbox/trunk/src/hokuyo_aist/python/CMakeLists.txt 2008-08-08 02:51:04 UTC (rev 301)
@@ -0,0 +1,67 @@
+# Find the Python libraries and headers
+FIND_PACKAGE (PythonLibs)
+IF (NOT PYTHON_LIBRARIES)
+ MESSAGE (STATUS "Python libaries not found. Cannot build Python bindings for Hokuyo_aist.")
+ENDIF (NOT PYTHON_LIBRARIES)
+
+# Find Boost::Python
+# There is a new, much better, FindBoost.cmake in 2.6
+IF (CMAKE_MAJOR_VERSION EQUAL 2 AND CMAKE_MINOR_VERSION EQUAL 6)
+ OPTION (Boost_USE_STATIC_LIBS "Use the static versions of the Boost libraries" OFF)
+ MARK_AS_ADVANCED (Boost_USE_STATIC_LIBS)
+
+ SET (BOOST_COMPONENTS python)
+ FIND_PACKAGE (Boost COMPONENTS ${BOOST_COMPONENTS})
+ IF (Boost_FOUND)
+ INCLUDE_DIRECTORIES (${Boost_INCLUDE_DIR})
+ LINK_DIRECTORIES (${Boost_LIBRARY_DIRS})
+
+ IF (Boost_PYTHON_FOUND)
+ GET_FILENAME_COMPONENT (boostPythonLib ${Boost_PYTHON_LIBRARY} NAME_WE CACHE)
+ # Chop off the lib at the front, too, if present
+ STRING (REGEX REPLACE "^lib" "" boostPythonLib ${boostPythonLib})
+ MESSAGE (STATUS
+ "PlayerC++ client library will be built with Boost::Thread support.")
+ ELSE (Boost_PYTHON_FOUND)
+ MESSAGE (STATUS
+ "Boost::Python library was not found. Cannot build Python bindings for Hokuyo_aist.")
+ ENDIF (Boost_PYTHON_FOUND)
+ ELSE (Boost_FOUND)
+ MESSAGE (STATUS
+ "Boost libraries were not found. Cannot build Python bindings for Hokuyo_aist.")
+ ENDIF (Boost_FOUND)
+ELSE (CMAKE_MAJOR_VERSION EQUAL 2 AND CMAKE_MINOR_VERSION EQUAL 6)
+ FIND_PACKAGE (Boost)
+ IF (Boost_FOUND)
+ # For 2.4, assume that if boost is found then boost::python is present
+ OPTION (Boost_USE_MULTITHREAD "Use the multithreaded versions of the Boost libraries" ON)
+ MARK_AS_ADVANCED (Boost_USE_MULTITHREAD)
+ IF (Boost_USE_MULTITHREAD)
+ SET (BOOST_LIB_SUFFIX "-mt" CACHE STRING "Boost library name suffix")
+ ELSE (Boost_USE_MULTITHREAD)
+ SET (BOOST_LIB_SUFFIX "" CACHE STRING "Boost library name suffix")
+ ENDIF (Boost_USE_MULTITHREAD)
+ MARK_AS_ADVANCED (BOOST_LIB_SUFFIX)
+
+ SET (boostPythonLib boost_python${BOOST_LIB_SUFFIX})
+ INCLUDE_DIRECTORIES (${Boost_INCLUDE_DIRS})
+ LINK_DIRECTORIES (${Boost_LIBRARY_DIRS})
+ ELSE (Boost_FOUND)
+ MESSAGE (STATUS
+ "Boost libraries were not found. Cannot build Python bindings for Hokuyo_aist.")
+ ENDIF (Boost_FOUND)
+ENDIF (CMAKE_MAJOR_VERSION EQUAL 2 AND CMAKE_MINOR_VERSION EQUAL 6)
+
+IF (PYTHON_LIBRARIES AND Boost_FOUND)
+ MESSAGE (STATUS "Hokuyo_aist Python bindings will be built.")
+ SET (srcs hokuyo_aist.cpp)
+
+ SET (pyModuleTarget hokuyo_aist_py)
+ INCLUDE_DIRECTORIES (${PROJECT_SOURCE_DIR}/src/hokuyo_aist ${PYTHON_INCLUDE_PATH})
+ ADD_LIBRARY (${pyModuleTarget} MODULE ${srcs})
+ TARGET_LINK_LIBRARIES (${pyModuleTarget} hokuyo_aist ${boostPythonLib} ${PYTHON_LIBRARIES})
+ SET_TARGET_PROPERTIES (${pyModuleTarget} PROPERTIES PREFIX "" OUTPUT_NAME "hokuyo_aist")
+ INSTALL (TARGETS ${pyModuleTarget} LIBRARY DESTINATION lib/python/site-packages)
+
+ ADD_SUBDIRECTORY (test)
+ENDIF (PYTHON_LIBRARIES AND Boost_FOUND)
\ No newline at end of file
Added: gearbox/trunk/src/hokuyo_aist/python/hokuyo_aist.cpp
===================================================================
--- gearbox/trunk/src/hokuyo_aist/python/hokuyo_aist.cpp (rev 0)
+++ gearbox/trunk/src/hokuyo_aist/python/hokuyo_aist.cpp 2008-08-08 02:51:04 UTC (rev 301)
@@ -0,0 +1,162 @@
+#include <hokuyo_aist.h>
+using namespace hokuyo_aist;
+
+#include <boost/python.hpp>
+#include <boost/python/def.hpp>
+
+#include <iostream>
+
+class HokuyoErrorWrap : public HokuyoError, public boost::python::wrapper<HokuyoError>
+{
+ public:
+ HokuyoErrorWrap (unsigned int code, std::string desc)
+ : HokuyoError (code, desc)
+ {}
+
+ unsigned int Code (void) const throw ()
+ {
+ if (boost::python::override f = get_override ("Code"))
+ return f ();
+ return HokuyoError::Code ();
+ }
+ unsigned int DefaultCode (void) const throw ()
+ { return HokuyoError::Code (); }
+
+ const char* what (void) const throw ()
+ {
+ if (boost::python::override f = get_override ("what"))
+ return f ();
+ return HokuyoError::what ();
+ }
+ const char* Defaultwhat (void) const throw ()
+ { return HokuyoError::what (); }
+
+ std::string AsString (void) const throw ()
+ {
+ if (boost::python::override f = get_override ("AsString"))
+ return f ();
+ return HokuyoError::AsString ();
+ }
+ std::string DefaultAsString (void) const throw ()
+ { return HokuyoError::AsString (); }
+};
+
+class HokuyoDataWrap : public HokuyoData, public boost::python::wrapper<HokuyoData>
+{
+ public:
+ HokuyoDataWrap (void)
+ : HokuyoData ()
+ {}
+ HokuyoDataWrap (uint32_t *ranges, unsigned int length, bool error, unsigned int time)
+ : HokuyoData (ranges, length, error, time)
+ {}
+ HokuyoDataWrap (uint32_t *ranges, uint32_t *intensities, unsigned int length, bool error,
+ unsigned int time)
+ : HokuyoData (ranges, intensities, length, error, time)
+ {}
+
+ uint32_t Range (unsigned int index)
+ { return _ranges[index]; }
+ uint32_t Intensity (unsigned int index)
+ { return _intensities[index]; }
+};
+
+BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS (HokuyoLaserOverloads1, GetRanges, 1, 4)
+BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS (HokuyoLaserOverloads2, GetRangesByAngle, 3, 4)
+BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS (HokuyoLaserOverloads3, GetNewRanges, 1, 4)
+BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS (HokuyoLaserOverloads4, GetNewRangesByAngle, 3, 4)
+BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS (HokuyoLaserOverloads5, GetNewRangesAndIntensities, 1, 4)
+BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS (HokuyoLaserOverloads6, GetNewRangesAndIntensitiesByAngle, 3, 4)
+
+BOOST_PYTHON_MODULE (hokuyo_aist)
+{
+ using namespace boost::python;
+
+ class_<HokuyoErrorWrap, boost::noncopyable> ("HokuyoError", init<unsigned int, std::string> ())
+ .def ("Code", &HokuyoError::Code, &HokuyoErrorWrap::DefaultCode)
+ .def ("what", &HokuyoError::what, &HokuyoErrorWrap::Defaultwhat)
+ .def ("AsString", &HokuyoError::AsString, &HokuyoErrorWrap::DefaultAsString)
+ ;
+
+ scope ().attr ("HOKUYO_ERR_READ") = HOKUYO_ERR_READ;
+ scope ().attr ("HOKUYO_ERR_WRITE") = HOKUYO_ERR_WRITE;
+ scope ().attr ("HOKUYO_ERR_PROTOCOL") = HOKUYO_ERR_PROTOCOL;
+ scope ().attr ("HOKUYO_ERR_CHANGEBAUD") = HOKUYO_ERR_CHANGEBAUD;
+ scope ().attr ("HOKUYO_ERR_CONNECT_FAILED") = HOKUYO_ERR_CONNECT_FAILED;
+ scope ().attr ("HOKUYO_ERR_CLOSE_FAILED") = HOKUYO_ERR_CLOSE_FAILED;
+ scope ().attr ("HOKUYO_ERR_NODESTINATION") = HOKUYO_ERR_NODESTINATION;
+ scope ().attr ("HOKUYO_ERR_BADFIRMWARE") = HOKUYO_ERR_BADFIRMWARE;
+ scope ().attr ("HOKUYO_ERR_SCIPVERSION") = HOKUYO_ERR_SCIPVERSION;
+ scope ().attr ("HOKUYO_ERR_MEMORY") = HOKUYO_ERR_MEMORY;
+ scope ().attr ("HOKUYO_ERR_UNSUPPORTED") = HOKUYO_ERR_UNSUPPORTED;
+ scope ().attr ("HOKUYO_ERR_BADARG") = HOKUYO_ERR_BADARG;
+ scope ().attr ("HOKUYO_ERR_NODATA") = HOKUYO_ERR_NODATA;
+ scope ().attr ("HOKUYO_ERR_NOTSERIAL") = HOKUYO_ERR_NOTSERIAL;
+
+ // TODO: this causes an undefined symbol error when importing into Python
+// class_<HokuyoSensorInfo> ("HokuyoSensorInfo")
+// .def ("AsString", &HokuyoSensorInfo::AsString)
+// .def_readonly ("vendor", &HokuyoSensorInfo::vendor)
+// .def_readonly ("product", &HokuyoSensorInfo::product)
+// .def_readonly ("firmware", &HokuyoSensorInfo::firmware)
+// .def_readonly ("protocol", &HokuyoSensorInfo::protocol)
+// .def_readonly ("serial", &HokuyoSensorInfo::serial)
+// .def_readonly ("model", &HokuyoSensorInfo::model)
+// .def_readonly ("minRange", &HokuyoSensorInfo::minRange)
+// .def_readonly ("maxRange", &HokuyoSensorInfo::maxRange)
+// .def_readonly ("steps", &HokuyoSensorInfo::steps)
+// .def_readonly ("firstStep", &HokuyoSensorInfo::firstStep)
+// .def_readonly ("lastStep", &HokuyoSensorInfo::lastStep)
+// .def_readonly ("frontStep", &HokuyoSensorInfo::frontStep)
+// .def_readonly ("standardSpeed", &HokuyoSensorInfo::standardSpeed)
+// .def_readonly ("power", &HokuyoSensorInfo::power)
+// .def_readonly ("speed", &HokuyoSensorInfo::speed)
+// .def_readonly ("speedLevel", &HokuyoSensorInfo::speedLevel)
+// .def_readonly ("measureState", &HokuyoSensorInfo::measureState)
+// .def_readonly ("baud", &HokuyoSensorInfo::baud)
+// .def_readonly ("time", &HokuyoSensorInfo::time)
+// .def_readonly ("sensorDiagnostic", &HokuyoSensorInfo::sensorDiagnostic)
+// .def_readonly ("minAngle", &HokuyoSensorInfo::minAngle)
+// .def_readonly ("maxAngle", &HokuyoSensorInfo::maxAngle)
+// .def_readonly ("resolution", &HokuyoSensorInfo::resolution)
+// .def_readonly ("scanableSteps", &HokuyoSensorInfo::scanableSteps)
+// ;
+
+ class_ <HokuyoDataWrap, boost::noncopyable> ("HokuyoData")
+ .def (init<uint32_t*, unsigned int, bool, unsigned int> ())
+ .def (init<uint32_t*, uint32_t*, unsigned int, bool, unsigned int> ())
+ // TODO: write a wrapper function to copy the data into a python array, because this doesn't work
+// .def ("Ranges", &HokuyoData::Ranges, return_value_policy<reference_existing_object> (), with_custodian_and_ward_postcall<1, 0> ())
+ .def ("Range", &HokuyoDataWrap::Range)
+ .def ("Intensity", &HokuyoDataWrap::Intensity)
+ .def ("Length", &HokuyoData::Length)
+ .def ("GetErrorStatus", &HokuyoData::GetErrorStatus)
+ .def ("ErrorCodeToString", &HokuyoData::ErrorCodeToString)
+ .def ("TimeStamp", &HokuyoData::TimeStamp)
+ .def ("AsString", &HokuyoData::AsString)
+ .def ("CleanUp", &HokuyoData::CleanUp)
+ ;
+
+ class_ <HokuyoLaser> ("HokuyoLaser")
+ .def ("Open", &HokuyoLaser::Open)
+ .def ("Close", &HokuyoLaser::Close)
+ .def ("IsOpen", &HokuyoLaser::IsOpen)
+ .def ("SetPower", &HokuyoLaser::SetPower)
+ .def ("SetBaud", &HokuyoLaser::SetBaud)
+ .def ("Reset", &HokuyoLaser::Reset)
+ .def ("SetMotorSpeed", &HokuyoLaser::SetMotorSpeed)
+ .def ("SetHighSensitivity", &HokuyoLaser::SetHighSensitivity)
+ .def ("GetSensorInfo", &HokuyoLaser::GetSensorInfo)
+ .def ("GetTime", &HokuyoLaser::GetTime)
+ .def ("GetRanges", &HokuyoLaser::GetRanges, HokuyoLaserOverloads1 ())
+ .def ("GetRangesByAngle", &HokuyoLaser::GetRangesByAngle, HokuyoLaserOverloads2 ())
+ .def ("GetNewRanges", &HokuyoLaser::GetNewRanges, HokuyoLaserOverloads3 ())
+ .def ("GetNewRangesByAngle", &HokuyoLaser::GetNewRangesByAngle, HokuyoLaserOverloads4 ())
+ .def ("GetNewRangesAndIntensities", &HokuyoLaser::GetNewRangesAndIntensities, HokuyoLaserOverloads5 ())
+ .def ("GetNewRangesAndIntensitiesByAngle", &HokuyoLaser::GetNewRangesAndIntensitiesByAngle, HokuyoLaserOverloads6 ())
+ .def ("SCIPVersion", &HokuyoLaser::SCIPVersion)
+ .def ("SetVerbose", &HokuyoLaser::SetVerbose)
+ .def ("StepToAngle", &HokuyoLaser::StepToAngle)
+ .def ("AngleToStep", &HokuyoLaser::AngleToStep)
+ ;
+}
Added: gearbox/trunk/src/hokuyo_aist/python/test/CMakeLists.txt
===================================================================
--- gearbox/trunk/src/hokuyo_aist/python/test/CMakeLists.txt (rev 0)
+++ gearbox/trunk/src/hokuyo_aist/python/test/CMakeLists.txt 2008-08-08 02:51:04 UTC (rev 301)
@@ -0,0 +1 @@
+INSTALL (FILES hokuyo_aist_example.py DESTINATION share/${PROJECT_NAME}/hokuyo_aist/example)
Added: gearbox/trunk/src/hokuyo_aist/python/test/hokuyo_aist_example.py
===================================================================
--- gearbox/trunk/src/hokuyo_aist/python/test/hokuyo_aist_example.py (rev 0)
+++ gearbox/trunk/src/hokuyo_aist/python/test/hokuyo_aist_example.py 2008-08-08 02:51:04 UTC (rev 301)
@@ -0,0 +1,91 @@
+#!/usr/bin/env python
+
+import hokuyo_aist
+from optparse import OptionParser
+
+def main ():
+ parser = OptionParser ()
+ parser.add_option ('-b', '--baud', dest = 'baudRate', type = 'int', default = '19200',
+ help = 'Baud rate to set the laser to *after* connecting [default: %default]')
+ parser.add_option ('-c', '--clustercount', dest = 'clusterCount', type = 'int', default = '1',
+ help = 'Cluster count [default: %default]')
+ parser.add_option ('-e', '--endangle', dest = 'endAngle', type = 'float', default = '0',
+ help = 'End angle to get ranges to [default: %default]')
+ parser.add_option ('-f', '--firststep', dest = 'firstStep', type = 'int', default = '-1',
+ help = 'First step to get ranges from [default: %default]')
+ parser.add_option ('-l', '--laststep', dest = 'lastStep', type = 'int', default = '-1',
+ help = 'Last step to get ranges to [default: %default]')
+ parser.add_option ('-m', '--motorspeed', dest = 'motorSpeed', type = 'int', default = '0',
+ help = 'Motor speed stepping (higher is slower) [default: %default]')
+ parser.add_option ('-n', '--new', dest = 'getNew', action = 'store_true', default = 'False',
+ help = 'Get new ranges instead of latest ranges [default: %default]')
+ parser.add_option ('-o', '--portoptions', dest = 'portOptions', type = 'string', default = 'type=serial,device=/dev/ttyACM0,timeout=1',
+ help = 'Port options (see flexiport library) [default: %default]')
+ parser.add_option ('-s', '--startangle', dest = 'startAngle', type = 'float', default = '0',
+ help = 'Start angle to get ranges from [default: %default]')
+ parser.add_option ('-v', '--verbose', dest = 'verbose', action = 'store_true', default = 'False',
+ help = 'Put the hokuyo_aist library into verbose mode [default: %default]')
+
+ # Scan command line arguments
+ options, args = parser.parse_args ()
+
+ try:
+ # Create an instance of a laser scanner object
+ laser = hokuyo_aist.HokuyoLaser ()
+ if options.verbose == True:
+ # Set verbose mode so we see more information in stderr
+ laser.SetVerbose (True)
+
+ # Open the laser
+ laser.Open (options.portOptions)
+ # Turn the laser on
+ laser.SetPower (True)
+ # Set the baud rate
+ try:
+ laser.SetBaud (options.baudRate)
+ except hokuyo_aist.HokuyoError, e:
+ print 'Failed to change baud rate: (' + str (e.Code ()) + ') ' + e.what ()
+ # Set the motor speed
+ laser.SetMotorSpeed (options.motorSpeed)
+
+ # Get some laser info
+ #print 'Laser sensor information:'
+ #info = hokuyo_aist.HokuyoSensorInfo info ()
+ #laser.GetSensorInfo (info)
+ #print info.AsString ()
+
+ # Get range data
+ data = hokuyo_aist.HokuyoData ()
+ if (options.firstStep == -1 and options.lastStep == -1) and \
+ (options.startAngle == 0 and options.endAngle == 0):
+ # Get all ranges
+ if options.getNew == True:
+ laser.GetNewRanges (data, -1, -1, options.clusterCount)
+ else:
+ laser.GetRanges (data, -1, -1, options.clusterCount)
+ elif options.firstStep != -1 or options.lastStep != -1:
+ # Get by step
+ if options.getNew == True:
+ laser.GetNewRanges (data, options.firstStep, options.lastStep, options.clusterCount)
+ else:
+ laser.GetRanges (data, options.firstStep, options.lastStep, options.clusterCount)
+ else:
+ # Get by angle
+ if options.getNew == True:
+ laser.GetNewRangesByAngle (data, options.startAngle, options.endAngle, options.clusterCount)
+ else:
+ laser.GetRangesByAngle (data, options.startAngle, options.endAngle, options.clusterCount)
+
+ print 'Laser range data:'
+ print data.AsString ()
+
+ # Close the laser
+ laser.Close ()
+
+ except hokuyo_aist.HokuyoError, e:
+ print 'Caught exception: (' + str (e.Code ()) + ') ' + e.what ()
+ sys.exit (1)
+
+
+if __name__ == '__main__':
+ main ()
Property changes on: gearbox/trunk/src/hokuyo_aist/python/test/hokuyo_aist_example.py
___________________________________________________________________
Added: svn:executable
+ *
Modified: gearbox/trunk/src/hokuyo_aist/test/example.cpp
===================================================================
--- gearbox/trunk/src/hokuyo_aist/test/example.cpp 2008-08-06 00:37:42 UTC (rev 300)
+++ gearbox/trunk/src/hokuyo_aist/test/example.cpp 2008-08-08 02:51:04 UTC (rev 301)
@@ -137,7 +137,7 @@
else
laser.GetRanges (&data, -1, -1, clusterCount);
}
- else if (firstStep != -1 && lastStep != -1)
+ else if (firstStep != -1 || lastStep != -1)
{
// Get by step
if (getNew)
@@ -149,9 +149,9 @@
{
// Get by angle
if (getNew)
- laser.GetNewRanges (&data, startAngle, endAngle, clusterCount);
+ laser.GetNewRangesByAngle (&data, startAngle, endAngle, clusterCount);
else
- laser.GetRanges (&data, startAngle, endAngle, clusterCount);
+ laser.GetRangesByAngle (&data, startAngle, endAngle, clusterCount);
}
cout << "Laser range data:" << endl;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|