diff --git a/ur_rtde_driver/include/ur_rtde_driver/exceptions.h b/ur_rtde_driver/include/ur_rtde_driver/exceptions.h index c73e5ff..96bc450 100644 --- a/ur_rtde_driver/include/ur_rtde_driver/exceptions.h +++ b/ur_rtde_driver/include/ur_rtde_driver/exceptions.h @@ -16,6 +16,7 @@ #define UR_RTDE_DRIVER_EXCEPTIONS_H_INCLUDED #include +#include namespace ur_driver { @@ -40,5 +41,33 @@ public: private: /* data */ }; + +class VersionMismatch : public UrException +{ +public: + explicit VersionMismatch() : VersionMismatch("", 0, 0) + { + } + explicit VersionMismatch(const std::string& text, const uint32_t version_req, const uint32_t version_actual) + : std::runtime_error(text) + { + version_required_ = version_req; + version_actual_ = version_actual; + std::stringstream ss; + ss << text << "(Required version: " << version_required_ << ", actual version: " << version_actual_ << ")"; + text_ = ss.str(); + } + virtual ~VersionMismatch() = default; + + virtual const char* what() const noexcept override + { + return text_.c_str(); + } + +private: + uint32_t version_required_; + uint32_t version_actual_; + std::string text_; +}; } // namespace ur_driver #endif // ifndef UR_RTDE_DRIVER_EXCEPTIONS_H_INCLUDED diff --git a/ur_rtde_driver/src/ur/ur_driver.cpp b/ur_rtde_driver/src/ur/ur_driver.cpp index 94e61bb..6f79155 100644 --- a/ur_rtde_driver/src/ur/ur_driver.cpp +++ b/ur_rtde_driver/src/ur/ur_driver.cpp @@ -82,9 +82,16 @@ ur_driver::UrDriver::UrDriver(const std::string& robot_ip, const std::string& sc prog.replace(prog.find(SERVER_IP_REPLACE), SERVER_IP_REPLACE.length(), local_ip); prog.replace(prog.find(SERVER_PORT_REPLACE), SERVER_PORT_REPLACE.length(), std::to_string(reverse_port)); + auto urcontrol_version = rtde_client_->getVersion(); + std::stringstream begin_replace; if (tool_comm_setup != nullptr) { + if (urcontrol_version.major < 5) + { + throw VersionMismatch("This robot version does not support using the tool communication interface.", 5, + urcontrol_version.major); + } begin_replace << "set_tool_voltage(" << static_cast::type>(tool_comm_setup->getToolVoltage()) << ")\n"; begin_replace << "set_tool_communication("