Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 46 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
]
},
{
// Локальний debug стартера ДЗ 4. preLaunchTask збирає debug preset.
// debug ДЗ 4. preLaunchTask збирає debug preset.
"name": "Debug homework_04: ugv_odometry",
"type": "cppdbg",
"request": "launch",
Expand Down Expand Up @@ -75,6 +75,51 @@
"ignoreFailures": true
}
]
},
{
// debug ДЗ 6. preLaunchTask збирає debug preset.
"name": "Debug homework_06: ballistics",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/debug/homework_06/ballistics",
"args": [
"${workspaceFolder}/homework_06/data/input.txt"
],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb",
"preLaunchTask": "CMake: configure and build",
"setupCommands": [
{
"description": "Увімкнути pretty-printing для STL типів у GDB.",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
},
{
// debug тестів ДЗ 6. preLaunchTask збирає debug preset.
"type": "cppdbg",
"request": "launch",
"name": "Debug homework_06: ballistics_tests",
"program": "${workspaceFolder}/build/debug/homework_06/ballistics_tests",
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb",
"preLaunchTask": "CMake: configure and build",
"setupCommands": [
{
"description": "Увімкнути pretty-printing для STL типів у GDB.",
"text": "-enable-pretty-printing",
"ignoreFailures": false
}
]
}
]
}
5 changes: 5 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
"panel": "dedicated",
"clear": true
}
},
{
"label": "CTest: run all test",
"type": "shell",
"command": "ctest --test-dir build/debug --output-on-failure"
}
]
}
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# Домашні роботи. По мірі появи додаємо кожну окремим add_subdirectory.
enable_testing()

add_subdirectory(homework_04)
add_subdirectory(homework_05)
add_subdirectory(homework_06)

# Demo-код для заняття 2.4: локальне і віддалене відлагодження через GDB.
add_subdirectory(demos/lesson_2_4/debug_probe)

39 changes: 39 additions & 0 deletions homework_06/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
cmake_minimum_required(VERSION 3.20)
project(telemetry_check CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

add_library(ballistics src/ballistics.cpp)

target_include_directories(ballistics PUBLIC include)

add_executable(ballistics_cli src/main.cpp)

target_link_libraries(ballistics_cli PRIVATE ballistics)

if(NOT CMAKE_CROSSCOMPILING)

include(FetchContent)

include(GoogleTest)

FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/refs/tags/v1.14.0.zip
DOWNLOAD_EXTRACT_TIMESTAMP TRUE)

FetchContent_MakeAvailable(googletest)

add_executable(ballistics_tests tests/ballistics_tests.cpp)

target_compile_definitions(
ballistics_tests
PRIVATE TEST_DATA_DIR="${CMAKE_SOURCE_DIR}/homework_06/data")

target_link_libraries(ballistics_tests PRIVATE ballistics GTest::gtest_main)

gtest_discover_tests(ballistics_tests DISCOVERY_MODE PRE_TEST)

endif()
1 change: 1 addition & 0 deletions homework_06/data/sample_vog17.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
100 100 100 200 200 10 10 VOG-17
1 change: 1 addition & 0 deletions homework_06/data/unknown_ammo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
100 100 100 200 200 10 10 F1
65 changes: 65 additions & 0 deletions homework_06/include/ballistics.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#include <string>

struct Coord {
double x;
double y;
double z = 0.0f;
};

struct Ammo {
std::string name = "Unknown";
float mass; // маса (кг)
float drag; // коефіцієнт опору
float lift; // коефіцієнт підйому
};

struct DroneConfig {
Coord startPos; // початкова позиція (x, y)
Ammo ammo;
float altitude; // висота
float initialDir; // початковий напрямок (рад)
float attackSpeed; // швидкість атаки (м/с)
float accelPath; // шлях розгону (м)
float arrayTimeStep; // крок часу масиву цілей
float simTimeStep; // крок симуляції
float hitRadius; // радіус влучення
float angularSpeed; // кутова швидкість (рад/с)
float turnThreshold; // поріг повороту (рад)
};

struct BallisticsInput {
float droneX;
float droneY;
float droneZ;
float targetX;
float targetY;
float attackSpeed;
float accelerationPath;
std::string ammoName;
};
struct DropSolution {
float fireX;
float fireY;
bool isManoeuvrePerformed = false;
float manouvreX;
float manouvreY;
std::string errorMessage;
};

float calcAmmoFallTime(const Ammo &ammo, const float &attackSpeed,
const float &droneHeight);
float calcDistance(const Coord &a, const Coord &b);
Coord calcFireCoordinates(const float &horizontalDistance,
const float &distanceToTarget, const float &xd,
const float &yd, const float &targetX,
const float &targetY);
float calcHorizontalDistance(const float &fallTime, DroneConfig &drone,
const Coord &targetPosition);
bool isManoeuvreNeeded(const float &horizontalDistance,
const float &accelerationPath,
const float &distanceToTarget);
void processManouvre(DroneConfig &drone, const Coord &targetPosition);
BallisticsInput parseInputFile(const std::string &filePath);
DropSolution computeDropSolution(const BallisticsInput &input);
void writeOutputFile(const std::string &filePath,
const DropSolution &dropSolution);
Loading
Loading