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<NJointTCPController>
46 return "NJointTCPController";
57 const IceUtil::Time& timeSinceLastIteration)
62 if (mode == VirtualRobot::IKSolver::All)
69 else if (mode == VirtualRobot::IKSolver::Position)
74 else if (mode == VirtualRobot::IKSolver::Orientation)
86 Eigen::MatrixXf jacobiInv = ik->getPseudoInverseJacobianMatrix(tcp, mode);
87 Eigen::VectorXf jointTargetVelocities = jacobiInv *
x;
89 for (
size_t i = 0; i < targets.size(); ++i)
91 targets.at(i)->velocity = jointTargetVelocities(i);
95 ::armarx::WidgetDescription::WidgetSeq
99 ::armarx::WidgetDescription::WidgetSeq widgets;
100 auto addSlider = [&](
const std::string& label,
float limit)
102 widgets.emplace_back(
new Label(
false, label));
107 c_x->defaultValue = 0.0f;
109 widgets.emplace_back(c_x);
116 addSlider(
"roll", 0.5);
117 addSlider(
"pitch", 0.5);
118 addSlider(
"yaw", 0.5);
125 const std::map<std::string, ConstControlDevicePtr>& controlDevices,
126 const std::map<std::string, ConstSensorDevicePtr>&)
131 LabelPtr label =
new Label;
132 label->text =
"nodeset name";
133 layout->children.emplace_back(label);
134 StringComboBoxPtr box =
new StringComboBox;
135 box->defaultIndex = 0;
137 box->options = robot->getRobotNodeSetNames();
138 box->name =
"nodeSetName";
139 layout->children.emplace_back(box);
141 LabelPtr labelTCP =
new Label;
142 labelTCP->text =
"tcp name";
143 layout->children.emplace_back(labelTCP);
144 StringComboBoxPtr boxTCP =
new StringComboBox;
145 boxTCP->defaultIndex = 0;
147 boxTCP->options = robot->getRobotNodeNames();
149 boxTCP->name =
"tcpName";
150 layout->children.emplace_back(boxTCP);
152 LabelPtr labelMode =
new Label;
153 labelMode->text =
"mode";
154 layout->children.emplace_back(labelMode);
155 StringComboBoxPtr boxMode =
new StringComboBox;
156 boxMode->defaultIndex = 0;
158 boxMode->options = {
"Position",
"Orientation",
"Both"};
159 boxMode->name =
"mode";
160 layout->children.emplace_back(boxMode);
167 layout->children.emplace_back(
new HSpacer);
171 NJointTCPControllerConfigPtr
175 values.at(
"tcpName")->getString()};
179 const NJointTCPControllerConfigPtr& config,
185 auto nodeset =
rtGetRobot()->getRobotNodeSet(config->nodeSetName);
187 for (
size_t i = 0; i < nodeset->getSize(); ++i)
189 auto jointName = nodeset->getNode(i)->getName();
192 targets.push_back(ct->
asA<ControlTarget1DoFActuatorVelocity>());
193 sensors.push_back(sv->
asA<SensorValue1DoFActuatorPosition>());
195 ik.reset(
new VirtualRobot::DifferentialIK(
196 nodeset,
rtGetRobot()->getRootNode(), VirtualRobot::JacobiProvider::eSVDDamped));
199 :
rtGetRobot()->getRobotNode(config->tcpName);
202 nodeSetName = config->nodeSetName;
212 VirtualRobot::IKSolver::CartesianSelection mode)
242 layout->children.insert(layout->children.end(), sliders.begin(), sliders.end());
243 return {{
"ControllerTarget", layout}};
251 if (name ==
"ControllerTarget")
int Label(int n[], int size, int *curLabel, MiscLib::Vector< std::pair< int, size_t > > *labels)
#define DEFAULT_TCP_STRING
Brief description of class JointControlTargetBase.
const SensorValueBase * useSensorValue(const std::string &sensorDeviceName) const
Get a const ptr to the given SensorDevice's SensorValue.
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 NJointTCPControllerControlData & rtGetControlStruct() const
MutexType controlDataMutex
std::lock_guard< std::recursive_mutex > LockGuardType
void writeControlStruct()
NJointTCPControllerControlData & getWriterControlStruct()
void reinitTripleBuffer(const NJointTCPControllerControlData &initial)
VirtualRobot::IKSolver::CartesianSelection mode
static WidgetDescription::WidgetPtr GenerateConfigDescription(const VirtualRobot::RobotPtr &, const std::map< std::string, ConstControlDevicePtr > &, const std::map< std::string, ConstSensorDevicePtr > &)
NJointTCPController(RobotUnit *prov, const NJointTCPControllerConfigPtr &config, const VirtualRobot::RobotPtr &r)
WidgetDescription::StringWidgetDictionary getFunctionDescriptions(const Ice::Current &) const override
std::string getNodeSetName() const
::armarx::WidgetDescription::WidgetSeq createSliders()
static NJointTCPControllerConfigPtr GenerateConfigFromVariants(const StringVariantBaseMap &values)
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.
void setVelocities(float xVel, float yVel, float zVel, float rollVel, float pitchVel, float yawVel, VirtualRobot::IKSolver::CartesianSelection mode)
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.
The RobotUnit class manages a robot and its controllers.
The SensorValueBase class.
#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_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.
std::map< std::string, VariantBasePtr > StringVariantBaseMap
NJointControllerRegistration< NJointTCPController > registrationControllerNJointTCPController("NJointTCPController")