40 static std::vector<JointController*>
57 const std::set<NJointControllerBasePtr>& request)
66 JointAndNJointControllers
71 std::lock_guard<std::recursive_mutex> guard{controllersActivatedMutex};
72 return controllersActivated.getReadBuffer();
75 std::vector<JointController*>
80 std::lock_guard<std::recursive_mutex> guard{controllersActivatedMutex};
81 return controllersActivated.getReadBuffer().jointControllers;
84 std::vector<NJointControllerBase*>
89 std::lock_guard<std::recursive_mutex> guard{controllersActivatedMutex};
90 return controllersActivated.getReadBuffer().nJointControllers;
98 std::lock_guard<std::recursive_mutex> guard{controllersActivatedMutex};
99 return controllersActivated.updateReadBuffer();
107 std::lock_guard<std::recursive_mutex> guard{controllersRequestedMutex};
108 return controllersRequested.getWriteBuffer();
111 std::vector<JointController*>
116 std::lock_guard<std::recursive_mutex> guard{controllersRequestedMutex};
117 return controllersRequested.getWriteBuffer().jointControllers;
120 std::vector<NJointControllerBase*>
125 std::lock_guard<std::recursive_mutex> guard{controllersRequestedMutex};
126 return controllersRequested.getWriteBuffer().nJointControllers;
151 const auto& nJointCtrls = setOfControllers.nJointControllers;
152 std::set<NJointControllerBasePtr> nJointSet{nJointCtrls.begin(), nJointCtrls.end()};
153 nJointSet.erase(
nullptr);
155 const std::size_t nNJointCtrls =
156 std::count_if(nJointCtrls.begin(),
158 [](
const NJointControllerBasePtr& p) { return p; });
162 _module<Devices>().getNumberOfControlDevices());
165 nJointCtrls.begin() + nNJointCtrls,
173 nJointCtrls.begin(), nJointCtrls.end(), std::greater<NJointControllerBase*>{}));
175 nJointCtrls.begin(), nJointCtrls.begin() + nNJointCtrls));
178 const auto& jointCtrls = setOfControllers.jointControllers;
180 _module<Devices>().getNumberOfControlDevices());
182 jointCtrls.begin(), jointCtrls.end(), [](
JointController* p) { return p; }));
187 std::size_t grpIdx = 0;
188 for (
const auto& group : _module<Devices>().getControlModeGroups().groups)
192 setOfControllers.jointControllers
193 .at(_module<Devices>().getControlDeviceIndex(*group.begin()))
194 ->getHardwareControlMode();
195 ARMARX_DEBUG <<
"---- group " << grpIdx <<
" mode '" << hwMode <<
"'";
196 for (
const auto& other : group)
198 const auto& dev = _module<Devices>().getControlDeviceIndex(other);
200 const auto otherHwMode =
201 setOfControllers.jointControllers.at(dev)->getHardwareControlMode();
202 ARMARX_DEBUG <<
"-------- '" << other <<
"'' mode '" << otherHwMode <<
"'";
211 setOfControllers.resetAssignement();
212 for (std::size_t nJointCtrlIndex = 0;
213 nJointCtrlIndex < setOfControllers.nJointControllers.size();
216 const NJointControllerBase* nJoint =
217 setOfControllers.nJointControllers.at(nJointCtrlIndex);
223 for (std::size_t jointIndex : nJoint->getControlDeviceUsedIndices())
226 << setOfControllers.jointToNJointControllerAssignement.at(
228 <<
"-> " << nJointCtrlIndex;
231 setOfControllers.jointToNJointControllerAssignement.at(jointIndex) =
242 ControllerManagementAttorneyForControlThreadDataBuffer::
243 UpdateNJointControllerRequestedState(
this, nJointSet);
246 setOfControllers.jointControllers.size());
248 setOfControllers.nJointControllers.size());
250 setOfControllers.jointToNJointControllerAssignement.size());
252 std::lock_guard<std::recursive_mutex> guard{controllersRequestedMutex};
253 controllersRequested.getWriteBuffer() = std::move(setOfControllers);
254 controllersRequested.commitWrite();
257 <<
"writeRequestedControllers(JointAndNJointControllers&& setOfControllers)...done!";
262 std::set<NJointControllerBasePtr, std::greater<NJointControllerBasePtr>> ctrls)
265 std::lock_guard<std::recursive_mutex> guardRequested{controllersRequestedMutex};
268 ctrls.erase(
nullptr);
271 const std::set<NJointControllerBasePtr, std::greater<NJointControllerBasePtr>>
272 setOfRequestedCtrls{controllersRequested.getWriteBuffer().nJointControllers.begin(),
273 controllersRequested.getWriteBuffer().nJointControllers.end()};
274 if (setOfRequestedCtrls == ctrls)
277 controllersRequested.commitWrite();
282 for (
const NJointControllerBasePtr& nJointCtrl : ctrls)
286 for (
const auto& cd2cm : nJointCtrl->getControlDeviceUsedControlModeMap())
288 std::size_t jointCtrlIndex =
289 _module<Devices>().getControlDevices().index(cd2cm.first);
290 if (request.jointControllers.at(jointCtrlIndex))
292 std::stringstream ss;
293 ss <<
"RobotUnit:setActivateControllersRequest controllers to activate are in "
294 "conflict!\ncontrollers:";
295 for (
const auto& ctrl : ctrls)
297 ss <<
"\n" << ctrl->getInstanceName();
300 throw InvalidArgumentException{ss.str()};
302 request.jointControllers.at(jointCtrlIndex) =
306 ->getJointController(cd2cm.second);
310 std::size_t jointControllersCount = request.jointControllers.size();
311 for (std::size_t i = 0; i < jointControllersCount; ++i)
317 controllersRequested.getWriteBuffer().jointControllers.at(i);
319 _module<Devices>().getControlDevices().at(i)->getJointStopMovementController())
322 jointCtrl = jointCtrlOld;
327 jointCtrl = _module<Devices>()
330 ->getJointEmergencyStopController();
337 for (std::size_t i = 0; i < request.nJointControllers.size(); ++i)
339 const auto& ctrl = request.nJointControllers.at(i);
342 out << i <<
"\t'" << ctrl->getInstanceName() <<
"' \t of class '"
343 << ctrl->getClassName() <<
"'\n";
347 writeRequestedControllers(std::move(request));
353 const std::vector<VirtualRobot::RobotNodePtr>& nodes)
const
356 _module<Devices>().updateVirtualRobotFromSensorValues(
364 _module<Devices>().updateVirtualRobotFromSensorValues(
369 ControlThreadDataBuffer::_postFinishDeviceInitialization()
374 ARMARX_DEBUG <<
"----initializing controller buffers for "
375 << _module<Devices>().getNumberOfControlDevices() <<
" control devices";
379 ctrlinitReq.jointControllers.size());
381 ctrlinitReq.nJointControllers.size());
383 ctrlinitReq.jointToNJointControllerAssignement.size());
384 controllersActivated.reinitAllBuffers(ctrlinitReq);
386 ctrlinitReq.jointControllers =
387 DevicesAttorneyForControlThreadDataBuffer::GetStopMovementJointControllers(
this);
389 ctrlinitReq.jointControllers.size());
391 ctrlinitReq.nJointControllers.size());
393 ctrlinitReq.jointToNJointControllerAssignement.size());
394 controllersRequested.reinitAllBuffers(ctrlinitReq);