ESP Line Following Buggy
2nd Year Embedded System Project (Group 48 - 2023/24)
Loading...
Searching...
No Matches
Motor Class Reference

Represents a motor with integrated quadrature encoder for the buggy. More...

#include <motor.h>

Public Member Functions

 Motor (PinName pwm, PinName dir, PinName bip, PinName CH_A, PinName CH_B, int pulsePerRev, int pwmFreq, int updateRate, float LowPass_a0, float LowPass_b0, float LowPass_b1, float wheelRadius)
 Construct a new Motor object.
 
void set_direction (bool DirState)
 Set the direction of the motor.
 
void set_bipolar_mode (bool BipState)
 Set the bipolar mode of the motor.
 
void set_duty_cycle (float DutyCycle)
 Set the duty cycle of the motor.
 
bool get_direction ()
 Get the direction of the motor.
 
bool get_bipolar_mode ()
 Get the bipolar mode of the motor.
 
float get_duty_cycle ()
 Get the duty cycle of the motor.
 
void update (void)
 Calculate and update all the speed variables.
 
void reset (void)
 Reset the encoder tick count.
 
int get_tick_count (void)
 Get the cumulative tick count.
 
float get_rotational_freq (void)
 Get the rotational frequency of the motor in revolutions per second (rev/s).
 
float get_rpm (void)
 Get the revolutions per minute (RPM) of the motor.
 
float get_speed (void)
 Get the tangential speed of the wheel.
 
float get_filtered_speed (void)
 Get the low-pass filtered speed of the wheel.
 

Detailed Description

Represents a motor with integrated quadrature encoder for the buggy.

This class provides functionality to control the speed and direction of the motor, read encoder tick counts, and calculate various parameters such as rotational frequency, speed, and revolutions per minute (RPM). It also includes a low-pass filter for noise reduction in speed measurements.

Definition at line 21 of file motor.h.

Constructor & Destructor Documentation

◆ Motor()

Motor::Motor ( PinName pwm,
PinName dir,
PinName bip,
PinName CH_A,
PinName CH_B,
int pulsePerRev,
int pwmFreq,
int updateRate,
float LowPass_a0,
float LowPass_b0,
float LowPass_b1,
float wheelRadius )

Construct a new Motor object.

Parameters
pwmThe PWM pin.
dirThe direction pin.
bipThe bipolar/unipolar mode pin.
CH_AThe encoder channel A pin.
CH_BThe encoder channel B pin.
pulsePerRevThe number of pulses per revolution of the motor.
pwmFreqThe PWM frequency.
updateRateThe update rate.
LowPass_a0Coefficient a0 for the low-pass filter.
LowPass_b0Coefficient b0 for the low-pass filter.
LowPass_b1Coefficient b1 for the low-pass filter.
wheelRadiusThe radius of the wheel in meters.

Definition at line 7 of file motor.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ get_bipolar_mode()

bool Motor::get_bipolar_mode ( void )

Get the bipolar mode of the motor.

Returns
The bipolar mode state (true for bipolar mode, false for unipolar mode).

Definition at line 102 of file motor.cpp.

◆ get_direction()

bool Motor::get_direction ( void )

Get the direction of the motor.

Returns
The direction state (true for forward, false for reverse).

Definition at line 97 of file motor.cpp.

◆ get_duty_cycle()

float Motor::get_duty_cycle ( void )

Get the duty cycle of the motor.

Returns
The duty cycle value (0 to 1).

Definition at line 107 of file motor.cpp.

Here is the caller graph for this function:

◆ get_filtered_speed()

float Motor::get_filtered_speed ( void )

Get the low-pass filtered speed of the wheel.

Returns
The low-pass filtered speed.

Definition at line 132 of file motor.cpp.

Here is the caller graph for this function:

◆ get_rotational_freq()

float Motor::get_rotational_freq ( void )

Get the rotational frequency of the motor in revolutions per second (rev/s).

Returns
The rotational frequency.

Definition at line 117 of file motor.cpp.

◆ get_rpm()

float Motor::get_rpm ( void )

Get the revolutions per minute (RPM) of the motor.

Returns
The RPM value.

Definition at line 122 of file motor.cpp.

◆ get_speed()

float Motor::get_speed ( void )

Get the tangential speed of the wheel.

Returns
The tangential speed.

Definition at line 127 of file motor.cpp.

Here is the caller graph for this function:

◆ get_tick_count()

int Motor::get_tick_count ( void )

Get the cumulative tick count.

Returns
The cumulative tick count.

Definition at line 112 of file motor.cpp.

Here is the caller graph for this function:

◆ reset()

void Motor::reset ( void )

Reset the encoder tick count.

Definition at line 56 of file motor.cpp.

Here is the caller graph for this function:

◆ set_bipolar_mode()

void Motor::set_bipolar_mode ( bool BipState)

Set the bipolar mode of the motor.

Parameters
BipStateThe bipolar mode state (true for bipolar mode, false for unipolar mode).

Definition at line 91 of file motor.cpp.

Here is the caller graph for this function:

◆ set_direction()

void Motor::set_direction ( bool DirState)

Set the direction of the motor.

Parameters
DirStateThe direction state (true for forward, false for reverse).

Definition at line 85 of file motor.cpp.

Here is the caller graph for this function:

◆ set_duty_cycle()

void Motor::set_duty_cycle ( float DutyCycle)

Set the duty cycle of the motor.

Parameters
DutyCycleThe duty cycle value (0 to 1).

Definition at line 70 of file motor.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ update()

void Motor::update ( void )

Calculate and update all the speed variables.

Preferably run in an Interrupt Service Routine (ISR).

Definition at line 33 of file motor.cpp.

Here is the caller graph for this function:

The documentation for this class was generated from the following files: