-
-
Notifications
You must be signed in to change notification settings - Fork 23
controls algo setup #1936
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
Open
Lucien950
wants to merge
35
commits into
master
Choose a base branch
from
Shayan/algo_set_up
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
controls algo setup #1936
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
42cdbb8
base work for tire model done (pure slip).... will change for combine…
shayana18 26f9b13
algo in progress changes
shayana18 7cd32b8
work in progress, most peices are there
shayana18 f5ef2f3
logic is there now
shayana18 9bcb1ba
fahh
Lucien950 3600b82
small changes
Lucien950 80aa912
a few more small changes
Lucien950 1e509fe
kms hours
Lucien950 8e44ed2
rotations
Lucien950 13ced94
edwin zheng forgot how to do rotation matrix
Lucien950 c8a8020
template metaprogramming masturbation
Lucien950 ffb80cd
W optimizer?
Lucien950 4940e26
nuclearize
Lucien950 9471b20
penis
Lucien950 731d184
name
Lucien950 479c14e
I didnt even know this was possible
Aditya-Dhiman4 3741ff9
wow
Lucien950 a66fb4c
L
Lucien950 6baefc0
maybe everything is fucked idk man, love matlab
Lucien950 ba10cbb
clean up matlab interface
Lucien950 32ceac5
small mistake
Lucien950 f2d8942
matplotlib and others
Lucien950 2dd61e9
fixed torque bounds plus multiplied speed request by gear ratio to ma…
Aditya-Dhiman4 a182398
tweaks for ta
Lucien950 68b41ff
WORKS?S???????
Lucien950 6c91f74
working optimizer
Lucien950 b95da94
torque allocator W
Lucien950 14cfe3f
working for floats as well now
Lucien950 ba6f1a5
better ig
Lucien950 6a3cf82
turning tests
Lucien950 3b10a21
consistent optimizer
Lucien950 2945824
Steering Model (#1949)
Aditya-Dhiman4 da931f5
6.2 implemented
shayana18 1328739
tire model :)
Lucien950 79d12c4
Optimizer converges, Fz temporarily removed
Aditya-Dhiman4 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| message("") | ||
| message("Configuring matplotlib-cpp...") | ||
|
|
||
| # Library target | ||
| find_package(Python3 COMPONENTS Development REQUIRED) | ||
| add_library(matplotlib_cpp INTERFACE) | ||
| target_include_directories(matplotlib_cpp INTERFACE ${matplotlibcpp_SOURCE_DIR}) | ||
| target_link_libraries(matplotlib_cpp INTERFACE | ||
| Python3::Python | ||
| Python3::Module | ||
| ) | ||
| #find_package(Python3 COMPONENTS NumPy) | ||
| #if (Python3_NumPy_FOUND) | ||
| # target_link_libraries(matplotlib_cpp INTERFACE | ||
| # Python3::NumPy | ||
| # ) | ||
| #else () | ||
| message(WARNING "NumPy not found. Matplotlib-cpp will be built without NumPy support.") | ||
| target_compile_definitions(matplotlib_cpp INTERFACE WITHOUT_NUMPY) | ||
| #endif () |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| // ReSharper disable CppTooWideScope | ||
| #include "matplotlibcpp.h" | ||
| #include "torque_vectoring/estimation/tire_model.hpp" | ||
| #include "torque_vectoring/controllers/torque_allocator.hpp" | ||
|
|
||
| #include <vector> | ||
| #include <string> | ||
| #include <iomanip> | ||
|
|
||
| namespace plt = matplotlibcpp; | ||
|
|
||
| static void plot_combined_fx() | ||
| { | ||
| constexpr int n_points = 301; // includes endpoints | ||
| constexpr float fz_N = 700.0f; | ||
|
|
||
| std::vector<double> kappas; | ||
| kappas.reserve(n_points); | ||
| for (int i = 0; i < n_points; ++i) | ||
| { | ||
| constexpr double kappa_max = 0.6f; | ||
| constexpr double kappa_min = -0.6f; | ||
| const double t = static_cast<float>(i) / static_cast<float>(n_points - 1); | ||
| const double kappa = kappa_min + t * (kappa_max - kappa_min); | ||
| kappas.push_back(kappa); | ||
| } | ||
|
|
||
| for (const float alpha_rad : { 0.15f, 0.125f, 0.1f, 0.075f, 0.05f, 0.025f, 0.0f }) | ||
| { | ||
| std::vector<double> fxs; | ||
| fxs.reserve(kappas.size()); | ||
| for (const double kappa : kappas) | ||
| { | ||
| fxs.push_back(app::tv::estimation::tire_model.computeCombinedFx_N<double>(fz_N, alpha_rad, kappa)); | ||
| } | ||
| std::stringstream ss; | ||
| ss << "\\alpha = " << std::setprecision(2) << alpha_rad; | ||
| plt::named_plot(ss.str(), kappas, fxs); | ||
| } | ||
|
|
||
| plt::title("F_x as a function of \\kappa and \\alpha"); | ||
| plt::xlabel("\\kappa"); | ||
| plt::ylabel("F_x (N)"); | ||
| plt::grid(true); | ||
| plt::legend(); | ||
| plt::show(); | ||
| } | ||
|
|
||
| static void plot_combined_fy() | ||
| { | ||
| constexpr int n_points = 301; // includes endpoints | ||
| constexpr float fz_N = 700.0f; | ||
|
|
||
| std::vector<float> alphas; | ||
| alphas.reserve(n_points); | ||
| for (int i = 0; i < n_points; ++i) | ||
| { | ||
| constexpr float alpha_max = 0.6f; | ||
| constexpr float alpha_min = -0.6f; | ||
| const float t = static_cast<float>(i) / static_cast<float>(n_points - 1); | ||
| const float alpha = alpha_min + t * (alpha_max - alpha_min); | ||
| alphas.push_back(alpha); | ||
| } | ||
|
|
||
| for (const double kappa : { 0.3, 0.25, 0.2, 0.15, 0.1, 0.05, 0.0 }) | ||
| { | ||
| std::vector<double> fys; | ||
| fys.reserve(alphas.size()); | ||
| for (const float alpha : alphas) | ||
| { | ||
| fys.push_back(app::tv::estimation::tire_model.computeCombinedFy_N<double>(fz_N, alpha, kappa)); | ||
| } | ||
| std::stringstream ss; | ||
| ss << "\\kappa = " << std::setprecision(2) << kappa; | ||
| plt::named_plot(ss.str(), alphas, fys); | ||
| } | ||
|
|
||
| plt::title("F_y as a function of \\alpha and \\kappa"); | ||
| plt::xlabel("\\alpha"); | ||
| plt::ylabel("F_y (N)"); | ||
| plt::grid(true); | ||
| plt::legend(); | ||
| plt::show(); | ||
| } | ||
|
|
||
| int main() | ||
| { | ||
| // constexpr app::tv::shared_datatypes::VehicleState<double> state{ | ||
| // .v_x_mps = 10, | ||
| // .v_y_mps = 0, | ||
| // .yaw_rate_radps = 0, | ||
| // .a_x_mps2 = 1, | ||
| // .a_y_mps2 = 0, | ||
| // .apps = 0.2, | ||
| // .delta = 0, | ||
| // }; | ||
| // const auto [fl, fr, rl, rr] = app::tv::controllers::allocator::optimize(state, 10.0, 5.0); | ||
| // std::cout << "Optimal slip found: " << fl << " " << fr << " " << rl << " " << rr << std::endl; | ||
|
|
||
| // plot_combined_fx(); | ||
| plot_combined_fy(); | ||
| } |
1 change: 1 addition & 0 deletions
1
firmware/hexray/VC/src/app/torque_vectoring/controllers/controllers_config.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| #pragma once | ||
| #include "app_pid.hpp" | ||
|
|
||
| namespace app::tv::controllers::dyrc | ||
|
|
||
40 changes: 40 additions & 0 deletions
40
firmware/hexray/VC/src/app/torque_vectoring/controllers/controllers_dyrc.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| #include "controllers_dyrc.hpp" | ||
| #include "torque_vectoring/controllers/controllers_config.hpp" | ||
| #include "torque_vectoring/shared_datatypes/constants.hpp" | ||
|
|
||
| using namespace app::tv::shared_datatypes::vd_constants; | ||
|
|
||
| namespace app::tv::controllers::dyrc | ||
| { | ||
|
|
||
| // Configuration | ||
| static float ku = DYRC_ku; // understeer gradient | ||
|
|
||
| // Control Scheme | ||
| static PID pid(PID_DYRC_config); | ||
|
|
||
| // purely for debugging purposes | ||
| static float yaw_moment_Nm = 0.0f; | ||
| static float r_ref_rad = 0.0f; | ||
|
|
||
| [[nodiscard]] float computeRefYawRate(const float steer_ang_rad, const float body_velx_mps) | ||
| { | ||
| return (body_velx_mps * steer_ang_rad) / (WHEELBASE_m * (1.0f + ku * body_velx_mps * body_velx_mps)); | ||
| } | ||
|
|
||
| [[nodiscard]] float computeYawMoment(const float r_actual_rad, const float steer_ang_rad, const float body_velx_mps) | ||
| { | ||
| r_ref_rad = computeRefYawRate(steer_ang_rad, body_velx_mps); | ||
| return yaw_moment_Nm = pid.compute(r_ref_rad, r_actual_rad, 0.0f); | ||
| } | ||
|
|
||
| [[nodiscard]] float getYawMoment() | ||
| { | ||
| return yaw_moment_Nm; | ||
| } | ||
|
|
||
| [[nodiscard]] float getRefYawRate() | ||
| { | ||
| return r_ref_rad; | ||
| } | ||
| } // namespace app::tv::controllers::dyrc |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
Empty file.
Empty file.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lowkey can we calculate yawacceleration
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
??