diff --git a/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleControlThread.cpp b/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleControlThread.cpp index e0131a416855174e5571d22d9e44cfac50f76954..88cf11c532113f593f4dfa9056e4469fbc9a7992 100644 --- a/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleControlThread.cpp +++ b/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleControlThread.cpp @@ -853,7 +853,7 @@ namespace armarx::RobotUnitModule } SensorAndControl& sc = _module<ControlThreadDataBuffer>().rtGetSensorAndControlBuffer(); - sc.writeTimestamp = IceUtil::Time::now(); // this has to be in real time + sc.writeTimestamp = armarx::rtNow(); // this has to be in real time sc.sensorValuesTimestamp = sensorValuesTimestamp; sc.timeSinceLastIteration = timeSinceLastIteration; ARMARX_CHECK_EQUAL(rtGetSensorDevices().size(), sc.sensors.size()); diff --git a/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleControllerManagement.cpp b/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleControllerManagement.cpp index 6f0001391b69aa246edc781fee744997f214f988..e53bb97efcc50b5571512f6149706c44c7501cea 100644 --- a/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleControllerManagement.cpp +++ b/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleControllerManagement.cpp @@ -95,8 +95,11 @@ namespace armarx::RobotUnitModule std::stringstream ss; ss << "Requested controller class '" << className << "' unknown! Known classes:" << NJointControllerRegistry::getKeys() - << " (If this class exists in a different lib then load it via " - "loadLibFromPath(path) or loadLibFromPackage(package, lib))"; + << " (If this class exists in a different lib then load it in the property " + "definitions of the RT-unit. DO NOT load it via " + "loadLibFromPath(path) or loadLibFromPackage(package, lib)) (see " + "https://git.h2t.iar.kit.edu/sw/armarx-integration/robots/armar7/documentation/-/" + "issues/85)"; ARMARX_ERROR << ss.str(); throw InvalidArgumentException{ss.str()}; } @@ -303,6 +306,9 @@ namespace armarx::RobotUnitModule ControllerManagement::loadLibFromPath(const std::string& path, const Ice::Current&) { throwIfInControlThread(BOOST_CURRENT_FUNCTION); + ARMARX_WARNING << "Do not use this function as it has implications on the RT thread (see " + "https://git.h2t.iar.kit.edu/sw/armarx-integration/robots/armar7/" + "documentation/-/issues/85)"; const bool result = getArmarXManager()->loadLibFromPath(path); ARMARX_INFO << "loadLibFromPath('" << path << "') -> " << result; return result; @@ -314,6 +320,9 @@ namespace armarx::RobotUnitModule const Ice::Current&) { throwIfInControlThread(BOOST_CURRENT_FUNCTION); + ARMARX_WARNING << "Do not use this function as it has implications on the RT thread (see " + "https://git.h2t.iar.kit.edu/sw/armarx-integration/robots/armar7/" + "documentation/-/issues/85)"; const bool result = getArmarXManager()->loadLibFromPackage(package, lib); ARMARX_INFO << "loadLibFromPackage('" << package << "', '" << lib << "') -> " << result; return result; diff --git a/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleLogging.cpp b/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleLogging.cpp index ee8522d21984cbf6936bd1b2c259e37850398d7f..725bb380ed3638ac9ad71102375c0c4a4a0c8f5d 100644 --- a/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleLogging.cpp +++ b/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModuleLogging.cpp @@ -50,14 +50,14 @@ namespace armarx::RobotUnitModule::details void start() { - t -= IceUtil::Time::now(); + t -= armarx::rtNow(); ++n; } void stop() { - t += IceUtil::Time::now(); + t += armarx::rtNow(); } double @@ -562,11 +562,11 @@ namespace armarx::RobotUnitModule ARMARX_TRACE; throwIfInControlThread(BOOST_CURRENT_FUNCTION); std::lock_guard<std::mutex> guard{rtLoggingMutex}; - const auto now = IceUtil::Time::now(); + const auto now = armarx::rtNow(); // entries are removed last //remove backlog entries - const auto start_time_remove_backlog_entries = IceUtil::Time::now(); + const auto start_time_remove_backlog_entries = armarx::rtNow(); { if (rtLoggingBacklogEnabled) { @@ -579,10 +579,9 @@ namespace armarx::RobotUnitModule } } //log all - const auto start_time_log_all = IceUtil::Time::now(); + const auto start_time_log_all = armarx::rtNow(); details::DoLoggingDurations dlogdurs; { - ARMARX_TRACE; if (!rtLoggingEntries.empty() || !rtDataStreamingEntry.empty()) { ARMARX_DEBUG << deactivateSpam() << "Number of logs " << rtLoggingEntries.size() @@ -617,7 +616,7 @@ namespace armarx::RobotUnitModule ARMARX_DEBUG << ::deactivateSpam() << "the last " << backlog.size() << " iterations are stored"; //flush all files - const auto start_time_flush_all_files = IceUtil::Time::now(); + const auto start_time_flush_all_files = armarx::rtNow(); { for (auto& pair : rtLoggingEntries) { @@ -626,7 +625,7 @@ namespace armarx::RobotUnitModule } //remove entries - const auto start_time_remove_entries = IceUtil::Time::now(); + const auto start_time_remove_entries = armarx::rtNow(); { ARMARX_TRACE; std::vector<std::string> toRemove; @@ -646,7 +645,7 @@ namespace armarx::RobotUnitModule } } //deal with data streaming - const auto start_time_data_streaming = IceUtil::Time::now(); + const auto start_time_data_streaming = armarx::rtNow(); { ARMARX_TRACE; std::vector<RobotUnitDataStreaming::ReceiverPrx> toRemove; @@ -671,7 +670,7 @@ namespace armarx::RobotUnitModule } } // clang-format off - const auto end_time = IceUtil::Time::now(); + const auto end_time = armarx::rtNow(); const auto time_total = (end_time - now).toMilliSecondsDouble(); ARMARX_DEBUG_S << deactivateSpam(1) << "rtlogging time required: " << time_total << "ms\n" @@ -1150,12 +1149,12 @@ void Logging::DataStreamingEntry::send(const RobotUnitDataStreaming::ReceiverPrx& r, std::uint64_t msgId) { ARMARX_TRACE; - const auto start_send = IceUtil::Time::now(); + const auto start_send = armarx::rtNow(); const auto num_timesteps = result.size(); updateCalls.emplace_back(r->begin_update(result, static_cast<Ice::Long>(msgId))); - const auto start_clear = IceUtil::Time::now(); + const auto start_clear = armarx::rtNow(); clearResult(); - const auto end = IceUtil::Time::now(); + const auto end = armarx::rtNow(); ARMARX_DEBUG_S << "Logging::DataStreamingEntry::send" << "\n update " << (start_clear - start_send).toMilliSecondsDouble() << "ms (" << num_timesteps << " timesteps)" diff --git a/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModulePublisher.cpp b/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModulePublisher.cpp index 5d51c4ca2474c8e46bd3be0140ae45ec9e877e55..4b9a12a21520e58e87f0038c808715be940b8584 100644 --- a/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModulePublisher.cpp +++ b/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModulePublisher.cpp @@ -255,7 +255,7 @@ namespace armarx::RobotUnitModule { ARMARX_TRACE; throwIfInControlThread(BOOST_CURRENT_FUNCTION); - const auto beg = TimeUtil::GetTime(true); + const auto beg = armarx::rtNow(); StringVariantBaseMap ctrlDevMap; @@ -314,7 +314,7 @@ namespace armarx::RobotUnitModule } } - const auto end = TimeUtil::GetTime(true); + const auto end = armarx::rtNow(); return new TimedVariant{TimestampVariant{end - beg}, lastControlThreadTimestamp}; } @@ -476,6 +476,7 @@ namespace armarx::RobotUnitModule getProperty<std::string>("DebugDrawerUpdatesTopicName").getValue(); debugObserverTopicName = getProperty<std::string>("DebugObserverTopicName").getValue(); + observerEnablePublishing = getProperty<bool>("ObserverEnablePublishing").getValue(); observerPublishSensorValues = getProperty<bool>("ObserverPublishSensorValues").getValue(); observerPublishControlTargets = getProperty<bool>("ObserverPublishControlTargets").getValue(); @@ -575,7 +576,10 @@ namespace armarx::RobotUnitModule [&] { publish({}); }, publishPeriodMs, false, getName() + "_PublisherTask"); ARMARX_INFO << "starting publisher with timestep " << publishPeriodMs; publisherTask->setDelayWarningTolerance(10 * publishPeriodMs); - publisherTask->start(); + if (observerEnablePublishing) + { + publisherTask->start(); + } } void diff --git a/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModulePublisher.h b/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModulePublisher.h index 9f061fd02cad06539fb919e32087912f72713f6e..ffa451eb40630cf7f54e9e4966a93575d6c2fb98 100644 --- a/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModulePublisher.h +++ b/source/RobotAPI/components/units/RobotUnit/RobotUnitModules/RobotUnitModulePublisher.h @@ -58,6 +58,10 @@ namespace armarx::RobotUnitModule defineOptionalProperty<std::size_t>( "PublishPeriodMs", 10, "Milliseconds between each publish"); + defineOptionalProperty<bool>("ObserverEnablePublishing", + true, + "Whether the publishing thread is started or not", + PropertyDefinitionBase::eModifiable); defineOptionalProperty<bool>("ObserverPublishSensorValues", true, "Whether sensor values are send to the observer", @@ -271,6 +275,8 @@ namespace armarx::RobotUnitModule /// @brief Whether \ref SensorValueBase "SensorValues" should be published to the observers std::atomic_bool observerPublishSensorValues; + /// @brief Whether the publishing thread should be started or not + std::atomic_bool observerEnablePublishing; /// @brief Whether \ref ControlTargetBase "ControlTargets" should be published to the observers std::atomic_bool observerPublishControlTargets; /// @brief Whether \ref Timing information should be published to the observers diff --git a/source/RobotAPI/components/units/RobotUnit/util/RtTiming.h b/source/RobotAPI/components/units/RobotUnit/util/RtTiming.h index 2fa3ffe573037a4c7b27b55a5a8fe43129156c7b..78c86b83633a83ccaf0d73238da632271b956889 100644 --- a/source/RobotAPI/components/units/RobotUnit/util/RtTiming.h +++ b/source/RobotAPI/components/units/RobotUnit/util/RtTiming.h @@ -40,7 +40,7 @@ namespace armarx { using namespace rt_timing::constants; struct timespec ts; - clock_gettime(CLOCK_MONOTONIC, &ts); + clock_gettime(CLOCK_MONOTONIC_RAW, &ts); return IceUtil::Time::microSeconds(ts.tv_sec * seconds2MicroSeconds + ts.tv_nsec / nanoSeconds2MicroSeconds); } @@ -50,9 +50,8 @@ namespace armarx //! \ingroup VirtualTime //! Prints duration with comment in front of it, yet only once per second. #define RT_TIMING_END_COMMENT(name, comment) \ - ARMARX_RT_LOGF_INFO( \ - "%s - duration: %.3f ms", comment, (armarx::rtNow() - name).toMilliSecondsDouble()) \ - .deactivateSpam(1); + printf( \ + "%s - duration: %.3f ms \n", comment, (armarx::rtNow() - name).toMilliSecondsDouble()); //! \ingroup VirtualTime //! Prints duration #define RT_TIMING_END(name) RT_TIMING_END_COMMENT(name, #name) diff --git a/source/RobotAPI/interface/units/RobotUnit/RobotUnitInterface.ice b/source/RobotAPI/interface/units/RobotUnit/RobotUnitInterface.ice index f59b430191bb535cf527d0d3a624849102385756..32bfba607c2147414e9e61bc8ddd8ea50e9be4d6 100644 --- a/source/RobotAPI/interface/units/RobotUnit/RobotUnitInterface.ice +++ b/source/RobotAPI/interface/units/RobotUnit/RobotUnitInterface.ice @@ -284,7 +284,9 @@ module armarx void deactivateAndDeleteNJointControllers(Ice::StringSeq controllerInstanceNames)throws InvalidArgumentException, LogicError; //loading libs + ["deprecate:loadLibFromPath(string path) has dangerous implications on the RT thread. Use the scenario config instead to load additional libraries. See https://git.h2t.iar.kit.edu/sw/armarx-integration/robots/armar7/documentation/-/issues/85"] bool loadLibFromPath(string path); + ["deprecate:loadLibFromPackage(string package, string libname) has dangerous implications on the RT thread. Use the scenario config instead to load additional libraries. See https://git.h2t.iar.kit.edu/sw/armarx-integration/robots/armar7/documentation/-/issues/85"] bool loadLibFromPackage(string package, string libname); }; interface RobotUnitSelfCollisionCheckerInterface