Smartcar Shield
ServoMotor.hpp
Go to the documentation of this file.
1 
9 #pragma once
10 
11 #include <Servo.h>
12 #include <stdint.h> // NOLINT(modernize-deprecated-headers)
13 
14 #include "../../Motor.hpp"
15 
16 namespace smartcarlib
17 {
18 namespace constants
19 {
20 namespace servomotor
21 {
22 const int kDefaultMinPulseLength = 1000;
23 const int kDefaultIdlePulseLength = 1500;
24 const int kDefaultMaxPulseLength = 2000;
25 } // namespace servomotor
26 } // namespace constants
27 } // namespace smartcarlib
28 
29 class ServoMotor : public Servo, public Motor
30 {
31 public:
45  ServoMotor(uint8_t controlPin,
49 
50  /* Check `Motor` interface for documentation */
51  void setSpeed(int speed) override;
52 
53 private:
54  const uint8_t kControlPin;
55  const int kMinPulseLength;
56  const int kIdlePulseLength;
57  const int kMaxPulseLength;
58  bool mAttached;
59 };
ServoMotor::setSpeed
void setSpeed(int speed) override
Sets the motor speed and direction as the percentage of the maximum possible speed,...
Definition: ServoMotor.cpp:19
smartcarlib
Definition: DistanceCar.hpp:11
ServoMotor::ServoMotor
ServoMotor(uint8_t controlPin, int minPulseLength=smartcarlib::constants::servomotor::kDefaultMinPulseLength, int idlePulseLength=smartcarlib::constants::servomotor::kDefaultIdlePulseLength, int maxPulseLength=smartcarlib::constants::servomotor::kDefaultMaxPulseLength)
Constructs a servo motor.
Definition: ServoMotor.cpp:7
Motor
Definition: Motor.hpp:22
smartcarlib::constants::servomotor::kDefaultMaxPulseLength
const int kDefaultMaxPulseLength
Definition: ServoMotor.hpp:24
smartcarlib::constants::servomotor::kDefaultMinPulseLength
const int kDefaultMinPulseLength
Definition: ServoMotor.hpp:22
ServoMotor
Definition: ServoMotor.hpp:29
smartcarlib::constants::servomotor::kDefaultIdlePulseLength
const int kDefaultIdlePulseLength
Definition: ServoMotor.hpp:23