Go to the documentation of this file.
29 using namespace KITHand;
33 KITHandUnitPropertyDefinitions::KITHandUnitPropertyDefinitions(std::string prefix) :
36 defineOptionalProperty<KITHandCommunicationDriver::ScanMode>(
"ConnectionType", KITHandCommunicationDriver::ScanMode::Bluetooth,
"Type of the connection to the hand, either Bluetooth or Serial")
37 .map(
"Bluetooth", KITHandCommunicationDriver::ScanMode::Bluetooth)
38 .map(
"Serial", KITHandCommunicationDriver::ScanMode::Serial);
39 defineRequiredProperty<std::string>(
"MAC-Address",
"MAC-Address of the hand to connect to.");
40 defineOptionalProperty<bool>(
"AutomaticReconnectActive",
false,
"Whether the hand unit should try to reconnect after the connection is lost.");
41 defineOptionalProperty<bool>(
"ScanUntilHandFound",
true,
"Wheather to keep scanning until the hand with the given MAC-Address is found.");
42 defineOptionalProperty<int>(
"ScanTimeout", 5,
"Timeout for scanning repeatedly.");
65 _driver = std::make_unique<KITHandCommunicationDriver>();
71 std::string macAddress = getProperty<std::string>(
"MAC-Address");
72 KITHandCommunicationDriver::ScanMode mode = getProperty<KITHandCommunicationDriver::ScanMode>(
"ConnectionType").getValue();
74 auto start = std::chrono::system_clock::now();
77 std::vector<HandDevice> devices = _driver->scanForDevices(mode);
78 for (HandDevice& d : devices)
80 if (mode == KITHandCommunicationDriver::ScanMode::Bluetooth)
82 ARMARX_INFO <<
"Found device with MAC-Address: " << d.macAdress;
84 else if (mode == KITHandCommunicationDriver::ScanMode::Serial)
86 ARMARX_INFO <<
"Found device at serial port: " << d.serialDeviceFile;
92 if (d.macAdress == macAddress || (mode == KITHandCommunicationDriver::ScanMode::Serial))
94 d.hardwareTarget = mode == KITHandCommunicationDriver::ScanMode::Bluetooth ? KITHand::HardwareTarget::Bluetooth : KITHand::HardwareTarget::Serial;
96 while (!_driver->connected())
98 std::this_thread::sleep_for(std::chrono::milliseconds(100));
111 while (getProperty<bool>(
"ScanUntilHandFound").getValue()
113 && std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now() -
start).count() < getProperty<int>(
"ScanTimeout").getValue());
115 if (mode == KITHandCommunicationDriver::ScanMode::Bluetooth)
117 ARMARX_WARNING <<
"Could not find hand with the given MAC-Address: " << macAddress <<
" Shutting down this KITHandUnit.";
121 ARMARX_WARNING <<
"Could not find hand ove serial ports. Shutting down this KITHHandUnit";
129 _driver->disconnect();
135 if (std::regex_match(shapeName, std::regex{
"[gG](0|[1-9][0-9]*)"}) && _driver->getCurrentConnectedDevice()->abilities.receivesAdditionalGraspCommands)
137 _driver->sendGrasp(std::stoul(shapeName.substr(1)));
139 else if (shapeName ==
"Open")
141 _driver->sendGrasp(0);
143 else if (shapeName ==
"Close")
145 _driver->sendGrasp(1);
147 else if (!_shapes.count(shapeName))
150 <<
"'\nKnown shapes: " << _shapes;
162 for (
const std::pair<std::string, float>& pair : targetJointAngles)
164 if (pair.first ==
"Fingers")
167 static_cast<std::uint64_t
>(pair.second * KITHand::ControlOptions::maxPosFingers),
168 static_cast<std::uint64_t
>(0),
169 KITHand::ControlOptions::maxPosFingers);
171 _driver->sendFingersPosition(pos);
173 else if (pair.first ==
"Thumb")
176 static_cast<std::uint64_t
>(pair.second * KITHand::ControlOptions::maxPosThumb),
177 static_cast<std::uint64_t
>(0),
178 KITHand::ControlOptions::maxPosThumb);
180 _driver->sendThumbPosition(pos);
184 ARMARX_WARNING <<
"Invalid HandJointName '" << pair.first <<
"', ignoring.";
186 _driver->waitForCommunicationMedium();
193 jointValues[
"Fingers"] = _driver->getFingersPos() * 1.f / KITHand::ControlOptions::maxPosFingers;
194 jointValues[
"Thumb"] = _driver->getThumbPos() * 1.f / KITHand::ControlOptions::maxPosThumb;
200 _shapes[name] = shape;
220 if (state == State::DeviceLost)
253 const auto fingers = prx.
getValue<
float>(
"Fingers").get();
254 const auto thumb = prx.
getValue<
float>(
"Thumb").get();
255 ARMARX_INFO <<
"setting Fingers " << fingers <<
" and Thumb " << thumb;
260 _driver->sendRaw(prx.
getValue<std::string>(
"Raw").get());
void addShape(const std::string &name, const std::map< std::string, float > &shape)
The Variant class is described here: Variants.
SingleTypeVariantListPtr shapeNames
List containing the names of all valid shapes.
void processGui(RemoteGui::TabProxy &prx)
detail::ButtonBuilder makeButton(std::string const &name)
void start(const Ice::Current &c=Ice::emptyCurrent) override
Set execution state to eStarted.
#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...
void setString(const std::string &s, const Ice::Current &c=Ice::emptyCurrent) override
Sets the Variant's value to s.
ArmarXManagerPtr getArmarXManager() const
Returns the ArmarX manager used to add and remove components.
std::vector< T > max(const std::vector< T > &v1, const std::vector< T > &v2)
detail::LineEditBuilder makeLineEdit(std::string const &name)
SimpleGridLayoutBuilder & addChild(WidgetPtr const &child, int colspan)
void connectionStateChangedCallback(const KITHand::State state)
detail::SimpleGridLayoutBuilder makeSimpleGridLayout(std::string const &name="")
double clamp(double x, double a, double b)
void setJointAngles(const NameValueMap &targetJointAngles, const Ice::Current &=Ice::emptyCurrent) override
std::shared_ptr< Value > value()
detail::CheckBoxBuilder makeCheckBox(std::string const &name)
NameValueMap getCurrentJointValues(const Ice::Current &=Ice::emptyCurrent) override
virtual std::string getDefaultName() const override
SimpleGridLayoutBuilder & addTextLabel(std::string const &text, int colspan)
Defines all necessary properties for armarx::HandUnit.
void setShape(const std::string &shapeName, const Ice::Current &=Ice::emptyCurrent) override
const std::string & to_string(const std::string &s)
void onStartHandUnit() override
ValueProxy< T > getValue(std::string const &name)
void onExitHandUnit() override
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
bool getButtonClicked(std::string const &name)
RemoteGui::WidgetPtr buildGui()
SimpleGridLayoutBuilder & cols(int n)
std::vector< T > min(const std::vector< T > &v1, const std::vector< T > &v2)
void onInitHandUnit() override
SpamFilterDataPtr deactivateSpam(float deactivationDurationSec=10.0f, const std::string &identifier="", bool deactivate=true) const
disables the logging for the current line for the given amount of seconds.
void createOrUpdateRemoteGuiTab(Ts &&...ts)
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
virtual armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
detail::FloatSpinBoxBuilder makeFloatSpinBox(std::string const &name)
This file offers overloads of toIce() and fromIce() functions for STL container types.
void addShapeName(const std::string &name)