Wyatt  1.0.1
EncoderAdapter.h
1 #pragma once
2 
3 #define GEAR_RATIO ((double) 1/19.0 * 3.0/5.0)
4 
5 #include "Thread.h"
6 #include "IHardwareInterface.h"
7 #include "messages/IMessage.h"
8 #include <atomic>
9 #include <list>
10 #include <chrono>
11 #include "wiringPiInclude.h"
12 #include <stdlib.h>
13 #include <string>
14 #include "messages/EncoderMessage.h"
15 #include <mutex>
16 
22 {
23 public:
31  EncoderAdapter(int channelA, int channelB, int ticksPerRev, Hardware hardware);
35  ~EncoderAdapter() override;
40  void* run() override;
45  long getCount();
49  void resetCount();
54  double getSpeedRPM();
61  std::list<IMessage*>* read() override;
62  void write(IMessage* message) override {};
63 private:
65  int m_channelA;
67  int m_channelB;
69  int m_channelAState;
71  int m_channelBState;
73  int m_lastTransition;
75  int m_direction;
77  int m_ticksPerRevolution;
79  double m_revolutionsPerTick;
81  std::chrono::high_resolution_clock::time_point m_lastTickTime;
83  volatile double m_speed;
84  std::mutex m_lock;
86  std::atomic<long> m_count;
88  Hardware hardware;
89 };
EncoderAdapter(int channelA, int channelB, int ticksPerRev, Hardware hardware)
std::list< IMessage * > * read() override
void write(IMessage *message) override
double getSpeedRPM()
~EncoderAdapter() override
void * run() override
Definition: Thread.h:32