From 3cdc705316101c4b667dd258958194ceeeb8108e Mon Sep 17 00:00:00 2001 From: Gerry Salinas Date: Wed, 21 Feb 2024 11:21:57 -0800 Subject: [PATCH 1/6] Make 20ms a default argument of the master & driver bridges. --- .../canopen_base_driver/lely_driver_bridge.hpp | 13 ++++++++----- .../canopen_master_driver/lely_master_bridge.hpp | 13 +++++++++---- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/canopen_base_driver/include/canopen_base_driver/lely_driver_bridge.hpp b/canopen_base_driver/include/canopen_base_driver/lely_driver_bridge.hpp index f25993c2c..c95a29c2a 100644 --- a/canopen_base_driver/include/canopen_base_driver/lely_driver_bridge.hpp +++ b/canopen_base_driver/include/canopen_base_driver/lely_driver_bridge.hpp @@ -314,6 +314,8 @@ class LelyDriverBridge : public canopen::FiberDriver uint8_t nodeid; std::string name_; + + std::chrono::milliseconds sdo_timeout; std::function on_sync_function_; @@ -400,7 +402,7 @@ class LelyDriverBridge : public canopen::FiberDriver */ LelyDriverBridge( ev_exec_t * exec, canopen::AsyncMaster & master, uint8_t id, std::string name, std::string eds, - std::string bin) + std::string bin, std::chrono::milliseconds timeout = 20ms) : FiberDriver(exec, master, id), rpdo_queue(new SafeQueue()), emcy_queue(new SafeQueue()) @@ -417,6 +419,7 @@ class LelyDriverBridge : public canopen::FiberDriver dictionary_->readDCF(a, b, bin.c_str()); } pdo_map_ = dictionary_->createPDOMapping(); + sdo_timeout = timeout; } /** @@ -476,7 +479,7 @@ class LelyDriverBridge : public canopen::FiberDriver this->running = false; this->sdo_cond.notify_one(); }, - 20ms); + this->sdo_timeout); return prom->get_future(); } @@ -568,7 +571,7 @@ class LelyDriverBridge : public canopen::FiberDriver this->running = false; this->sdo_cond.notify_one(); }, - 20ms); + this->sdo_timeout); return prom->get_future(); } @@ -736,7 +739,7 @@ class LelyDriverBridge : public canopen::FiberDriver this->running = false; this->sdo_cond.notify_one(); }, - 20ms); + this->sdo_timeout); } template @@ -763,7 +766,7 @@ class LelyDriverBridge : public canopen::FiberDriver this->running = false; this->sdo_cond.notify_one(); }, - 20ms); + this->sdo_timeout); } template diff --git a/canopen_master_driver/include/canopen_master_driver/lely_master_bridge.hpp b/canopen_master_driver/include/canopen_master_driver/lely_master_bridge.hpp index 1c7cbcf03..cef678434 100644 --- a/canopen_master_driver/include/canopen_master_driver/lely_master_bridge.hpp +++ b/canopen_master_driver/include/canopen_master_driver/lely_master_bridge.hpp @@ -49,6 +49,8 @@ class LelyMasterBridge : public lely::canopen::AsyncMaster bool running; ///< Bool to indicate whether an sdo call is running std::condition_variable sdo_cond; ///< Condition variable to sync service calls (one at a time) uint8_t node_id; ///< Node id of the master + std::chrono::milliseconds + sdo_timeout; ///< Timeout for SDO reads & writes public: /** @@ -60,11 +62,14 @@ class LelyMasterBridge : public lely::canopen::AsyncMaster * @param [in] dcf_txt Path to the DCF file * @param [in] dcf_bin Path to the DCF bin file * @param [in] id CANopen node id of the master + * @param [in] timeout Timeout in milliseconds for SDO reads/writes */ LelyMasterBridge( ev_exec_t * exec, lely::io::TimerBase & timer, lely::io::CanChannelBase & chan, - const std::string & dcf_txt, const std::string & dcf_bin = "", uint8_t id = (uint8_t)255U) - : lely::canopen::AsyncMaster(exec, timer, chan, dcf_txt, dcf_bin, id), node_id(id) + const std::string & dcf_txt, const std::string & dcf_bin = "", uint8_t id = (uint8_t)255U, + std::chrono::milliseconds timeout = 20ms) + : lely::canopen::AsyncMaster(exec, timer, chan, dcf_txt, dcf_bin, id), node_id(id), + sdo_timeout(timeout) { } @@ -120,7 +125,7 @@ class LelyMasterBridge : public lely::canopen::AsyncMaster this->running = false; this->sdo_cond.notify_one(); }, - 20ms); + this->sdo_timeout); } template @@ -145,7 +150,7 @@ class LelyMasterBridge : public lely::canopen::AsyncMaster this->running = false; this->sdo_cond.notify_one(); }, - 20ms); + this->sdo_timeout); } }; From d901cbde8376df81937b1a9940ced171726384cb Mon Sep 17 00:00:00 2001 From: Gerry Salinas Date: Wed, 21 Feb 2024 11:25:59 -0800 Subject: [PATCH 2/6] Include timeout in documentation comment for LelyDriverBridge. --- .../include/canopen_base_driver/lely_driver_bridge.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/canopen_base_driver/include/canopen_base_driver/lely_driver_bridge.hpp b/canopen_base_driver/include/canopen_base_driver/lely_driver_bridge.hpp index c95a29c2a..498c17bdf 100644 --- a/canopen_base_driver/include/canopen_base_driver/lely_driver_bridge.hpp +++ b/canopen_base_driver/include/canopen_base_driver/lely_driver_bridge.hpp @@ -398,6 +398,7 @@ class LelyDriverBridge : public canopen::FiberDriver * @param [in] id NodeId to connect to * @param [in] eds EDS file * @param [in] bin BIN file (concise dcf) + * @param [in] timeout Timeout in milliseconds for SDO reads/writes * */ LelyDriverBridge( From 26ca3cfcace276fdbd4c6ba7f2071661655a7212 Mon Sep 17 00:00:00 2001 From: Gerry Salinas Date: Wed, 21 Feb 2024 11:29:48 -0800 Subject: [PATCH 3/6] Replace two more hardcoded timeouts. --- .../include/canopen_base_driver/lely_driver_bridge.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/canopen_base_driver/include/canopen_base_driver/lely_driver_bridge.hpp b/canopen_base_driver/include/canopen_base_driver/lely_driver_bridge.hpp index 498c17bdf..493fca9ff 100644 --- a/canopen_base_driver/include/canopen_base_driver/lely_driver_bridge.hpp +++ b/canopen_base_driver/include/canopen_base_driver/lely_driver_bridge.hpp @@ -786,7 +786,7 @@ class LelyDriverBridge : public canopen::FiberDriver } if (!is_tpdo) { - if (sync_sdo_read_typed(index, subindex, value, std::chrono::milliseconds(20))) + if (sync_sdo_read_typed(index, subindex, value, this->sdo_timeout)) { return value; } @@ -843,7 +843,7 @@ class LelyDriverBridge : public canopen::FiberDriver } else { - sync_sdo_write_typed(index, subindex, value, std::chrono::milliseconds(20)); + sync_sdo_write_typed(index, subindex, value, this->sdo_timeout); } } }; From e4f737d6b35a2b5195615f2addec96bc64594ab0 Mon Sep 17 00:00:00 2001 From: Gerry Salinas Date: Tue, 27 Feb 2024 13:57:11 -0800 Subject: [PATCH 4/6] Set SDO timeout from node config. --- .../node_canopen_base_driver.hpp | 1 + .../node_canopen_base_driver_impl.hpp | 22 ++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/canopen_base_driver/include/canopen_base_driver/node_interfaces/node_canopen_base_driver.hpp b/canopen_base_driver/include/canopen_base_driver/node_interfaces/node_canopen_base_driver.hpp index a40874606..b075459ae 100644 --- a/canopen_base_driver/include/canopen_base_driver/node_interfaces/node_canopen_base_driver.hpp +++ b/canopen_base_driver/include/canopen_base_driver/node_interfaces/node_canopen_base_driver.hpp @@ -44,6 +44,7 @@ class NodeCanopenBaseDriver : public NodeCanopenDriver std::mutex driver_mutex_; std::shared_ptr lely_driver_; uint32_t period_ms_; + int sdo_timeout_ms_; bool polling_; // nmt state callback diff --git a/canopen_base_driver/include/canopen_base_driver/node_interfaces/node_canopen_base_driver_impl.hpp b/canopen_base_driver/include/canopen_base_driver/node_interfaces/node_canopen_base_driver_impl.hpp index 26ebddab4..b810a0518 100644 --- a/canopen_base_driver/include/canopen_base_driver/node_interfaces/node_canopen_base_driver_impl.hpp +++ b/canopen_base_driver/include/canopen_base_driver/node_interfaces/node_canopen_base_driver_impl.hpp @@ -86,6 +86,16 @@ void NodeCanopenBaseDriver::configure(bool call diagnostic_updater_ = std::make_shared(this->node_); diagnostic_updater_->setHardwareID(std::to_string(this->node_id_)); } + + std::optional sdo_timeout_ms; + try + { + sdo_timeout_ms = std::optional(this->config_["sdo_timeout_ms"].as()); + } + catch(...) + { + } + sdo_timeout_ms_ = sdo_timeout_ms.value_or(20); } template <> void NodeCanopenBaseDriver::configure(bool called_from_base) @@ -141,6 +151,16 @@ void NodeCanopenBaseDriver::configure(bool called_from_base) diagnostic_updater_ = std::make_shared(this->node_); diagnostic_updater_->setHardwareID(std::to_string(this->node_id_)); } + + std::optional sdo_timeout_ms; + try + { + sdo_timeout_ms = std::optional(this->config_["sdo_timeout_ms"].as()); + } + catch(...) + { + } + sdo_timeout_ms_ = sdo_timeout_ms.value_or(20); } template @@ -211,7 +231,7 @@ void NodeCanopenBaseDriver::add_to_master() std::scoped_lock lock(this->driver_mutex_); this->lely_driver_ = std::make_shared( *(this->exec_), *(this->master_), this->node_id_, this->node_->get_name(), this->eds_, - this->bin_); + this->bin_, std::chrono::milliseconds(this->sdo_timeout_ms_)); this->driver_ = std::static_pointer_cast(this->lely_driver_); prom->set_value(lely_driver_); }); From 2fa9268437e72306f84971a0ef76f505ab163b73 Mon Sep 17 00:00:00 2001 From: Gerry Salinas Date: Tue, 27 Feb 2024 14:54:55 -0800 Subject: [PATCH 5/6] Add SDO timeout to device config documentation. --- canopen/sphinx/user-guide/configuration.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/canopen/sphinx/user-guide/configuration.rst b/canopen/sphinx/user-guide/configuration.rst index abdc3579d..d2e5d0d2f 100644 --- a/canopen/sphinx/user-guide/configuration.rst +++ b/canopen/sphinx/user-guide/configuration.rst @@ -151,6 +151,7 @@ device. software_version; The expected software version (default: 0x00000000, see object 1F55). configuration_file; The name of the file containing the configuration (default: "/.bin" (where is the section name), see object 1F22). restore_configuration; The sub-index of object 1011 to be used when restoring the configuration (default: 0x00). + sdo_timeout_ms; The timeout to use for SDO reads/writes to this device. (default: 20ms) sdo; Additional SDO requests to be sent during configuration (see below). From 508f08f3896c4002db71636c6472ac93f87bc83d Mon Sep 17 00:00:00 2001 From: Gerry Salinas Date: Tue, 27 Feb 2024 15:34:32 -0800 Subject: [PATCH 6/6] Revert timeout change to master since I'm not providing a way to set that timeout. --- .../canopen_master_driver/lely_master_bridge.hpp | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/canopen_master_driver/include/canopen_master_driver/lely_master_bridge.hpp b/canopen_master_driver/include/canopen_master_driver/lely_master_bridge.hpp index cef678434..1c7cbcf03 100644 --- a/canopen_master_driver/include/canopen_master_driver/lely_master_bridge.hpp +++ b/canopen_master_driver/include/canopen_master_driver/lely_master_bridge.hpp @@ -49,8 +49,6 @@ class LelyMasterBridge : public lely::canopen::AsyncMaster bool running; ///< Bool to indicate whether an sdo call is running std::condition_variable sdo_cond; ///< Condition variable to sync service calls (one at a time) uint8_t node_id; ///< Node id of the master - std::chrono::milliseconds - sdo_timeout; ///< Timeout for SDO reads & writes public: /** @@ -62,14 +60,11 @@ class LelyMasterBridge : public lely::canopen::AsyncMaster * @param [in] dcf_txt Path to the DCF file * @param [in] dcf_bin Path to the DCF bin file * @param [in] id CANopen node id of the master - * @param [in] timeout Timeout in milliseconds for SDO reads/writes */ LelyMasterBridge( ev_exec_t * exec, lely::io::TimerBase & timer, lely::io::CanChannelBase & chan, - const std::string & dcf_txt, const std::string & dcf_bin = "", uint8_t id = (uint8_t)255U, - std::chrono::milliseconds timeout = 20ms) - : lely::canopen::AsyncMaster(exec, timer, chan, dcf_txt, dcf_bin, id), node_id(id), - sdo_timeout(timeout) + const std::string & dcf_txt, const std::string & dcf_bin = "", uint8_t id = (uint8_t)255U) + : lely::canopen::AsyncMaster(exec, timer, chan, dcf_txt, dcf_bin, id), node_id(id) { } @@ -125,7 +120,7 @@ class LelyMasterBridge : public lely::canopen::AsyncMaster this->running = false; this->sdo_cond.notify_one(); }, - this->sdo_timeout); + 20ms); } template @@ -150,7 +145,7 @@ class LelyMasterBridge : public lely::canopen::AsyncMaster this->running = false; this->sdo_cond.notify_one(); }, - this->sdo_timeout); + 20ms); } };