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

#include <BrushedMotor.hpp>

Inheritance diagram for BrushedMotor:
Inheritance graph
Collaboration diagram for BrushedMotor:
Collaboration graph

Public Member Functions

 BrushedMotor (Runtime &runtime, uint8_t forwardPin, uint8_t backwardPin, uint8_t enablePin)
 Constructs a brushed DC motor instance. More...
 
 BrushedMotor (Runtime &runtime, BrushedMotorPins pins)
 Constructs a brushed DC motor instance. 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 brushed motor is controlled via two wires where the flow of current determines the direction of rotation and the duty cycle the speed.

For their control, we will assume the existince of a half-bridge such as the L293D chip where three signals are needed, two for determining the direction and another for determining the speed.

Definition at line 41 of file BrushedMotor.hpp.

Constructor & Destructor Documentation

◆ BrushedMotor() [1/2]

BrushedMotor::BrushedMotor ( Runtime runtime,
uint8_t  forwardPin,
uint8_t  backwardPin,
uint8_t  enablePin 
)

Constructs a brushed DC motor instance.

Parameters
runtimeThe runtime environment you want to run the class for
forwardPinThe direction pin that when set to HIGH makes the motor spin forward
backwardPinThe direction pin that when set to HIGH makes the motor spin forward
enablePinThe pin that controls the motor's speed

Example:

ArduinoRuntime arduinoRuntime;
BrushedMotor leftMotor(arduinoRuntime, 8, 9, 10);

Definition at line 13 of file BrushedMotor.cpp.

◆ BrushedMotor() [2/2]

BrushedMotor::BrushedMotor ( Runtime runtime,
BrushedMotorPins  pins 
)

Constructs a brushed DC motor instance.

Parameters
runtimeThe runtime environment you want to run the class for
pinsThe BrushedMotorPins object with the pins of the motor

Example:

ArduinoRuntime arduinoRuntime;

Definition at line 27 of file BrushedMotor.cpp.

Member Function Documentation

◆ setSpeed()

void BrushedMotor::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 32 of file BrushedMotor.cpp.

Here is the call graph for this function:

The documentation for this class was generated from the following files:
smartcarlib::pins::v2::leftMotorPins
const BrushedMotorPins leftMotorPins
Definition: Smartcar.h:50
BrushedMotor
Definition: BrushedMotor.hpp:41
ArduinoRuntime
Definition: ArduinoRuntime.hpp:11