Hotwheels-Cluster 1.2
Creation of Cluster APP for SEA:ME project.
 
Loading...
Searching...
No Matches
EngineController Class Reference

The EngineController class. More...

#include <EngineController.hpp>

Signals

void directionUpdated (CarDirection newDirection)
 
void steeringUpdated (int newAngle)
 

Public Member Functions

 EngineController ()
 Default constructor for the EngineController class.
 
 EngineController (int servo_addr, int motor_addr, QObject *parent=nullptr)
 Constructs an EngineController object, initializing motor and servo controllers.
 
 ~EngineController ()
 Destructor for the EngineController class.
 
void start ()
 Starts the engine.
 
void stop ()
 Stops the engine.
 
void set_speed (int speed)
 Sets the speed of the car.
 
void set_steering (int angle)
 Sets the steering angle of the car.
 

Private Member Functions

void setDirection (CarDirection newDirection)
 Sets the direction of the car and emits the directionUpdated signal if the direction has changed.
 

Private Attributes

const int MAX_ANGLE = 180
 
const int SERVO_CENTER_PWM = 340
 
const int SERVO_LEFT_PWM = 340 - 100
 
const int SERVO_RIGHT_PWM = 340 + 130
 
const int STEERING_CHANNEL = 0
 
std::atomic< bool > m_running
 
std::atomic< int > m_current_speed
 
std::atomic< int > m_current_angle
 
CarDirection m_currentDirection = CarDirection::Stop
 
IPeripheralControllerpcontrol
 

Detailed Description

The EngineController class.

This class is responsible for controlling the engine of the car.

Definition at line 27 of file EngineController.hpp.

Constructor & Destructor Documentation

◆ EngineController() [1/2]

EngineController::EngineController ( )

Default constructor for the EngineController class.

Definition at line 41 of file EngineController.cpp.

◆ EngineController() [2/2]

EngineController::EngineController ( int servo_addr,
int motor_addr,
QObject * parent = nullptr )

Constructs an EngineController object, initializing motor and servo controllers.

Parameters
servo_addrThe address of the servo controller.
motor_addrThe address of the motor controller.
parentThe parent QObject for this instance.

Sets up the PeripheralController and initializes the servo and motor controllers.

Definition at line 50 of file EngineController.cpp.

◆ ~EngineController()

EngineController::~EngineController ( )

Destructor for the EngineController class.

Stops the engine and deletes the peripheral controller.

Definition at line 65 of file EngineController.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ directionUpdated

void EngineController::directionUpdated ( CarDirection newDirection)
signal
Here is the caller graph for this function:

◆ set_speed()

void EngineController::set_speed ( int speed)

Sets the speed of the car.

Parameters
speedThe desired speed value, ranging from -100 to 100.

This function adjusts the motor PWM signals based on the input speed value. Positive values set the car to move in reverse due to joystick reversal, while negative values move it forward. A speed of zero stops the car. The function also updates the car's direction accordingly and clamps the speed to ensure it is within the valid range.

Definition at line 112 of file EngineController.cpp.

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

◆ set_steering()

void EngineController::set_steering ( int angle)

Sets the steering angle of the car.

Parameters
angleThe desired steering angle in degrees, ranging from -MAX_ANGLE to MAX_ANGLE.

This function adjusts the servo PWM signal based on the input angle value. The function clamps the angle to ensure it is within the valid range and calculates the corresponding PWM value. The function also updates the internal steering angle and emits the steeringUpdated signal.

Definition at line 152 of file EngineController.cpp.

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

◆ setDirection()

void EngineController::setDirection ( CarDirection newDirection)
private

Sets the direction of the car and emits the directionUpdated signal if the direction has changed.

Parameters
newDirectionThe new direction to set.

Definition at line 94 of file EngineController.cpp.

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

◆ start()

void EngineController::start ( )

Starts the engine.

Sets the m_running flag to true.

Definition at line 75 of file EngineController.cpp.

◆ steeringUpdated

void EngineController::steeringUpdated ( int newAngle)
signal
Here is the caller graph for this function:

◆ stop()

void EngineController::stop ( )

Stops the engine.

Sets the m_running flag to false and sets both speed and steering to 0.

Definition at line 82 of file EngineController.cpp.

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

Field Documentation

◆ m_current_angle

std::atomic<int> EngineController::m_current_angle
private

Definition at line 39 of file EngineController.hpp.

◆ m_current_speed

std::atomic<int> EngineController::m_current_speed
private

Definition at line 38 of file EngineController.hpp.

◆ m_currentDirection

CarDirection EngineController::m_currentDirection = CarDirection::Stop
private

Definition at line 40 of file EngineController.hpp.

◆ m_running

std::atomic<bool> EngineController::m_running
private

Definition at line 37 of file EngineController.hpp.

◆ MAX_ANGLE

const int EngineController::MAX_ANGLE = 180
private

Definition at line 31 of file EngineController.hpp.

◆ pcontrol

IPeripheralController* EngineController::pcontrol
private

Definition at line 44 of file EngineController.hpp.

◆ SERVO_CENTER_PWM

const int EngineController::SERVO_CENTER_PWM = 340
private

Definition at line 32 of file EngineController.hpp.

◆ SERVO_LEFT_PWM

const int EngineController::SERVO_LEFT_PWM = 340 - 100
private

Definition at line 33 of file EngineController.hpp.

◆ SERVO_RIGHT_PWM

const int EngineController::SERVO_RIGHT_PWM = 340 + 130
private

Definition at line 34 of file EngineController.hpp.

◆ STEERING_CHANNEL

const int EngineController::STEERING_CHANNEL = 0
private

Definition at line 35 of file EngineController.hpp.


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