ArPiRobot-CoreLib C++
C++ library for ArPiRobot robots
SingleEncoder.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 SingleEncoder : public ArduinoDevice{
32  public:
33 
40  SingleEncoder(int pin, bool useInternalPullup, bool createDevice = true, int deviceId = -1);
41 
48  SingleEncoder(std::string pin, bool useInternalPullup, bool createDevice = true, int deviceId = -1);
49 
54  int32_t getPosition();
55 
60  void setPosition(int32_t currentPosition);
61 
66  float getVelocity();
67 
68  protected:
69  void applyDefaultState() override;
70  std::vector<uint8_t> getCreateData() override;
71  void handleData(const std::vector<uint8_t> &data) override;
72 
73  private:
74  static const uint8_t numSamples = 5;
75 
76  std::string pin;
77  uint8_t useInternalPullup;
78  int32_t count = 0;
79  int32_t countOffset = 0;
80  float velocity = 0;
81  };
82 }
Definition: ArduinoDevice.hpp:35
Definition: SingleEncoder.hpp:31
SingleEncoder(std::string pin, bool useInternalPullup, bool createDevice=true, int deviceId=-1)
SingleEncoder(int pin, bool useInternalPullup, bool createDevice=true, int deviceId=-1)
void setPosition(int32_t currentPosition)
Definition: ArduinoDevice.hpp:27