ZeroTorqueOrVelocityWithFT.cpp
Go to the documentation of this file.
2 
3 #include <VirtualRobot/Robot.h>
4 #include <VirtualRobot/RobotNodeSet.h>
5 
8 
11 
13 {
14 
15  NJointControllerRegistration<NJointZeroTorqueOrVelocityWithFTController>
17  "NJointZeroTorqueOrVelocityWithFTController");
18 
19  std::string
21  {
22  return "NJointZeroTorqueOrVelocityWithFTController";
23  }
24 
26  RobotUnitPtr prov,
27  const NJointZeroTorqueOrVelocityWithFTControllerConfigPtr& config,
28  const VirtualRobot::RobotPtr& r)
29  {
31  RobotUnitPtr robotUnit = RobotUnitPtr::dynamicCast(prov);
33  ARMARX_CHECK_NOT_NULL(robotUnit);
34  ARMARX_CHECK_NOT_NULL(config);
35  ARMARX_CHECK_EXPRESSION(not(config->robotNodeSetList.empty()));
36 
37  for (auto& robotNodeSetName : config->robotNodeSetList)
38  {
39  VirtualRobot::RobotNodeSetPtr rtRns = rtGetRobot()->getRobotNodeSet(robotNodeSetName);
40  ARMARX_CHECK_EXPRESSION(rtRns) << robotNodeSetName;
41 
42  for (size_t i = 0; i < rtRns->getSize(); i++)
43  {
44  std::string jointName = rtRns->getNode(i)->getName();
45  if (jointName.find("wri") != std::string::npos and
46  config->useZeroVelocityModeForWrist)
47  {
48  ControlTargetBase* ct =
49  useControlTarget(jointName, ControlModes::ZeroVelocity1DoF);
51  targetsVel.push_back(ct->asA<ControlTarget1DoFActuatorZeroVelocity>());
52  torqueControlled.push_back(false);
53  }
54  else
55  {
56  ControlTargetBase* ct =
57  useControlTarget(jointName, ControlModes::ZeroTorque1DoF);
59  targetsTorque.push_back(ct->asA<ControlTarget1DoFActuatorZeroTorque>());
60  torqueControlled.push_back(true);
61  }
62  }
63  }
64  size_t numJoints = targetsVel.size() + targetsTorque.size();
65  ARMARX_CHECK_EQUAL(numJoints, torqueControlled.size());
66 
67  maxTorque = config->maxTorque;
68  maxVelocity = config->maxVelocity;
69 
71  target.targetTorqueOrVelocity = Ice::FloatSeq(numJoints, 0.0f);
72  this->reinitTripleBuffer(target);
73 
74  ik.reset(new VirtualRobot::DifferentialIK(
75  rtRns, rtRns->getRobot()->getRootNode(), VirtualRobot::JacobiProvider::eSVDDamped));
76 
77 
78  I = Eigen::MatrixXf::Identity(numOfJoints, numOfJoints);
79  }
80 
81  void
83  {
84  auto numJoints = targetsVel.size() + targetsTorque.size();
86  target.targetTorqueOrVelocity = Ice::FloatSeq(numJoints, 0.0f);
87  this->reinitTripleBuffer(target);
88  }
89 
90  void
92  const IceUtil::Time& timeSinceLastIteration)
93  {
94  /// compute jocobi
95  rtStatus.jacobi =
96  ik->getJacobianMatrix(rtTCP, VirtualRobot::IKSolver::CartesianSelection::All);
97  rtStatus.jacobi.block(0, 0, 3, rtStatus.numJoints) =
98  0.001 * rtStatus.jacobi.block(0, 0, 3, rtStatus.numJoints);
99  ARMARX_CHECK_EQUAL(rtStatus.numJoints, rtStatus.jacobi.cols());
100  ARMARX_CHECK_EQUAL(6, rtStatus.jacobi.rows());
101 
102  rtStatus.jtpinv =
103  ik->computePseudoInverseJacobianMatrix(rtStatus.jacobi.transpose(), lambda);
104  rtStatus.jpinv = ik->computePseudoInverseJacobianMatrix(rtStatus.jacobi, lambda);
105  ARMARX_CHECK_EQUAL(rtStatus.numJoints, rtStatus.jtpinv.cols());
106  ARMARX_CHECK_EQUAL(6, rtStatus.jtpinv.rows());
107 
108 
109  size_t torqueIndex = 0;
110  size_t velIndex = 0;
111  for (size_t i = 0; i < torqueControlled.size(); ++i)
112  {
113  if (torqueControlled.at(i))
114  {
115  targetsTorque.at(torqueIndex)->torque = math::MathUtils::LimitTo(
116  rtGetControlStruct().targetTorqueOrVelocity.at(i), maxTorque);
117  torqueIndex++;
118  }
119  else
120  {
121  targetsVel.at(velIndex)->velocity = math::MathUtils::LimitTo(
122  rtGetControlStruct().targetTorqueOrVelocity.at(i), maxVelocity);
123  velIndex++;
124  }
125  }
126  }
127 
128  void
132  {
133  }
134 
137  const VirtualRobot::RobotPtr& robot,
138  const std::map<std::string, ConstControlDevicePtr>& controlDevices,
139  const std::map<std::string, ConstSensorDevicePtr>&)
140  {
141  using namespace armarx::WidgetDescription;
142  HBoxLayoutPtr layout = new HBoxLayout;
143 
144 
145  ::armarx::WidgetDescription::WidgetSeq widgets;
146  auto addSlider = [&](const std::string& label, float min, float max, float defaultValue)
147  {
148  widgets.emplace_back(new Label(false, label));
149  {
150  FloatSliderPtr c_x = new FloatSlider;
151  c_x->name = label;
152  c_x->min = min;
153  c_x->defaultValue = defaultValue;
154  c_x->max = max;
155  widgets.emplace_back(c_x);
156  }
157  };
158 
159  /// joint names
160  LabelPtr label = new Label;
161  label->text = "Robot Node Sets";
162  layout->children.emplace_back(label);
163 
164  StringComboBoxPtr box = new StringComboBox;
165  box->name = "robotNodeSetSelector";
166  box->defaultIndex = 0;
167  box->multiSelect = true;
168  box->options.push_back("LeftArm");
169  box->options.push_back("RightArm");
170  layout->children.emplace_back(box);
171 
172  // LabelPtr labelZeroVelToggle = new Label;
173  // labelZeroVelToggle->text = "Wrist ZeroVelocity?";
174  // layout->children.emplace_back(labelZeroVelToggle);
175 
176  CheckBoxPtr checkBox = new CheckBox;
177  checkBox->name = "useZeroVelocityModeForWrist";
178  checkBox->label = "Wrist ZeroVelocity";
179  checkBox->defaultValue = true;
180 
181  addSlider("maxTorque", 0, 100, 10);
182  addSlider("maxVeloicty", 0, 3.14, 2.0);
183 
184  layout->children.insert(layout->children.end(), widgets.begin(), widgets.end());
185  return layout;
186  }
187 
188  NJointZeroTorqueOrVelocityWithFTControllerConfigPtr
191  {
192  auto varNodeSets = VariantPtr::dynamicCast(values.at("robotNodeSetSelector"));
193  ARMARX_CHECK_EXPRESSION(varNodeSets) << "robotNodeSetSelector";
194 
195  ARMARX_TRACE;
197  varNodeSets->get<SingleTypeVariantList>()->toStdVector<std::string>(),
198  values.at("useZeroVelocityModeForWrist")->getBool(),
199  values.at("maxTorque")->getFloat(),
200  values.at("maxVeloicty")->getFloat()};
201  }
202 
203  void
205  {
206  }
207 
208  void
210  const Ice::Current&)
211  {
213  this->getWriterControlStruct().targetTorqueOrVelocity = targets;
215  }
216 } // namespace armarx::control::njoint_controller::joint_space
armarx::NJointControllerWithTripleBuffer< NJointZeroTorqueOrVelocityWithFTControllerTarget >::reinitTripleBuffer
void reinitTripleBuffer(const NJointZeroTorqueOrVelocityWithFTControllerTarget &initial)
Definition: NJointControllerWithTripleBuffer.h:68
armarx::ControlTargetBase::asA
const T * asA() const
Definition: ControlTargetBase.h:76
SingleTypeVariantList.h
armarx::control::njoint_controller::joint_space::NJointZeroTorqueOrVelocityWithFTControllerTarget
Definition: ZeroTorqueOrVelocityWithFT.h:37
MathUtils.h
armarx::NJointControllerBase::useSynchronizedRtRobot
const VirtualRobot::RobotPtr & useSynchronizedRtRobot(bool updateCollisionModel=false)
Requests a VirtualRobot for use in rtRun *.
Definition: NJointController.cpp:293
armarx::NJointControllerWithTripleBuffer< NJointZeroTorqueOrVelocityWithFTControllerTarget >::rtGetControlStruct
const NJointZeroTorqueOrVelocityWithFTControllerTarget & rtGetControlStruct() const
Definition: NJointControllerWithTripleBuffer.h:32
armarx::StringVariantBaseMap
std::map< std::string, VariantBasePtr > StringVariantBaseMap
Definition: ManagedIceObject.h:111
armarx::control::njoint_controller::joint_space::NJointZeroTorqueOrVelocityWithFTController::rtRun
void rtRun(const IceUtil::Time &sensorValuesTimestamp, const IceUtil::Time &timeSinceLastIteration) override
TODO make protected and use attorneys.
Definition: ZeroTorqueOrVelocityWithFT.cpp:91
armarx::ControlTargetBase
Brief description of class JointControlTargetBase.
Definition: ControlTargetBase.h:47
RobotUnit.h
armarx::NJointControllerBase::useControlTarget
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...
Definition: NJointController.cpp:410
ARMARX_CHECK_NOT_NULL
#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...
Definition: ExpressionException.h:206
armarx::control::njoint_controller::joint_space::NJointZeroTorqueOrVelocityWithFTController::getClassName
std::string getClassName(const Ice::Current &) const override
Definition: ZeroTorqueOrVelocityWithFT.cpp:20
armarx::control::njoint_controller::joint_space::NJointZeroTorqueOrVelocityWithFTController::setControllerTarget
void setControllerTarget(const Ice::FloatSeq &, const Ice::Current &) override
Definition: ZeroTorqueOrVelocityWithFT.cpp:209
boost::target
Vertex target(const detail::edge_base< Directed, Vertex > &e, const PCG &)
Definition: point_cloud_graph.h:688
armarx::control::njoint_controller::joint_space::NJointZeroTorqueOrVelocityWithFTController::GenerateConfigDescription
static WidgetDescription::WidgetPtr GenerateConfigDescription(const VirtualRobot::RobotPtr &, const std::map< std::string, ConstControlDevicePtr > &, const std::map< std::string, ConstSensorDevicePtr > &)
Definition: ZeroTorqueOrVelocityWithFT.cpp:136
armarx::max
std::vector< T > max(const std::vector< T > &v1, const std::vector< T > &v2)
Definition: VectorHelpers.h:267
ProsthesisInterface.values
values
Definition: ProsthesisInterface.py:190
armarx::NJointControllerWithTripleBuffer< NJointZeroTorqueOrVelocityWithFTControllerTarget >::getWriterControlStruct
NJointZeroTorqueOrVelocityWithFTControllerTarget & getWriterControlStruct()
Definition: NJointControllerWithTripleBuffer.h:54
armarx::control::NJointZeroTorqueOrVelocityWithFTControllerConfig
Definition: ControllerInterface.ice:64
armarx::NJointControllerWithTripleBuffer< NJointZeroTorqueOrVelocityWithFTControllerTarget >::LockGuardType
std::lock_guard< std::recursive_mutex > LockGuardType
Definition: NJointControllerWithTripleBuffer.h:14
IceInternal::Handle
Definition: forward_declarations.h:8
armarx::NJointControllerBase::rtGetRobot
const VirtualRobot::RobotPtr & rtGetRobot()
TODO make protected and use attorneys.
Definition: NJointControllerBase.h:845
armarx::control::njoint_controller::joint_space::NJointZeroTorqueOrVelocityWithFTController::targetsVel
std::vector< ControlTarget1DoFActuatorZeroVelocity * > targetsVel
Definition: ZeroTorqueOrVelocityWithFT.h:116
armarx::control::njoint_controller::joint_space::registrationControllerNJointZeroTorqueOrVelocityWithFTController
NJointControllerRegistration< NJointZeroTorqueOrVelocityWithFTController > registrationControllerNJointZeroTorqueOrVelocityWithFTController("NJointZeroTorqueOrVelocityWithFTController")
armarx::detail::ControlThreadOutputBufferEntry
Definition: ControlThreadOutputBuffer.h:177
visionx::voxelgrid::Label
uint32_t Label
Type of an object label.
Definition: types.h:7
armarx::WidgetDescription
Definition: DefaultWidgetDescriptions.cpp:27
ARMARX_TRACE
#define ARMARX_TRACE
Definition: trace.h:69
GfxTL::Identity
void Identity(MatrixXX< N, N, T > *a)
Definition: MatrixXX.h:523
armarx::control::njoint_controller::joint_space
Definition: Torque.cpp:9
armarx::control::njoint_controller::joint_space::NJointZeroTorqueOrVelocityWithFTController::rtPreActivateController
void rtPreActivateController() override
This function is called before the controller is activated.
Definition: ZeroTorqueOrVelocityWithFT.cpp:82
armarx::RemoteGui::Client::FloatSlider
Definition: Widgets.h:107
armarx::control::njoint_controller::joint_space::NJointZeroTorqueOrVelocityWithFTController::targetsTorque
std::vector< ControlTarget1DoFActuatorZeroTorque * > targetsTorque
Definition: ZeroTorqueOrVelocityWithFT.h:115
armarx::SingleTypeVariantList
The SingleTypeVariantList class is a subclass of VariantContainer and is comparable to a std::vector<...
Definition: SingleTypeVariantList.h:47
armarx::NJointControllerWithTripleBuffer< NJointZeroTorqueOrVelocityWithFTControllerTarget >::writeControlStruct
void writeControlStruct()
Definition: NJointControllerWithTripleBuffer.h:44
armarx::control::njoint_controller::joint_space::NJointZeroTorqueOrVelocityWithFTController::maxTorque
float maxTorque
Definition: ZeroTorqueOrVelocityWithFT.h:117
armarx::NJointControllerWithTripleBuffer< NJointZeroTorqueOrVelocityWithFTControllerTarget >::controlDataMutex
MutexType controlDataMutex
Definition: NJointControllerWithTripleBuffer.h:73
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
ZeroTorqueOrVelocityWithFT.h
armarx::RemoteGui::Client::HBoxLayout
Definition: Widgets.h:160
armarx::math::MathUtils::LimitTo
static double LimitTo(double value, double absThreshold)
Definition: MathUtils.h:56
ARMARX_CHECK_EXPRESSION
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
Definition: ExpressionException.h:73
armarx::control::njoint_controller::joint_space::NJointZeroTorqueOrVelocityWithFTController::rtPostDeactivateController
void rtPostDeactivateController() override
This function is called after the controller is deactivated.
Definition: ZeroTorqueOrVelocityWithFT.cpp:204
armarx::control::njoint_controller::joint_space::NJointZeroTorqueOrVelocityWithFTController::maxVelocity
float maxVelocity
Definition: ZeroTorqueOrVelocityWithFT.h:118
armarx::control::njoint_controller::joint_space::NJointZeroTorqueOrVelocityWithFTController::NJointZeroTorqueOrVelocityWithFTController
NJointZeroTorqueOrVelocityWithFTController(RobotUnitPtr prov, const NJointZeroTorqueOrVelocityWithFTControllerConfigPtr &config, const VirtualRobot::RobotPtr &)
Definition: ZeroTorqueOrVelocityWithFT.cpp:25
armarx::min
std::vector< T > min(const std::vector< T > &v1, const std::vector< T > &v2)
Definition: VectorHelpers.h:294
IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface >
armarx::control::njoint_controller::joint_space::NJointZeroTorqueOrVelocityWithFTController::GenerateConfigFromVariants
static NJointZeroTorqueOrVelocityWithFTControllerConfigPtr GenerateConfigFromVariants(const StringVariantBaseMap &values)
Definition: ZeroTorqueOrVelocityWithFT.cpp:189
armarx::RemoteGui::Client::CheckBox
Definition: Widgets.h:129
Logging.h
ARMARX_CHECK_EQUAL
#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...
Definition: ExpressionException.h:130
armarx::control::njoint_controller::joint_space::NJointZeroTorqueOrVelocityWithFTController::torqueControlled
std::vector< bool > torqueControlled
Definition: ZeroTorqueOrVelocityWithFT.h:120
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:18
armarx::control::njoint_controller::joint_space::NJointZeroTorqueOrVelocityWithFTController::onPublish
void onPublish(const SensorAndControl &, const DebugDrawerInterfacePrx &, const DebugObserverInterfacePrx &) override
Definition: ZeroTorqueOrVelocityWithFT.cpp:129