78 auto addFinger = [&](std::string name,
float min,
float max,
float val,
int steps)
92 .addChild(
new RemoteGui::HSpacer()));
97 .addChild(
new RemoteGui::HSpacer()));
100 addFinger(
"Thumb", 0, 1, _lastGuiValueThumb, _driver->getMaxPosThumb());
101 addFinger(
"Fingers", 0, 1, _lastGuiValueFingers, _driver->getMaxPosFingers());
103 rootLayoutBuilder.
addChild(
new RemoteGui::VSpacer());
108 _guiTab.receiveUpdates();
109 _driver->getMaxPosThumb();
110 const float t = _guiTab.getValue<
float>(
"Thumb").get();
111 const float f = _guiTab.getValue<
float>(
"Fingers").get();
113 bool updateT = t != _lastGuiValueThumb;
114 bool updateF = f != _lastGuiValueFingers;
115 _lastGuiValueThumb = t;
116 _lastGuiValueFingers = f;
118 if (updateT && updateF)
131 _guiTab.getValue<std::string>(
"Thumb_pos")
132 .set(std::to_string(_driver->getThumbPos()));
133 _guiTab.getValue<std::string>(
"Thumb_pwm")
134 .set(std::to_string(_driver->getThumbPWM()));
135 _guiTab.getValue<std::string>(
"Fingers_pos")
136 .set(std::to_string(_driver->getFingerPos()));
137 _guiTab.getValue<std::string>(
"Fingers_pwm")
138 .set(std::to_string(_driver->getFingerPWM()));
139 _guiTab.sendUpdates();
143 RemoteGui::WidgetPtr rootLayout = rootLayoutBuilder;
145 _remoteGuiPrx->createTab(
"KITProstheticHandUnit", rootLayout);
164 for (
const auto& pair : targetJointAngles)
166 if (pair.first ==
"Fingers")
168 const std::uint64_t pos = std::clamp(
169 static_cast<std::uint64_t
>(pair.second * _driver->getMaxPosFingers()),
171 _driver->getMaxPosFingers());
173 _driver->sendFingerPWM(200, 2999, pos);
175 std::this_thread::sleep_for(std::chrono::milliseconds(100));
177 else if (pair.first ==
"Thumb")
179 const std::uint64_t pos =
180 std::clamp(
static_cast<std::uint64_t
>(pair.second * _driver->getMaxPosThumb()),
182 _driver->getMaxPosThumb());
184 _driver->sendThumbPWM(200, 2999, pos);
186 std::this_thread::sleep_for(std::chrono::milliseconds(100));
190 ARMARX_WARNING <<
"Invalid HandJointName '" << pair.first <<
"', ignoring.";
198 NameValueMap jointValues;
199 jointValues[
"Fingers"] = _driver->getFingerPos() * 1.f / _driver->getMaxPosFingers();
200 jointValues[
"Thumb"] = _driver->getThumbPos() * 1.f / _driver->getMaxPosThumb();
206 const std::map<std::string, float>& shape)
208 _shapes[name] = shape;
223 if (std::regex_match(shapeName, std::regex{
"[gG](0|[1-9][0-9]*)"}))
225 _driver->sendGrasp(std::stoul(shapeName.substr(1)));
227 else if (shapeName ==
"Open")
229 _driver->sendGrasp(0);
231 else if (shapeName ==
"Close")
233 _driver->sendGrasp(1);
235 else if (!_shapes.count(shapeName))
237 ARMARX_WARNING <<
"Unknown shape name '" << shapeName <<
"'\nKnown shapes: " << _shapes;
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.
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)