80 auto addFinger = [&](std::string name,
float min,
float max,
float val,
int steps)
94 .addChild(
new RemoteGui::HSpacer()));
99 .addChild(
new RemoteGui::HSpacer()));
102 addFinger(
"Thumb", 0, 1, _lastGuiValueThumb, _driver->getMaxPosThumb());
103 addFinger(
"Fingers", 0, 1, _lastGuiValueFingers, _driver->getMaxPosFingers());
105 rootLayoutBuilder.
addChild(
new RemoteGui::VSpacer());
110 _guiTab.receiveUpdates();
111 _driver->getMaxPosThumb();
112 const float t = _guiTab.getValue<
float>(
"Thumb").get();
113 const float f = _guiTab.getValue<
float>(
"Fingers").get();
115 bool updateT = t != _lastGuiValueThumb;
116 bool updateF = f != _lastGuiValueFingers;
117 _lastGuiValueThumb = t;
118 _lastGuiValueFingers = f;
120 if (updateT && updateF)
133 _guiTab.getValue<std::string>(
"Thumb_pos")
134 .set(std::to_string(_driver->getThumbPos()));
135 _guiTab.getValue<std::string>(
"Thumb_pwm")
136 .set(std::to_string(_driver->getThumbPWM()));
137 _guiTab.getValue<std::string>(
"Fingers_pos")
138 .set(std::to_string(_driver->getFingerPos()));
139 _guiTab.getValue<std::string>(
"Fingers_pwm")
140 .set(std::to_string(_driver->getFingerPWM()));
141 _guiTab.sendUpdates();
145 RemoteGui::WidgetPtr rootLayout = rootLayoutBuilder;
147 _remoteGuiPrx->createTab(
"KITProstheticHandUnit", rootLayout);
166 for (
const auto& pair : targetJointAngles)
168 if (pair.first ==
"Fingers")
170 const std::uint64_t pos = std::clamp(
171 static_cast<std::uint64_t
>(pair.second * _driver->getMaxPosFingers()),
173 _driver->getMaxPosFingers());
175 _driver->sendFingerPWM(200, 2999, pos);
177 std::this_thread::sleep_for(std::chrono::milliseconds(100));
179 else if (pair.first ==
"Thumb")
181 const std::uint64_t pos =
182 std::clamp(
static_cast<std::uint64_t
>(pair.second * _driver->getMaxPosThumb()),
184 _driver->getMaxPosThumb());
186 _driver->sendThumbPWM(200, 2999, pos);
188 std::this_thread::sleep_for(std::chrono::milliseconds(100));
192 ARMARX_WARNING <<
"Invalid HandJointName '" << pair.first <<
"', ignoring.";
200 NameValueMap jointValues;
201 jointValues[
"Fingers"] = _driver->getFingerPos() * 1.f / _driver->getMaxPosFingers();
202 jointValues[
"Thumb"] = _driver->getThumbPos() * 1.f / _driver->getMaxPosThumb();
208 const std::map<std::string, float>& shape)
210 _shapes[name] = shape;
225 if (std::regex_match(shapeName, std::regex{
"[gG](0|[1-9][0-9]*)"}))
227 _driver->sendGrasp(std::stoul(shapeName.substr(1)));
229 else if (shapeName ==
"Open")
231 _driver->sendGrasp(0);
233 else if (shapeName ==
"Close")
235 _driver->sendGrasp(1);
237 else if (!_shapes.count(shapeName))
239 ARMARX_WARNING <<
"Unknown shape name '" << shapeName <<
"'\nKnown shapes: " << _shapes;
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Property< PropertyType > getProperty(const std::string &name)
SingleTypeVariantListPtr shapeNames
List containing the names of all valid shapes.
Brief description of class KITProstheticHandUnit.
void addShapeName(const std::string &name)
void onInitHandUnit() override
void onExitHandUnit() override
NameValueMap getCurrentJointValues(const Ice::Current &) override
void setShape(const std::string &shapeName, const Ice::Current &c=Ice::emptyCurrent) override
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void addShape(const std::string &name, const std::map< std::string, float > &shape)
void onStartHandUnit() override
void setJointAngles(const NameValueMap &targetJointAngles, const Ice::Current &=Ice::emptyCurrent) override
void offeringTopic(const std::string &name)
Registers a topic for retrival after initialization.
TopicProxyType getTopic(const std::string &name)
Returns a proxy of the specified topic.
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
The Variant class is described here: Variants.
void setString(const std::string &s, const Ice::Current &c=Ice::emptyCurrent) override
Sets the Variant's value to s.
#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_INFO
The normal logging level.
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
detail::FloatSliderBuilder makeFloatSlider(std::string const &name)
detail::VBoxLayoutBuilder makeVBoxLayout(std::string const &name="")
detail::LabelBuilder makeTextLabel(std::string const &text)
detail::HBoxLayoutBuilder makeHBoxLayout(std::string const &name="")
detail::LabelBuilder makeLabel(std::string const &name)
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
std::vector< T > max(const std::vector< T > &v1, const std::vector< T > &v2)
SimplePeriodicTask(Ts...) -> SimplePeriodicTask< std::function< void(void)> >
std::vector< T > min(const std::vector< T > &v1, const std::vector< T > &v2)
Derived & addChild(WidgetPtr const &child)