From 441f2df6e3019eea4648c51e72aa9764198ed425 Mon Sep 17 00:00:00 2001 From: Chi Huu Huynh <73843190+Chi-EEE@users.noreply.github.com> Date: Wed, 3 Jan 2024 19:05:38 +0000 Subject: [PATCH] fix compile_commands, Use CXX instead of HPP for compile_commands --- app/raspberry_pi/include/global/Config.hpp | 4 +- app/raspberry_pi/include/rplidar/RPLidar.cpp | 633 ------------------ .../packages/t/tb6612/tb6612/include/TB6612.h | 32 + .../t/tb6612/tb6612/include/TB6612.hpp | 54 -- .../packages/t/tb6612/tb6612/src/TB6612.cpp | 37 + .../packages/t/tb6612/tb6612/xmake.lua | 5 +- .../repository/packages/t/tb6612/xmake.lua | 1 - .../{CarConsole.hpp => CarConsole.cxx} | 0 app/raspberry_pi/src/car/system/CarSystem.h | 6 +- .../{LidarDevice.hpp => LidarDevice.cxx} | 4 +- .../lidar/{LidarDummy.hpp => LidarDummy.cxx} | 6 +- .../{LidarScanner.hpp => LidarScanner.cxx} | 6 +- ...essagingSystem.hpp => MessagingSystem.cxx} | 8 +- .../{MoveCommand.hpp => MoveCommand.cxx} | 4 +- .../{TurnCommand.hpp => TurnCommand.cxx} | 4 +- ...{MovementSystem.hpp => MovementSystem.cxx} | 11 +- .../wheels/{FrontWheel.hpp => FrontWheel.cxx} | 5 + .../wheels/{RearWheel.hpp => RearWheel.cxx} | 9 +- app/raspberry_pi/src/main.cpp | 8 +- app/raspberry_pi/xmake.lua | 7 +- 20 files changed, 120 insertions(+), 724 deletions(-) delete mode 100644 app/raspberry_pi/include/rplidar/RPLidar.cpp create mode 100644 app/raspberry_pi/repository/packages/t/tb6612/tb6612/include/TB6612.h delete mode 100644 app/raspberry_pi/repository/packages/t/tb6612/tb6612/include/TB6612.hpp create mode 100644 app/raspberry_pi/repository/packages/t/tb6612/tb6612/src/TB6612.cpp rename app/raspberry_pi/src/car/display/{CarConsole.hpp => CarConsole.cxx} (100%) rename app/raspberry_pi/src/car/system/lidar/{LidarDevice.hpp => LidarDevice.cxx} (87%) rename app/raspberry_pi/src/car/system/lidar/{LidarDummy.hpp => LidarDummy.cxx} (86%) rename app/raspberry_pi/src/car/system/lidar/{LidarScanner.hpp => LidarScanner.cxx} (95%) rename app/raspberry_pi/src/car/system/messaging/{MessagingSystem.hpp => MessagingSystem.cxx} (95%) rename app/raspberry_pi/src/car/system/messaging/commands/{MoveCommand.hpp => MoveCommand.cxx} (69%) rename app/raspberry_pi/src/car/system/messaging/commands/{TurnCommand.hpp => TurnCommand.cxx} (70%) rename app/raspberry_pi/src/car/system/movement/{MovementSystem.hpp => MovementSystem.cxx} (77%) rename app/raspberry_pi/src/car/system/movement/wheels/{FrontWheel.hpp => FrontWheel.cxx} (96%) rename app/raspberry_pi/src/car/system/movement/wheels/{RearWheel.hpp => RearWheel.cxx} (94%) diff --git a/app/raspberry_pi/include/global/Config.hpp b/app/raspberry_pi/include/global/Config.hpp index 953bbd93..97ced0aa 100644 --- a/app/raspberry_pi/include/global/Config.hpp +++ b/app/raspberry_pi/include/global/Config.hpp @@ -1,5 +1,5 @@ -#ifndef CONFIG_HPP -#define CONFIG_HPP +#ifndef CONFIG_CXX +#define CONFIG_CXX #pragma once diff --git a/app/raspberry_pi/include/rplidar/RPLidar.cpp b/app/raspberry_pi/include/rplidar/RPLidar.cpp deleted file mode 100644 index d6a8a509..00000000 --- a/app/raspberry_pi/include/rplidar/RPLidar.cpp +++ /dev/null @@ -1,633 +0,0 @@ -#include "RPLidar.h" - -// Made with the help of ChatGPT - -/* -auto lidar = RPLidar("COM3"); - -auto info = lidar.get_info(); -std::cout << fmt::format("model: {}, firmware: ({}, {}), hardware: {}, serialnumber: {}\n", info.model, info.firmware.first, info.firmware.second, info.hardware, info.serialNumber); - -auto health = lidar.get_health(); -std::cout << fmt::format("({}, {})\n", health.status, health.errorCode); - -std::function()> scanGenerator = lidar.iter_scans(); -for (int i = 0; i < 10; i++) -{ - std::vector scan = scanGenerator(); - std::cout << "Got " << scan.size() << " Measures!\n"; - for (const Measure &measure : scan) - { - // Access individual measurements in the scan - bool newScan = measure.newScan; - int quality = measure.quality; - float angle = measure.angle; - float distance = measure.distance; - } -} - -lidar.stop(); -lidar.stop_motor(); -lidar.disconnect(); - -*/ - -namespace rplidar { - /** - * @brief Initilize RPLidar object for communicating with the sensor - * - * @param port Serial port name to which sensor is connected - * @param baudrate Baudrate for serial connection (the default is 115200) - */ - RPLidar::RPLidar(const std::string& port, uint32_t baudrate, std::unique_ptr serial): port(port), baudrate(baudrate), _serial(std::move(serial)) - { - } - - tl::expected, nullptr_t> RPLidar::create(const std::string& port, uint32_t baudrate) - { - try - { - std::unique_ptr serial = std::make_unique(port, baudrate, serial::Timeout(1000U, 60000U, 0U, 1000U, 0U)); - std::unique_ptr lidar = std::make_unique(port, baudrate, std::move(serial)); - return std::move(lidar); - } - catch (std::exception& e) - { - return tl::make_unexpected(nullptr); - } - - } - - RPLidar::~RPLidar() - { - } - - void RPLidar::disconnect() - { - if (!this->_serial->isOpen()) - { - return; - } - this->_serial->close(); - } - - void RPLidar::_set_pwm(int pwm) - { - std::string payload; - payload.push_back(static_cast(pwm & 0xFF)); - payload.push_back(static_cast((pwm >> 8) & 0xFF)); - this->_send_payload_cmd(SET_PWM_BYTE, payload); - } - - void RPLidar::set_motor_speed(int pwm) - { - if (0 <= pwm && pwm <= MAX_MOTOR_PWM) - { - std::abort(); - } - this->_motor_speed = pwm; - if (this->motor_running) - this->_set_pwm(this->_motor_speed); - } - - /** - * @brief Starts sensor motor - * - */ - void RPLidar::start_motor() - { - spdlog::info("Starting motor"); - // For A1 - this->_serial->setDTR(false); - - // For A2 - this->_set_pwm(this->_motor_speed); - this->motor_running = true; - } - - /** - * @brief Stops sensor motor - * - */ - void RPLidar::stop_motor() - { - spdlog::info("Stopping motor"); - // For A2 - this->_set_pwm(0); - std::this_thread::sleep_for(std::chrono::milliseconds(1)); - - // For A1 - this->_serial->setDTR(true); - this->motor_running = false; - } - - /** - * @brief Sends `cmd` command with `payload` to the sensor - * - * @param cmd - * @param payload - */ - void RPLidar::_send_payload_cmd(uint8_t cmd, const std::string& payload) - { - // Calculate the size - uint8_t size = static_cast(payload.size()); - - // Construct the request string - std::string req; - req += static_cast(SYNC_BYTE); - req += static_cast(cmd); - req += static_cast(size); - req += payload; - - // Calculate the checksum - uint8_t checksum = 0; - for (const uint8_t& c : req) - { - checksum ^= static_cast(c); - } - - req += static_cast(checksum); - - this->_serial->write(req); - spdlog::debug("Command sent: {}", spdlog::to_hex(req)); - } - - /** - * @brief Sends `cmd` command to the sensor - * - * @param cmd - */ - void RPLidar::_send_cmd(uint8_t cmd) - { - std::string req; - req += static_cast(SYNC_BYTE); - req += static_cast(cmd); - - this->_serial->write(req); - spdlog::debug("Command sent: {}", spdlog::to_hex(req)); - } - - /** - * @brief Reads descriptor packet - * - * @return tl::expected, std::string> - */ - tl::expected, std::string> RPLidar::_read_descriptor() - { - // Read descriptor packet - std::vector descriptor(DESCRIPTOR_LEN); - this->_serial->read(descriptor.data(), DESCRIPTOR_LEN); - spdlog::debug("Received descriptor: {}", spdlog::to_hex(descriptor)); - - if (descriptor.size() != DESCRIPTOR_LEN) - { - return tl::make_unexpected("Descriptor length mismatch"); - } - else if (descriptor[0] != SYNC_BYTE || descriptor[1] != SYNC_BYTE2) - { - return tl::make_unexpected("Incorrect descriptor starting bytes"); - } - - bool isSingle = descriptor[5] == 0; - return std::make_tuple(descriptor[2], isSingle, descriptor[6]); - } - - /** - * @brief Reads response packet with length of `dsize` bytes - * - * @param dsize - * @return std::vector - */ - std::vector RPLidar::_read_response(int dsize) - { - spdlog::debug("Trying to read response: {} bytes", dsize); - - std::vector data; - data.reserve(dsize); - - while (this->_serial->available() < dsize) - { - std::this_thread::sleep_for(std::chrono::milliseconds(1)); - } - - this->_serial->read(data, dsize); - - spdlog::debug("Received data: {}", spdlog::to_hex(data)); - return data; - } - - std::string convertToHexString(uint8_t value) - { - // Convert a uint8_t to a hexadecimal string - std::stringstream stream; - stream << std::hex << std::uppercase << std::setw(2) << std::setfill('0') << static_cast(value); - return stream.str(); - } - - /** - * @brief Get device information - * - * @return tl::expected - */ - tl::expected RPLidar::get_info() - { - // Check if there's data in the buffer - if (this->_serial->available() > 0) - { - throw std::runtime_error("Data in buffer, you can't have info! Run flush() to empty the buffer."); - } - this->_send_cmd(GET_INFO_BYTE); - - uint8_t dsize; - bool isSingle; - uint8_t dtype; - auto descriptor_result = this->_read_descriptor(); - if (!descriptor_result.has_value()) - return tl::make_unexpected(descriptor_result.error()); - std::tie(dsize, isSingle, dtype) = descriptor_result.value(); - - // Check response properties - if (dsize != INFO_LEN) - { - return tl::make_unexpected("Wrong get_info reply length"); - } - if (!isSingle) - { - return tl::make_unexpected("Not a single response mode"); - } - if (dtype != INFO_TYPE) - { - return tl::make_unexpected("Wrong response data type"); - } - - // Read the response - std::vector raw = this->_read_response(dsize); - - // Convert serial number to a hex string - std::string serialNumber; - for (size_t i = 4; i < raw.size(); ++i) - { - serialNumber += convertToHexString(raw[i]); - } - - // Construct the device info struct - DeviceInfo info; - info.model = raw[0]; - info.firmware.first = raw[2]; - info.firmware.second = raw[1]; - info.hardware = raw[3]; - info.serialNumber = serialNumber; - - return info; - } - - /** - * @brief Get device health state. When the core system detects some - potential risk that may cause hardware failure in the future, - the returned status value will be 'Warning'. But sensor can still work - as normal. When sensor is in the Protection Stop state, the returned - status value will be 'Error'. In case of warning or error statuses - non-zero error code will be returned. - * - * @return tl::expected - */ - tl::expected RPLidar::get_health() - { - // Check if there's data in the buffer - if (this->_serial->available() > 0) - { - return tl::make_unexpected("Data in buffer, you can't get health info! Run cleanInput() to empty the buffer."); - } - spdlog::info("Asking for health"); - - this->_send_cmd(GET_HEALTH_BYTE); - - // Read the descriptor - uint8_t dsize; - bool isSingle; - uint8_t dtype; - auto descriptor_result = this->_read_descriptor(); - if (!descriptor_result.has_value()) - return tl::make_unexpected(descriptor_result.error()); - std::tie(dsize, isSingle, dtype) = descriptor_result.value(); - - // Check response properties - if (dsize != HEALTH_LEN) - { - return tl::make_unexpected("Wrong get_health reply length"); - } - if (!isSingle) - { - return tl::make_unexpected("Not a single response mode"); - } - if (dtype != HEALTH_TYPE) - { - return tl::make_unexpected("Wrong response data type"); - } - - // Read the response - std::vector raw = this->_read_response(dsize); - - // Extract status and error code - std::string status = HEALTH_STATUSES[raw[0]]; - int errorCode = (static_cast(raw[1]) << 8) + static_cast(raw[2]); - - return HealthInfo{ status, errorCode }; - } - - /** - * @brief - * Clean input buffer by reading all available data - */ - void RPLidar::clean_input() - { - if (this->scanning.currently_scanning) - { - throw std::runtime_error("Cleaning not allowed during scanning process active!"); - } - this->_serial->flushInput(); - this->express_trame = 32; - this->express_data = nullptr; - } - - /** - * @brief - * Stops scanning process, disables laser diode and the measurement - system, moves sensor to the idle state. - */ - void RPLidar::stop() - { - spdlog::info("Stopping scanning"); - this->_send_cmd(STOP_BYTE); - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - this->scanning.currently_scanning = false; - this->clean_input(); - } - - /** - * @brief Start the scanning process - * - * @param scanType NORMAL, FORCE or EXPRESS - */ - tl::expected RPLidar::start(ScanType scanType = NORMAL) - { - if (this->scanning.currently_scanning) - { - return tl::make_unexpected("Scanning already running!"); - } - - auto health_info_result = this->get_health(); - if (!health_info_result.has_value()) - return tl::make_unexpected(health_info_result.error()); - HealthInfo healthInfo = health_info_result.value(); - std::string status = healthInfo.status; - int errorCode = healthInfo.errorCode; - spdlog::debug("Health status: {} [{}}]", status, errorCode); - - if (status == "Error") - { - this->reset(); - health_info_result = this->get_health(); - if (!health_info_result.has_value()) - return tl::make_unexpected(health_info_result.error()); - healthInfo = health_info_result.value(); - status = healthInfo.status; - errorCode = healthInfo.errorCode; - if (status == "Error") - { - return tl::make_unexpected("RPLidar hardware failure. Error code: " + std::to_string(errorCode)); - } - } - else if (status == "Warning") - { - spdlog::warn("Warning sensor status detected! Error code: {}", errorCode); - } - - uint8_t cmd = SCAN_TYPE[scanType]["byte"]; - - spdlog::warn("starting scan process in {} mode", scanType); - - if (scanType == EXPRESS) - { - // Adjust this part according to your payload format - std::string payload = "\x00\x00\x00\x00\x00"; - this->_send_payload_cmd(cmd, payload); - } - else - { - this->_send_cmd(cmd); - } - - uint8_t dsize; - bool isSingle; - uint8_t dtype; - auto descriptor_result = this->_read_descriptor(); - if (!descriptor_result.has_value()) - return tl::make_unexpected(descriptor_result.error()); - std::tie(dsize, isSingle, dtype) = descriptor_result.value(); - - if (dsize != SCAN_TYPE[scanType]["size"]) - { - return tl::make_unexpected("Wrong get_info reply length"); - } - if (isSingle) - { - return tl::make_unexpected("Not a multiple response mode"); - } - if (dtype != SCAN_TYPE[scanType]["response"]) - { - return tl::make_unexpected("Wrong response data type"); - } - - scanning = { true, dsize, scanType }; - } - - /** - * @brief Resets sensor core, reverting it to a similar state as it has - just been powered up. - * - */ - void RPLidar::reset() - { - spdlog::info("Resetting the sensor"); - this->_send_cmd(RESET_BYTE); - std::this_thread::sleep_for(std::chrono::milliseconds(2000)); - this->clean_input(); - } - - tl::expected _process_scan(const std::vector& raw) - { - Measure measurementData; - - bool newScan = static_cast(raw[0] & 0b1); - bool inversedNewScan = static_cast((raw[0] >> 1) & 0b1); - int quality = static_cast(raw[0] >> 2); - - if (newScan == inversedNewScan) - { - return tl::make_unexpected("New scan flags mismatch"); - } - - int checkBit = static_cast(raw[1] & 0b1); - if (checkBit != 1) - { - return tl::make_unexpected("Check bit not equal to 1"); - } - - int anglePart1 = static_cast(raw[1] >> 1); - int anglePart2 = static_cast(raw[2]) << 7; - float angle = (anglePart1 + anglePart2) / 64.0; - - int distancePart1 = static_cast(raw[3]); - int distancePart2 = static_cast(raw[4]) << 8; - float distance = (distancePart1 + distancePart2) / 4.0; - - measurementData.newScan = newScan; - measurementData.quality = quality; - measurementData.angle = angle; - measurementData.distance = distance; - - return measurementData; - } - - Measure _process_express_scan(std::unique_ptr& data, float newAngle, int trame) - { - Measure measurementData; - - bool newScan = (newAngle < data->start_angle) && (trame == 1); - - float angle = std::fmod((data->start_angle + ((newAngle - data->start_angle) / 32 * trame - data->angle[trame - 1])), 360); - float distance = data->distance[trame - 1]; - - measurementData.newScan = newScan; - measurementData.quality = 0; // Replace this with your actual quality value - measurementData.angle = angle; - measurementData.distance = distance; - - return measurementData; - } - - /** - * @brief Iterate over measures. Note that consumer must be fast enough, - otherwise data will be accumulated inside buffer and consumer will get - data with increasing lag. - * - * @param scanType - * @param maxBufMeas int or False if you want unlimited buffer - Maximum number of bytes to be stored inside the buffer. Once - numbe exceeds this limit buffer will be emptied out. - * @return std::function - */ - std::function()> RPLidar::iter_measures(ScanType scanType, int maxBufMeas) - { - if (!this->motor_running) { - this->start_motor(); - } - - if (!this->scanning.currently_scanning) - { - this->start(scanType); - } - - // Define a lambda function to generate measures - auto generator = [this, scanType, maxBufMeas]() -> tl::expected - { - while (true) - { - int dsize = scanning.dsize; - - if (maxBufMeas != 0) - { - int dataInBuf = this->_serial->available(); - if (dataInBuf > maxBufMeas) - { - spdlog::warn( - "Too many bytes in the input buffer: {}/{}. \n" - "Cleaning buffer...", - dataInBuf, maxBufMeas); - this->stop(); - this->start(scanning.type); - } - } - - if (scanType == NORMAL) - { - std::vector raw = this->_read_response(dsize); - auto process_scan_result = _process_scan(raw); - if (!process_scan_result.has_value()) - return tl::make_unexpected(process_scan_result.error()); - Measure measure = process_scan_result.value(); - return measure; - } - else if (scanType == EXPRESS) - { - if (this->express_trame == 32) - { - this->express_trame = 0; - - if (this->express_data == nullptr) - { - spdlog::debug("reading first time bytes"); - this->express_data = std::make_unique(ExpressPacket(this->_read_response(dsize))); - } - - this->express_old_data = std::move(this->express_data); - spdlog::debug("set old_data with start_angle {}", this->express_old_data->start_angle); - this->express_data = std::make_unique(ExpressPacket(this->_read_response(dsize))); - spdlog::debug("set new_data with start_angle {}", this->express_data->start_angle); - } - this->express_trame++; - spdlog::debug("process scan of frame %d with angle : \n" - "%f and angle new : %f", this->express_trame, - this->express_old_data->start_angle, - this->express_data->start_angle); - Measure measure = _process_express_scan(this->express_old_data, this->express_data->start_angle, this->express_trame); - return measure; - } - } - }; - - return generator; - } - - /** - * @brief Iterate over scans. Note that consumer must be fast enough, - otherwise data will be accumulated inside buffer and consumer will get - data with increasing lag. - * - * @param scanType - * @param maxBufMeas Maximum number of measures to be stored inside the buffer. Once - numbe exceeds this limit buffer will be emptied out. - * @param minLen Minimum number of measures in the scan for it to be yelded. - * @return std::function()> - */ - std::function()> RPLidar::iter_scans(ScanType scanType, int maxBufMeas, int minLen) - { - std::vector scanList; - std::function()> measureIterator = this->iter_measures(scanType, maxBufMeas); - - // Define a lambda function to generate scans - auto scanGenerator = [this, scanType, maxBufMeas, minLen, measureIterator]() -> std::vector - { - std::vector scanList; - for (;;) - { - Measure measure = measureIterator().value(); - bool newScan = measure.newScan; - if (newScan) - { - if (scanList.size() > minLen) - { - return scanList; - } - scanList.clear(); - } - if (measure.distance > 0) - { - scanList.push_back(measure); - } - } - }; - return scanGenerator; - } -} // namespace rplidar \ No newline at end of file diff --git a/app/raspberry_pi/repository/packages/t/tb6612/tb6612/include/TB6612.h b/app/raspberry_pi/repository/packages/t/tb6612/tb6612/include/TB6612.h new file mode 100644 index 00000000..8a085374 --- /dev/null +++ b/app/raspberry_pi/repository/packages/t/tb6612/tb6612/include/TB6612.h @@ -0,0 +1,32 @@ +#ifndef TB6612_HPP +#define TB6612_HPP + +#pragma once + +// Made with the help of ChatGPT + +#include "pigpio.h" +#include "pigpiod_if2.h" + +class TB6612 +{ +public: + TB6612(int motor_pin, int pwm_pin); + + void setPWM(int value); + + void forward(); + + void backward(); + + void stop(); + + void setOffset(int offset); + +private: + int motor_pin; + int pwm_pin; + int offset; +}; + +#endif \ No newline at end of file diff --git a/app/raspberry_pi/repository/packages/t/tb6612/tb6612/include/TB6612.hpp b/app/raspberry_pi/repository/packages/t/tb6612/tb6612/include/TB6612.hpp deleted file mode 100644 index f9fc5506..00000000 --- a/app/raspberry_pi/repository/packages/t/tb6612/tb6612/include/TB6612.hpp +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef TB6612_H -#define TB6612_H - -#pragma once - -// Made with the help of ChatGPT - -#include "pigpio.h" -#include "pigpiod_if2.h" - -class TB6612 -{ -public: - TB6612(int motor_pin, int pwm_pin) : motor_pin(motor_pin), pwm_pin(pwm_pin), offset(1) - { - gpioSetMode(this->motor_pin, PI_OUTPUT); - gpioSetMode(this->pwm_pin, PI_OUTPUT); - gpioWrite(this->motor_pin, 0); - gpioPWM(this->pwm_pin, 0); - } - - void setPWM(int value) - { - gpioPWM(this->pwm_pin, value); - } - - void forward() - { - gpioWrite(this->motor_pin, this->offset); - } - - void backward() - { - gpioWrite(this->motor_pin, 1 - this->offset); - } - - void stop() - { - gpioWrite(this->motor_pin, 0); - gpioPWM(this->pwm_pin, 0); - } - - void setOffset(int offset) - { - this->offset = offset; - } - -private: - int motor_pin; - int pwm_pin; - int offset; -}; - -#endif \ No newline at end of file diff --git a/app/raspberry_pi/repository/packages/t/tb6612/tb6612/src/TB6612.cpp b/app/raspberry_pi/repository/packages/t/tb6612/tb6612/src/TB6612.cpp new file mode 100644 index 00000000..b350f437 --- /dev/null +++ b/app/raspberry_pi/repository/packages/t/tb6612/tb6612/src/TB6612.cpp @@ -0,0 +1,37 @@ +#include "TB6612.h" + +// Made with the help of ChatGPT + +TB6612::TB6612(int motor_pin, int pwm_pin) : motor_pin(motor_pin), pwm_pin(pwm_pin), offset(1) +{ + gpioSetMode(this->motor_pin, PI_OUTPUT); + gpioSetMode(this->pwm_pin, PI_OUTPUT); + gpioWrite(this->motor_pin, 0); + gpioPWM(this->pwm_pin, 0); +} + +void TB6612::setPWM(int value) +{ + gpioPWM(this->pwm_pin, value); +} + +void TB6612::forward() +{ + gpioWrite(this->motor_pin, this->offset); +} + +void TB6612::backward() +{ + gpioWrite(this->motor_pin, 1 - this->offset); +} + +void TB6612::stop() +{ + gpioWrite(this->motor_pin, 0); + gpioPWM(this->pwm_pin, 0); +} + +void TB6612::setOffset(int offset) +{ + this->offset = offset; +} \ No newline at end of file diff --git a/app/raspberry_pi/repository/packages/t/tb6612/tb6612/xmake.lua b/app/raspberry_pi/repository/packages/t/tb6612/tb6612/xmake.lua index 19881444..af72ffe7 100644 --- a/app/raspberry_pi/repository/packages/t/tb6612/tb6612/xmake.lua +++ b/app/raspberry_pi/repository/packages/t/tb6612/tb6612/xmake.lua @@ -1,7 +1,8 @@ add_requires("pigpio") target("tb6612") - set_kind("headeronly") - add_headerfiles("include/(TB6612.hpp)") + set_kind("static") + add_files("src/*.cpp") + add_headerfiles("include/(TB6612.h)") add_includedirs("include") add_packages("pigpio") diff --git a/app/raspberry_pi/repository/packages/t/tb6612/xmake.lua b/app/raspberry_pi/repository/packages/t/tb6612/xmake.lua index 7f921c20..d6d92a9c 100644 --- a/app/raspberry_pi/repository/packages/t/tb6612/xmake.lua +++ b/app/raspberry_pi/repository/packages/t/tb6612/xmake.lua @@ -1,7 +1,6 @@ package("tb6612") add_deps("pigpio") set_sourcedir(path.join(os.scriptdir(), "tb6612")) - set_policy("package.install_always", true) on_install(function (package) local configs = {} import("package.tools.xmake").install(package, configs) diff --git a/app/raspberry_pi/src/car/display/CarConsole.hpp b/app/raspberry_pi/src/car/display/CarConsole.cxx similarity index 100% rename from app/raspberry_pi/src/car/display/CarConsole.hpp rename to app/raspberry_pi/src/car/display/CarConsole.cxx diff --git a/app/raspberry_pi/src/car/system/CarSystem.h b/app/raspberry_pi/src/car/system/CarSystem.h index aa40f8f3..c6d9ad5f 100644 --- a/app/raspberry_pi/src/car/system/CarSystem.h +++ b/app/raspberry_pi/src/car/system/CarSystem.h @@ -7,9 +7,9 @@ #include -#include "lidar/LidarDevice.hpp" -#include "messaging/MessagingSystem.hpp" -#include "movement/MovementSystem.hpp" +#include "lidar/LidarDevice.cxx" +#include "messaging/MessagingSystem.cxx" +#include "movement/MovementSystem.cxx" using json = nlohmann::json; diff --git a/app/raspberry_pi/src/car/system/lidar/LidarDevice.hpp b/app/raspberry_pi/src/car/system/lidar/LidarDevice.cxx similarity index 87% rename from app/raspberry_pi/src/car/system/lidar/LidarDevice.hpp rename to app/raspberry_pi/src/car/system/lidar/LidarDevice.cxx index 99a2913f..b0390a89 100644 --- a/app/raspberry_pi/src/car/system/lidar/LidarDevice.hpp +++ b/app/raspberry_pi/src/car/system/lidar/LidarDevice.cxx @@ -1,5 +1,5 @@ -#ifndef LidarDevice_HPP -#define LidarDevice_HPP +#ifndef LidarDevice_CXX +#define LidarDevice_CXX #pragma once diff --git a/app/raspberry_pi/src/car/system/lidar/LidarDummy.hpp b/app/raspberry_pi/src/car/system/lidar/LidarDummy.cxx similarity index 86% rename from app/raspberry_pi/src/car/system/lidar/LidarDummy.hpp rename to app/raspberry_pi/src/car/system/lidar/LidarDummy.cxx index b9132187..407e1a0f 100644 --- a/app/raspberry_pi/src/car/system/lidar/LidarDummy.hpp +++ b/app/raspberry_pi/src/car/system/lidar/LidarDummy.cxx @@ -1,5 +1,5 @@ -#ifndef LIDARDUMMY_HPP -#define LIDARDUMMY_HPP +#ifndef LIDARDUMMY_CXX +#define LIDARDUMMY_CXX #pragma once @@ -7,7 +7,7 @@ #include -#include "LidarDevice.hpp" +#include "LidarDevice.cxx" namespace car::system::lidar { class LidarDummy : public LidarDevice diff --git a/app/raspberry_pi/src/car/system/lidar/LidarScanner.hpp b/app/raspberry_pi/src/car/system/lidar/LidarScanner.cxx similarity index 95% rename from app/raspberry_pi/src/car/system/lidar/LidarScanner.hpp rename to app/raspberry_pi/src/car/system/lidar/LidarScanner.cxx index c093b5ee..75016d25 100644 --- a/app/raspberry_pi/src/car/system/lidar/LidarScanner.hpp +++ b/app/raspberry_pi/src/car/system/lidar/LidarScanner.cxx @@ -1,9 +1,9 @@ -#ifndef LIDARSCANNER_HPP -#define LIDARSCANNER_HPP +#ifndef LIDARSCANNER_CXX +#define LIDARSCANNER_CXX #pragma once -#include "LidarDevice.hpp" +#include "LidarDevice.cxx" #include diff --git a/app/raspberry_pi/src/car/system/messaging/MessagingSystem.hpp b/app/raspberry_pi/src/car/system/messaging/MessagingSystem.cxx similarity index 95% rename from app/raspberry_pi/src/car/system/messaging/MessagingSystem.hpp rename to app/raspberry_pi/src/car/system/messaging/MessagingSystem.cxx index 0da70c23..86937601 100644 --- a/app/raspberry_pi/src/car/system/messaging/MessagingSystem.hpp +++ b/app/raspberry_pi/src/car/system/messaging/MessagingSystem.cxx @@ -1,5 +1,5 @@ -#ifndef MESSAGINGSYSTEM_HPP -#define MESSAGINGSYSTEM_HPP +#ifndef MESSAGINGSYSTEM_CXX +#define MESSAGINGSYSTEM_CXX #pragma once @@ -15,8 +15,8 @@ #include -#include "commands/MoveCommand.hpp" -#include "commands/TurnCommand.hpp" +#include "commands/MoveCommand.cxx" +#include "commands/TurnCommand.cxx" using json = nlohmann::json; diff --git a/app/raspberry_pi/src/car/system/messaging/commands/MoveCommand.hpp b/app/raspberry_pi/src/car/system/messaging/commands/MoveCommand.cxx similarity index 69% rename from app/raspberry_pi/src/car/system/messaging/commands/MoveCommand.hpp rename to app/raspberry_pi/src/car/system/messaging/commands/MoveCommand.cxx index 9c433db7..e83b73bd 100644 --- a/app/raspberry_pi/src/car/system/messaging/commands/MoveCommand.hpp +++ b/app/raspberry_pi/src/car/system/messaging/commands/MoveCommand.cxx @@ -1,5 +1,5 @@ -#ifndef MOVECOMMAND_HPP -#define MOVECOMMAND_HPP +#ifndef MOVECOMMAND_CXX +#define MOVECOMMAND_CXX #pragma once diff --git a/app/raspberry_pi/src/car/system/messaging/commands/TurnCommand.hpp b/app/raspberry_pi/src/car/system/messaging/commands/TurnCommand.cxx similarity index 70% rename from app/raspberry_pi/src/car/system/messaging/commands/TurnCommand.hpp rename to app/raspberry_pi/src/car/system/messaging/commands/TurnCommand.cxx index 6f5a73e8..029980c5 100644 --- a/app/raspberry_pi/src/car/system/messaging/commands/TurnCommand.hpp +++ b/app/raspberry_pi/src/car/system/messaging/commands/TurnCommand.cxx @@ -1,5 +1,5 @@ -#ifndef TURNCOMMAND_HPP -#define TURNCOMMAND_HPP +#ifndef TURNCOMMAND_CXX +#define TURNCOMMAND_CXX #pragma once diff --git a/app/raspberry_pi/src/car/system/movement/MovementSystem.hpp b/app/raspberry_pi/src/car/system/movement/MovementSystem.cxx similarity index 77% rename from app/raspberry_pi/src/car/system/movement/MovementSystem.hpp rename to app/raspberry_pi/src/car/system/movement/MovementSystem.cxx index da834a97..85460cf1 100644 --- a/app/raspberry_pi/src/car/system/movement/MovementSystem.hpp +++ b/app/raspberry_pi/src/car/system/movement/MovementSystem.cxx @@ -1,5 +1,5 @@ -#ifndef MOVEMENTSYSTEM_HPP -#define MOVEMENTSYSTEM_HPP +#ifndef MOVEMENTSYSTEM_CXX +#define MOVEMENTSYSTEM_CXX #pragma once @@ -7,8 +7,11 @@ #include "PCA9685.h" -#include "../messaging/commands/MoveCommand.hpp" -#include "../messaging/commands/TurnCommand.hpp" +#include "../messaging/commands/MoveCommand.cxx" +#include "../messaging/commands/TurnCommand.cxx" + +#include "wheels/FrontWheel.cxx" +#include "wheels/RearWheel.cxx" using namespace car::system::messaging::commands; diff --git a/app/raspberry_pi/src/car/system/movement/wheels/FrontWheel.hpp b/app/raspberry_pi/src/car/system/movement/wheels/FrontWheel.cxx similarity index 96% rename from app/raspberry_pi/src/car/system/movement/wheels/FrontWheel.hpp rename to app/raspberry_pi/src/car/system/movement/wheels/FrontWheel.cxx index 862368dd..caaa868c 100644 --- a/app/raspberry_pi/src/car/system/movement/wheels/FrontWheel.hpp +++ b/app/raspberry_pi/src/car/system/movement/wheels/FrontWheel.cxx @@ -1,3 +1,6 @@ +#ifndef FRONTWHEEL_CXX +#define FRONTWHEEL_CXX + #include #include @@ -54,3 +57,5 @@ namespace car::system::movement::wheels int angle; }; } // namespace car::system::movement::wheels + +#endif \ No newline at end of file diff --git a/app/raspberry_pi/src/car/system/movement/wheels/RearWheel.hpp b/app/raspberry_pi/src/car/system/movement/wheels/RearWheel.cxx similarity index 94% rename from app/raspberry_pi/src/car/system/movement/wheels/RearWheel.hpp rename to app/raspberry_pi/src/car/system/movement/wheels/RearWheel.cxx index 997adb93..d9713e73 100644 --- a/app/raspberry_pi/src/car/system/movement/wheels/RearWheel.hpp +++ b/app/raspberry_pi/src/car/system/movement/wheels/RearWheel.cxx @@ -1,9 +1,12 @@ +#ifndef REARWHEEL_CXX +#define REARWHEEL_CXX + #include #include -#include -#include +#include +#include // Made with the help of ChatGPT @@ -87,3 +90,5 @@ namespace car::system::movement::wheels int speed; }; } // namespace car::system::movement::wheels + +#endif \ No newline at end of file diff --git a/app/raspberry_pi/src/main.cpp b/app/raspberry_pi/src/main.cpp index aba04f6a..37413d83 100644 --- a/app/raspberry_pi/src/main.cpp +++ b/app/raspberry_pi/src/main.cpp @@ -3,14 +3,14 @@ #include -#include "global/Config.hpp" +#include "global/Config.cxx" -#include "car/display/CarConsole.hpp" +#include "car/display/CarConsole.cxx" #include "car/system/CarSystem.h" -#include "car/system/lidar/LidarScanner.hpp" -#include "car/system/lidar/LidarDummy.hpp" +#include "car/system/lidar/LidarScanner.cxx" +#include "car/system/lidar/LidarDummy.cxx" std::string getWebSocketUrl() { diff --git a/app/raspberry_pi/xmake.lua b/app/raspberry_pi/xmake.lua index 30b2580f..cbd68ab6 100644 --- a/app/raspberry_pi/xmake.lua +++ b/app/raspberry_pi/xmake.lua @@ -48,12 +48,12 @@ target("raspberry_pi") -- For the SunFounder Car add_packages("rplidar") add_packages("pca9685") - add_packages("pigpio") + add_packages("tb6612") add_headerfiles("include/**.h") - add_headerfiles("src/**.h", "src/**.hpp") - add_files("src/**.cpp") + add_headerfiles("src/**.h") + add_files("src/**.cpp", "src/**.cxx") add_includedirs("include") @@ -63,6 +63,7 @@ target("raspberry_pi") set_configdir("$(buildir)/$(plat)/$(arch)/$(mode)") add_configfiles("settings/config.jsonc", {onlycopy = true, prefixdir = "settings"}) +target_end() -- From xmake sample code: if is_plat("linux") then