ArPiRobot-CoreLib C++
C++ library for ArPiRobot robots
MotorController.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 <string>
23 #include <mutex>
24 #include <arpirobot/core/device/BaseDevice.hpp>
25 
26 namespace arpirobot{
32  class MotorController : public BaseDevice{
33  public:
34 
35  virtual ~MotorController() = default;
36 
41  bool isInverted();
42 
47  void setInverted(bool inverted);
48 
53  bool isBrakeMode();
54 
59  void setBrakeMode(bool brakeMode);
60 
65  double getSpeed();
66 
71  void setSpeed(double speed);
72 
73  protected:
74  bool isEnabled() override;
75 
76  bool shouldMatchRobotState() override;
77 
78  bool shouldDisableWithWatchdog() override;
79 
80  void enable() override;
81 
82  void disable() override;
83 
84  virtual void run() = 0;
85 
86  double speed = 0;
87  std::mutex lock;
88  bool enabled = false;
89  bool brakeMode = false;
90  int8_t speedFactor = 1; // 1 or -1
91  };
92 
93 }
Definition: BaseDevice.hpp:35
Definition: MotorController.hpp:32
void setBrakeMode(bool brakeMode)
void setSpeed(double speed)
void setInverted(bool inverted)
Definition: ArduinoDevice.hpp:27