25#include <VirtualRobot/MathTools.h>
26#include <VirtualRobot/RobotNodeSet.h>
37#include <armarx/control/common/control_law/aron/KeypointControllerConfig.aron.generated.h>
42 NJointControllerRegistration<NJointKeypointsImpedanceController>
44 "NJointKeypointsImpedanceController");
48 const NJointControllerConfigPtr& config,
51 ConfigPtrT cfg = ConfigPtrT::dynamicCast(config);
80 for (
size_t i = 0; i < rtRns->getSize(); ++i)
82 std::string jointName = rtRns->getNode(i)->getName();
88 auto casted_ct = ct->
asA<ControlTarget1DoFActuatorTorque>();
92 const SensorValue1DoFActuatorTorque* torqueSensor =
93 sv->
asA<SensorValue1DoFActuatorTorque>();
94 const SensorValue1DoFActuatorVelocity* velocitySensor =
95 sv->
asA<SensorValue1DoFActuatorVelocity>();
96 const SensorValue1DoFActuatorPosition* positionSensor =
97 sv->
asA<SensorValue1DoFActuatorPosition>();
104 ARMARX_WARNING <<
"No velocity sensor available for " << jointName;
108 ARMARX_WARNING <<
"No position sensor available for " << jointName;
122 return "NJointKeypointsImpedanceController";
133 runTask(
"NJointTaskspaceAdmittanceAdditionalTask",
139 <<
"Create a new thread alone NJointKeypointsImpedanceController";
140 while (
getState() == eManagedIceObjectStarted)
146 c.waitForCycleDuration();
162 const IceUtil::Time& timeSinceLastIteration)
164 double deltaT = timeSinceLastIteration.toSecondsDouble();
176 for (
size_t i = 0; i < nDoF; ++i)
178 s.jointPosition[i] =
sensorDevices.positionSensors[i]->position;
179 s.jointVelocity[i] =
sensorDevices.velocitySensors[i]->velocity;
199 const Ice::Current& iceCurrent)
224 const auto checkSize = [nDoF](
const auto& v)
226 const auto checkNonNegative = [](
const auto& v) {
ARMARX_CHECK((v.array() >= 0).all()); };
230 ARMARX_INFO <<
"No user defined nullspace target, reset to zero with " <<
VAROUT(nDoF);
231 configData.desiredNullspaceJointAngles = Eigen::VectorXf::Zero(nDoF);
234 checkSize(configData.desiredNullspaceJointAngles.value());
235 checkSize(configData.kdNullspaceTorque);
236 checkSize(configData.kpNullspaceTorque);
238 checkNonNegative(configData.kdNullspaceTorque);
239 checkNonNegative(configData.kpNullspaceTorque);
240 checkNonNegative(configData.kdImpedance);
241 checkNonNegative(configData.kpImpedance);
261 auto nonRtData =
controller.bufferNonRtToOnPublish.getUpToDateReadBuffer();
262 auto rtData =
controller.bufferRtToOnPublish.getUpToDateReadBuffer();
280 datafields,
"desiredKeypointPosition", nonRtData.desiredKeypointPosition);
282 datafields,
"currentKeypointPosition", nonRtData.currentKeypointPosition);
284 datafields,
"currentKeypointVelocity", nonRtData.currentKeypointVelocity);
286 datafields,
"filteredKeypointPosition", nonRtData.filteredKeypointPosition);
288 debugObs->setDebugChannel(
"NJointKeypointsImpedanceController", datafields);
295 Eigen::Matrix4f currentPose = rns->getTCP()->getPoseInRootFrame();
296 ARMARX_IMPORTANT <<
"rt preactivate controller with target pose\n\n" << currentPose;
302 c.desiredNullspaceJointAngles.value() = rns->getJointValuesEigen();
310 const auto nDoF = rns->getSize();
313 law::RobotStatus rtToNonRtStatus;
314 rtToNonRtStatus.jointPosition.resize(nDoF, 0.);
315 rtToNonRtStatus.jointVelocity.resize(nDoF, 0.);
316 rtToNonRtStatus.jointTorque.resize(nDoF, 0.);
317 for (
size_t i = 0; i < nDoF; ++i)
319 rtToNonRtStatus.jointPosition[i] =
sensorDevices.positionSensors[i]->position;
320 rtToNonRtStatus.jointVelocity[i] =
sensorDevices.velocitySensors[i]->velocity;
321 rtToNonRtStatus.jointTorque[i] =
sensorDevices.torqueSensors[i]->torque;
Brief description of class JointControlTargetBase.
This util class helps with keeping a cycle time during a control cycle.
ArmarXObjectSchedulerPtr getObjectScheduler() const
int getState() const
Retrieve current state of the ManagedIceObject.
bool isControllerActive(const Ice::Current &=Ice::emptyCurrent) const final override
const SensorValueBase * useSensorValue(const std::string &sensorDeviceName) const
Get a const ptr to the given SensorDevice's SensorValue.
void runTask(const std::string &taskName, Task &&task)
Executes a given task in a separate thread from the Application ThreadPool.
const VirtualRobot::RobotPtr & useSynchronizedRtRobot(bool updateCollisionModel=false)
Requests a VirtualRobot for use in rtRun *.
const VirtualRobot::RobotPtr & rtGetRobot()
TODO make protected and use attorneys.
ControlTargetBase * useControlTarget(const std::string &deviceName, const std::string &controlMode)
Declares to calculate the ControlTarget for the given ControlDevice in the given ControlMode when rtR...
The SensorValueBase class.
std::atomic_bool rtFirstRun
void onPublish(const SensorAndControl &, const DebugDrawerInterfacePrx &, const DebugObserverInterfacePrx &) override
void onInitNJointController() override
NJointControllerBase interface.
ConfigurableNJointControllerConfigPtr ConfigPtrT
TripleBuffer< BO > bufferUserToAdditionalTask
set buffers
::armarx::aron::data::dto::DictPtr getConfig(const Ice::Current &iceCurrent=Ice::emptyCurrent) override
std::vector< ControlTarget1DoFActuatorTorque * > targets
std::string kinematicChainName
variables
std::vector< std::string > jointNames
NJointKeypointsImpedanceController(const RobotUnitPtr &robotUnit, const NJointControllerConfigPtr &config, const VirtualRobot::RobotPtr &)
void validateConfigData(BO &config)
void rtPostDeactivateController() override
This function is called after the controller is deactivated.
virtual void additionalTask()
common::control_law::ControlTarget controlTargets
std::atomic_bool reInitPreActivate
void rtRun(const IceUtil::Time &sensorValuesTimestamp, const IceUtil::Time &timeSinceLastIteration) override
TODO make protected and use attorneys.
TripleBuffer< BO > bufferUserToRt
void updateConfig(const ::armarx::aron::data::dto::DictPtr &dto, const Ice::Current &iceCurrent=Ice::emptyCurrent) override
NJointController interface.
TripleBuffer< BO > bufferAdditionalTaskToUser
law::KeypointsImpedanceController::Config BO
VirtualRobot::RobotPtr nonRtRobot
TripleBuffer< law::RobotStatus > bufferRtToAdditionalTask
std::string getClassName(const Ice::Current &) const override
void rtPreActivateController() override
This function is called before the controller is activated.
SensorDevices sensorDevices
#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(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
#define ARMARX_CHECK_GREATER_EQUAL(lhs, rhs)
This macro evaluates whether lhs is greater or equal (>=) rhs and if it turns out to be false it will...
#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_INFO
The normal logging level.
#define ARMARX_IMPORTANT
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
std::shared_ptr< class Robot > RobotPtr
::IceInternal::Handle< Dict > DictPtr
void debugEigenVec(StringVariantBaseMap &datafields, const std::string &name, Eigen::VectorXf vec)
void debugEigenPose(StringVariantBaseMap &datafields, const std::string &name, Eigen::Matrix4f pose)
NJointControllerRegistration< NJointKeypointsImpedanceController > registrationControllerNJointKeypointsImpedanceController("NJointKeypointsImpedanceController")
::IceInternal::ProxyHandle<::IceProxy::armarx::DebugObserverInterface > DebugObserverInterfacePrx
std::map< std::string, VariantBasePtr > StringVariantBaseMap
::armarx::aron::data::dto::DictPtr toAronDict(const BOType &bo)
T fromAronDict(const ::armarx::aron::data::dto::DictPtr &dto)
IceUtil::Handle< class RobotUnit > RobotUnitPtr
::IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface > DebugDrawerInterfacePrx
detail::ControlThreadOutputBufferEntry SensorAndControl