Skip to content

Commit e50f713

Browse files
Added Funnel Two-Layer MRAC controller (#11)
2 parents 0e250fc + e4531d8 commit e50f713

48 files changed

Lines changed: 8671 additions & 564 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,3 @@
1212

1313
# Ignore .vscode folder
1414
.vscode/
15-
16-

CMakeLists.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,15 @@ find_package(lifecycle_msgs REQUIRED)
5151
find_package(rclcpp_lifecycle REQUIRED)
5252

5353
include_directories(${Boost_INCLUDE_DIRS})
54+
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
5455
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/eigen)
5556
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/flightstack)
5657
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/flightstack/config)
5758
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/flightstack/control)
59+
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/flightstack/control/funnel_two_layer_mrac)
5860
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/flightstack/control/mrac)
5961
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/flightstack/control/pid)
62+
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/flightstack/control/two_layer_mrac)
6063
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/flightstack/logging)
6164
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/flightstack/mocap)
6265
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/flightstack/pixhawk_interface)
@@ -69,10 +72,15 @@ set(SOURCES
6972
src/config/config.cpp
7073
src/control/control.cpp
7174
src/control/control_callback.cpp
75+
src/control/outer_loop_safety_mechanism.cpp
76+
src/control/funnel_two_layer_mrac/funnel_two_layer_mrac.cpp
77+
src/control/funnel_two_layer_mrac/logging_funnel_two_layer_mrac.cpp
7278
src/control/mrac/logging_mrac.cpp
7379
src/control/mrac/mrac.cpp
7480
src/control/pid/logging_pid.cpp
7581
src/control/pid/pid.cpp
82+
src/control/two_layer_mrac/two_layer_mrac.cpp
83+
src/control/two_layer_mrac/logging_two_layer_mrac.cpp
7684
src/logging/logging_mocap.cpp
7785
src/main.cpp
7886
src/mocap/io_context.cpp
@@ -109,6 +117,23 @@ install(TARGETS
109117
if(BUILD_TESTING)
110118
find_package(ament_lint_auto REQUIRED)
111119
ament_lint_auto_find_test_dependencies()
120+
121+
find_package(ament_cmake_gtest REQUIRED)
122+
123+
ament_add_gtest(test_low_pass_filter
124+
test/utils/low_pass_filter_test.cpp
125+
)
126+
127+
if(TARGET test_low_pass_filter)
128+
target_include_directories(test_low_pass_filter PUBLIC
129+
${CMAKE_CURRENT_SOURCE_DIR}/include
130+
)
131+
# Optional: link extra libraries if needed
132+
# target_link_libraries(test_low_pass_filter some_library)
133+
134+
# Correct way to label the test for CTest
135+
set_tests_properties(test_low_pass_filter PROPERTIES LABELS "flightstack_core")
136+
endif()
112137
endif()
113138

114139
ament_package()

include/flightstack/config/config.hpp

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
#include <fstream>
4141
#include <nlohmann/json.hpp>
42+
#include <Eigen/Dense>
4243

4344
// Forward declaration of MultiThreadedNode class
4445
class MultiThreadedNode;
@@ -50,9 +51,11 @@ class MultiThreadedNode;
5051
// Define named constants for controller types
5152
#define __PID__ 1
5253
#define __MRAC__ 2
54+
#define __TWO_LAYER_MRAC__ 3
55+
#define __FUNNEL_TWO_LAYER_MRAC__ 4
5356

5457
// SELECT here the CONTROLLER you want to run -----------------------------------------------------------------------
55-
#define SELECTED_CONTROLLER __MRAC__
58+
#define SELECTED_CONTROLLER __FUNNEL_TWO_LAYER_MRAC__
5659
// ------------------------------------------------------------------------------------------------------------------
5760

5861
// Define ControlType based on SELECTED_CONTROLLER using type aliasing
@@ -68,10 +71,41 @@ using ControlType = PID;
6871
#include "logging_mrac.hpp"
6972
using ControlType = MRAC;
7073

74+
#elif SELECTED_CONTROLLER == __TWO_LAYER_MRAC__
75+
76+
#include "two_layer_mrac.hpp"
77+
#include "logging_two_layer_mrac.hpp"
78+
using ControlType = TwoLayerMRAC;
79+
80+
#elif SELECTED_CONTROLLER == __FUNNEL_TWO_LAYER_MRAC__
81+
82+
#include "funnel_two_layer_mrac.hpp"
83+
#include "logging_funnel_two_layer_mrac.hpp"
84+
using ControlType = FunnelTwoLayerMRAC;
85+
7186
#else
7287
#error "ERROR: Unsupported controller type selected."
7388
#endif
7489

90+
namespace config_param {
91+
92+
// Flag for publishing data to the motors
93+
inline constexpr bool PUBLISH_ACTUATOR_MOTORS_FLAG = true;
94+
95+
// Flag to enable/disable the MRAC projection operator
96+
inline constexpr bool USE_PROJECTION_OPERATOR = true;
97+
98+
// Flag to enable/disable the debug logger
99+
inline constexpr bool USE_DEBUG_LOGGER = false;
100+
101+
// Flag to enable/disable the safety mechanism between outer and inner loop
102+
inline constexpr bool USE_OUTER_LOOP_SAFETY_MECHANISM = true;
103+
104+
// Flag to enable/disable motor failure
105+
inline constexpr bool ENABLE_MOTOR_FAILURE = false;
106+
107+
} // namespace config_param
108+
75109

76110
/*********************************************************************************************************************
77111
Configurations Parameters set from config.json
@@ -85,6 +119,16 @@ struct ConfigurationParameters
85119
// Time in seconds for which the UAV will perform hovering after having completed the user-defined trajectory
86120
double hover_after_trajectory_time_seconds;
87121

122+
// Time in seconds at which motor failure happens (start)
123+
double motor_failure_start_time_seconds;
124+
125+
// Time in seconds for the motor failure duration
126+
double motor_failure_duration_time_seconds;
127+
128+
// Array containing the motor efficiencies to simulate motor failure. Order: T1, T2, ..., T8.
129+
// A "zero" turns off the motor completely, a "one" means the motor works as usual.
130+
Eigen::Matrix<double, 8, 1> motor_failure_efficiencies;
131+
88132
static ConfigurationParameters readConfigurationParametersFile(const std::string& configFileName);
89133

90134
};
@@ -95,9 +139,6 @@ struct ConfigurationParameters
95139
*/
96140
struct GlobalParameters
97141
{
98-
// Flag for publishing data to the motors
99-
bool PUBLISH_ACTUATOR_MOTORS_FLAG;
100-
101142
// Time in seconds at which we arm the motors
102143
double ARM_START_TIME_SECONDS;
103144

@@ -117,6 +158,12 @@ struct GlobalParameters
117158
// This must always be performed before takeoff
118159
double OFFSET_ODOMETRY_TIME_SECONDS;
119160

161+
// Time in seconds at which motor failure happens (start)
162+
double MOTOR_FAILURE_START_TIME_SECONDS;
163+
164+
// Time in seconds at which motor failure is resolved (end)
165+
double MOTOR_FAILURE_END_TIME_SECONDS;
166+
120167
// Default constructor
121168
GlobalParameters() = default;
122169

0 commit comments

Comments
 (0)