BLEProthesisInterface.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <atomic>
4 #include <memory>
5 #include <string>
6 
9 
11 {
12 public:
13  enum class State
14  {
15  Created,
19  Connecting,
24  Running,
25  Killed
26  };
28  {
31  };
32 
33 public:
34  BLEProthesisInterface(const std::string& mac,
37 
38  std::int64_t getThumbPWM() const;
39  std::int64_t getThumbPos() const;
40  std::int64_t getFingerPWM() const;
41  std::int64_t getFingerPos() const;
42 
43  State getState() const;
44 
45  void sendRaw(const std::string& cmd);
46 
47  void sendGrasp(std::uint64_t n);
48  void sendThumbPWM(std::uint64_t v, std::uint64_t maxPWM, std::uint64_t pos);
49  void sendFingerPWM(std::uint64_t v, std::uint64_t maxPWM, std::uint64_t pos);
50 
51  void verboseReceive(bool b = true);
52  void verboseSend(bool b = true);
53 
54 private:
56  //sensor values
57  std::atomic_int64_t _thumbPWM{0};
58  std::atomic_int64_t _thumbPos{0};
59  std::atomic_int64_t _fingerPWM{0};
60  std::atomic_int64_t _fingerPos{0};
61 
62  //management
63  std::unique_ptr<BLEProthesisInterfaceQtWorkerThread> _worker;
64  std::atomic<State> _state{State::Created};
65  std::atomic_bool _verboseReceive{false};
66  std::atomic_bool _verboseSend{true};
67  SensorValueProtocol _protocol;
68 
69 public:
70  static constexpr std::uint64_t
72  {
73  return 8;
74  }
75 
76  static constexpr std::uint64_t
78  {
79  return 10;
80  }
81 
82  static constexpr std::uint64_t
84  {
85  return 200;
86  }
87 
88  static constexpr std::uint64_t
90  {
91  return 2999;
92  }
93 
94  static constexpr std::uint64_t
96  {
97  return 100'000;
98  }
99 
100  static constexpr std::uint64_t
101  getMaxPosFingers()
102  {
103  return 200'000;
104  }
105 };
106 
BLEProthesisInterface::State::Running
@ Running
BLEProthesisInterface::State::Disconnected
@ Disconnected
BLEProthesisInterface::getMaxG
static constexpr std::uint64_t getMaxG()
Definition: BLEProthesisInterface.h:71
BLEProthesisInterface::verboseReceive
void verboseReceive(bool b=true)
Definition: BLEProthesisInterface.cpp:134
BLEProthesisInterface::State::Killed
@ Killed
BLEProthesisInterface::State::DiscoveringServices
@ DiscoveringServices
BLEProthesisInterface::SensorValueProtocol::tpos_tpwm_fpos_fpwm
@ tpos_tpwm_fpos_fpwm
BLEProthesisInterface::State::ConnectingDone
@ ConnectingDone
BLEProthesisInterface::getMaxV
static constexpr std::uint64_t getMaxV()
Definition: BLEProthesisInterface.h:83
BLEProthesisInterface::getMaxPosThumb
static constexpr std::uint64_t getMaxPosThumb()
Definition: BLEProthesisInterface.h:95
BLEProthesisInterface::getMinV
static constexpr std::uint64_t getMinV()
Definition: BLEProthesisInterface.h:77
BLEProthesisInterface::State::Connecting
@ Connecting
BLEProthesisInterface::getFingerPWM
std::int64_t getFingerPWM() const
Definition: BLEProthesisInterface.cpp:36
BLEProthesisInterface::State
State
Definition: BLEProthesisInterface.h:13
BLEProthesisInterface::getState
State getState() const
Definition: BLEProthesisInterface.cpp:48
BLEProthesisInterface::SensorValueProtocol
SensorValueProtocol
Definition: BLEProthesisInterface.h:27
BLEProthesisInterface::State::Created
@ Created
BLEProthesisInterface::getThumbPos
std::int64_t getThumbPos() const
Definition: BLEProthesisInterface.cpp:30
BLEProthesisInterfaceQtWorkerThread
Definition: BLEProthesisInterfaceQtWorkerThread.h:14
BLEProthesisInterface::State::DiscoveringServicesDone
@ DiscoveringServicesDone
BLEProthesisInterfaceQtWorker
Definition: BLEProthesisInterfaceQtWorker.h:13
BLEProthesisInterface::SensorValueProtocol::mx_pos_pwm
@ mx_pos_pwm
BLEProthesisInterface::BLEProthesisInterface
BLEProthesisInterface(const std::string &mac, SensorValueProtocol protocol=SensorValueProtocol::mx_pos_pwm)
Definition: BLEProthesisInterface.cpp:7
to_string
std::string to_string(BLEProthesisInterface::State s)
Definition: BLEProthesisInterface.cpp:146
BLEProthesisInterface::verboseSend
void verboseSend(bool b=true)
Definition: BLEProthesisInterface.cpp:140
BLEProthesisInterface::State::ConnectingService
@ ConnectingService
BLEProthesisInterface::sendThumbPWM
void sendThumbPWM(std::uint64_t v, std::uint64_t maxPWM, std::uint64_t pos)
Definition: BLEProthesisInterface.cpp:76
BLEProthesisInterface::getFingerPos
std::int64_t getFingerPos() const
Definition: BLEProthesisInterface.cpp:42
armarx::ctrlutil::v
double v(double t, double v0, double a0, double j)
Definition: CtrlUtil.h:39
BLEProthesisInterface::~BLEProthesisInterface
~BLEProthesisInterface()
Definition: BLEProthesisInterface.cpp:13
BLEProthesisInterface
Definition: BLEProthesisInterface.h:10
BLEProthesisInterface::getThumbPWM
std::int64_t getThumbPWM() const
Definition: BLEProthesisInterface.cpp:24
BLEProthesisInterface::State::DiscoveringDevicesDone
@ DiscoveringDevicesDone
BLEProthesisInterface::sendGrasp
void sendGrasp(std::uint64_t n)
Definition: BLEProthesisInterface.cpp:65
armarx::ctrlutil::s
double s(double t, double s0, double v0, double a0, double j)
Definition: CtrlUtil.h:33
BLEProthesisInterface::State::DiscoveringDevices
@ DiscoveringDevices
BLEProthesisInterface::sendRaw
void sendRaw(const std::string &cmd)
Definition: BLEProthesisInterface.cpp:54
BLEProthesisInterface::sendFingerPWM
void sendFingerPWM(std::uint64_t v, std::uint64_t maxPWM, std::uint64_t pos)
Definition: BLEProthesisInterface.cpp:105
BLEProthesisInterface::getMaxPWM
static constexpr std::uint64_t getMaxPWM()
Definition: BLEProthesisInterface.h:89