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

Controller arch development #26

Merged
merged 35 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
7c09578
updated changes from branch 8
andrewwchong Oct 2, 2023
a54b145
new unit test file for triangulation
sfu699 Oct 23, 2023
eeee42c
basic unit tests for a line of cones
sfu699 Oct 23, 2023
03632e6
added text file for unit test points
dorisbwang Oct 23, 2023
034146e
merge changes
sfu699 Oct 23, 2023
1f3aa48
added basic curve test, turning to the right
sfu699 Oct 30, 2023
9073fa6
removed main in generator
GeoffTheJetson Oct 30, 2023
ba58fb6
Merge branch '6-plan-midpoint_triangulation' of github.com:carnegieme…
GeoffTheJetson Oct 30, 2023
3049939
working
GeoffTheJetson Oct 30, 2023
2cfb6c6
Minor Stereocamera fix
GeoffTheJetson Oct 30, 2023
27051e7
Merge branch 'main' into 6-plan-midpoint_triangulation
GeoffTheJetson Oct 31, 2023
1cfb4d3
fixed merge issues
GeoffTheJetson Oct 31, 2023
374f7e6
changed midpoint and generator.hpp to Eigen and added generatorEigen.…
Jai0307 Nov 1, 2023
93d3500
singular extraneuous ` removed
Jai0307 Nov 1, 2023
4f4239c
some racelineEigen.cpp translation
Jai0307 Nov 4, 2023
6a2ad56
racelineEigenhpp
ishinshah Nov 4, 2023
4ea1e0d
most raceline translation done
Jai0307 Nov 4, 2023
b498cd8
raceline translation finished, added frenetEigen
Jai0307 Nov 4, 2023
752a1cf
half of frenet translated, but miminizer hasnt been translated
Jai0307 Nov 5, 2023
d33f5af
fixes on raceline eigen
GeoffTheJetson Nov 7, 2023
f124b53
remade file struct ure, debugging
GeoffTheJetson Nov 11, 2023
fcdc950
eigen bug fixes WIP
GeoffTheJetson Nov 12, 2023
9a954a3
eigen bug fixes WIP x2
GeoffTheJetson Nov 12, 2023
db7dd08
zoo wee mama
GeoffTheJetson Nov 18, 2023
f8aab89
manan fix ur code bruh
GeoffTheJetson Nov 28, 2023
1882726
wow worky
GeoffTheJetson Nov 30, 2023
98da0b1
changed spline constructor
andrewwchong Dec 9, 2023
b4fc65e
added function to create message from splines
andrewwchong Dec 9, 2023
2b19a30
LINKING WORKS RAHHHHHHH
andrewwchong Dec 9, 2023
c72ca1f
removed submodules
griffinteller Dec 12, 2023
c7672d5
fixed submodules and started laying out architecture
griffinteller Dec 12, 2023
ee1eead
redid multithreading setup, created superclasses for cuda/cpu environ…
griffinteller Dec 16, 2023
82778e0
idk a bunch of stuff
griffinteller Dec 21, 2023
4f512ca
added cuda types
griffinteller Jan 8, 2024
abad6f4
Merge branch 'main' into controller-arch-development
griffinteller Jan 8, 2024
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
10 changes: 10 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@

[submodule "driverless_ws/src/HesaiLidar_ROS_2.0"]
path = driverless_ws/src/HesaiLidar_ROS_2.0
url = https://github.com/HesaiTechnology/HesaiLidar_ROS_2.0
[submodule "driverless_ws/src/ros2_numpy"]
path = driverless_ws/src/ros2_numpy
url = https://github.com/Box-Robotics/ros2_numpy.git
[submodule "driverless_ws/src/zed-ros2-wrapper"]
path = driverless_ws/src/zed-ros2-wrapper
url = https://github.com/stereolabs/zed-ros2-wrapper.git
[submodule "driverless_ws/src/eufs_msgs"]
path = driverless_ws/src/eufs_msgs
url = https://gitlab.com/eufs/eufs_msgs.git
Expand Down
Empty file removed driverless_ws/log.log
Empty file.
2 changes: 1 addition & 1 deletion driverless_ws/src/HesaiLidar_ROS_2.0
1 change: 0 additions & 1 deletion driverless_ws/src/common_interfaces
Submodule common_interfaces deleted from 366eea
68 changes: 52 additions & 16 deletions driverless_ws/src/controls/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
cmake_minimum_required(VERSION 3.5)
project(controls)

set(NO_CUDA FALSE)

# disable cuda compilation
#set(NO_CUDA TRUE)

if(NO_CUDA)
add_compile_definitions(CONTROLS_NO_CUDA)
else()
enable_language(CUDA)
endif()

# Default to C99
if(NOT CMAKE_C_STANDARD)
set(CMAKE_C_STANDARD 99)
Expand All @@ -11,25 +22,50 @@ if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()
#if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# add_compile_options(-Wall -Wextra -Wpedantic)
#endif()

# find dependencies
find_package(ament_cmake REQUIRED)
# uncomment the following section in order to fill in
# further dependencies manually.
# find_package(<dependency> REQUIRED)

if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
# the following line skips the linter which checks for copyrights
# uncomment the line when a copyright and license is not present in all source files
#set(ament_cmake_copyright_FOUND TRUE)
# the following line skips cpplint (only works in a git repo)
# uncomment the line when this package is not in a git repo
#set(ament_cmake_cpplint_FOUND TRUE)
ament_lint_auto_find_test_dependencies()
find_package(planning REQUIRED)
find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)

include_directories(${PROJECT_SOURCE_DIR}/src)
include_directories(${PROJECT_SOURCE_DIR}/../)


set(LIB_SOURCES
src/interface/interface.cpp
src/interface/cpu_environment.cpp
src/mppi/cpu_mppi.cpp)
if(NOT NO_CUDA)
set(LIB_SOURCES ${LIB_SOURCES}
src/interface/cuda_environment.cu
src/mppi/cuda_mppi.cu)
endif()

add_library(controls_lib SHARED ${LIB_SOURCES})
ament_target_dependencies(controls_lib planning rclcpp std_msgs)

add_executable(controller src/nodes/controller.cpp)
target_link_libraries(controller controls_lib)

ament_target_dependencies(controller rclcpp)

ament_export_targets(controls_libExport HAS_LIBRARY_TARGET)
ament_export_dependencies(planning rclcpp std_msgs)

install(
TARGETS controls_lib
EXPORT controls_libExport
DESTINATION lib/${PROJECT_NAME}
)

install(
TARGETS controller
DESTINATION lib/${PROJECT_NAME}
)

ament_package()
30 changes: 30 additions & 0 deletions driverless_ws/src/controls/conventions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
## Conventions

Conventions for the controls subteam code.

### Naming

Use python naming:

- ``lower_snake_case`` for values (including functions/methods, 150 moment)
- Reason: ``lowerCamelCase`` is just ugly
- ``PascalCase`` for types
- Reason: prevents declaration issues like ``car car;``
- Namespace-level declarations should have namespae corresponding to their directory
- e.g. a declaration in ``src/mppi`` should belong to namespace ``controls::mppi``


### Code Style

- Follow the cpp core guidelines, except for anything that uses the GSL. Or is otherwise clearly dumb.
- Misc. notes:
- use uniform initialization (`{...}` constructor syntax) wherever possible.
- Reason: far more
readable than `(...)` in many cases (looks like a function call/declaration)
- `m_` prefix should be used for all private fields
- Reason: disambiguates fields from parameters before it becomes an issue. If you wait until
you notice ambiguity, you're already too late!
- By defualt, prefer immutable data (i.e. `const` lvalues). This also necessitates marking
methonds `const` wherever possible.
- Reason: _especially_ since we're multithreading, this makes code easier to reason about. Also
makes it easier for the compiler to reason about.
4 changes: 4 additions & 0 deletions driverless_ws/src/controls/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@

<buildtool_depend>ament_cmake</buildtool_depend>

<depend>std_msgs</depend>
<depend>rclcpp</depend>
<depend>planning</depend>

<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>

Expand Down
28 changes: 28 additions & 0 deletions driverless_ws/src/controls/src/constants.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once

#include <rclcpp/rclcpp.hpp>

#include "types.hpp"


namespace controls {

/* ROS moments */

constexpr const char *controller_node_name = "controller";
constexpr const char *control_action_topic_name = "control_action";
const rclcpp::QoS control_action_qos (rclcpp::KeepLast(10));


// MPPI stuff

constexpr Device default_device = Device::Cuda;

/** Controller target frequency, in Hz */
constexpr double controller_freq = 50.;

/** Controller target period, in sec */
constexpr auto controller_period = std::chrono::operator""ms(1000. / controller_freq);
constexpr uint num_samples = 1024;
constexpr uint num_timesteps = 128;
}
6 changes: 6 additions & 0 deletions driverless_ws/src/controls/src/cuda_constants.cuh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "cuda_types.cuh"

namespace controls {
constexpr csize num_spline_interpolations = 512;
constexpr cfloat spline_interpolation_separation = 0.5;
}
4 changes: 4 additions & 0 deletions driverless_ws/src/controls/src/cuda_types.cuh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace controls {
using cfloat = float;
using csize = unsigned int;
}
23 changes: 23 additions & 0 deletions driverless_ws/src/controls/src/interface/cpu_environment.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "cpu_environment.hpp"

namespace controls {
namespace interface {
void CpuEnvironment::update_spline(const SplineMsg& msg) {
}

void CpuEnvironment::update_slam(const SlamMsg& msg) {
}

void CpuEnvironment::update_gps(const GpsMsg& msg) {
}

State CpuEnvironment::get_curv_state() const {
}

State CpuEnvironment::get_world_state() const {
}

double CpuEnvironment::get_curvature(double progress_from_current) const {
}
}
}
24 changes: 24 additions & 0 deletions driverless_ws/src/controls/src/interface/cpu_environment.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once

#include <planning/src/planning_codebase/raceline/raceline.hpp>
#include <interfaces/msg/spline_list.hpp>

#include "interface.hpp"


namespace controls {
namespace interface {
class CpuEnvironment : public Environment {
public:
CpuEnvironment() = default;

void update_spline(const SplineMsg& msg) override;
void update_slam(const SlamMsg& msg) override;
void update_gps(const GpsMsg& msg) override;

State get_curv_state() const override;
State get_world_state() const override;
double get_curvature(double progress_from_current) const override;
};
}
}
16 changes: 16 additions & 0 deletions driverless_ws/src/controls/src/interface/cuda_environment.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <exception>

#include "cuda_environment.cuh"


namespace controls {
namespace interface {
void CudaEnvironment::update_spline(const controls::SplineMsg &msg) {
throw std::runtime_error("cuda spline update not implemented");
}

void CudaEnvironment::update_gps(const controls::SplineMsg &msg) {
throw std::runtime_error("cuda spline update not implemented");
}
}
}
29 changes: 29 additions & 0 deletions driverless_ws/src/controls/src/interface/cuda_environment.cuh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <types.hpp>
#include <cuda_types.cuh>
#include <cuda_constants.cuh>
#include <cuda_types.cuh>
#include <planning/src/planning_codebase/raceline/raceline.hpp>

#include "interface.hpp"


namespace controls {
namespace cuda {
cfloat* d_spline_curvatures; // allocated on first CudaEnvironment construction
}

namespace interface {
// should be able to be constructed/destructed multiple times without an issue
// but there can only be one at once
class CudaEnvironment : public Environment {
public:
void update_spline(const SplineMsg& msg) override;
void update_slam(const SlamMsg& msg) override;
void update_gps(const GpsMsg& msg) override;

State get_curv_state() const override;
State get_world_state() const override;
double get_curvature(double progress_from_current) const override;
};
}
}
12 changes: 12 additions & 0 deletions driverless_ws/src/controls/src/interface/interface.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "interface.hpp"


namespace controls {
namespace interface {
bool Environment::get_valid() const {
return m_valid;
}


}
}
43 changes: 43 additions & 0 deletions driverless_ws/src/controls/src/interface/interface.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#ifndef CONTROLS_INTERFACE_HPP
#define CONTROLS_INTERFACE_HPP

#include <mutex>
#include <condition_variable>
#include <types.hpp>

namespace controls {
namespace interface {
class Environment {
public:
virtual ~Environment () =0;

virtual void update_spline(const SplineMsg& msg) =0;
virtual void update_slam(const SlamMsg& msg) =0;
virtual void update_gps(const GpsMsg& msg) =0;

virtual State get_curv_state() const =0;
virtual State get_world_state() const =0;
virtual double get_curvature(double progress_from_current) const =0;

bool get_valid() const;


std::mutex mutex;

protected:
bool m_valid {false};
};
}
}


// included so other classes only need to include one header for all of them
// at bottom to avoid loop

#include "cpu_environment.hpp"

#ifndef CONTROLS_NO_CUDA
#include "cuda_environment.cuh"
#endif

#endif
1 change: 1 addition & 0 deletions driverless_ws/src/controls/src/mppi/cpu_mppi.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "cpu_mppi.hpp"
15 changes: 15 additions & 0 deletions driverless_ws/src/controls/src/mppi/cpu_mppi.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

#include <types.hpp>

#include "mppi.hpp"


namespace controls {
namespace mppi {
class CpuMppiController : public MppiController {
public:
Action generate_action(const State& current_state) override;
};
}
}
1 change: 1 addition & 0 deletions driverless_ws/src/controls/src/mppi/cuda_mppi.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "cuda_mppi.cuh"
1 change: 1 addition & 0 deletions driverless_ws/src/controls/src/mppi/cuda_mppi.cuh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#pragma once
15 changes: 15 additions & 0 deletions driverless_ws/src/controls/src/mppi/mppi.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once


namespace controls {
namespace mppi {
class MppiController : public Controller { };
}
}


#include "cpu_mppi.hpp"

#ifndef CONTROLS_NO_CUDA
#include "cuda_mppi.cuh"
#endif
Loading
Loading