ZeroTorqueOrVelocityWithFT.cpp
Go to the documentation of this file.
2
3#include <VirtualRobot/Robot.h>
4#include <VirtualRobot/RobotNodeSet.h>
5
8
13
15{
16
17 NJointControllerRegistration<NJointZeroTorqueOrVelocityWithFTController>
19 "NJointZeroTorqueOrVelocityWithFTController");
20
21 std::string
23 {
24 return "NJointZeroTorqueOrVelocityWithFTController";
25 }
26
28 RobotUnitPtr prov,
29 const NJointZeroTorqueOrVelocityWithFTControllerConfigPtr& config,
31 {
33 RobotUnitPtr robotUnit = RobotUnitPtr::dynamicCast(prov);
35 ARMARX_CHECK_NOT_NULL(robotUnit);
37 ARMARX_CHECK_EXPRESSION(not(config->robotNodeSetList.empty()));
38
39 for (auto& robotNodeSetName : config->robotNodeSetList)
40 {
41 VirtualRobot::RobotNodeSetPtr rtRns = rtGetRobot()->getRobotNodeSet(robotNodeSetName);
42 ARMARX_CHECK_EXPRESSION(rtRns) << robotNodeSetName;
43
44 for (size_t i = 0; i < rtRns->getSize(); i++)
45 {
46 std::string jointName = rtRns->getNode(i)->getName();
47 if (jointName.find("wri") != std::string::npos and
48 config->useZeroVelocityModeForWrist)
49 {
51 useControlTarget(jointName, ControlModes::ZeroVelocity1DoF);
53 targetsVel.push_back(ct->asA<ControlTarget1DoFActuatorZeroVelocity>());
54 torqueControlled.push_back(false);
55 }
56 else
57 {
59 useControlTarget(jointName, ControlModes::ZeroTorque1DoF);
61 targetsTorque.push_back(ct->asA<ControlTarget1DoFActuatorZeroTorque>());
62 torqueControlled.push_back(true);
63 }
64 }
65 }
66 size_t numJoints = targetsVel.size() + targetsTorque.size();
67 ARMARX_CHECK_EQUAL(numJoints, torqueControlled.size());
68
69 maxTorque = config->maxTorque;
70 maxVelocity = config->maxVelocity;
71
73 target.targetTorqueOrVelocity = Ice::FloatSeq(numJoints, 0.0f);
74 this->reinitTripleBuffer(target);
75
76 ik.reset(new VirtualRobot::DifferentialIK(
77 rtRns, rtRns->getRobot()->getRootNode(), VirtualRobot::JacobiProvider::eSVDDamped));
78
79
80 I = Eigen::MatrixXf::Identity(numOfJoints, numOfJoints);
81 }
82
83 void
85 {
86 auto numJoints = targetsVel.size() + targetsTorque.size();
88 target.targetTorqueOrVelocity = Ice::FloatSeq(numJoints, 0.0f);
89 this->reinitTripleBuffer(target);
90 }
91
92 void
93 NJointZeroTorqueOrVelocityWithFTController::rtRun(const IceUtil::Time& sensorValuesTimestamp,
94 const IceUtil::Time& timeSinceLastIteration)
95 {
96 /// compute jocobi
97 rtStatus.jacobi =
98 ik->getJacobianMatrix(rtTCP, VirtualRobot::IKSolver::CartesianSelection::All);
99 rtStatus.jacobi.block(0, 0, 3, rtStatus.numJoints) =
100 0.001 * rtStatus.jacobi.block(0, 0, 3, rtStatus.numJoints);
101 ARMARX_CHECK_EQUAL(rtStatus.numJoints, rtStatus.jacobi.cols());
102 ARMARX_CHECK_EQUAL(6, rtStatus.jacobi.rows());
103
104 rtStatus.jtpinv =
105 ik->computePseudoInverseJacobianMatrix(rtStatus.jacobi.transpose(), lambda);
106 rtStatus.jpinv = ik->computePseudoInverseJacobianMatrix(rtStatus.jacobi, lambda);
107 ARMARX_CHECK_EQUAL(rtStatus.numJoints, rtStatus.jtpinv.cols());
108 ARMARX_CHECK_EQUAL(6, rtStatus.jtpinv.rows());
109
110
111 size_t torqueIndex = 0;
112 size_t velIndex = 0;
113 for (size_t i = 0; i < torqueControlled.size(); ++i)
114 {
115 if (torqueControlled.at(i))
116 {
117 targetsTorque.at(torqueIndex)->torque = math::MathUtils::LimitTo(
118 rtGetControlStruct().targetTorqueOrVelocity.at(i), maxTorque);
119 torqueIndex++;
120 }
121 else
122 {
123 targetsVel.at(velIndex)->velocity = math::MathUtils::LimitTo(
124 rtGetControlStruct().targetTorqueOrVelocity.at(i), maxVelocity);
125 velIndex++;
126 }
127 }
128 }
129
130 void
136
139 const VirtualRobot::RobotPtr& robot,
140 const std::map<std::string, ConstControlDevicePtr>& controlDevices,
141 const std::map<std::string, ConstSensorDevicePtr>&)
142 {
143 using namespace armarx::WidgetDescription;
144 HBoxLayoutPtr layout = new HBoxLayout;
145
146
147 ::armarx::WidgetDescription::WidgetSeq widgets;
148 auto addSlider = [&](const std::string& label, float min, float max, float defaultValue)
149 {
150 widgets.emplace_back(new Label(false, label));
151 {
152 FloatSliderPtr c_x = new FloatSlider;
153 c_x->name = label;
154 c_x->min = min;
155 c_x->defaultValue = defaultValue;
156 c_x->max = max;
157 widgets.emplace_back(c_x);
158 }
159 };
160
161 /// joint names
162 LabelPtr label = new Label;
163 label->text = "Robot Node Sets";
164 layout->children.emplace_back(label);
165
166 StringComboBoxPtr box = new StringComboBox;
167 box->name = "robotNodeSetSelector";
168 box->defaultIndex = 0;
169 box->multiSelect = true;
170 box->options.push_back("LeftArm");
171 box->options.push_back("RightArm");
172 layout->children.emplace_back(box);
173
174 // LabelPtr labelZeroVelToggle = new Label;
175 // labelZeroVelToggle->text = "Wrist ZeroVelocity?";
176 // layout->children.emplace_back(labelZeroVelToggle);
177
178 CheckBoxPtr checkBox = new CheckBox;
179 checkBox->name = "useZeroVelocityModeForWrist";
180 checkBox->label = "Wrist ZeroVelocity";
181 checkBox->defaultValue = true;
182
183 addSlider("maxTorque", 0, 100, 10);
184 addSlider("maxVeloicty", 0, 3.14, 2.0);
185
186 layout->children.insert(layout->children.end(), widgets.begin(), widgets.end());
187 return layout;
188 }
189
190 NJointZeroTorqueOrVelocityWithFTControllerConfigPtr
192 const StringVariantBaseMap& values)
193 {
194 auto varNodeSets = VariantPtr::dynamicCast(values.at("robotNodeSetSelector"));
195 ARMARX_CHECK_EXPRESSION(varNodeSets) << "robotNodeSetSelector";
196
199 varNodeSets->get<SingleTypeVariantList>()->toStdVector<std::string>(),
200 values.at("useZeroVelocityModeForWrist")->getBool(),
201 values.at("maxTorque")->getFloat(),
202 values.at("maxVeloicty")->getFloat()};
203 }
204
205 void
209
210 void
212 const Ice::Current&)
213 {
215 this->getWriterControlStruct().targetTorqueOrVelocity = targets;
217 }
218} // namespace armarx::control::njoint_controller::joint_space
int Label(int n[], int size, int *curLabel, MiscLib::Vector< std::pair< int, size_t > > *labels)
Definition Bitmap.cpp:801
Brief description of class JointControlTargetBase.
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 SingleTypeVariantList class is a subclass of VariantContainer and is comparable to a std::vector<...
void onPublish(const SensorAndControl &, const DebugDrawerInterfacePrx &, const DebugObserverInterfacePrx &) override
static WidgetDescription::WidgetPtr GenerateConfigDescription(const VirtualRobot::RobotPtr &, const std::map< std::string, ConstControlDevicePtr > &, const std::map< std::string, ConstSensorDevicePtr > &)
NJointZeroTorqueOrVelocityWithFTController(RobotUnitPtr prov, const NJointZeroTorqueOrVelocityWithFTControllerConfigPtr &config, const VirtualRobot::RobotPtr &)
static NJointZeroTorqueOrVelocityWithFTControllerConfigPtr 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 rtPreActivateController() override
This function is called before the controller is activated.
static double LimitTo(double value, double absThreshold)
Definition MathUtils.h:71
Brief description of class targets.
Definition targets.h:39
#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_NOT_NULL(ptr)
This macro evaluates whether ptr is not null and if it turns out to be false it will throw an Express...
#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...
std::shared_ptr< class Robot > RobotPtr
Definition Bus.h:19
::IceInternal::Handle<::armarx::WidgetDescription::Widget > WidgetPtr
NJointControllerRegistration< NJointZeroTorqueOrVelocityWithFTController > registrationControllerNJointZeroTorqueOrVelocityWithFTController("NJointZeroTorqueOrVelocityWithFTController")
::IceInternal::ProxyHandle<::IceProxy::armarx::DebugObserverInterface > DebugObserverInterfacePrx
std::map< std::string, VariantBasePtr > StringVariantBaseMap
std::vector< T > max(const std::vector< T > &v1, const std::vector< T > &v2)
IceUtil::Handle< class RobotUnit > RobotUnitPtr
Definition FTSensor.h:34
::IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface > DebugDrawerInterfacePrx
detail::ControlThreadOutputBufferEntry SensorAndControl
std::vector< T > min(const std::vector< T > &v1, const std::vector< T > &v2)
#define ARMARX_TRACE
Definition trace.h:77