Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove sfml and add sdl3 as submodule #29

Merged
merged 4 commits into from
Aug 23, 2024
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/cmake-single-platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,4 @@ jobs:
- name: Run Docker
working-directory: ${{github.workspace}}/docker
run: |
bash run.sh
bash test.sh
12 changes: 9 additions & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@ on:
branches: [ "main" ]
types: [opened, labeled, unlabeled, synchronize]
jobs:
format:
format-code:
runs-on: ubuntu-latest

permissions:
# Give the default GITHUB_TOKEN write permission to commit and push the
# added or changed files to the repository.
contents: write

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
token: ${{ secrets.BOT_TOKEN || github.token }}
# check out HEAD on the branch
Expand All @@ -27,7 +33,7 @@ jobs:
find . -not -path "./.git/*" -not -path "./.vscode/*" -name "*.cpp" -o -name "*.h" | xargs clang-format -i -style=file
# commit the changes (if there are any)
- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4.16.0
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: 🎨 apply clang-format changes
branch: ${{ github.head_ref }}
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "third-party/yaml-cpp"]
path = third-party/yaml-cpp
url = https://github.com/jbeder/yaml-cpp.git
[submodule "third-party/SDL"]
path = third-party/SDL
url = https://github.com/libsdl-org/SDL.git
13 changes: 7 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ project(PathFind)
set(CMAKE_CXX_STANDARD 17)
add_definitions("-Wall" "-g")

find_package(SFML COMPONENTS window graphics system)
find_package(Git QUIET)

set(DATA_DIR ${PROJECT_SOURCE_DIR}/maps)
Expand Down Expand Up @@ -32,23 +31,25 @@ if(NOT EXISTS "${PROJECT_SOURCE_DIR}/third-party/yaml-cpp/CMakeLists.txt")
endif()


add_subdirectory(${PROJECT_SOURCE_DIR}/third-party/yaml-cpp)
add_subdirectory(${PROJECT_SOURCE_DIR}/third-party/SDL)
add_subdirectory(${PROJECT_SOURCE_DIR}/planning)
add_subdirectory(${PROJECT_SOURCE_DIR}/tools)

include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${PROJECT_SOURCE_DIR}
${PROJECT_SOURCE_DIR}/third-party/yaml-cpp/include
${PROJECT_SOURCE_DIR}/third-party/SDL/include
)

link_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${PROJECT_SOURCE_DIR}
${PROJECT_SOURCE_DIR}/third-party/yaml-cpp/include
${PROJECT_SOURCE_DIR}/third-party/SDL/include
)


add_subdirectory(${PROJECT_SOURCE_DIR}/third-party/yaml-cpp)
add_subdirectory(${PROJECT_SOURCE_DIR}/planning)
add_subdirectory(${PROJECT_SOURCE_DIR}/tools)

# enable test
enable_testing()
add_subdirectory(${PROJECT_SOURCE_DIR}/test)
Expand Down
4 changes: 0 additions & 4 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
FROM ubuntu:22.04

ENV DEBIAN_FRONTEND=noninteractive

ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8

RUN apt-get update && \
apt-get upgrade -y && \
Expand All @@ -13,7 +10,6 @@ RUN apt-get update && \
vim \
nano \
cmake \
libsfml-dev \
build-essential \
software-properties-common && \
rm -rf /var/lib/apt/lists/*
Expand Down
9 changes: 7 additions & 2 deletions docker/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,15 @@ then
fi
else
printf "${RED}---CREATING DOCKER CONTAINER---\n${NC}"
docker run \
xhost +local:root &> /dev/null
docker run -it \
--rm \
--net=host \
--privileged \
--net=host \
--gpus all \
--env=NVIDIA_VISIBLE_DEVICES=all \
--env=NVIDIA_DRIVER_CAPABILITIES=all \
--env=DISPLAY \
$VOLUMES \
--name="${CONTAINER_NAME}" \
$IMAGE_NAME
Expand Down
40 changes: 40 additions & 0 deletions docker/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

RED='\033[0;31m' # red
GREEN='\033[0;32m' # green
YELLOW='\033[1;33m' # yellow
BLUE='\033[1;34m' # blue
CYAN='\033[1;36m' # cyan
NC='\033[0m' # no color

IMAGE_NAME="path_planning:latest"
CONTAINER_NAME=planning

XSOCK=/tmp/.X11-unix
XAUTH=$HOME/.Xauthority

VOLUMES="--volume=$XSOCK:$XSOCK:rw
--volume=$XAUTH:$XAUTH:rw"

if (docker ps --all | grep -q ${CONTAINER_NAME})
then
printf "${GREEN}---DOCKER CONTAINER IS VALID---\n${NC}"
if (docker ps | grep -q ${CONTAINER_NAME})
then
printf "${YELLOW}---OPENNING DOCKER CONTAINER---\n${NC}"
docker exec ${CONTAINER_NAME} /bin/bash
else
printf "${YELLOW}---STARTING DOCKER CONTAINER---\n${NC}"
docker start ${CONTAINER_NAME} 1>/dev/null 2>&1
docker exec ${CONTAINER_NAME} /bin/bash
fi
else
printf "${RED}---CREATING DOCKER CONTAINER---\n${NC}"
docker run \
--rm \
--net=host \
--privileged \
$VOLUMES \
--name="${CONTAINER_NAME}" \
$IMAGE_NAME
fi
2 changes: 1 addition & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ int main(int argc, char **argv)
// Visualize start and goal nodes
visualizer->SetStartAndGoal(start_node, goal_node);

while (true)
while (visualizer->IsRunning())
{
visualizer->SetGetLogFunction(
std::bind(&planning::IPlanningWithLogging::GetLog, planner));
Expand Down
1 change: 0 additions & 1 deletion planning/grid_base/a_star/a_star.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ Path AStar::FindPath(const Node &start_node, const Node &goal_node,

search_list.push(neighbor_node);
}
std::this_thread::sleep_for(std::chrono::microseconds(100));
}

if (search_list.empty())
Expand Down
1 change: 0 additions & 1 deletion planning/grid_base/bfs/bfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ Path BFS::FindPath(const Node &start_node, const Node &goal_node,

search_list.push(neighbor_node);
}
std::this_thread::sleep_for(std::chrono::microseconds(100));
}
if (search_list.empty())
{
Expand Down
1 change: 0 additions & 1 deletion planning/grid_base/dfs/dfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ Path DFS::FindPath(const Node &start_node, const Node &goal_node,

search_list.push(new_node_parent);
}
std::this_thread::sleep_for(std::chrono::microseconds(100));
}

if (search_list.empty())
Expand Down
1 change: 0 additions & 1 deletion planning/tree_base/rrt/rrt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ Path RRT::FindPath(const Node &start_node, const Node &goal_node,
// Get path.
return ReconstructPath(goal);
}
std::this_thread::sleep_for(std::chrono::milliseconds(1));
}

return Path();
Expand Down
1 change: 1 addition & 0 deletions third-party/SDL
Submodule SDL added at 8bcfdb
21 changes: 11 additions & 10 deletions tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,33 @@ include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/include
${PROJECT_SOURCE_DIR}
${PROJECT_SOURCE_DIR}/third-party/SDL/include

)

link_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/include
${PROJECT_SOURCE_DIR}
${PROJECT_SOURCE_DIR}/third-party/SDL/include
)

set(
VISUALIZER_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/visualizer.cpp
${COMMON_PLANNING_FILES}
)

add_library(
visualizer
SHARED
${VISUALIZER_SOURCES}
STATIC
src/visualizer.cpp
)

target_include_directories(visualizer PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/include
)

target_link_libraries(
visualizer
PUBLIC
sfml-system
sfml-graphics
sfml-window
common_tree_base
SDL3::SDL3
)

41 changes: 23 additions & 18 deletions tools/include/visualizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@
#ifndef TOOLS_INCLUDE_VISUALIZER_H_
#define TOOLS_INCLUDE_VISUALIZER_H_

#include "SDL3/SDL.h"
#include "planning/include/data_types.h"
#include "planning/include/i_planning.h"
#include "planning/tree_base/include/common_tree_base.h"
#include <SFML/Graphics.hpp>
#include <SFML/Graphics/RenderTexture.hpp>
#include <cstddef>
#include <functional>
#include <memory>
Expand All @@ -29,15 +28,15 @@ namespace tools
using pair_size_t = std::pair<std::size_t, std::size_t>;
using pair_double = std::pair<double, double>;

inline std::unordered_map<planning::NodeState, sf::Color> GetColorMap()
inline std::unordered_map<planning::NodeState, SDL_Color> GetColorMap()
{
std::unordered_map<planning::NodeState, sf::Color> colors_;
colors_.insert({planning::NodeState::kFree, sf::Color::White});
colors_.insert({planning::NodeState::kVisited, sf::Color::Blue});
colors_.insert({planning::NodeState::kOccupied, sf::Color::Black});
colors_.insert({planning::NodeState::kStart, sf::Color::Green});
colors_.insert({planning::NodeState::kGoal, sf::Color::Yellow});
colors_.insert({planning::NodeState::kPath, sf::Color::Red});
std::unordered_map<planning::NodeState, SDL_Color> colors_;
colors_.insert({planning::NodeState::kFree, SDL_Color{255, 255, 255, 255}});
colors_.insert({planning::NodeState::kVisited, SDL_Color{0, 0, 255, 255}});
colors_.insert({planning::NodeState::kOccupied, SDL_Color{0, 0, 0, 255}});
colors_.insert({planning::NodeState::kStart, SDL_Color{0, 255, 0, 255}});
colors_.insert({planning::NodeState::kGoal, SDL_Color{255, 0, 0, 255}});
colors_.insert({planning::NodeState::kPath, SDL_Color{255, 0, 0, 255}});

return colors_;
}
Expand All @@ -47,12 +46,11 @@ class Visualizer
public:
Visualizer(std::shared_ptr<planning::Map> map, pair_double size_coeff,
double kDelay, std::string window_name, std::string planner_name);
~Visualizer() { window_.close(); }

~Visualizer() = default;
void SetStartAndGoal(const planning::Node &start_node,
const planning::Node &goal_node);

void MapToTexture();
void RenderMap();

void VizGridLog();
void VizTreeLog();
Expand All @@ -63,22 +61,29 @@ class Visualizer
}

void Run();
bool IsRunning() { return is_running_; }
void CheckEvent();
void ClearScreen();
void DrawLine(planning::Node start, planning::Node end);
void DrawFilledRectangle(planning::Node start, planning::Node end);

private:
std::shared_ptr<planning::Map> map;
pair_double size_coeff_;
double kDelay_;
std::string window_name_;
std::string planner_name_;
SDL_bool loopShouldStop = SDL_FALSE;
bool is_running_ = true;

std::unordered_map<planning::NodeState, sf::Color> colors_;
sf::RenderWindow window_;
sf::RenderTexture render_texture_;
std::unordered_map<planning::NodeState, SDL_Color> colors_;
SDL_Window *win = NULL;
SDL_Renderer *renderer = NULL;
std::function<void()> viz_function_;
std::function<planning::Log()> get_log_function_;

sf::CircleShape start_node_;
sf::CircleShape goal_node_;
planning::Node start_node_;
planning::Node goal_node_;
std::thread window_thread_;
};

Expand Down
Loading
Loading