From: <gb...@us...> - 2010-10-28 09:09:01
|
Revision: 522 http://gearbox.svn.sourceforge.net/gearbox/?rev=522&view=rev Author: gbiggs Date: 2010-10-28 09:08:54 +0000 (Thu, 28 Oct 2010) Log Message: ----------- Updated Python bindings to match v2 api Modified Paths: -------------- gearbox/trunk/src/hokuyo_aist/CMakeLists.txt gearbox/trunk/src/hokuyo_aist/hokuyo_errors.cpp gearbox/trunk/src/hokuyo_aist/hokuyo_errors.h gearbox/trunk/src/hokuyo_aist/python/hokuyo_aist.cpp 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 2010-09-24 06:17:05 UTC (rev 521) +++ gearbox/trunk/src/hokuyo_aist/CMakeLists.txt 2010-10-28 09:08:54 UTC (rev 522) @@ -52,7 +52,7 @@ add_subdirectory (test) endif (GBX_BUILD_TESTS) - option (HOKUYO_AIST_BUILD_BINDINGS "Build the Python bindings for Hokuyo_aist" OFF) + 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) Modified: gearbox/trunk/src/hokuyo_aist/hokuyo_errors.cpp =================================================================== --- gearbox/trunk/src/hokuyo_aist/hokuyo_errors.cpp 2010-09-24 06:17:05 UTC (rev 521) +++ gearbox/trunk/src/hokuyo_aist/hokuyo_errors.cpp 2010-10-28 09:08:54 UTC (rev 522) @@ -324,23 +324,23 @@ BaseError::BaseError(unsigned int desc_code, char const* error_type) - : _desc_code(desc_code) + : desc_code_(desc_code) { - strncpy(_error_type, error_type, 32); + strncpy(error_type_, error_type, 32); } BaseError::BaseError(BaseError const& rhs) - : _desc_code(rhs.desc_code()) + : desc_code_(rhs.desc_code()) { - strncpy(_error_type, rhs.error_type(), 32); + strncpy(error_type_, rhs.error_type(), 32); } const char* BaseError::what() throw() { - ss << _error_type << " (" << _desc_code << "): " << - desc_code_to_string(_desc_code); + ss << error_type_ << " (" << desc_code_ << "): " << + desc_code_to_string(desc_code_); return ss.str().c_str(); } @@ -348,7 +348,7 @@ const char* BaudrateError::what() throw() { RuntimeError::what(); - ss << _baud; + ss << baud_; return ss.str().c_str(); } @@ -356,7 +356,7 @@ const char* ChecksumError::what() throw() { ProtocolError::what(); - ss << "expected " << _expected << ", calculated " << _calculated; + ss << "expected " << expected_ << ", calculated " << calculated_; return ss.str().c_str(); } @@ -364,21 +364,21 @@ UnknownLineError::UnknownLineError(char const* const line) : ProtocolError(27, "UnknownLineError") { - strncpy(_line, line, 128); + strncpy(line_, line, 128); } UnknownLineError::UnknownLineError(UnknownLineError const& rhs) : ProtocolError(rhs) { - strncpy(_line, rhs.line(), 128); + strncpy(line_, rhs.line(), 128); } const char* UnknownLineError::what() throw() { ProtocolError::what(); - ss << _line; + ss << line_; return ss.str().c_str(); } @@ -386,23 +386,23 @@ ParseError::ParseError(char const* const line, char const* const type) : ProtocolError(28, "ParseError") { - strncpy(_line, line, 128); - strncpy(_type, type, 16); + strncpy(line_, line, 128); + strncpy(type_, type, 16); } ParseError::ParseError(ParseError const& rhs) : ProtocolError(rhs) { - strncpy(_line, rhs.line(), 128); - strncpy(_type, rhs.type(), 16); + strncpy(line_, rhs.line(), 128); + strncpy(type_, rhs.type(), 16); } const char* ParseError::what() throw() { ProtocolError::what(); - ss << "Line type: " << _type << ". Line: " << _line; + ss << "Line type: " << type_ << ". Line: " << line_; return ss.str().c_str(); } @@ -410,9 +410,9 @@ const char* ResponseError::what() throw() { ProtocolError::what(); - ss << " Command: " << _cmd[0] << _cmd[1]; - ss << " Error : (" << _error[0] << _error[1] << ") " << - scip2_error_to_string(_error, _cmd); + ss << " Command: " << cmd_[0] << cmd_[1]; + ss << " Error : (" << error_[0] << error_[1] << ") " << + scip2_error_to_string(error_, cmd_); return ss.str().c_str(); } @@ -420,8 +420,8 @@ const char* Scip1ResponseError::what() throw() { ProtocolError::what(); - ss << " Command: " << _cmd; - ss << " Error : " << _error; + ss << " Command: " << cmd_; + ss << " Error : " << error_; return ss.str().c_str(); } @@ -429,8 +429,8 @@ const char* CommandEchoError::what() throw() { ProtocolError::what(); - ss << " Command: " << _cmd[0] << _cmd[1]; - ss << " Received echo: " << _echo[0] << _echo[1]; + ss << " Command: " << cmd_[0] << cmd_[1]; + ss << " Received echo: " << echo_[0] << echo_[1]; return ss.str().c_str(); } @@ -438,7 +438,7 @@ const char* ParamEchoError::what() throw() { ProtocolError::what(); - ss << " Command: " << _cmd[0] << _cmd[1]; + ss << " Command: " << cmd_[0] << cmd_[1]; return ss.str().c_str(); } @@ -446,8 +446,8 @@ const char* InsufficientBytesError::what() throw() { ProtocolError::what(); - ss << " Number of bytes: " << _num; - ss << " Line length: " << _line_length; + ss << " Number of bytes: " << num_; + ss << " Line length: " << line_length_; return ss.str().c_str(); } @@ -455,8 +455,8 @@ const char* LineLengthError::what() throw() { ProtocolError::what(); - ss << " Received length: " << _length; - ss << " Expected line length: " << _expected; + ss << " Received length: " << length_; + ss << " Expected line length: " << expected_; return ss.str().c_str(); } Modified: gearbox/trunk/src/hokuyo_aist/hokuyo_errors.h =================================================================== --- gearbox/trunk/src/hokuyo_aist/hokuyo_errors.h 2010-09-24 06:17:05 UTC (rev 521) +++ gearbox/trunk/src/hokuyo_aist/hokuyo_errors.h 2010-10-28 09:08:54 UTC (rev 522) @@ -64,21 +64,21 @@ virtual ~BaseError() throw() {}; virtual unsigned int desc_code() const throw() - { return _desc_code; } + { return desc_code_; } virtual char const* error_type() const throw() - { return _error_type; } + { return error_type_; } virtual const char* what() throw(); protected: /** Description code for use with the error string table. */ - unsigned int _desc_code; + unsigned int desc_code_; /** Formatted description of the error. */ std::stringstream ss; /** String representation of the error. */ - char _error_type[32]; + char error_type_[32]; }; //class BaseError @@ -150,20 +150,20 @@ @param baud The bad baud rate. */ BaudrateError(unsigned int baud) - : RuntimeError(6, "BaudrateError"), _baud(baud) + : RuntimeError(6, "BaudrateError"), baud_(baud) {} BaudrateError(BaudrateError const& rhs) - : RuntimeError(rhs), _baud(rhs.baud()) + : RuntimeError(rhs), baud_(rhs.baud()) {} unsigned int baud() const throw() - { return _baud; } + { return baud_; } const char* what() throw(); protected: /** Baud rate that caused the error. */ - unsigned int _baud; + unsigned int baud_; }; // class BaudrateError @@ -343,27 +343,27 @@ @param expected The expected checksum. @param calculated The calculated checksum. */ ChecksumError(int expected, int calculated) - : ProtocolError(24, "ChecksumError"), _expected(expected), - _calculated(calculated) + : ProtocolError(24, "ChecksumError"), expected_(expected), + calculated_(calculated) {} ChecksumError(ChecksumError const& rhs) - : ProtocolError(rhs), _expected(rhs.expected()), - _calculated(rhs.calculated()) + : ProtocolError(rhs), expected_(rhs.expected()), + calculated_(rhs.calculated()) {} virtual int expected() const throw() - { return _expected; } + { return expected_; } virtual int calculated() const throw() - { return _calculated; } + { return calculated_; } const char* what() throw(); protected: /** Expected checksum value. */ - int _expected; + int expected_; /** Calculated checksum value. */ - int _calculated; + int calculated_; }; // class ProtocolError @@ -398,13 +398,13 @@ UnknownLineError(UnknownLineError const& rhs); virtual char const* const line() const throw() - { return _line; } + { return line_; } const char* what() throw(); protected: /** The mystery line. */ - char _line[128]; + char line_[128]; }; // class UnknownLineError @@ -420,18 +420,18 @@ ParseError(ParseError const& rhs); virtual char const* const line() const throw() - { return _line; } + { return line_; } virtual char const* const type() const throw() - { return _type; } + { return type_; } const char* what() throw(); protected: /** The bad line. */ - char _line[128]; + char line_[128]; /** The type of line. */ - char _type[16]; + char type_[16]; }; // class ParseError @@ -456,33 +456,33 @@ ResponseError(char const* const error, char const* const cmd) : ProtocolError(30, "ResponseError") { - _error[0] = error[0]; _error[1] = error[1]; - _cmd[0] = cmd[0]; _cmd[1] = cmd[1]; + error_[0] = error[0]; error_[1] = error[1]; + cmd_[0] = cmd[0]; cmd_[1] = cmd[1]; } ResponseError(ResponseError const& rhs) : ProtocolError(rhs) { - _error[0] = rhs.error_code()[0]; - _error[1] = rhs.error_code()[1]; - _cmd[0] = rhs.cmd_code()[0]; - _cmd[1] = rhs.cmd_code()[1]; + error_[0] = rhs.error_code()[0]; + error_[1] = rhs.error_code()[1]; + cmd_[0] = rhs.cmd_code()[0]; + cmd_[1] = rhs.cmd_code()[1]; } /// Get the two-byte error code as a non-null-terminated array. virtual char const* const error_code() const throw() - { return _error; } + { return error_; } /// Get the two-byte command code as a non-null-terminated array. virtual char const* const cmd_code() const throw() - { return _cmd; } + { return cmd_; } const char* what() throw(); protected: /** Error code as defined in SCIP2 (two bytes). */ - char _error[2]; + char error_[2]; /** Command that triggered the error, from SCIP2 (two bytes). */ - char _cmd[2]; + char cmd_[2]; }; // class ResponseError @@ -496,28 +496,28 @@ @param type The command that caused the error. */ Scip1ResponseError(char error, char cmd) : ProtocolError(30, "Scip1ResponseError"), - _error(error), _cmd(cmd) + error_(error), cmd_(cmd) {} Scip1ResponseError(Scip1ResponseError const& rhs) - : ProtocolError(rhs), _error(rhs.error_code()), - _cmd(rhs.cmd_code()) + : ProtocolError(rhs), error_(rhs.error_code()), + cmd_(rhs.cmd_code()) {} /// Get the one-byte error code. virtual char error_code() const throw() - { return _error; } + { return error_; } /// Get the one-byte command code. virtual char cmd_code() const throw() - { return _cmd; } + { return cmd_; } const char* what() throw(); protected: /** Error code as defined in SCIP2 (two bytes). */ - char _error; + char error_; /** Command that triggered the error, from SCIP2 (two bytes). */ - char _cmd; + char cmd_; }; // class Scip1ResponseError @@ -532,33 +532,33 @@ CommandEchoError(char const* const cmd, char const* const echo) : ProtocolError(31, "CommandEchoError") { - _cmd[0] = cmd[0]; _cmd[1] = cmd[1]; - _echo[0] = echo[0]; _echo[1] = echo[1]; + cmd_[0] = cmd[0]; cmd_[1] = cmd[1]; + echo_[0] = echo[0]; echo_[1] = echo[1]; } CommandEchoError(CommandEchoError const& rhs) : ProtocolError(rhs) { - _cmd[0] = rhs.cmd_code()[0]; - _cmd[1] = rhs.cmd_code()[1]; - _echo[0] = rhs.cmd_echo()[0]; - _echo[1] = rhs.cmd_echo()[1]; + cmd_[0] = rhs.cmd_code()[0]; + cmd_[1] = rhs.cmd_code()[1]; + echo_[0] = rhs.cmd_echo()[0]; + echo_[1] = rhs.cmd_echo()[1]; } /// Get the two-byte command code as a non-null-terminated array. virtual char const* const cmd_code() const throw() - { return _cmd; } + { return cmd_; } /// Get the two-byte command echo as a non-null-terminated array. virtual char const* const cmd_echo() const throw() - { return _echo; } + { return echo_; } const char* what() throw(); protected: /** Command that triggered the error, from SCIP2 (two bytes). */ - char _cmd[2]; + char cmd_[2]; /** Received echo. */ - char _echo[2]; + char echo_[2]; }; // class CommandEchoError @@ -572,24 +572,24 @@ ParamEchoError(char const* const cmd) : ProtocolError(32, "ParamEchoError") { - _cmd[0] = cmd[0]; _cmd[1] = cmd[1]; + cmd_[0] = cmd[0]; cmd_[1] = cmd[1]; } ParamEchoError(ParamEchoError const& rhs) : ProtocolError(rhs) { - _cmd[0] = rhs.cmd_code()[0]; - _cmd[1] = rhs.cmd_code()[1]; + cmd_[0] = rhs.cmd_code()[0]; + cmd_[1] = rhs.cmd_code()[1]; } /// Get the two-byte command code as a non-null-terminated array. virtual char const* const cmd_code() const throw() - { return _cmd; } + { return cmd_; } const char* what() throw(); protected: /** Command that triggered the error, from SCIP2 (two bytes). */ - char _cmd[2]; + char cmd_[2]; }; // class ParamEchoError @@ -603,26 +603,26 @@ @param line_length The length of the line. */ InsufficientBytesError(int num, int line_length) : ProtocolError(33, "InsufficientBytesError"), - _num(num), _line_length(line_length) + num_(num), line_length_(line_length) {} InsufficientBytesError(InsufficientBytesError const& rhs) - : ProtocolError(rhs), _num(rhs.num()), - _line_length(rhs.line_length()) + : ProtocolError(rhs), num_(rhs.num()), + line_length_(rhs.line_length()) {} virtual int num() const throw() - { return _num; } + { return num_; } virtual int line_length() const throw() - { return _line_length; } + { return line_length_; } const char* what() throw(); protected: /** Number of bytes available. */ - int _num; + int num_; /** Length of the line. */ - int _line_length; + int line_length_; }; // class InsufficientBytesError @@ -636,26 +636,26 @@ @param line_length The length of the line. */ LineLengthError(int length, int expected) : ProtocolError(34, "LineLengthError"), - _length(length), _expected(expected) + length_(length), expected_(expected) {} LineLengthError(LineLengthError const& rhs) - : ProtocolError(rhs), _length(rhs.length()), - _expected(rhs.expected()) + : ProtocolError(rhs), length_(rhs.length()), + expected_(rhs.expected()) {} virtual int length() const throw() - { return _length; } + { return length_; } virtual int expected() const throw() - { return _expected; } + { return expected_; } const char* what() throw(); protected: /** The received line length. */ - int _length; + int length_; /** The expected line length. */ - int _expected; + int expected_; }; // class LineLengthError }; // namespace hokuyo_aist Modified: gearbox/trunk/src/hokuyo_aist/python/hokuyo_aist.cpp =================================================================== --- gearbox/trunk/src/hokuyo_aist/python/hokuyo_aist.cpp 2010-09-24 06:17:05 UTC (rev 521) +++ gearbox/trunk/src/hokuyo_aist/python/hokuyo_aist.cpp 2010-10-28 09:08:54 UTC (rev 522) @@ -6,157 +6,216 @@ #include <iostream> -class HokuyoErrorWrap : public HokuyoError, public boost::python::wrapper<HokuyoError> +class BaseErrorWrap + : public BaseError, public boost::python::wrapper<BaseError> { - public: - HokuyoErrorWrap (unsigned int code, std::string desc) - : HokuyoError (code, desc) - {} + public: + BaseErrorWrap(unsigned int desc_code, char const* error_type) + : BaseError(desc_code, error_type) + {} - 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 (); } + BaseErrorWrap(unsigned int desc_code, std::string error_type) + : BaseError(desc_code, error_type.c_str()) + {} - 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 (); } + unsigned int desc_code() const throw() + { + if (boost::python::override f = get_override("desc_code")) + { + return f(); + } + return BaseError::desc_code(); + } + unsigned int default_desc_code() const throw() + { + return BaseError::desc_code(); + } - 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 (); } + char const* error_type() const throw() + { + if (boost::python::override f = get_override("error_type")) + { + return f(); + } + return BaseError::error_type(); + } + char const* default_error_type() const throw() + { + return BaseError::error_type(); + } + + const char* what() throw() + { + if (boost::python::override f = get_override("what")) + { + return f(); + } + return BaseError::what(); + } + const char* default_what() throw() + { + return BaseError::what(); + } }; -class HokuyoDataWrap : public HokuyoData, public boost::python::wrapper<HokuyoData> + +class ScanDataWrap : public ScanData, public boost::python::wrapper<ScanData> { - 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) - {} + public: + ScanDataWrap(void) + : ScanData() + {} + ScanDataWrap(ScanDataWrap const& rhs) + : ScanData(rhs) + {} - uint32_t Range (unsigned int index) - { return _ranges[index]; } - uint32_t Intensity (unsigned int index) - { return _intensities[index]; } + uint32_t range(unsigned int index) + { return ranges_[index]; } + /*unsigned int ranges_length() const + { + if (boost::python::override f = get_override("ranges_length")) + { + return f(); + } + return ScanData::ranges_length(); + }*/ + + uint32_t intensity(unsigned int index) + { return intensities_[index]; } + /*unsigned int intensities_length() const + { + if (boost::python::override f = get_override("intensities_length")) + { + return f(); + } + return ScanData::intensities_length(); + }*/ + + /*bool get_error_status() const + { + if (boost::python::override f = get_override("get_error_status")) + { + return f(); + } + return ScanData::get_error_status(); + } + + std::string error_code_to_string(uint32_t error_code) + { + if (boost::python::override f = get_override("error_code_to_string")) + { + return f(error_code); + } + return ScanData::error_code_to_string(error_code); + } + + unsigned int laser_time_stamp() + { + if (boost::python::override f = get_override("laser_time_stamp")) + { + return f(); + } + return ScanData::laser_time_stamp(); + } + + unsigned int system_time_stamp() + { + if (boost::python::override f = get_override("system_time_stamp")) + { + return f(); + } + return ScanData::system_time_stamp(); + }*/ }; -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_MEMBER_FUNCTION_OVERLOADS(sensor_overloads1, + get_ranges, 1, 4) +BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(sensor_overloads2, + get_ranges_by_angle, 3, 4) +BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(sensor_overloads3, + get_ranges_intensities, 1, 4) +BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(sensor_overloads4, + get_ranges_intensities_by_angle, 3, 4) +BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(sensor_overloads5, + get_new_ranges, 1, 4) +BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(sensor_overloads6, + get_new_ranges_by_angle, 3, 4) +BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(sensor_overloads7, + get_new_ranges_intensities, 1, 4) +BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(sensor_overloads8, + get_new_ranges_intensities_by_angle, 3, 4) -BOOST_PYTHON_MODULE (hokuyo_aist) +BOOST_PYTHON_MODULE(hokuyo_aist) { - using namespace boost::python; + 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) - ; + class_<BaseErrorWrap, boost::noncopyable>("BaseError", init<unsigned int, std::string>()) + .def("desc_code", &BaseError::desc_code, &BaseErrorWrap::default_desc_code) + .def("error_type", &BaseError::error_type, &BaseErrorWrap::default_error_type) + .def("what", &BaseError::what, &BaseErrorWrap::default_what) + ; - 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; + class_<ScanDataWrap, boost::noncopyable>("ScanData") + // TODO: write a wrapper function to copy the data into a python array, because this doesn't work +// .def("ranges", &ScanData::ranges, return_value_policy<reference_existing_object> (), with_custodian_and_ward_postcall<1, 0> ()) +// .def("intensities", &ScanData::intensities, return_value_policy<reference_existing_object> (), with_custodian_and_ward_postcall<1, 0> ()) + .def("range", &ScanDataWrap::range) + .def("intensity", &ScanDataWrap::intensity) + .def("ranges_length", &ScanData::ranges_length) + .def("intensities_length", &ScanData::intensities_length) + .def("get_error_status", &ScanData::get_error_status) + .def("error_code_to_string", &ScanData::error_code_to_string) + .def("laser_time_stamp", &ScanData::laser_time_stamp) + .def("system_time_stamp", &ScanData::system_time_stamp) + .def("model", &ScanData::model) + .def("buffers_provided", &ScanData::buffers_provided) + .def("as_string", &ScanData::as_string) + .def("clean_up", &ScanData::clean_up) + ; - // 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) - ; + class_<Sensor>("Sensor") + .def("open", &Sensor::open) + .def("open_with_probing", &Sensor::open_with_probing) + .def("close", &Sensor::close) + .def("is_open", &Sensor::is_open) + .def("set_power", &Sensor::set_power) + .def("set_baud", &Sensor::set_baud) + .def("set_ip", &Sensor::set_ip) + .def("reset", &Sensor::reset) + .def("semi_reset", &Sensor::semi_reset) + .def("set_motor_speed", &Sensor::set_motor_speed) + .def("set_high_sensitivity", &Sensor::set_high_sensitivity) + .def("get_sensor_info", &Sensor::get_sensor_info) + .def("get_time", &Sensor::get_time) + .def("get_raw_time", &Sensor::get_raw_time) + .def("calibrate_time", &Sensor::calibrate_time) + .def("time_offset", &Sensor::time_offset) + .def("set_time_offset", &Sensor::set_time_offset) + .def("drift_rate", &Sensor::drift_rate) + .def("set_drift_rate", &Sensor::set_drift_rate) + .def("skew_alpha", &Sensor::skew_alpha) + .def("set_skew_alpha", &Sensor::set_skew_alpha) + .def("get_ranges", &Sensor::get_ranges, sensor_overloads1()) + .def("get_ranges_by_angle", + &Sensor::get_ranges_by_angle, sensor_overloads2()) + .def("get_ranges_intensities", + &Sensor::get_ranges_intensities, sensor_overloads3()) + .def("get_ranges_intensities_by_angle", + &Sensor::get_ranges_intensities_by_angle, sensor_overloads4()) + .def("get_new_ranges", + &Sensor::get_new_ranges, sensor_overloads5()) + .def("get_new_ranges_by_angle", + &Sensor::get_new_ranges_by_angle, sensor_overloads6()) + .def("get_new_ranges_intensities", + &Sensor::get_new_ranges_intensities, sensor_overloads7()) + .def("get_new_ranges_intensities_by_angle", + &Sensor::get_new_ranges_intensities_by_angle, + sensor_overloads8()) + .def("scip_version", &Sensor::scip_version) + .def("set_verbose", &Sensor::set_verbose) + .def("ignore_unknowns", &Sensor::ignore_unknowns) + .def("set_multiecho_mode", &Sensor::set_multiecho_mode) + .def("step_to_angle", &Sensor::step_to_angle) + .def("angle_to_step", &Sensor::angle_to_step) + ; } Modified: gearbox/trunk/src/hokuyo_aist/python/test/hokuyo_aist_example.py =================================================================== --- gearbox/trunk/src/hokuyo_aist/python/test/hokuyo_aist_example.py 2010-09-24 06:17:05 UTC (rev 521) +++ gearbox/trunk/src/hokuyo_aist/python/test/hokuyo_aist_example.py 2010-10-28 09:08:54 UTC (rev 522) @@ -3,89 +3,89 @@ 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]') +def main(): + parser = OptionParser() + parser.add_option('-c', '--clustercount', dest='cluster_count', + type='int', default='1', + help='Cluster count [default: %default]') + parser.add_option('-e', '--endangle', dest='end_angle', type='float', + default='0', + help='End angle to get ranges to [default: %default]') + parser.add_option('-f', '--firststep', dest='first_step', type='int', + default='-1', + help='First step to get ranges from [default: %default]') + parser.add_option('-l', '--laststep', dest='last_step', type='int', + default='-1', + help='Last step to get ranges to [default: %default]') + parser.add_option('-n', '--new', dest='get_new', action='store_true', + default='False', help='Get new ranges instead of latest \ +ranges [default: %default]') + parser.add_option('-o', '--portoptions', dest='port_options', type='string', + default='type=serial,device=/dev/ttyACM0,timeout=1', + help='Port options (see flexiport library) [default: %default]') + parser.add_option('-s', '--startangle', dest='start_angle', 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 () + # 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) + try: + # Create an instance of a laser scanner object + laser = hokuyo_aist.Sensor() + if options.verbose == True: + # Set verbose mode so we see more information in stderr + laser.set_verbose(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) + # Open the laser + laser.open(options.port_options) + # Turn the laser on + laser.set_power(True) - # Get some laser info - #print 'Laser sensor information:' - #info = hokuyo_aist.HokuyoSensorInfo info () - #laser.GetSensorInfo (info) - #print info.AsString () + # Get some laser info + #print 'Laser sensor information:' + #info = hokuyo_aist.SensorInfo info() + #laser.get_sensor_info(info) + #print info.as_string() - # 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) + # Get range data + data = hokuyo_aist.ScanData() + if (options.first_step == -1 and options.last_step == -1) and \ + (options.start_angle == 0 and options.end_angle == 0): + # Get all ranges + if options.get_new == True: + laser.get_new_ranges(data, -1, -1, options.cluster_count) + else: + laser.get_ranges(data, -1, -1, options.cluster_count) + elif options.first_step != -1 or options.last_step != -1: + # Get by step + if options.get_new == True: + laser.get_new_ranges(data, options.first_step, options.last_step, options.cluster_count) + else: + laser.get_ranges(data, options.first_step, options.last_step, options.cluster_count) + else: + # Get by angle + if options.get_new == True: + laser.get_new_ranges_by_angle(data, options.start_angle, options.end_angle, options.cluster_count) + else: + laser.get_ranges_by_angle(data, options.start_angle, options.end_angle, options.cluster_count) - print 'Laser range data:' - print data.AsString () + print 'Laser range data:' + print data.as_string() - # Close the laser - laser.Close () + # Close the laser + laser.close() - except hokuyo_aist.HokuyoError, e: - print 'Caught exception: (' + str (e.Code ()) + ') ' + e.what () - sys.exit (1) + except hokuyo_aist.BaseError, e: + print 'Caught exception: ' + e.what() + return 1 + return 0 if __name__ == '__main__': - main () + main() + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |