From c2df3da50b8f42659441c2d4ff70ed3a07370a0a Mon Sep 17 00:00:00 2001 From: Sam Date: Sat, 2 Dec 2023 13:53:01 -0800 Subject: [PATCH 1/3] Create new ros package and execute Hello World --- .gitignore | 2 -- CMakeLists.txt | 29 +++++++++++++++++++---------- build.sh | 14 -------------- config/CMakeLists.txt | 4 ---- config/yaml/sampleTest.yaml | 11 ----------- package.xml | 18 ++++++++++++++++++ src/CMakeLists.txt | 3 --- src/main/CMakeLists.txt | 17 ----------------- src/main/diagnostics.cpp | 10 ++++++++++ src/main/main.cpp | 34 ---------------------------------- src/yaml/CMakeLists.txt | 19 ------------------- src/yaml/parse_yaml.cpp | 29 ----------------------------- src/yaml/parse_yaml.h | 10 ---------- 13 files changed, 47 insertions(+), 153 deletions(-) delete mode 100644 .gitignore delete mode 100755 build.sh delete mode 100644 config/CMakeLists.txt delete mode 100644 config/yaml/sampleTest.yaml create mode 100644 package.xml delete mode 100644 src/CMakeLists.txt create mode 100644 src/main/diagnostics.cpp delete mode 100644 src/main/main.cpp delete mode 100644 src/yaml/CMakeLists.txt delete mode 100644 src/yaml/parse_yaml.cpp delete mode 100644 src/yaml/parse_yaml.h diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 57f8067..0000000 --- a/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -out/ -diagnostics diff --git a/CMakeLists.txt b/CMakeLists.txt index c1b3f19..36bb47d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,15 +1,24 @@ -# Top level CMake file for entire Diagnostics app - -# Set CMake version and create project -cmake_minimum_required(VERSION 3.22) +cmake_minimum_required(VERSION 3.8) project(diagnostics) -# Set C++ Standard -set(CMAKE_CXX_STANDARD 20) +if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") + add_compile_options(-Wall -Wextra -Wpedantic) +endif() -# Import rapidYaml +# find dependencies +find_package(ament_cmake REQUIRED) find_package(ryml REQUIRED) +# uncomment the following section in order to fill in +# further dependencies manually. +# find_package( REQUIRED) + +add_executable(diagnostics src/main/diagnostics.cpp) +target_include_directories(diagnostics PUBLIC + $ + $) +target_compile_features(diagnostics PUBLIC c_std_99 cxx_std_17) # Require C99 and C++17 + +install(TARGETS diagnostics + DESTINATION lib/${PROJECT_NAME}) -# Add source files -add_subdirectory(config) -add_subdirectory(src) +ament_package() diff --git a/build.sh b/build.sh deleted file mode 100755 index 6546cf4..0000000 --- a/build.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -# Remove previously built files -rm -rf out/ -rm -rf diagnostics - -# Run CMake with source directory '.' and build directory out/build -cmake -S . -B out/build - -# Compile and link the project with generated MakeFile from CMake -make -C out/build - -# Copy the results to output file -cp -r out/build/src/main/diagnostics . diff --git a/config/CMakeLists.txt b/config/CMakeLists.txt deleted file mode 100644 index fff47e3..0000000 --- a/config/CMakeLists.txt +++ /dev/null @@ -1,4 +0,0 @@ -# Create constants and export it to the rest of the CMAKE project -set( - YAML_TEST_PATH ${CMAKE_CURRENT_LIST_DIR}/yaml/sampleTest.yaml CACHE INTERNAL "Path to test yaml config file" -) diff --git a/config/yaml/sampleTest.yaml b/config/yaml/sampleTest.yaml deleted file mode 100644 index 10f8b17..0000000 --- a/config/yaml/sampleTest.yaml +++ /dev/null @@ -1,11 +0,0 @@ -foo: - bar: "a" - barbar: "b" - barbarbar: "c" - -matrix: - array: - - 0.5 - - 0.67 - - 0.78 - - 0.89 diff --git a/package.xml b/package.xml new file mode 100644 index 0000000..a561f12 --- /dev/null +++ b/package.xml @@ -0,0 +1,18 @@ + + + + diagnostics + 0.0.0 + TODO: Package description + ros + TODO: License declaration + + ament_cmake + + ament_lint_auto + ament_lint_common + + + ament_cmake + + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt deleted file mode 100644 index 745d04d..0000000 --- a/src/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -# Add modules for project as required -add_subdirectory(main) -add_subdirectory(yaml) diff --git a/src/main/CMakeLists.txt b/src/main/CMakeLists.txt index 791c692..e69de29 100644 --- a/src/main/CMakeLists.txt +++ b/src/main/CMakeLists.txt @@ -1,17 +0,0 @@ -# Add main.exe -add_executable(diagnostics main.cpp) - -# List of required header files -target_include_directories(diagnostics PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) - -# Modules that main depends on -# ex: target_link_libraries(SailbotDiagnostics_main PRIVATE module1 module2) -target_link_libraries(diagnostics PRIVATE - yaml - ryml::ryml -) - -# Import configuration file -target_compile_definitions( - diagnostics PUBLIC YAML_TEST_PATH="${YAML_TEST_PATH}" -) diff --git a/src/main/diagnostics.cpp b/src/main/diagnostics.cpp new file mode 100644 index 0000000..dafed14 --- /dev/null +++ b/src/main/diagnostics.cpp @@ -0,0 +1,10 @@ +#include + +int main(int argc, char ** argv) +{ + (void)argc; + (void)argv; + + printf("Welcome to UBC Sailbot diagnostics!\n"); + return 0; +} diff --git a/src/main/main.cpp b/src/main/main.cpp deleted file mode 100644 index 2664003..0000000 --- a/src/main/main.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* Include files */ -#include -#include -#include -#include -#include - -#include -#include -#include "parse_yaml.h" - -/* Functions */ - -int main() -{ - std::cout << "UBC Sailbot Diagnostics App" << std::endl; - std::cout << "Instructions for use can be found on https://ubcsailbot.atlassian.net/l/cp/mRm7BF1k" << std::endl; - std::string contents = readFile(YAML_TEST_PATH); - std::cout << contents << std::endl; - std::cout << "------------------------------------" << std::endl; - ryml::Tree tree = ryml::parse_in_place(ryml::to_substr(contents)); - ryml::NodeRef foo = tree["foo"]; - for (ryml::NodeRef const& child : foo.children()) { - std::cout << "key: " << child.key() << " val: " << child.val() << std::endl; - } - - ryml::NodeRef array = tree["matrix"]["array"]; - for (ryml::NodeRef const& child : array.children()) { - double val; - child >> val; - std::cout << "float val: " << std::setprecision (18) << val << std::endl; - } - return 0; -} diff --git a/src/yaml/CMakeLists.txt b/src/yaml/CMakeLists.txt deleted file mode 100644 index 338780e..0000000 --- a/src/yaml/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -# src/yaml/CMakeLists.txt - -# Collect header files -set(HEADER_FILES - parse_yaml.h -) - -# Collect source files -set(SOURCE_FILES - parse_yaml.cpp -) - -# Create a library from the source files -add_library(yaml ${SOURCE_FILES} ${HEADER_FILES}) - -# Include directories -target_include_directories(${PROJECT_NAME} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR} -) diff --git a/src/yaml/parse_yaml.cpp b/src/yaml/parse_yaml.cpp deleted file mode 100644 index ea91ba3..0000000 --- a/src/yaml/parse_yaml.cpp +++ /dev/null @@ -1,29 +0,0 @@ -/* Include files */ -#include -#include -#include -#include - -/* Functions */ - -/** - * @brief Parses a file and returns all its contents in a string - * - * @param file_path - * @return std::string contains everything inside the defined file - */ -std::string readFile( const char *file_path ) { - // open the file as input and read as binary - std::ifstream in_file( file_path, std::ios::in | std::ios::binary ); - if (!in_file) { - std::cerr << "PARSE_YAML: ifstream could not open file " << file_path << std::endl; - throw std::ifstream::failure("ERROR: ifstream could not open file"); - } - - // put the contents of the file into a stringstream - std::stringstream file_buffer; - file_buffer << in_file.rdbuf(); - - // return all contents of stringstream as a single string - return file_buffer.str(); -} diff --git a/src/yaml/parse_yaml.h b/src/yaml/parse_yaml.h deleted file mode 100644 index 6423988..0000000 --- a/src/yaml/parse_yaml.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef PARSE_YAML_H_ -#define PARSE_YAML_H_ - -/* Include Files */ -#include - -/* Function Declarations */ -std::string readFile( const char *file_path ); - -#endif From c3ecf002cd1d5285f15a45ee8498272b03cba19f Mon Sep 17 00:00:00 2001 From: Sam Dai Date: Sun, 7 Jan 2024 11:22:22 -0800 Subject: [PATCH 2/3] added gitignore to keep colcon build files out of repo --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8b4cebe --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +build +install +log From a2b611e96356d88144de120bdd4cadd1240977b2 Mon Sep 17 00:00:00 2001 From: Sam Dai Date: Sun, 7 Jan 2024 11:28:34 -0800 Subject: [PATCH 3/3] change gitignore to files --- .gitignore | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 8b4cebe..1345657 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ -build -install -log +build/ +install/ +log/