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