-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Update include directories and source file paths
- Loading branch information
1 parent
f181f02
commit ff23893
Showing
7 changed files
with
206 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
{ | ||
"files.associations": { | ||
"array": "cpp", | ||
"atomic": "cpp", | ||
"bit": "cpp", | ||
"*.tcc": "cpp", | ||
"cctype": "cpp", | ||
"charconv": "cpp", | ||
"chrono": "cpp", | ||
"cinttypes": "cpp", | ||
"clocale": "cpp", | ||
"cmath": "cpp", | ||
"compare": "cpp", | ||
"concepts": "cpp", | ||
"condition_variable": "cpp", | ||
"csignal": "cpp", | ||
"cstdarg": "cpp", | ||
"cstddef": "cpp", | ||
"cstdint": "cpp", | ||
"cstdio": "cpp", | ||
"cstdlib": "cpp", | ||
"ctime": "cpp", | ||
"cwchar": "cpp", | ||
"cwctype": "cpp", | ||
"deque": "cpp", | ||
"list": "cpp", | ||
"map": "cpp", | ||
"set": "cpp", | ||
"string": "cpp", | ||
"unordered_map": "cpp", | ||
"vector": "cpp", | ||
"exception": "cpp", | ||
"algorithm": "cpp", | ||
"functional": "cpp", | ||
"iterator": "cpp", | ||
"memory": "cpp", | ||
"memory_resource": "cpp", | ||
"numeric": "cpp", | ||
"optional": "cpp", | ||
"random": "cpp", | ||
"ratio": "cpp", | ||
"string_view": "cpp", | ||
"system_error": "cpp", | ||
"tuple": "cpp", | ||
"type_traits": "cpp", | ||
"utility": "cpp", | ||
"format": "cpp", | ||
"fstream": "cpp", | ||
"future": "cpp", | ||
"initializer_list": "cpp", | ||
"iomanip": "cpp", | ||
"iosfwd": "cpp", | ||
"iostream": "cpp", | ||
"istream": "cpp", | ||
"limits": "cpp", | ||
"mutex": "cpp", | ||
"new": "cpp", | ||
"numbers": "cpp", | ||
"ostream": "cpp", | ||
"semaphore": "cpp", | ||
"shared_mutex": "cpp", | ||
"span": "cpp", | ||
"sstream": "cpp", | ||
"stdexcept": "cpp", | ||
"stop_token": "cpp", | ||
"streambuf": "cpp", | ||
"thread": "cpp", | ||
"typeinfo": "cpp", | ||
"variant": "cpp" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,35 @@ | ||
#pragma once | ||
|
||
#include <linux/joystick.h> | ||
|
||
|
||
|
||
class BackMotors; | ||
class FServo; | ||
|
||
class CarControl { | ||
private: | ||
BackMotors _backMotors; | ||
FServo _fServo; | ||
|
||
std::atomic<bool> _running; | ||
std::thread _controlThread; | ||
int _currenntGear; | ||
double _currentSpeed; | ||
double _gear[5] = {20, 40, 60, 80, 100}; | ||
|
||
void _shiftDown(); | ||
void _shiftUp(); | ||
|
||
public: | ||
CarControl(); | ||
~CarControl(); | ||
|
||
void processJoystick(); | ||
void process(); | ||
void start(); | ||
void stop(); | ||
}; | ||
|
||
#include "BackMotors.hpp" | ||
#include "FrontMotors.hpp" | ||
#include "FServo.hpp" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
#include "CarControl.hpp" | ||
|
||
CarControl::CarControl() : _running(false), _currenntGear(0), _currentSpeed(0) { | ||
|
||
} | ||
|
||
CarControl::~CarControl() { | ||
} | ||
|
||
void CarControl::processJoystick() { | ||
int joy_fd = open("/dev/input/js0", O_RDONLY); | ||
if (joy_fd < 0) { | ||
std::cerr << "Erro ao abrir o joystick" << std::endl; | ||
return; | ||
} | ||
|
||
struct js_event js; | ||
|
||
while (_running) { | ||
ssize_t n = read(joy_fd, &js, sizeof(js)); | ||
if (n == sizeof(js)) { | ||
js.type &= ~JS_EVENT_INIT; // Ignora eventos de inicialização | ||
if (js.type == JS_EVENT_BUTTON){ | ||
if (js.number == 4 && js.value == 1) { //Left Button BTN_TL | ||
_shiftDown(); | ||
std::cout << "Shift Down: " << _currenntGear + 1 << ", Max speed" << _gear[_currenntGear] << std::endl; | ||
} | ||
else if (js.number == 5 && js.value == 1) { //Right Button BTN_TR | ||
_shiftUp(); | ||
std::cout << "Shift Up: " << _currenntGear + 1 << ", Max speed" << _gear[_currenntGear] << std::endl; | ||
} | ||
else if ((js.number == 7 || js.number == 6) && js.value == 1) { //Start/Select Button BTN_START | ||
_backMotors.setSpeed(0); | ||
_running = false; | ||
std::cout << "Stop" << std::endl; | ||
break; | ||
} | ||
} | ||
else if (js.type == JS_EVENT_AXIS) { | ||
if (js.number == 0) { // ABS_X | ||
_fServo.set_steering( js.value / 32767.0 * 100); | ||
} | ||
else if (js.number == 5) { // ABS_RZ | ||
if (js.value == 0){ | ||
_backMotors.setSpeed(0); | ||
} | ||
else { | ||
_backMotors.setSpeed(js.value / 32767.0 * 100); | ||
} | ||
} | ||
} | ||
} | ||
else if (n < 0) { | ||
std::cerr << "Erro ao ler o joystick" << std::endl; | ||
_running = false; | ||
break; | ||
} | ||
} | ||
close (joy_fd); | ||
} | ||
|
||
void CarControl::start() { | ||
_running = true; | ||
_controlThread = std::thread(&CarControl::processJoystick, this); | ||
} | ||
|
||
void CarControl::stop() { | ||
_running = false; | ||
if (_controlThread.joinable()) { | ||
_controlThread.join(); | ||
} | ||
_backMotors.setSpeed(0); | ||
_fServo.set_steering(0); | ||
} | ||
|
||
void CarControl::_shiftDown() { | ||
if (_currenntGear > 0) { | ||
_currenntGear--; | ||
} | ||
} | ||
|
||
void CarControl::_shiftUp() { | ||
if (_currenntGear < 4) { | ||
_currenntGear++; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters