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

Ali/simple planning simulator with disturbance generator #573

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
77c92de
Started to implement standalone control_toolbox.
boyali May 13, 2022
8a784c5
Reproduced the linking problem.
boyali May 13, 2022
0735ca9
Solved the linking problem.
boyali May 13, 2022
a110033
Solved fvisibility setting and will use in other packages.
boyali May 15, 2022
253ae2a
Syncronized with the other repos that uses the ACT.
boyali May 25, 2022
2e385c8
Syncronized with the other repos that uses the ACT.
boyali May 25, 2022
27cd1ec
Version txt is added.
boyali May 25, 2022
e5f404d
Tustin Bilinear discretization is added.
boyali May 30, 2022
8df1702
ACT is separated into the headers. Started balancing algorithm.
boyali May 30, 2022
4fa6606
Implemented matrix balancing.
boyali May 30, 2022
3b1197d
Balancing finished, comparing with others.
boyali May 30, 2022
0834ee9
Balancing finished: lapack diag subtraction is enabled.
boyali May 30, 2022
dfd9735
Balancing finalized:integrating into the ss methods.
boyali May 30, 2022
03f80b8
Automatic discretization is added to tf2ss.
boyali May 30, 2022
428a674
Automatic balancing is added to tf2ss.
boyali May 30, 2022
1051e5c
Balancing permutation method signature is added.
boyali May 31, 2022
410de74
Introduced the signal builder methods.
boyali May 31, 2022
031da29
Triangle wave implementation is changed.
boyali Jun 1, 2022
2ae4255
Added tffactor_zero initializaiton.
boyali Jun 1, 2022
ae7fb8e
added F inversion.
boyali Jun 1, 2022
c409aca
added TF from tf_factor construciton.
boyali Jun 1, 2022
6f2fb8c
Implementing TF*TF multiplication.
boyali Jun 1, 2022
32c4e51
Implementing TF*TF LAZY evaluation implemented.
boyali Jun 1, 2022
4578522
COmpleted TF TF multiplication.
boyali Jun 1, 2022
0939f02
std vector is overloaded. A TF multiplication bug is removed.
boyali Jun 2, 2022
135e18e
std vector is overloaded
boyali Jun 2, 2022
064b1b2
Completed: std vector is overloaded.
boyali Jun 2, 2022
8a3c933
Swapped when taking tf.inv().
boyali Jun 2, 2022
e7bbc70
Improved code * vector overloading.
boyali Jun 3, 2022
b3f3597
Improved TF * TF mult adding num den constants.
boyali Jun 3, 2022
9a32bc2
implemented ss system getter. PSSim needs to change.
boyali Jun 3, 2022
64df004
state space getters A(), B() .. are implemented.
boyali Jun 3, 2022
7f2fee2
explicit is removed from tf2ss
boyali Jun 3, 2022
9eb3435
static gain guard is put in the state space models.
boyali Jun 3, 2022
97abb49
Returning by a constant reference in tf2ss.
boyali Jun 3, 2022
721225a
Returning by a constant reference reverted in tf2ss.
boyali Jun 3, 2022
d87c450
implementing templated ss: before changing tf2ss default constructor.
boyali Jun 4, 2022
a9bc806
matrix printing improved.
boyali Jun 4, 2022
20de455
cleaning up tf2ss.
boyali Jun 4, 2022
0b6b7af
Changed tf2ss to have a single system matrix, instead of separate [A,…
boyali Jun 4, 2022
9bc87e2
Changed tf2ss after change make ups
boyali Jun 4, 2022
f15977a
Added a discrete system matrix simulation method into the tf2ss.
boyali Jun 4, 2022
e5ccddd
Added tf2ss parameter update method.
boyali Jun 5, 2022
bfd74d6
Added tf2ss simulateOneStep template for compile time eigen matrices.
boyali Jun 5, 2022
5db1153
Added tf2ss simulateOneStep template for compile time eigen matrices.…
boyali Jun 5, 2022
fe40cb8
Verifying with q-filters.
boyali Jun 5, 2022
2983dd6
Verifying with q-filters.
boyali Jun 5, 2022
4dfdc5f
Verified sinusoidal signal productions.
boyali Jun 5, 2022
9180e79
Balancing code block is changed.
boyali Jun 5, 2022
06c3d02
Another simulateOneStep method is added.
boyali Jun 5, 2022
77a30ef
Another simulateOneStep method is added.
boyali Jun 5, 2022
5829c65
Get order is fixed.
boyali Jun 5, 2022
59175a7
Get order is fixed.
boyali Jun 5, 2022
c0403f2
Get order is fixed.
boyali Jun 5, 2022
f711252
Reverting sysMATABCD -> separate A, B, C, D.
boyali Jun 6, 2022
26d1a5f
Balancing C, B part is being implemented.
boyali Jun 6, 2022
5f3822c
Balancing C, B part is being implemented.
boyali Jun 6, 2022
5039825
removed an infinite loop bug.
boyali Jun 6, 2022
9f4078d
ci: add sync-upstream.yaml (#4)
kenji-miyake Jan 29, 2022
7c73be6
ci(sync-upstream): update settings (#19)
kenji-miyake Mar 3, 2022
8abdf24
Added the autoware_control_toolbox and copied vehicle model for distu…
boyali Mar 4, 2022
ed347f1
Disturbance generator is added.
boyali Mar 4, 2022
b65c8f7
Copied vehicle model is tested.
boyali Mar 4, 2022
ffe1825
Input queue related code sections are removed from the vehicle distur…
boyali Mar 4, 2022
50af46f
Restarted.
boyali Mar 6, 2022
a1bcf10
IDisturbanceCollection disturbance_collection_ is added to the inter…
boyali Mar 6, 2022
665534f
Disturbance Parameters are added to yaml file.
boyali Mar 6, 2022
716f5ab
Disturbance collection is integrated.
boyali Mar 6, 2022
a830a2c
Fully integrated, but initially engaged.
boyali Mar 6, 2022
5939290
disturbance msg is added and tested.
boyali Mar 6, 2022
272a121
disturbance plots are completed.
boyali Mar 7, 2022
1675a74
ReadMe is updated.
boyali Mar 7, 2022
c6fe2db
ReadMe is updated.
boyali Mar 7, 2022
46e49ca
After the PR - geared_dist model header and cpp are added.
boyali Mar 7, 2022
ef5d52f
Geared Vehicle Model with disturbance is integrated with the simulator.
boyali Mar 7, 2022
a82f59e
Geared Vehicle Model is tested with the disturbance generator.
boyali Mar 7, 2022
6a38edb
Geared Vehicle Model is tested with the disturbance generator.
boyali Mar 7, 2022
b93b6bc
Slope is added to the plotjuggler and core.
boyali Mar 7, 2022
be677af
Started to implement TIME-VARYING DEADZONE disturbance.
boyali Mar 7, 2022
9c37450
progressed in Deadzon. Improved the code navigation in dist generator…
boyali Mar 8, 2022
1fa2482
progressed in Deadzone. Implemented getDeadzone
boyali Mar 8, 2022
ab0a5dc
Some clang-tidy and MISRA corrections.
boyali Mar 8, 2022
210c198
Parameters added for the deadzone.
boyali Mar 8, 2022
a0f7557
Deadzone is put in the disturbance collection. Ready to integrate wit…
boyali Mar 8, 2022
28a535a
Put use_steering_input_delay option in the parameters.
boyali Mar 9, 2022
a8adc0d
Put use_acceleration_input_delay option in the parameters.
boyali Mar 9, 2022
9b397be
Put use_road_slope_disturbance option in the parameters.
boyali Mar 9, 2022
582d240
Put use_deadzone_disturbance option in the parameters.
boyali Mar 9, 2022
c7ab167
Disturbance message structure is implemented.
boyali Mar 9, 2022
bc1052b
Deadzone is completed, will check deadzone function implementation.
boyali Mar 9, 2022
2e67ef3
Deadzone description is added to the MD file.
boyali Mar 9, 2022
8e3bfcb
Deadzone function is amended.
boyali Mar 9, 2022
a87c6ab
Autoware_Control_Toolbox is separately implemented.
boyali May 15, 2022
ee40a29
Autoware_Control_Toolbox is separately implemented.
boyali May 23, 2022
c03756c
utils in ACT changed to act_utils
boyali May 23, 2022
3637295
Rebased on to the ACT, delay model continuous time update -> discrete…
boyali May 31, 2022
7559481
Rebased on to the improved ACT.
boyali Jun 3, 2022
e6a8638
Virtual destructors added to the disturbance interfaces.
boyali Jun 6, 2022
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
Prev Previous commit
Next Next commit
Balancing code block is changed.
  • Loading branch information
boyali committed Jun 5, 2022
commit 9180e79b8d3e5a51f71ad76e0feb96e6043dd5bc
71 changes: 23 additions & 48 deletions control/autoware_control_toolbox/src/utils_act/balance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,75 +39,50 @@ void ns_control_toolbox::permute(Eigen::MatrixXd& P)
void ns_control_toolbox::balance(Eigen::MatrixXd& A)
{

// get the size of the matrix.
auto const& nx = A.rows();
bool converged{ false };
const int p = 1;
bool converged = false;


while (!converged)
do
{
converged = true;

for (auto k = 1; k < nx; ++k)
for (Eigen::Index k = 0; k < A.rows(); ++k)
{

// Compute row and column norms.
auto r = A.row(k).lpNorm<1>(); // instead of 1-norm, one can use other norms as well.
auto c = A.col(k).lpNorm<1>();

// In the lapack implementation diagonal element is ignored in the norms.
// r = r - std::abs(A.row(k)(k));
// c = c - std::abs(A.col(k)(k));

// auto s = std::pow(r, 1) + std::pow(c, 1);
double f{ 1. };
double c = A.col(k).lpNorm<p>();
double r = A.row(k).lpNorm<p>();
double s = std::pow(c, p) + std::pow(r, p);
double f = 1;

if ((r > EPS) && (c > EPS))
{
// In the lapack implementation diagonal element is ignored in the norms.

auto g = r / RADIX;
auto&& s = r + c;

while (c < g)
while (c < r / RADIX)
{
f = f * RADIX;
c = c * RADIX;
r = r / RADIX;
g = g / RADIX;
c *= RADIX;
r /= RADIX;
f *= RADIX;
}

g = c / RADIX;
while (g > r)
while (c >= r * RADIX)
{
f = f / RADIX;
c = c / RADIX;
r = r * RADIX;
g = g / RADIX;
c /= RADIX;
r *= RADIX;
f /= RADIX;
}

// Convergence block.
if (c + r < 0.95 * s)
if (std::pow(c, p) + std::pow(r, p) < 0.95 * s)
{
converged = true;

// Apply similarity transformation to the rows and cols.
A.col(k).noalias() = A.col(k) * f;
A.row(k).noalias() = A.row(k) / f;
converged = false;

// ns_utils::print("f in the balancing algorithm : ", f);
A.col(k) *= f;
A.row(k) /= f;
}

}

else
{
// Apply similarity transformation to the rows and cols.
A.col(k).noalias() = A.col(k) * f;
A.row(k).noalias() = A.row(k) / f;
converged = false;
}
}

}
} while (!converged);

}

35 changes: 19 additions & 16 deletions control/autoware_control_toolbox/src/utils_act/state_space.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ void ns_control_toolbox::tf2ss::computeSystemMatrices(const std::vector<double>&

// Balance the matrices.
// Call balance method on the system matrices.
// ns_utils::print("Unbalanced System Matrix.");
// ns_eigen_utils::printEigenMat(sys_matABCD_cont_);

ns_control_toolbox::balance(sys_matABCD_cont_);
}

Expand Down Expand Up @@ -285,52 +288,52 @@ void ns_control_toolbox::tf2ss::discretisize(double const& Ts)
// Discrete time state-space matrices.
Eigen::MatrixXd ns_control_toolbox::tf2ss::Ad() const
{
auto&& Ad = sys_matABCD_disc_.topLeftCorner(N_ - 1, N_ - 1);
return Ad;
// auto&& Ad = sys_matABCD_disc_.topLeftCorner(N_ - 1, N_ - 1);
return sys_matABCD_disc_.topLeftCorner(N_ - 1, N_ - 1);
}

Eigen::MatrixXd ns_control_toolbox::tf2ss::Bd() const
{
auto&& Bd = sys_matABCD_disc_.topRightCorner(N_ - 1, 1);
return Bd;
// auto&& Bd = sys_matABCD_disc_.topRightCorner(N_ - 1, 1);
return sys_matABCD_disc_.topRightCorner(N_ - 1, 1);
}

Eigen::MatrixXd ns_control_toolbox::tf2ss::Cd() const
{
auto&& Cd = sys_matABCD_disc_.bottomLeftCorner(1, N_ - 1);
return Cd;
// auto&& Cd = sys_matABCD_disc_.bottomLeftCorner(1, N_ - 1);
return sys_matABCD_disc_.bottomLeftCorner(1, N_ - 1);
}

Eigen::MatrixXd ns_control_toolbox::tf2ss::Dd() const
{
auto&& Dd = sys_matABCD_disc_.bottomRightCorner(1, 1);
return Dd;
// auto&& Dd = sys_matABCD_disc_.bottomRightCorner(1, 1);
return sys_matABCD_disc_.bottomRightCorner(1, 1);;
}


// Continuous time state-space matrices.
Eigen::MatrixXd ns_control_toolbox::tf2ss::A() const
{
auto&& A = sys_matABCD_cont_.topLeftCorner(N_ - 1, N_ - 1);
return A;
// auto A = sys_matABCD_cont_.topLeftCorner(N_ - 1, N_ - 1);
return sys_matABCD_cont_.topLeftCorner(N_ - 1, N_ - 1);
}

Eigen::MatrixXd ns_control_toolbox::tf2ss::B() const
{
auto&& B = sys_matABCD_cont_.topRightCorner(N_ - 1, 1);
return B;
// auto&& B = sys_matABCD_cont_.topRightCorner(N_ - 1, 1);
return sys_matABCD_cont_.topRightCorner(N_ - 1, 1);
}

Eigen::MatrixXd ns_control_toolbox::tf2ss::C() const
{
auto&& C = sys_matABCD_cont_.bottomLeftCorner(1, N_ - 1);
return C;
// auto&& C = sys_matABCD_cont_.bottomLeftCorner(1, N_ - 1);
return sys_matABCD_cont_.bottomLeftCorner(1, N_ - 1);
}

Eigen::MatrixXd ns_control_toolbox::tf2ss::D() const
{
auto&& D = sys_matABCD_cont_.bottomRightCorner(1, 1);
return D;
// auto&& D = sys_matABCD_cont_.bottomRightCorner(1, 1);
return sys_matABCD_cont_.bottomRightCorner(1, 1);
}


Expand Down
39 changes: 34 additions & 5 deletions control/autoware_control_toolbox/usage_examples/main_balance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,9 @@ int main()
ss_sys.print();

// Test discretization and compare with Matlab.

ss_sys.discretisize(Ts);
ss_sys.print_discrete_system();

// ns_control_toolbox::balance(ss_sys.A_);
// ns_utils::print("Balanced matrix A_");
// ns_eigen_utils::printEigenMat(ss_sys.A_);

// Concat
auto AB = ns_eigen_utils::hstack<double>(ss_sys.A(), ss_sys.B());
auto CD = ns_eigen_utils::hstack<double>(ss_sys.C(), ss_sys.D());
Expand All @@ -39,9 +34,43 @@ int main()
ns_control_toolbox::balance(ss_system);
ns_eigen_utils::printEigenMat(ss_system);

// COMPARE with MATLAB RESULTS.
double tau_steer{ 0.3 };
double wheelbase{ 2.9 }; // L in vehicle model.

ns_control_toolbox::tf_factor m_den1{{ wheelbase, 0, 0 }}; // L*s^2
ns_control_toolbox::tf_factor m_den2{{ tau_steer, 1 }}; // (tau*s + 1)
auto den_tf_factor = m_den1 * m_den2;

ns_control_toolbox::tf Gey({ 1. }, den_tf_factor(), 4., 1.); // num, den, num constant, den constant
Gey.print();

// Qfilter
double dt = 1. / 40;
double frq = 20.;
double wc = 2 * M_PI * frq;
double tau_q = 1 / wc;

ns_control_toolbox::tf_factor den_q{{ tau_q, 1 }};
den_q.power(3);

auto Qtf = ns_control_toolbox::tf({ 1 }, { den_q() });
Qtf.print();

Gey.inv();
Gey.print();

auto QGinv = Qtf * Gey;
QGinv.print();

auto QGinvss = ns_control_toolbox::tf2ss(QGinv, dt);

ns_utils::print("Balanced System Matrices");
QGinvss.print();
// PERMUTATION TEST




return 0;
}