KITProstheticHandDriverExampleNoArmarX.cpp
Go to the documentation of this file.
1 #include <iostream>
2 #include <thread>
3 
4 #include <QCoreApplication>
5 
7 
8 [[maybe_unused]] static constexpr auto old = "DF:70:E8:81:DB:D6";
9 [[maybe_unused]] static constexpr auto dlr = "DF:A2:F5:48:E7:50";
10 [[maybe_unused]] static constexpr auto arches = "XX:XX:XX:XX:XX:XX";
11 
12 int
13 main(int argc, char* argv[])
14 {
15  for (int i = 0; i < argc; ++i)
16  {
17  if (std::string(argv[i]) == "-h" ||
18  std::string(argv[i]) == "--print-options") // needed for ArmarX Doc generation
19  {
20  // TODO: print help
21  return 0;
22  }
23  }
24  QCoreApplication a(argc, argv);
25  {
26  BLEProthesisInterface iface{dlr};
27  iface.verboseReceive(false);
28  iface.verboseSend(true);
29  std::size_t dcCounter = 0;
30  while (iface.getState() != BLEProthesisInterface::State::Running)
31  {
32  std::cout << "Waiting for Running State: " << to_string(iface.getState()) << std::endl;
33 
34  if (iface.getState() == BLEProthesisInterface::State::Disconnected)
35  {
36  ++dcCounter;
37  }
38 
39  if (dcCounter > 50)
40  {
41  return 1;
42  }
43 
44  std::this_thread::sleep_for(std::chrono::milliseconds{100});
45  }
46 
47  auto printAndSleep = [&](std::size_t n = 25)
48  {
49  for (std::size_t i2 = 0; i2 < n; ++i2)
50  {
51  std::cout << iface.getThumbPos() << "\t" << iface.getThumbPWM() << "\t"
52  << iface.getFingerPos() << "\t" << iface.getFingerPWM() << std::endl;
53  std::this_thread::sleep_for(std::chrono::milliseconds{100});
54  }
55  };
56 
57  for (std::size_t i = 0; i < 4; ++i)
58  {
59  iface.sendGrasp(i % 2);
60  printAndSleep();
61  }
62  iface.sendThumbPWM(200, 2999, 0);
63  printAndSleep(1);
64  iface.sendFingerPWM(200, 2999, 0);
65  printAndSleep();
66  }
67  return 0;
68 }
BLEProthesisInterface::State::Running
@ Running
BLEProthesisInterface::State::Disconnected
@ Disconnected
armarx::ctrlutil::a
double a(double t, double a0, double j)
Definition: CtrlUtil.h:45
armarx::to_string
const std::string & to_string(const std::string &s)
Definition: StringHelpers.h:41
main
int main(int argc, char *argv[])
Definition: KITProstheticHandDriverExampleNoArmarX.cpp:13
BLEProthesisInterface
Definition: BLEProthesisInterface.h:10
BLEProthesisInterface.h