From b9dce03f3c04be20a0be610a7c607afa09837b4d Mon Sep 17 00:00:00 2001 From: Shawn Hanna Date: Mon, 4 Nov 2019 17:02:24 -0500 Subject: [PATCH 1/2] added command interface for http setting of iq params --- .../http_command_interface.h | 6 +++ .../pepperl_fuchs_r2000/r2000_driver.h | 35 ++++++++++++++ .../src/driver/http_command_interface.cpp | 6 +++ .../src/driver/r2000_driver.cpp | 47 +++++++++++++++++++ 4 files changed, 94 insertions(+) diff --git a/pepperl_fuchs_r2000/include/pepperl_fuchs_r2000/http_command_interface.h b/pepperl_fuchs_r2000/include/pepperl_fuchs_r2000/http_command_interface.h index 1f5bfab..8c21d0a 100644 --- a/pepperl_fuchs_r2000/include/pepperl_fuchs_r2000/http_command_interface.h +++ b/pepperl_fuchs_r2000/include/pepperl_fuchs_r2000/http_command_interface.h @@ -36,6 +36,12 @@ class HttpCommandInterface //! @returns True on success, false otherwise bool setParameter(const std::string name, const std::string value); + //! Set iq (io) parameter + //! @param name Name + //! @param value Value + //! @returns True on success, false otherwise + bool setIQParameter(const std::string name, const std::string value); + //! Get sensor parameter //! @param name Parameter name //! @returns Optional string value with value of given parameter name diff --git a/pepperl_fuchs_r2000/include/pepperl_fuchs_r2000/r2000_driver.h b/pepperl_fuchs_r2000/include/pepperl_fuchs_r2000/r2000_driver.h index 50ed157..ac69c1e 100644 --- a/pepperl_fuchs_r2000/include/pepperl_fuchs_r2000/r2000_driver.h +++ b/pepperl_fuchs_r2000/include/pepperl_fuchs_r2000/r2000_driver.h @@ -122,6 +122,41 @@ class R2000Driver //! @returns True on success, False otherwise bool setSamplesPerScan( unsigned int samples ); + //! Enable I/Q operations on device + //! @param enabled I/Q global enable switch for all channels. true = on. false = off + //! @returns True on success, False otherwise + bool setIQGlobalEnable(bool enabled); + + //! Set the IQ mode of the given port + //! @param port 1 or 2 + //! @param mode I/Q channel operation mode. Options are: disabled, input_high_z, output_push_pull, output_n_switching, output_p_switching + //! @returns True on success, False otherwise + bool setIQMode(uint8_t iq_port, std::string mode); + + //! Set the IQ polarity of the given port + //! @param port 1 or 2 + //! @param polarity I/Q channel polarity. Options are: active_high, active_low + //! @returns True on success, False otherwise + bool setIQPolarity(uint8_t iq_port, std::string polarity); + + //! Set the IQ off delay param of the given port + //! @param port 1 or 2 + //! @param off_delay I/Q channel pulse extension (ms) + //! @returns True on success, False otherwise + bool setIQOffDelay(uint8_t iq_port, unsigned int off_delay); + + //! Set the IQ source of the given port + //! @param port 1 or 2 (timesync is only on port 2) + //! @param source Options are: iq_output, timesync + //! @returns True on success, False otherwise + bool setIQSource(uint8_t iq_port, std::string source); + + //! Set the IQ timesync interval + //! @param port 1 or 2 (timesync is only on port 2) + //! @param interval Interval for generating a timesync pulse (ms). Intervals MUST be defined in increments of 1000ms. Default = 4000 + //! @returns True on success, False otherwise + bool setIQTimesyncInterval(unsigned int interval); + //! Reboot Laserscanner (Takes ~60s) //! @returns True if command was successfully received, False otherwise bool rebootDevice(); diff --git a/pepperl_fuchs_r2000/src/driver/http_command_interface.cpp b/pepperl_fuchs_r2000/src/driver/http_command_interface.cpp index bc92906..687a055 100644 --- a/pepperl_fuchs_r2000/src/driver/http_command_interface.cpp +++ b/pepperl_fuchs_r2000/src/driver/http_command_interface.cpp @@ -168,6 +168,12 @@ bool HttpCommandInterface::setParameter(const std::string name, const std::strin return sendHttpCommand("set_parameter",name,value) && checkErrorCode(); } +//----------------------------------------------------------------------------- +bool HttpCommandInterface::setIQParameter(const std::string name, const std::string value) +{ + return sendHttpCommand("set_iq_parameter",name,value) && checkErrorCode(); +} + //----------------------------------------------------------------------------- boost::optional< std::string > HttpCommandInterface::getParameter(const std::string name) { diff --git a/pepperl_fuchs_r2000/src/driver/r2000_driver.cpp b/pepperl_fuchs_r2000/src/driver/r2000_driver.cpp index 484132b..eea137c 100644 --- a/pepperl_fuchs_r2000/src/driver/r2000_driver.cpp +++ b/pepperl_fuchs_r2000/src/driver/r2000_driver.cpp @@ -226,6 +226,53 @@ const std::map< std::string, std::string >& R2000Driver::getParameters() return parameters_; } +//----------------------------------------------------------------------------- +bool R2000Driver::setIQGlobalEnable(bool enabled) +{ + return command_interface_->setIQParameter("iq_global_enable", enabled ? "on" : "off"); +} + +//----------------------------------------------------------------------------- +bool R2000Driver::setIQMode(uint8_t iq_port, std::string mode) +{ + std::stringstream ss; + ss << "iq"<setIQParameter(ss.str(), mode); +} + +//----------------------------------------------------------------------------- +bool R2000Driver::setIQPolarity(uint8_t iq_port, std::string polarity) +{ + std::stringstream ss; + ss << "iq"<setIQParameter(ss.str(), polarity); +} + +//----------------------------------------------------------------------------- +bool R2000Driver::setIQOffDelay(uint8_t iq_port, unsigned int off_delay) +{ + std::stringstream ss; + ss << "iq"<setIQParameter(ss.str(), std::to_string(off_delay)); +} + +//----------------------------------------------------------------------------- +bool R2000Driver::setIQSource(uint8_t iq_port, std::string source) +{ + std::stringstream ss; + ss << "iq"<setIQParameter(ss.str(), source); +} + +//----------------------------------------------------------------------------- +bool R2000Driver::setIQTimesyncInterval(unsigned int interval) +{ + if (interval % 1000 != 0){ + std::cerr << "WARNING: Cannot set iq_timesync_interval to " << interval << "(ms). value must be a multiple of 1000 (ms)" << std::endl; + } + return command_interface_->setIQParameter("iq_timesync_interval", std::to_string(interval)); +} + //----------------------------------------------------------------------------- bool R2000Driver::setScanFrequency(unsigned int frequency) { From af103c1561e5e688df07c62cb1894e6031965b31 Mon Sep 17 00:00:00 2001 From: Shawn Hanna Date: Mon, 4 Nov 2019 17:13:03 -0500 Subject: [PATCH 2/2] Fix stringstream creating of iq commands --- pepperl_fuchs_r2000/src/driver/r2000_driver.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pepperl_fuchs_r2000/src/driver/r2000_driver.cpp b/pepperl_fuchs_r2000/src/driver/r2000_driver.cpp index eea137c..1572998 100644 --- a/pepperl_fuchs_r2000/src/driver/r2000_driver.cpp +++ b/pepperl_fuchs_r2000/src/driver/r2000_driver.cpp @@ -236,7 +236,7 @@ bool R2000Driver::setIQGlobalEnable(bool enabled) bool R2000Driver::setIQMode(uint8_t iq_port, std::string mode) { std::stringstream ss; - ss << "iq"<setIQParameter(ss.str(), mode); } @@ -244,7 +244,7 @@ bool R2000Driver::setIQMode(uint8_t iq_port, std::string mode) bool R2000Driver::setIQPolarity(uint8_t iq_port, std::string polarity) { std::stringstream ss; - ss << "iq"<setIQParameter(ss.str(), polarity); } @@ -252,7 +252,7 @@ bool R2000Driver::setIQPolarity(uint8_t iq_port, std::string polarity) bool R2000Driver::setIQOffDelay(uint8_t iq_port, unsigned int off_delay) { std::stringstream ss; - ss << "iq"<setIQParameter(ss.str(), std::to_string(off_delay)); } @@ -260,7 +260,7 @@ bool R2000Driver::setIQOffDelay(uint8_t iq_port, unsigned int off_delay) bool R2000Driver::setIQSource(uint8_t iq_port, std::string source) { std::stringstream ss; - ss << "iq"<setIQParameter(ss.str(), source); }