BLEProthesisInterface.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <atomic>
4 #include <string>
5 #include <memory>
6 
9 
11 {
12 public:
13  enum class State
14  {
15  Created,
19  Connecting,
24  Running,
25  Killed
26  };
28  {
31  };
32 public:
35 
36  std::int64_t getThumbPWM() const;
37  std::int64_t getThumbPos() const;
38  std::int64_t getFingerPWM() const;
39  std::int64_t getFingerPos() const;
40 
41  State getState() const;
42 
43  void sendRaw(const std::string& cmd);
44 
45  void sendGrasp(std::uint64_t n);
46  void sendThumbPWM(std::uint64_t v, std::uint64_t maxPWM, std::uint64_t pos);
47  void sendFingerPWM(std::uint64_t v, std::uint64_t maxPWM, std::uint64_t pos);
48 
49  void verboseReceive(bool b = true);
50  void verboseSend(bool b = true);
51 private:
53  //sensor values
54  std::atomic_int64_t _thumbPWM{0};
55  std::atomic_int64_t _thumbPos{0};
56  std::atomic_int64_t _fingerPWM{0};
57  std::atomic_int64_t _fingerPos{0};
58 
59  //management
60  std::unique_ptr<BLEProthesisInterfaceQtWorkerThread> _worker;
61  std::atomic<State> _state{State::Created};
62  std::atomic_bool _verboseReceive{false};
63  std::atomic_bool _verboseSend{true};
64  SensorValueProtocol _protocol;
65 public:
66  static constexpr std::uint64_t getMaxG()
67  {
68  return 8;
69  }
70  static constexpr std::uint64_t getMinV()
71  {
72  return 10;
73  }
74  static constexpr std::uint64_t getMaxV()
75  {
76  return 200;
77  }
78  static constexpr std::uint64_t getMaxPWM()
79  {
80  return 2999;
81  }
82  static constexpr std::uint64_t getMaxPosThumb()
83  {
84  return 100'000;
85  }
86  static constexpr std::uint64_t getMaxPosFingers()
87  {
88  return 200'000;
89  }
90 };
91 
BLEProthesisInterface::State::Running
@ Running
BLEProthesisInterface::State::Disconnected
@ Disconnected
BLEProthesisInterface::getMaxG
static constexpr std::uint64_t getMaxG()
Definition: BLEProthesisInterface.h:66
BLEProthesisInterface::verboseReceive
void verboseReceive(bool b=true)
Definition: BLEProthesisInterface.cpp:154
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:74
BLEProthesisInterface::getMaxPosThumb
static constexpr std::uint64_t getMaxPosThumb()
Definition: BLEProthesisInterface.h:82
BLEProthesisInterface::getMinV
static constexpr std::uint64_t getMinV()
Definition: BLEProthesisInterface.h:70
BLEProthesisInterface::State::Connecting
@ Connecting
BLEProthesisInterface::getFingerPWM
std::int64_t getFingerPWM() const
Definition: BLEProthesisInterface.cpp:33
BLEProthesisInterface::State
State
Definition: BLEProthesisInterface.h:13
BLEProthesisInterface::getState
State getState() const
Definition: BLEProthesisInterface.cpp:43
BLEProthesisInterface::SensorValueProtocol
SensorValueProtocol
Definition: BLEProthesisInterface.h:27
BLEProthesisInterface::State::Created
@ Created
BLEProthesisInterface::getThumbPos
std::int64_t getThumbPos() const
Definition: BLEProthesisInterface.cpp:28
BLEProthesisInterfaceQtWorkerThread
Definition: BLEProthesisInterfaceQtWorkerThread.h:16
BLEProthesisInterface::State::DiscoveringServicesDone
@ DiscoveringServicesDone
BLEProthesisInterfaceQtWorker
Definition: BLEProthesisInterfaceQtWorker.h:15
BLEProthesisInterface::SensorValueProtocol::mx_pos_pwm
@ mx_pos_pwm
BLEProthesisInterface::BLEProthesisInterface
BLEProthesisInterface(const std::string &mac, SensorValueProtocol protocol=SensorValueProtocol::mx_pos_pwm)
Definition: BLEProthesisInterface.cpp:6
to_string
std::string to_string(BLEProthesisInterface::State s)
Definition: BLEProthesisInterface.cpp:164
BLEProthesisInterface::verboseSend
void verboseSend(bool b=true)
Definition: BLEProthesisInterface.cpp:159
BLEProthesisInterface::State::ConnectingService
@ ConnectingService
BLEProthesisInterface::sendThumbPWM
void sendThumbPWM(std::uint64_t v, std::uint64_t maxPWM, std::uint64_t pos)
Definition: BLEProthesisInterface.cpp:74
BLEProthesisInterface::getFingerPos
std::int64_t getFingerPos() const
Definition: BLEProthesisInterface.cpp:38
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:23
BLEProthesisInterface::State::DiscoveringDevicesDone
@ DiscoveringDevicesDone
BLEProthesisInterface::sendGrasp
void sendGrasp(std::uint64_t n)
Definition: BLEProthesisInterface.cpp:61
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:48
BLEProthesisInterface::sendFingerPWM
void sendFingerPWM(std::uint64_t v, std::uint64_t maxPWM, std::uint64_t pos)
Definition: BLEProthesisInterface.cpp:114
BLEProthesisInterface::getMaxPWM
static constexpr std::uint64_t getMaxPWM()
Definition: BLEProthesisInterface.h:78