26#include <VirtualRobot/IK/DifferentialIK.h>
27#include <VirtualRobot/Robot.h>
28#include <VirtualRobot/RobotNodeSet.h>
35#define DEFAULT_TCP_STRING "default TCP"
40 NJointControllerRegistration<NJointCartesianTorqueController>
46 return "NJointCartesianTorqueController";
51 NJointCartesianTorqueControllerConfigPtr config,
56 VirtualRobot::RobotNodeSetPtr rns =
rtGetRobot()->getRobotNodeSet(config->nodeSetName);
58 for (
size_t i = 0; i < rns->getSize(); ++i)
60 std::string jointName = rns->getNode(i)->getName();
63 targets.push_back(ct->
asA<ControlTarget1DoFActuatorTorque>());
84 nodeSetName = config->nodeSetName;
86 ik.reset(
new VirtualRobot::DifferentialIK(
87 rns, rns->getRobot()->getRootNode(), VirtualRobot::JacobiProvider::eSVDDamped));
104 const IceUtil::Time& timeSinceLastIteration)
106 Eigen::VectorXf cartesianFT(6);
111 Eigen::MatrixXf jacobi =
112 ik->getJacobianMatrix(tcp, VirtualRobot::IKSolver::CartesianSelection::All);
113 Eigen::MatrixXf jacobiT = jacobi.transpose();
116 Eigen::VectorXf jointTargetTorques = jacobiT * cartesianFT;
120 for (
size_t i = 0; i < targets.size(); ++i)
122 targets.at(i)->torque = jointTargetTorques(i);
126 WidgetDescription::HBoxLayoutPtr
131 auto addSlider = [&](
const std::string& label,
float min,
float max,
float defaultValue)
133 layout->children.emplace_back(
new Label(
false, label));
135 floatSlider->name = label;
136 floatSlider->min =
min;
137 floatSlider->defaultValue = defaultValue;
138 floatSlider->max =
max;
139 layout->children.emplace_back(floatSlider);
142 addSlider(
"forceX", -10, 10, 0);
143 addSlider(
"forceY", -10, 10, 0);
144 addSlider(
"forceZ", -10, 10, 0);
145 addSlider(
"torqueX", -1, 1, 0);
146 addSlider(
"torqueY", -1, 1, 0);
147 addSlider(
"torqueZ", -1, 1, 0);
178 const std::map<std::string, ConstControlDevicePtr>& controlDevices,
179 const std::map<std::string, ConstSensorDevicePtr>&)
184 LabelPtr label =
new Label;
185 label->text =
"nodeset name";
186 layout->children.emplace_back(label);
187 StringComboBoxPtr box =
new StringComboBox;
188 box->defaultIndex = 0;
190 box->options = robot->getRobotNodeSetNames();
191 box->name =
"nodeSetName";
192 layout->children.emplace_back(box);
194 LabelPtr labelTCP =
new Label;
195 labelTCP->text =
"tcp name";
196 layout->children.emplace_back(labelTCP);
197 StringComboBoxPtr boxTCP =
new StringComboBox;
198 boxTCP->defaultIndex = 0;
200 boxTCP->options = robot->getRobotNodeNames();
202 boxTCP->name =
"tcpName";
203 layout->children.emplace_back(boxTCP);
216 layout->children.emplace_back(
new HSpacer);
220 NJointCartesianTorqueControllerConfigPtr
223 return new NJointCartesianTorqueControllerConfig(values.at(
"nodeSetName")->getString(),
224 values.at(
"tcpName")->getString());
244 return {{
"ControllerTarget", layout}};
252 if (name ==
"ControllerTarget")
int Label(int n[], int size, int *curLabel, MiscLib::Vector< std::pair< int, size_t > > *labels)
SpamFilterDataPtr deactivateSpam(SpamFilterDataPtr const &spamFilter, float deactivationDurationSec, const std::string &identifier, bool deactivate)
#define DEFAULT_TCP_STRING
Brief description of class JointControlTargetBase.
static WidgetDescription::WidgetPtr GenerateConfigDescription(const VirtualRobot::RobotPtr &, const std::map< std::string, ConstControlDevicePtr > &, const std::map< std::string, ConstSensorDevicePtr > &)
WidgetDescription::StringWidgetDictionary getFunctionDescriptions(const Ice::Current &) const override
NJointCartesianTorqueController(RobotUnit *prov, const NJointControllerConfigPtr &config, const VirtualRobot::RobotPtr &)
std::string getNodeSetName() const
void setControllerTarget(float forceX, float forceY, float forceZ, float torqueX, float torqueY, float torqueZ, const Ice::Current &) override
void rtPostDeactivateController() override
This function is called after the controller is deactivated.
void rtRun(const IceUtil::Time &sensorValuesTimestamp, const IceUtil::Time &timeSinceLastIteration) override
TODO make protected and use attorneys.
static NJointCartesianTorqueControllerConfigPtr GenerateConfigFromVariants(const StringVariantBaseMap &values)
::armarx::WidgetDescription::HBoxLayoutPtr createSliders()
std::string getClassName(const Ice::Current &) const override
void callDescribedFunction(const std::string &name, const StringVariantBaseMap &valueMap, const Ice::Current &) override
void rtPreActivateController() override
This function is called before the controller is activated.
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...
const NJointCartesianTorqueControllerControlData & rtGetControlStruct() const
MutexType controlDataMutex
std::lock_guard< std::recursive_mutex > LockGuardType
void writeControlStruct()
NJointCartesianTorqueControllerControlData & getWriterControlStruct()
The RobotUnit class manages a robot and its controllers.
#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_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
This file offers overloads of toIce() and fromIce() functions for STL container types.
NJointControllerRegistration< NJointCartesianTorqueController > registrationControllerNJointCartesianTorqueController("NJointCartesianTorqueController")
std::map< std::string, VariantBasePtr > StringVariantBaseMap
std::vector< T > max(const std::vector< T > &v1, const std::vector< T > &v2)
std::vector< T > min(const std::vector< T > &v1, const std::vector< T > &v2)