Smartcar Shield
Loading...
Searching...
No Matches
ServoMotor.hpp
Go to the documentation of this file.
1
9#pragma once
10
11#if defined(ESP32)
12#include <ESP32Servo.h>
13#else
14#include <Servo.h>
15#endif
16#include <stdint.h> // NOLINT(modernize-deprecated-headers)
17
18#include "../../Motor.hpp"
19
20namespace smartcarlib
21{
22namespace constants
23{
24namespace servomotor
25{
26const int kDefaultMinPulseLength = 1000;
27const int kDefaultIdlePulseLength = 1500;
28const int kDefaultMaxPulseLength = 2000;
29} // namespace servomotor
30} // namespace constants
31} // namespace smartcarlib
32
33class ServoMotor : public Servo, public Motor
34{
35public:
49 explicit ServoMotor(
50 uint8_t controlPin,
54
55 /* Check `Motor` interface for documentation */
56 void setSpeed(int speed) override;
57
58private:
59 const uint8_t kControlPin;
60 const int kMinPulseLength;
61 const int kIdlePulseLength;
62 const int kMaxPulseLength;
63 bool mAttached{ false };
64};
Interface programmatically representing any kind of motor.
Definition Motor.hpp:23
A motor that is controlled via the length of pulses that are sent to it through a single signal line.
void setSpeed(int speed) override
Sets the motor speed and direction as the percentage of the maximum possible speed,...