Skip to content
Snippets Groups Projects
Commit b2de1957 authored by Raphael Grimm's avatar Raphael Grimm
Browse files

Rename getRequestedXYZ functions to copyRequestedXYZ (the new name makes their functionality clear)

Also fix some errors due to value return instead of reference return
parent 1a9885c7
No related branches found
No related tags found
1 merge request!39Robot unit v3
......@@ -90,21 +90,21 @@ namespace armarx
return controllersActivated.updateReadBuffer();
}
JointAndNJointControllers ControlThreadDataBuffer::getRequestedControllers() const
JointAndNJointControllers ControlThreadDataBuffer::copyRequestedControllers() const
{
throwIfDevicesNotReady(__FUNCTION__);
std::lock_guard<std::recursive_mutex> guard{controllersRequestedMutex};
return controllersRequested.getWriteBuffer();
}
std::vector<JointController *> ControlThreadDataBuffer::getRequestedJointControllers() const
std::vector<JointController *> ControlThreadDataBuffer::copyRequestedJointControllers() const
{
throwIfDevicesNotReady(__FUNCTION__);
std::lock_guard<std::recursive_mutex> guard{controllersRequestedMutex};
return controllersRequested.getWriteBuffer().jointControllers;
}
std::vector<NJointController *> ControlThreadDataBuffer::getRequestedNJointControllers() const
std::vector<NJointController *> ControlThreadDataBuffer::copyRequestedNJointControllers() const
{
throwIfDevicesNotReady(__FUNCTION__);
std::lock_guard<std::recursive_mutex> guard{controllersRequestedMutex};
......@@ -229,11 +229,12 @@ namespace armarx
//erase nullptr
ctrls.erase(nullptr);
ARMARX_CHECK_EXPRESSION(ctrls.size() <= _module<Devices>().getNumberOfControlDevices());
const std::set<NJointControllerPtr, std::greater<NJointControllerPtr>> setOfRequestedCtrls
{
getRequestedNJointControllers().begin(),
getRequestedNJointControllers().end()
} ;
controllersRequested.getWriteBuffer().nJointControllers.begin(),
controllersRequested.getWriteBuffer().nJointControllers.end()
};
if (setOfRequestedCtrls == ctrls)
{
//redirty the flag to swap in the same set again
......@@ -268,7 +269,7 @@ namespace armarx
JointController*& jointCtrl = request.jointControllers.at(i);
if (!jointCtrl)
{
JointController* jointCtrlOld = getRequestedJointControllers().at(i);
JointController* jointCtrlOld = controllersRequested.getWriteBuffer().jointControllers.at(i);
if (jointCtrlOld == _module<Devices>().getControlDevices().at(i)->getJointStopMovementController())
{
//don't replace this controller with emergency stop
......
......@@ -155,7 +155,7 @@ namespace armarx
* @see NJointController::deactivateController
* @see setActivateControllersRequest
*/
JointAndNJointControllers getRequestedControllers() const;
JointAndNJointControllers copyRequestedControllers() const;
/**
* @brief Returns the set of requsted \ref JointController "JointControllers".
* @return The set of requested \ref JointController "JointControllers".
......@@ -167,7 +167,7 @@ namespace armarx
* @see NJointController::deactivateController
* @see setActivateControllersRequest
*/
std::vector<JointController*> getRequestedJointControllers() const;
std::vector<JointController*> copyRequestedJointControllers() const;
/**
* @brief Returns the set of requsted \ref NJointController "NJointControllers".
* @return The set of requested \ref NJointController "NJointControllers".
......@@ -179,7 +179,7 @@ namespace armarx
* @see NJointController::deactivateController
* @see setActivateControllersRequest
*/
std::vector<NJointController *> getRequestedNJointControllers() const;
std::vector<NJointController *> copyRequestedNJointControllers() const;
/**
* @brief Updates the sensor and control buffer and returns whether the buffer was updated.
......
......@@ -78,7 +78,7 @@ namespace armarx
Ice::StringSeq ControllerManagement::getRequestedNJointControllerNames(const Ice::Current &) const
{
auto guard = getGuard();
return GetNonNullNames(_module<ControlThreadDataBuffer>().getRequestedNJointControllers());
return GetNonNullNames(_module<ControlThreadDataBuffer>().copyRequestedNJointControllers());
}
Ice::StringSeq ControllerManagement::getActivatedNJointControllerNames(const Ice::Current &) const
......@@ -284,11 +284,8 @@ namespace armarx
ARMARX_DEBUG << "all requested controllers exist" << std::flush;
std::set<NJointControllerPtr, std::greater<NJointControllerPtr>> ctrlsToAct {ctrlsToActVec.begin(), ctrlsToActVec.end()};
ARMARX_CHECK_EXPRESSION(!ctrlsToAct.count(nullptr));
std::set<NJointControllerPtr, std::greater<NJointControllerPtr>> ctrls
{
_module<ControlThreadDataBuffer>().getRequestedNJointControllers().begin(),
_module<ControlThreadDataBuffer>().getRequestedNJointControllers().end()
};
const auto ctrlVector = _module<ControlThreadDataBuffer>().copyRequestedNJointControllers();
std::set<NJointControllerPtr, std::greater<NJointControllerPtr>> ctrls {ctrlVector.begin(), ctrlVector.end()};
ctrls.erase(nullptr);
//check for conflict
std::vector<char> inuse;
......@@ -353,11 +350,8 @@ namespace armarx
auto guard = getGuard();
throwIfDevicesNotReady(__FUNCTION__);
auto ctrlsDeacVec = getNJointControllersNotNull(names); //also checks if these controllers exist
std::set<NJointControllerPtr, std::greater<NJointControllerPtr>> ctrls
{
_module<ControlThreadDataBuffer>().getRequestedNJointControllers().begin(),
_module<ControlThreadDataBuffer>().getRequestedNJointControllers().end()
};
const auto ctrlVector = _module<ControlThreadDataBuffer>().copyRequestedNJointControllers();
std::set<NJointControllerPtr, std::greater<NJointControllerPtr>> ctrls {ctrlVector.begin(), ctrlVector.end()};
for (const auto& nJointCtrlToDeactivate : ctrlsDeacVec)
{
ctrls.erase(nJointCtrlToDeactivate);
......
......@@ -136,8 +136,9 @@ namespace armarx
const auto activeJointCtrl = _module<ControlThreadDataBuffer>().getActivatedJointControllers().at(idx);
status.activeControlMode = activeJointCtrl ? activeJointCtrl->getControlMode() : std::string {"!!JointController is nullptr!!"};
status.deviceName = controlDevice->getDeviceName();
ARMARX_CHECK_EXPRESSION(_module<ControlThreadDataBuffer>().getRequestedJointControllers().at(idx));
status.requestedControlMode = _module<ControlThreadDataBuffer>().getRequestedJointControllers().at(idx)->getControlMode();
const auto requestedJointControllers = _module<ControlThreadDataBuffer>().copyRequestedJointControllers();
ARMARX_CHECK_EXPRESSION(requestedJointControllers.at(idx));
status.requestedControlMode = requestedJointControllers.at(idx)->getControlMode();
for (const auto& targ : _module<ControlThreadDataBuffer>().getSensorAndControlBuffer().control.at(idx))
{
status.controlTargetValues[targ->getControlMode()] = targ->toVariants(_module<ControlThreadDataBuffer>().getSensorAndControlBuffer().sensorValuesTimestamp);
......
......@@ -285,7 +285,7 @@ namespace armarx
//setup datastructures
const auto& controlThreadOutputBuffer = _module<ControlThreadDataBuffer>().getSensorAndControlBuffer();
const auto& activatedControllers = _module<ControlThreadDataBuffer>().getActivatedControllers();
const auto& requestedJointControllers = _module<ControlThreadDataBuffer>().getRequestedJointControllers();
const auto requestedJointControllers = _module<ControlThreadDataBuffer>().copyRequestedJointControllers();
const auto timestamp = controlThreadOutputBuffer.sensorValuesTimestamp;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment