Smartcar Shield
Public Member Functions | List of all members
ServoMotor Class Reference

#include <ServoMotor.hpp>

Inheritance diagram for ServoMotor:
Inheritance graph
Collaboration diagram for ServoMotor:
Collaboration graph

Public Member Functions

 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. More...
 
void setSpeed (int speed) override
 Sets the motor speed and direction as the percentage of the maximum possible speed, where the sign of the argument represents the direction. More...
 
- Public Member Functions inherited from Motor
virtual ~Motor ()=default
 

Detailed Description

A motor that is controlled via the length of pulses that are sent to it through a single signal line. It can be either a traditional servo motor that controls a shaft (e.g. for steering) or an Electronic Speed Controller (ESC) that interpets speed in the same manner and controls a (typically brushless) motor.

Definition at line 29 of file ServoMotor.hpp.

Constructor & Destructor Documentation

◆ 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.

Parameters
controlPinThe pin controlling the speed of the motor
minPulseLengthThe motor's minimum pulse length in microseconds
idlePulseLengthThe pulse length that the motor is idle in microseconds
maxPulseLengthThe motor's maximum pulse length in microseconds

Example:

const unsigned short ESC_PIN = 7;
ServoMotor esc(ESC_PIN);

Definition at line 7 of file ServoMotor.cpp.

Member Function Documentation

◆ setSpeed()

void ServoMotor::setSpeed ( int  speed)
overridevirtual

Sets the motor speed and direction as the percentage of the maximum possible speed, where the sign of the argument represents the direction.

Parameters
speedThe speed and direction within the range of [-100, 100]. -100 means that the motor is spinning at full speed towards the direction we have defined as backward. 100 interpreted as full speed forward. 0 means that the motor is at its idle/neutral state.

Example:

motor.setSpeed(0); // Stop the motor

Implements Motor.

Definition at line 19 of file ServoMotor.cpp.

Here is the call graph for this function:

The documentation for this class was generated from the following files:
ServoMotor
Definition: ServoMotor.hpp:29