1 #include "hardwareinterface/EncoderAdapter.h" 9 m_ticksPerRevolution(ticksPerRev),
12 m_revolutionsPerTick = 10.0 / (double)ticksPerRev;
13 pinMode(channelA, INPUT);
14 pinMode(channelB, INPUT);
15 m_channelAState = digitalRead(m_channelA);
16 m_channelBState = digitalRead(m_channelB);
34 int newChannelAState = digitalRead(m_channelA);
35 int newChannelBState = digitalRead(m_channelB);
36 int newTransition = (newChannelAState != m_channelAState) ? 1 : (newChannelBState != m_channelBState) ? -1 : 0;
38 numTicks += abs(newTransition);
42 std::chrono::high_resolution_clock::time_point newTime = std::chrono::high_resolution_clock::now();
43 std::chrono::microseconds diffTime = std::chrono::duration_cast<std::chrono::microseconds>(newTime - m_lastTickTime);
44 m_lastTickTime = newTime;
45 m_speed = (m_revolutionsPerTick / (double)diffTime.count()) * 60000000.0;
46 m_speed = m_speed * GEAR_RATIO;
48 m_channelAState = newChannelAState;
49 m_channelBState = newChannelBState;
53 m_direction = (m_lastTransition == -2) ? newTransition : (newTransition == m_lastTransition) ? -m_direction : m_direction;
55 m_lastTransition = (newTransition == 0) ? m_lastTransition : newTransition;
57 m_count = (newTransition != 0) ? (
long)m_count + m_direction : (long)m_count;
74 std::list<IMessage*>* messages =
new std::list<IMessage*>();
76 messages->push_back(msg);
EncoderAdapter(int channelA, int channelB, int ticksPerRev, Hardware hardware)
std::list< IMessage * > * read() override
~EncoderAdapter() override