The EngineController class.
More...
#include <EngineController.hpp>
|
void | setDirection (CarDirection newDirection) |
| Sets the direction of the car and emits the directionUpdated signal if the direction has changed.
|
|
The EngineController class.
This class is responsible for controlling the engine of the car.
Definition at line 27 of file EngineController.hpp.
◆ EngineController() [1/2]
EngineController::EngineController |
( |
| ) |
|
◆ 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_addr | The address of the servo controller. |
motor_addr | The address of the motor controller. |
parent | The 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 |
( |
| ) |
|
◆ directionUpdated
void EngineController::directionUpdated |
( |
CarDirection | newDirection | ) |
|
|
signal |
◆ set_speed()
void EngineController::set_speed |
( |
int | speed | ) |
|
Sets the speed of the car.
- Parameters
-
speed | The 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.
◆ set_steering()
void EngineController::set_steering |
( |
int | angle | ) |
|
Sets the steering angle of the car.
- Parameters
-
angle | The 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.
◆ setDirection()
void EngineController::setDirection |
( |
CarDirection | newDirection | ) |
|
|
private |
Sets the direction of the car and emits the directionUpdated signal if the direction has changed.
- Parameters
-
newDirection | The new direction to set. |
Definition at line 94 of file EngineController.cpp.
◆ start()
void EngineController::start |
( |
| ) |
|
◆ steeringUpdated
void EngineController::steeringUpdated |
( |
int | newAngle | ) |
|
|
signal |
◆ 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.
◆ m_current_angle
std::atomic<int> EngineController::m_current_angle |
|
private |
◆ m_current_speed
std::atomic<int> EngineController::m_current_speed |
|
private |
◆ m_currentDirection
◆ m_running
std::atomic<bool> EngineController::m_running |
|
private |
◆ MAX_ANGLE
const int EngineController::MAX_ANGLE = 180 |
|
private |
◆ pcontrol
◆ SERVO_CENTER_PWM
const int EngineController::SERVO_CENTER_PWM = 340 |
|
private |
◆ SERVO_LEFT_PWM
const int EngineController::SERVO_LEFT_PWM = 340 - 100 |
|
private |
◆ SERVO_RIGHT_PWM
const int EngineController::SERVO_RIGHT_PWM = 340 + 130 |
|
private |
◆ STEERING_CHANNEL
const int EngineController::STEERING_CHANNEL = 0 |
|
private |
The documentation for this class was generated from the following files: