25#include <SimoxUtility/math/convert/pos_rpy_to_mat4f.h>
26#include <VirtualRobot/VirtualRobotException.h>
27#include <VirtualRobot/XML/RobotIO.h>
59 RtDeactivateController(
const NJointControllerBasePtr& nJointCtrl)
61 nJointCtrl->rtDeactivateController();
65 RtActivateController(
const NJointControllerBasePtr& nJointCtrl)
67 nJointCtrl->rtActivateController();
71 RtDeactivateControllerBecauseOfError(
const NJointControllerBasePtr& nJointCtrl)
73 nJointCtrl->rtDeactivateControllerBecauseOfError();
85 static std::vector<JointController*>&
89 .controllersActivated.getWriteBuffer()
93 static std::vector<NJointControllerBase*>&
97 .controllersActivated.getWriteBuffer()
101 static std::vector<std::size_t>&
102 GetActivatedJointToNJointControllerAssignement(
ControlThread* p)
104 return p->
_module<ControlThreadDataBuffer>()
105 .controllersActivated.getWriteBuffer()
106 .jointToNJointControllerAssignement;
109 static const std::vector<JointController*>&
112 return p->_module<ControlThreadDataBuffer>()
113 .controllersActivated.getWriteBuffer()
117 static const std::vector<NJointControllerBase*>&
120 return p->_module<ControlThreadDataBuffer>()
121 .controllersActivated.getWriteBuffer()
125 static const std::vector<std::size_t>&
126 GetActivatedJointToNJointControllerAssignement(
const ControlThread* p)
128 return p->_module<ControlThreadDataBuffer>()
129 .controllersActivated.getWriteBuffer()
130 .jointToNJointControllerAssignement;
134 AcceptRequestedJointToNJointControllerAssignement(
ControlThread* p)
136 p->_module<ControlThreadDataBuffer>()
137 .controllersActivated.getWriteBuffer()
138 .jointToNJointControllerAssignement = p->_module<ControlThreadDataBuffer>()
139 .controllersRequested.getReadBuffer()
140 .jointToNJointControllerAssignement;
146 return p->_module<ControlThreadDataBuffer>().controllersActivated.commitWrite();
152 return p->_module<ControlThreadDataBuffer>()
153 .controllersActivated.getWriteBuffer()
157 static const std::vector<JointController*>&
161 return p->_module<ControlThreadDataBuffer>()
162 .controllersRequested.getReadBuffer()
166 static const std::vector<NJointControllerBase*>&
170 return p->_module<ControlThreadDataBuffer>()
171 .controllersRequested.getReadBuffer()
175 static const std::vector<std::size_t>&
176 GetRequestedJointToNJointControllerAssignement(
const ControlThread* p)
179 return p->_module<ControlThreadDataBuffer>()
180 .controllersRequested.getReadBuffer()
181 .jointToNJointControllerAssignement;
188 return p->_module<ControlThreadDataBuffer>().controllersRequested.updateReadBuffer();
198 p->_module<ControlThreadDataBuffer>().controllersRequested._getNonConstReadBuffer();
199 auto& j = readbuf.jointControllers;
200 auto& assig = readbuf.jointToNJointControllerAssignement;
201 auto& nj = readbuf.nJointControllers;
203 const auto assigNJ = assig.at(
index);
207 nj.at(assigNJ) =
nullptr;
208 for (std::size_t i = 0; i < assig.size(); ++i)
210 if (assig.at(i) == assigNJ)
212 j.at(i) = j.at(i)->rtGetParent().rtGetJointStopMovementController();
228 static const std::vector<ControlDevicePtr>&
234 static const std::vector<SensorDevicePtr>&
240 static const std::vector<const SensorValueBase*>&
243 return p->
_module<Devices>().sensorValues;
246 static const std::vector<std::vector<PropagateConst<ControlTargetBase*>>>&
249 return p->_module<Devices>().controlTargets;
252 static RTThreadTimingsSensorDevice&
255 return *(p->_module<Devices>().rtThreadTimingsSensorDevice);
261 const std::vector<VirtualRobot::RobotNodePtr>& robotNodes)
263 p->_module<Devices>().updateVirtualRobotFromSensorValues(
264 robot, robotNodes, p->_module<Devices>().sensorValues);
281 if (!m.heartbeatRequired || now < m.controlLoopStartTime + m.heartbeatStartupMarginMS)
285 return (now - m.lastHeartbeat) > m.heartbeatMaxCycleMS;
303 preSwitchSetup_ActivatedJointControllers = rtGetActivatedJointControllers();
304 preSwitchSetup_ActivatedJointToNJointControllerAssignement =
305 rtGetActivatedJointToNJointControllerAssignement();
306 preSwitchSetup_ActivatedNJointControllers = rtGetActivatedNJointControllers();
311 const auto& actJC = rtGetActivatedJointControllers();
312 const auto& assig = rtGetActivatedJointToNJointControllerAssignement();
313 const auto& actNJC = rtGetActivatedNJointControllers();
317 postSwitchSetup_ActivatedJointControllers = actJC;
318 postSwitchSetup_ActivatedJointToNJointControllerAssignement = assig;
319 postSwitchSetup_ActivatedNJointControllers = actNJC;
322 std::size_t numSyncNj = 0;
323 std::size_t numAsyncNj = 0;
325 for (std::size_t i = 0; i < actJC.size(); ++i)
327 if (actNJC.at(i) ==
nullptr)
333 _activatedSynchronousNJointControllersIdx.at(numSyncNj++) = i;
337 _activatedAsynchronousNJointControllersIdx.at(numAsyncNj++) = i;
342 "NJoint controller that is neither SynchronousNJointController"
343 " nor AsynchronousNJointController: %s",
344 actNJC.at(i)->rtGetClassName().c_str());
349 for (std::size_t i = numSyncNj;
350 i < _maxControllerCount &&
351 _activatedSynchronousNJointControllersIdx.at(i) != _maxControllerCount;
354 _activatedSynchronousNJointControllersIdx.at(i) = _maxControllerCount;
356 for (std::size_t i = numAsyncNj;
357 i < _maxControllerCount &&
358 _activatedAsynchronousNJointControllersIdx.at(i) != _maxControllerCount;
361 _activatedAsynchronousNJointControllersIdx.at(i) = _maxControllerCount;
366 rtSwitchControllerSetupChangedControllers =
false;
369 if (!emergencyStop && ManagementAttorneyForControlThread::HeartbeatMissing(
this))
382 if (emergencyStop && !rtThreadOverridesControl)
388 rtIsInEmergencyStop_ =
true;
390 for (
auto& nJointCtrl : rtGetActivatedNJointControllers())
394 NJointControllerAttorneyForControlThread::RtDeactivateController(nJointCtrl);
395 nJointCtrl =
nullptr;
396 rtSwitchControllerSetupChangedControllers =
true;
403 const auto active = controlDevice->rtGetActiveJointController();
404 const auto stopMov = controlDevice->rtGetJointStopMovementController();
405 const auto emergency = controlDevice->rtGetJointEmergencyStopController();
406 if (active != stopMov && active != emergency)
408 controlDevice->rtSetActiveJointController(emergency);
409 rtGetActivatedJointControllers().at(i) = emergency;
410 rtSwitchControllerSetupChangedControllers =
true;
413 if (rtSwitchControllerSetupChangedControllers)
415 ControlThreadDataBufferAttorneyForControlThread::
416 ResetActivatedControllerAssignement(
this);
419 return rtSwitchControllerSetupChangedControllers;
422 if (!rtThreadOverridesControl &&
423 !ControlThreadDataBufferAttorneyForControlThread::RequestedControllersChanged(
this) &&
428 rtIsInEmergencyStop_ =
false;
432 const auto& allReqNJ = rtGetRequestedNJointControllers();
433 auto& allActdNJ = rtGetActivatedNJointControllers();
436 std::size_t idxAct = 0;
437 std::size_t idxReq = 0;
438 for (std::size_t i = 0; i < 2 * n; ++i)
441 while (idxAct < n && !allActdNJ.at(idxAct))
445 const NJointControllerBasePtr& req =
446 idxReq < n ? allReqNJ.at(idxReq) :
nullptr;
447 const NJointControllerBasePtr& act =
448 idxAct < n ? allActdNJ.at(idxAct) :
nullptr;
449 const auto reqId =
reinterpret_cast<std::uintptr_t
>(req.get());
450 const auto actId =
reinterpret_cast<std::uintptr_t
>(act.get());
455 rtSyncNJointControllerRobot(req.get());
456 NJointControllerAttorneyForControlThread::RtActivateController(req);
458 rtSwitchControllerSetupChangedControllers =
true;
460 else if (reqId < actId)
462 NJointControllerAttorneyForControlThread::RtDeactivateController(act);
463 rtSwitchControllerSetupChangedControllers =
true;
472 if (idxAct >= n && !req)
477 allActdNJ = allReqNJ;
482 const auto& allReqJ = rtGetRequestedJointControllers();
483 auto& allActdJ = rtGetActivatedJointControllers();
488 const auto requestedJointCtrl = allReqJ.at(i);
489 controlDevice->rtSetActiveJointController(requestedJointCtrl);
490 allActdJ.at(i) = requestedJointCtrl;
493 ControlThreadDataBufferAttorneyForControlThread::
494 AcceptRequestedJointToNJointControllerAssignement(
this);
505 controlDev->rtGetActiveJointController()->rtResetTarget();
514 numberOfInvalidTargetsInThisIteration = 0;
516 for (std::size_t i = 0; i < cdevs.size(); ++i)
518 if (!rtGetActivatedJointControllers().at(i)->rtIsTargetValid())
522 cdevs.at(i)->rtGetDeviceName());
523 ARMARX_ERROR <<
">>>INVALID TARGET for JointController (idx = " << i <<
") '"
524 << cdevs.at(i)->getDeviceName() <<
"'";
526 ++numberOfInvalidTargetsInThisIteration;
535 const IceUtil::Time& timeSinceLastIteration)
542 device->rtReadSensorValues(sensorValuesTimestamp, timeSinceLastIteration);
549 DevicesAttorneyForControlThread::UpdateRobotWithSensorValues(
this, rtRobot, rtRobotNodes);
556 const IceUtil::Time& timeSinceLastIteration)
561 dynamicsHelpers->update(sensorValuesTimestamp, timeSinceLastIteration);
569 const IceUtil::Time& timeSinceLastIteration)
574 device->rtRun(sensorValuesTimestamp, timeSinceLastIteration);
581 const IceUtil::Time& timeSinceLastIteration)
585 auto activatedNjointCtrls = rtGetActivatedNJointControllers();
587 for (std::size_t nJointCtrlIndex : _activatedAsynchronousNJointControllersIdx)
589 if (nJointCtrlIndex == _maxControllerCount)
594 activatedNjointCtrls.at(nJointCtrlIndex));
601 if (nJointCtrl->rtGetErrorState())
604 "NJointControllerBase '%s' requested deactivation while activating it",
605 nJointCtrl->rtGetInstanceName().c_str());
609 rtSyncNJointControllerRobot(nJointCtrl);
610 nJointCtrl->rtRunIterationBegin(sensorValuesTimestamp, timeSinceLastIteration);
612 if (nJointCtrl->rtGetErrorState())
615 "NJointControllerBase '%s' requested deactivation while running it",
616 nJointCtrl->rtGetInstanceName().c_str());
619 if (
static_cast<std::size_t
>(duration.toMicroSeconds()) >
620 nJointCtrl->rtGetNumberOfUsedControlDevices() * usPerDevUntilError)
623 nJointCtrl->rtGetInstanceName().c_str(),
624 duration.toMicroSeconds())
627 else if (
static_cast<std::size_t
>(duration.toMicroSeconds()) >
628 nJointCtrl->rtGetNumberOfUsedControlDevices() * usPerDevUntilWarn)
631 nJointCtrl->rtGetInstanceName().c_str(),
632 duration.toMicroSeconds())
638 ARMARX_ERROR <<
"NJoint Controller " << nJointCtrl->getInstanceName()
639 <<
" threw an exception and is now deactivated: "
646 for (std::size_t nJointCtrlIndex : _activatedSynchronousNJointControllersIdx)
648 if (nJointCtrlIndex == _maxControllerCount)
658 if (nJointCtrl->rtGetErrorState())
661 "NJointControllerBase '%s' requested deactivation while activating it",
662 nJointCtrl->rtGetInstanceName().c_str());
668 rtSyncNJointControllerRobot(nJointCtrl);
669 nJointCtrl->rtSwapBufferAndRun(sensorValuesTimestamp, timeSinceLastIteration);
671 if (nJointCtrl->rtGetErrorState())
674 "NJointControllerBase '%s' requested deactivation while running it",
675 nJointCtrl->rtGetInstanceName().c_str());
679 if (
static_cast<std::size_t
>(duration.toMicroSeconds()) >
680 nJointCtrl->rtGetNumberOfUsedControlDevices() * usPerDevUntilError)
683 nJointCtrl->rtGetInstanceName().c_str(),
684 duration.toMicroSeconds())
687 else if (
static_cast<std::size_t
>(duration.toMicroSeconds()) >
688 nJointCtrl->rtGetNumberOfUsedControlDevices() * usPerDevUntilWarn)
691 nJointCtrl->rtGetInstanceName().c_str(),
692 duration.toMicroSeconds())
699 ARMARX_ERROR <<
"NJoint Controller " << nJointCtrl->getInstanceName()
700 <<
" threw an exception and is now deactivated: "
707 for (std::size_t nJointCtrlIndex : _activatedAsynchronousNJointControllersIdx)
709 if (nJointCtrlIndex == _maxControllerCount)
714 activatedNjointCtrls.at(nJointCtrlIndex));
721 if (nJointCtrl->rtGetErrorState())
724 "NJointControllerBase '%s' requested deactivation while activating it",
725 nJointCtrl->rtGetInstanceName().c_str());
729 rtSyncNJointControllerRobot(nJointCtrl);
730 nJointCtrl->rtRunIterationEnd(sensorValuesTimestamp, timeSinceLastIteration);
732 if (nJointCtrl->rtGetErrorState())
735 "NJointControllerBase '%s' requested deactivation while running it",
736 nJointCtrl->rtGetInstanceName().c_str());
739 if (
static_cast<std::size_t
>(duration.toMicroSeconds()) >
740 nJointCtrl->rtGetNumberOfUsedControlDevices() * usPerDevUntilError)
743 nJointCtrl->rtGetInstanceName().c_str(),
744 duration.toMicroSeconds())
747 else if (
static_cast<std::size_t
>(duration.toMicroSeconds()) >
748 nJointCtrl->rtGetNumberOfUsedControlDevices() * usPerDevUntilWarn)
751 nJointCtrl->rtGetInstanceName().c_str(),
752 duration.toMicroSeconds())
758 ARMARX_ERROR <<
"NJoint Controller " << nJointCtrl->getInstanceName()
759 <<
" threw an exception and is now deactivated: "
771 const NJointControllerBasePtr& nJointCtrl =
772 rtGetActivatedNJointControllers().at(nJointCtrlIndex);
773 NJointControllerAttorneyForControlThread::RtDeactivateControllerBecauseOfError(nJointCtrl);
774 for (
auto ctrlDevIdx : nJointCtrl->rtGetControlDeviceUsedIndices())
777 JointController* es = controlDevice->rtGetJointEmergencyStopController();
781 <<
VAROUT(ctrlDevIdx) <<
"\n"
782 <<
VAROUT(controlDevice->getDeviceName()) <<
"\n"
785 controlDevice->rtSetActiveJointController(es);
786 rtGetActivatedJointControllers().at(ctrlDevIdx) = es;
787 rtGetActivatedJointToNJointControllerAssignement().at(ctrlDevIdx) =
IndexSentinel();
789 rtGetActivatedNJointControllers().at(nJointCtrlIndex) =
nullptr;
792 for (
auto ctrlDevIdx : nJointCtrl->rtGetControlDeviceUsedIndices())
795 const auto groupIdx = ctrlModeGroups.groupIndices.at(ctrlDevIdx);
805 for (
const auto otherIdx : ctrlModeGroups.deviceIndices.at(groupIdx))
810 if (hwModeHash == otherHwModeHash)
815 const auto otherNJointCtrl1Idx =
816 rtGetActivatedJointToNJointControllerAssignement().at(otherIdx);
826 rtGetActivatedJointControllers().at(otherIdx) = es;
840 std::size_t nJointCtrlIndex =
841 rtGetActivatedJointToNJointControllerAssignement().at(ctrlDevIndex);
843 <<
"no NJoint controller controls this device (name = "
845 << rtGetActivatedJointControllers().at(ctrlDevIndex)->getControlMode() <<
")!"
847 <<
"This means an invariant is violated! Dumping data for debugging:\n"
848 <<
VAROUT(ctrlDevIndex) <<
"\n"
856 const IceUtil::Time& timeSinceLastIteration)
861 ControlThreadDataBufferAttorneyForControlThread::CommitActivatedControllers(
this);
879 sc.
control.at(ctrlIdx).size());
893 const std::vector<ControlDevicePtr>&
896 return DevicesAttorneyForControlThread::GetControlDevices(
this);
899 const std::vector<SensorDevicePtr>&
902 return DevicesAttorneyForControlThread::GetSensorDevices(
this);
908 return DevicesAttorneyForControlThread::GetThreadTimingsSensorDevice(
this);
914 if (state == EmergencyStopState::eEmergencyStopActive)
916 emergencyStopStateRequest = EmergencyStopStateRequest::RequestActive;
920 emergencyStopStateRequest = EmergencyStopStateRequest::RequestInactive;
925 ControlThread::_preFinishControlThreadInitialization()
928 controlThreadId = std::this_thread::get_id();
930 _maxControllerCount = rtGetActivatedJointControllers().size();
933 rtGetActivatedJointToNJointControllerAssignement().size());
936 preSwitchSetup_ActivatedJointControllers.resize(_maxControllerCount);
937 postSwitchSetup_ActivatedJointControllers.resize(_maxControllerCount);
939 preSwitchSetup_ActivatedJointToNJointControllerAssignement.resize(_maxControllerCount);
940 postSwitchSetup_ActivatedJointToNJointControllerAssignement.resize(_maxControllerCount);
942 preSwitchSetup_ActivatedNJointControllers.resize(_maxControllerCount);
943 postSwitchSetup_ActivatedNJointControllers.resize(_maxControllerCount);
945 _activatedSynchronousNJointControllersIdx.resize(_maxControllerCount, _maxControllerCount);
946 _activatedAsynchronousNJointControllersIdx.resize(_maxControllerCount, _maxControllerCount);
953 std::shared_ptr<DynamicsHelper> dynamicsHelpers(
new DynamicsHelper(robotUnit));
955 auto rtRobotBodySet =
rtGetRobot()->getRobotNodeSet(bodySetName);
957 <<
"could not find robot node set with name: " << bodySetName
958 <<
" - Check property InverseDynamicsRobotBodySet";
969 for (
auto& set : setList)
971 auto rns =
rtGetRobot()->getRobotNodeSet(set);
973 <<
" - Check property InverseDynamicsRobotJointSets";
974 dynamicsHelpers->addRobotPart(rns, rtRobotBodySet, velFilter, accFilter);
975 ARMARX_VERBOSE <<
"Added nodeset " << set <<
" for inverse dynamics";
978 this->dynamicsHelpers = dynamicsHelpers;
983 ControlThread::_preOnInitRobotUnit()
989 VirtualRobot::RobotIO::eStructure);
990 rtRobot->setUpdateCollisionModel(
false);
991 rtRobot->setUpdateVisualization(
false);
992 rtRobot->setThreadsafe(
false);
993 rtRobotNodes = rtRobot->getRobotNodes();
995 catch (VirtualRobot::VirtualRobotException& e)
997 throw UserException(e.what());
1000 "NjointController_AllowedExecutionTimePerControlDeviceUntilWarning")
1003 "NjointController_AllowedExecutionTimePerControlDeviceUntilError")
1011 _module<Units>().getEmergencyStopMaster()->setEmergencyStopState(state);
1018 return emergencyStop ? EmergencyStopState::eEmergencyStopActive
1019 : EmergencyStopState::eEmergencyStopInactive;
1027 : EmergencyStopState::eEmergencyStopInactive;
1031 ControlThread::setEmergencyStopStateNoReportToTopic(EmergencyStopState state)
1034 emergencyStop = (state == EmergencyStopState::eEmergencyStopActive);
1038 ControlThread::processEmergencyStopRequest()
1041 emergencyStopStateRequest.exchange(EmergencyStopStateRequest::RequestNone);
1044 case EmergencyStopStateRequest::RequestActive:
1047 case EmergencyStopStateRequest::RequestInactive:
1050 case EmergencyStopStateRequest::RequestNone:
1054 <<
"Unkown value for EmergencyStopStateRequest";
1058 const std::vector<JointController*>&
1059 ControlThread::rtGetActivatedJointControllers()
const
1061 return ControlThreadDataBufferAttorneyForControlThread::GetActivatedJointControllers(
this);
1064 const std::vector<NJointControllerBase*>&
1065 ControlThread::rtGetActivatedNJointControllers()
const
1067 return ControlThreadDataBufferAttorneyForControlThread::GetActivatedNJointControllers(
this);
1070 const std::vector<std::size_t>&
1071 ControlThread::rtGetActivatedJointToNJointControllerAssignement()
const
1073 return ControlThreadDataBufferAttorneyForControlThread::
1074 GetActivatedJointToNJointControllerAssignement(
this);
1077 std::vector<JointController*>&
1078 ControlThread::rtGetActivatedJointControllers()
1080 return ControlThreadDataBufferAttorneyForControlThread::GetActivatedJointControllers(
this);
1083 std::vector<NJointControllerBase*>&
1084 ControlThread::rtGetActivatedNJointControllers()
1086 return ControlThreadDataBufferAttorneyForControlThread::GetActivatedNJointControllers(
this);
1089 std::vector<std::size_t>&
1090 ControlThread::rtGetActivatedJointToNJointControllerAssignement()
1092 return ControlThreadDataBufferAttorneyForControlThread::
1093 GetActivatedJointToNJointControllerAssignement(
this);
1096 const std::vector<JointController*>&
1097 ControlThread::rtGetRequestedJointControllers()
const
1099 return ControlThreadDataBufferAttorneyForControlThread::GetRequestedJointControllers(
this);
1102 const std::vector<NJointControllerBase*>&
1103 ControlThread::rtGetRequestedNJointControllers()
const
1105 return ControlThreadDataBufferAttorneyForControlThread::GetRequestedNJointControllers(
this);
1108 const std::vector<std::size_t>&
1109 ControlThread::rtGetRequestedJointToNJointControllerAssignement()
const
1111 return ControlThreadDataBufferAttorneyForControlThread::
1112 GetRequestedJointToNJointControllerAssignement(
this);
1116 ControlThread::rtSyncNJointControllerRobot(NJointControllerBase* njctrl)
1118 if (njctrl->rtGetRobot())
1121 auto&
from = rtRobotNodes;
1122 auto& to = njctrl->rtGetRobotNodes();
1123 for (std::size_t i = 0; i <
from.size(); ++i)
1125 to.at(i)->copyPoseFrom(
from.at(i));
1129 njctrl->rtGetRobot()->setGlobalPose(rtRobot->getGlobalPose(),
false);
1134 ControlThread::dumpRtControllerSetup(
1136 const std::string& indent,
1137 const std::vector<JointController*>& activeJCtrls,
1138 const std::vector<std::size_t>& assignement,
1139 const std::vector<NJointControllerBase*>& activeNJCtrls)
const
1141 out << indent <<
"JointControllers:\n";
1144 for (std::size_t i = 0; i < cdevs.size(); ++i)
1146 const JointController* jctrl = activeJCtrls.at(i);
1147 out << indent <<
"\t(" << i <<
")\t" << cdevs.at(i)->getDeviceName() <<
":\n"
1148 << indent <<
"\t\t Controller: " << jctrl->getControlMode() <<
" (" << jctrl
1150 << indent <<
"\t\t Assigned NJoint: " << assignement.at(i) <<
"\n";
1153 out << indent <<
"NJointControllers:\n";
1155 for (std::size_t i = 0; i < activeNJCtrls.size(); ++i)
1157 const auto* njctrl = activeNJCtrls.at(i);
1158 out << indent <<
"\t(" << i <<
")\t";
1161 out << njctrl->rtGetInstanceName() <<
" (" << njctrl <<
"):"
1162 <<
"\t Class: " << njctrl->rtGetClassName() <<
"\n";
1166 out <<
" (" << njctrl <<
")\n";
1173 ControlThread::dumpRtState()
const
1175 std::stringstream
str;
1176 str <<
"state requested\n";
1177 dumpRtControllerSetup(
str,
1179 rtGetRequestedJointControllers(),
1180 rtGetRequestedJointToNJointControllerAssignement(),
1181 rtGetRequestedNJointControllers());
1183 str <<
"state before rtSwitchControllerSetup() was called\n";
1184 dumpRtControllerSetup(
str,
1186 preSwitchSetup_ActivatedJointControllers,
1187 preSwitchSetup_ActivatedJointToNJointControllerAssignement,
1188 preSwitchSetup_ActivatedNJointControllers);
1190 str <<
"state after rtSwitchControllerSetup() was called\n";
1191 dumpRtControllerSetup(
str,
1193 postSwitchSetup_ActivatedJointControllers,
1194 postSwitchSetup_ActivatedJointToNJointControllerAssignement,
1195 postSwitchSetup_ActivatedNJointControllers);
1197 str <<
"state now\n";
1198 dumpRtControllerSetup(
str,
1200 rtGetActivatedJointControllers(),
1201 rtGetActivatedJointToNJointControllerAssignement(),
1202 rtGetActivatedNJointControllers());
1204 str <<
VAROUT(rtSwitchControllerSetupChangedControllers) <<
"\n";
1205 str <<
VAROUT(numberOfInvalidTargetsInThisIteration) <<
"\n";
1214 if (not globalPoseSensorDevice)
1219 const auto*
const sensorValue =
1221 if (sensorValue ==
nullptr)
1233 rtRobot->setGlobalPose(gp, updateRobot);
1239 ControlThreadDataBufferAttorneyForControlThread::RTSetJointController(
this,
c,
index);
#define ARMARX_RT_LOGF_ERROR(...)
#define ARMARX_RT_LOGF_WARNING(...)
Property< PropertyType > getProperty(const std::string &name)
The ControlDevice class represents a logical unit accepting commands via its JointControllers.
JointController * rtGetJointStopMovementController()
virtual void rtSetActiveJointController(JointController *jointCtrl)
Activates the given JointController for this device.
JointController * rtGetJointEmergencyStopController()
JointController * rtGetActiveJointController()
const std::vector< JointController * > & rtGetJointControllers()
void _copyTo(std::unique_ptr< T > &target) const
static std::string DeviceName()
The JointController class represents one joint in one control mode.
virtual ControlTargetBase * getControlTarget()=0
std::size_t rtGetHardwareControlModeHash() const
virtual void rtMarkRtHandleInvalidTargetsEnd()=0
virtual void rtMarkRtRunJointControllersEnd()=0
virtual void rtMarkRtHandleInvalidTargetsStart()=0
virtual void rtMarkRtUpdateSensorAndControlBufferEnd()=0
virtual void rtMarkRtRunNJointControllersStart()=0
virtual void rtMarkRtReadSensorDeviceValuesEnd()=0
virtual void rtMarkRtResetAllTargetsStart()=0
virtual void rtMarkRtUpdateSensorAndControlBufferStart()=0
virtual void rtMarkRtReadSensorDeviceValuesStart()=0
virtual void rtMarkRtRunNJointControllersEnd()=0
virtual void rtMarkRtRunJointControllersStart()=0
virtual void rtMarkRtSwitchControllerSetupEnd()=0
virtual void rtMarkRtSwitchControllerSetupStart()=0
virtual void rtMarkRtResetAllTargetsEnd()=0
This class allows minimal access to private members of ControlThreadDataBuffer in a sane fashion for ...
friend class ControlThread
This Module manages all communication into and out of the ControlThread.
This Module manages the ControlThread.
EmergencyStopState getEmergencyStopState() const
Returns the ControlThread's target EmergencyStopState.
void rtSetJointController(JointController *c, std::size_t index)
Activate a joint controller from the rt loop (only works in switch mode RTThread)
void setEmergencyStopState(EmergencyStopState state)
Sets the EmergencyStopState.
const std::vector< ControlDevicePtr > & rtGetControlDevices() const
Returns all ControlDevices.
const std::vector< SensorDevicePtr > & rtGetSensorDevices()
Returns all SensorDevices.
void rtResetAllTargets()
Calls rtResetTarget for all active Joint controllers.
void rtUpdateSensorAndControlBuffer(const IceUtil::Time &sensorValuesTimestamp, const IceUtil::Time &timeSinceLastIteration)
Updates the current SensorValues and ControlTargets for code running outside of the ControlThread.
void rtHandleInvalidTargets()
Deactivates all NJointControllers generating invalid targets.
RTThreadTimingsSensorDevice & rtGetThreadTimingsSensorDevice()
Returns the RTThreadTimingsSensorDevice.
virtual void rtDeactivatedNJointControllerBecauseOfError(const NJointControllerBasePtr &)
Hook for deriving classes (called AFTER a NJointControllerBase is deactivated due to an error)
void rtUpdateRobotGlobalPose()
bool rtSwitchControllerSetup(SwitchControllerMode mode=SwitchControllerMode::IceRequests)
Changes the set of active controllers.
void rtDeactivateAssignedNJointControllerBecauseOfError(std::size_t ctrlDevIndex)
Searches for the NJointControllerBase responsible for the given JointController and deactivates it.
const VirtualRobot::RobotPtr & rtGetRobot() const
Returns the simox robot used in the control thread.
void rtSetEmergencyStopState(EmergencyStopState state)
Set an EmergencyStopState request.
void rtDeactivateNJointControllerBecauseOfError(std::size_t nJointCtrlIndex)
Deactivates a NJointControllerBase and sets all used ControlDevices to EmergencyStop.
EmergencyStopState getRtEmergencyStopState() const
Returns the ControlThread's EmergencyStopState.
void rtRunNJointControllers(const IceUtil::Time &sensorValuesTimestamp, const IceUtil::Time &timeSinceLastIteration)
Runs NJoint controllers.
bool rtIsInEmergencyStop() const
Returns whether the rt thread is in emergency stop.
void rtSetRobotGlobalPose(const Eigen::Matrix4f &gp, bool updateRobot=true)
void rtRunJointControllers(const IceUtil::Time &sensorValuesTimestamp, const IceUtil::Time &timeSinceLastIteration)
Runs Joint controllers and writes target values to ControlDevices.
virtual void rtPostReadSensorDeviceValues(const IceUtil::Time &sensorValuesTimestamp, const IceUtil::Time &timeSinceLastIteration)
Execute code after updating the sensor values.
void rtReadSensorDeviceValues(const IceUtil::Time &sensorValuesTimestamp, const IceUtil::Time &timeSinceLastIteration)
Calls rtReadSensorValues for all SensorDevices.
This class allows minimal access to private members of Devices in a sane fashion for ControlThread.
friend class ControlThread
This Module manages sensor and control devices for a RobotUnit and only allows save and sane access.
This class allows minimal access to private members of Devices in a sane fashion for ControlThread.
friend class ControlThread
This Module handles some general management tasks.
T & _module()
Returns this as ref to the given type.
void throwIfInControlThread(const std::string &fnc) const
Throws if the current thread is the ControlThread.
static constexpr std::size_t IndexSentinel()
Returns a sentinel value for an index (std::numeric_limits<std::size_t>::max())
This class allows minimal access to private members of NJointControllerBase in a sane fashion for Con...
friend class ControlThread
The RobotUnit class manages a robot and its controllers.
Transformation global_T_root
static IceUtil::Time GetTime(TimeMode timeMode=TimeMode::VirtualTime)
Get the current time.
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
#define ARMARX_CHECK_LESS(lhs, rhs)
This macro evaluates whether lhs is less (<) than rhs and if it turns out to be false it will throw a...
#define ARMARX_CHECK_NOT_NULL(ptr)
This macro evaluates whether ptr is not null and if it turns out to be false it will throw an Express...
#define ARMARX_CHECK_EQUAL(lhs, rhs)
This macro evaluates whether lhs is equal (==) rhs and if it turns out to be false it will throw an E...
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
#define ARMARX_VERBOSE
The logging level for verbose information.
#define ARMARX_ON_SCOPE_EXIT
Executes given code when the enclosing scope is left.
std::shared_ptr< class Robot > RobotPtr
std::shared_ptr< RTFilterBase > RTFilterBasePtr
state::Type from(Eigen::Vector3f targetPosition)
std::string GetHandledExceptionString()
std::vector< std::string > Split(const std::string &source, const std::string &splitBy, bool trimElements=false, bool removeEmptyElements=false)
detail::ControlThreadOutputBufferEntry SensorAndControl
std::shared_ptr< const class SensorDevice > ConstSensorDevicePtr
static constexpr std::size_t Sentinel()
std::vector< std::vector< PropagateConst< ControlTargetBase * > > > control
IceUtil::Time writeTimestamp
Timestamp in wall time (never use the virtual time for this)
IceUtil::Time sensorValuesTimestamp
IceUtil::Time timeSinceLastIteration
std::vector< PropagateConst< SensorValueBase * > > sensors