ArPiRobot-CoreLib C++
C++ library for ArPiRobot robots
QuadEncoder.hpp
1 /*
2  * Copyright 2021 Marcus Behel
3  *
4  * This file is part of ArPiRobot-CoreLib.
5  *
6  * ArPiRobot-CoreLib is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * ArPiRobot-CoreLib is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with ArPiRobot-CoreLib. If not, see <https://www.gnu.org/licenses/>.
18  */
19 
20 #pragma once
21 
22 #include <arpirobot/arduino/device/ArduinoDevice.hpp>
23 #include <arpirobot/arduino/iface/BaseArduinoInterface.hpp>
24 
25 namespace arpirobot{
31  class QuadEncoder : public ArduinoDevice{
32  public:
33 
41  QuadEncoder(int pinA, int pinB, bool useInternalPullup, bool createDevice = true, int deviceId = -1);
42 
50  QuadEncoder(std::string pinA, int pinB, bool useInternalPullup, bool createDevice = true, int deviceId = -1);
51 
59  QuadEncoder(int pinA, std::string pinB, bool useInternalPullup, bool createDevice = true, int deviceId = -1);
60 
68  QuadEncoder(std::string pinA, std::string pinB, bool useInternalPullup, bool createDevice = true, int deviceId = -1);
69 
74  int32_t getPosition();
75 
80  void setPosition(int32_t currentPosition);
81 
86  float getVelocity();
87 
88  protected:
89  void applyDefaultState() override;
90  std::vector<uint8_t> getCreateData() override;
91  void handleData(const std::vector<uint8_t> &data) override;
92 
93  private:
94  static const uint8_t numSamples = 5;
95 
96  std::string pinA, pinB;
97  uint8_t useInternalPullup;
98  int32_t count = 0;
99  int32_t countOffset = 0;
100  float velocity = 0;
101  };
102 }
Definition: ArduinoDevice.hpp:35
Definition: QuadEncoder.hpp:31
void setPosition(int32_t currentPosition)
QuadEncoder(std::string pinA, std::string pinB, bool useInternalPullup, bool createDevice=true, int deviceId=-1)
QuadEncoder(int pinA, std::string pinB, bool useInternalPullup, bool createDevice=true, int deviceId=-1)
QuadEncoder(std::string pinA, int pinB, bool useInternalPullup, bool createDevice=true, int deviceId=-1)
QuadEncoder(int pinA, int pinB, bool useInternalPullup, bool createDevice=true, int deviceId=-1)
Definition: ArduinoDevice.hpp:27