Commit 071ec7ee authored by Gauthier Quesnel's avatar Gauthier Quesnel
Browse files

core: add up and down threshold detection in cross

parent 22f87cc6
Pipeline #16324 passed with stage
in 1 minute and 36 seconds
......@@ -5037,6 +5037,7 @@ struct abstract_cross
time sigma;
double default_threshold = 0.0;
bool default_detect_up = true;
double threshold;
double if_value[QssLevel];
......@@ -5044,7 +5045,7 @@ struct abstract_cross
double value[QssLevel];
double last_reset;
bool reach_threshold;
bool block_lambda;
bool detect_up;
enum port_name
{
......@@ -5072,7 +5073,7 @@ struct abstract_cross
sigma = time_domain<time>::infinity;
last_reset = time_domain<time>::infinity;
block_lambda = false;
detect_up = default_detect_up;
reach_threshold = false;
return status::success;
......@@ -5201,7 +5202,7 @@ struct abstract_cross
reach_threshold = false;
if (value[0] >= threshold) {
if ((detect_up && value[0] >= threshold) || (!detect_up && value[0] <= threshold)) {
if (t != last_reset) {
last_reset = t;
reach_threshold = true;
......@@ -5220,37 +5221,35 @@ struct abstract_cross
status lambda(
data_array<output_port, output_port_id>& output_ports) noexcept
{
if (!block_lambda) {
if constexpr (QssLevel == 1) {
output_ports.get(y[o_else_value])
.messages.emplace_front(else_value[0]);
if (reach_threshold) {
output_ports.get(y[o_if_value])
.messages.emplace_front(if_value[0]);
output_ports.get(y[o_event]).messages.emplace_front(1.0);
}
if constexpr (QssLevel == 1) {
output_ports.get(y[o_else_value])
.messages.emplace_front(else_value[0]);
if (reach_threshold) {
output_ports.get(y[o_if_value])
.messages.emplace_front(if_value[0]);
output_ports.get(y[o_event]).messages.emplace_front(1.0);
}
}
if constexpr (QssLevel == 2) {
output_ports.get(y[o_else_value])
.messages.emplace_front(else_value[0], else_value[1]);
if (reach_threshold) {
output_ports.get(y[o_if_value])
.messages.emplace_front(if_value[0], if_value[1]);
output_ports.get(y[o_event]).messages.emplace_front(1.0);
}
if constexpr (QssLevel == 2) {
output_ports.get(y[o_else_value])
.messages.emplace_front(else_value[0], else_value[1]);
if (reach_threshold) {
output_ports.get(y[o_if_value])
.messages.emplace_front(if_value[0], if_value[1]);
output_ports.get(y[o_event]).messages.emplace_front(1.0);
}
}
if constexpr (QssLevel == 3) {
output_ports.get(y[o_else_value])
.messages.emplace_front(
else_value[0], else_value[1], else_value[2]);
if (reach_threshold) {
output_ports.get(y[o_if_value])
.messages.emplace_front(
if_value[0], if_value[1], if_value[2]);
output_ports.get(y[o_event]).messages.emplace_front(1.0);
}
if constexpr (QssLevel == 3) {
output_ports.get(y[o_else_value])
.messages.emplace_front(
else_value[0], else_value[1], else_value[2]);
if (reach_threshold) {
output_ports.get(y[o_if_value])
.messages.emplace_front(
if_value[0], if_value[1], if_value[2]);
output_ports.get(y[o_event]).messages.emplace_front(1.0);
}
}
......
......@@ -2538,6 +2538,7 @@ main()
integrator.default_dQ = 0.001;
cross.default_threshold = Vt;
cross.default_detect_up = false;
expect(sim.models.can_alloc(10));
!expect(irt::is_success(
......@@ -2622,9 +2623,10 @@ main()
constant_cross.default_value = Vr;
integrator.default_X = 0.0;
integrator.default_dQ = 0.001;
integrator.default_dQ = 0.0001;
cross.default_threshold = Vt;
cross.default_detect_up = false;
expect(sim.models.can_alloc(10));
!expect(irt::is_success(
......@@ -2709,9 +2711,10 @@ main()
constant_cross.default_value = Vr;
integrator.default_X = 0.0;
integrator.default_dQ = 0.00001;
integrator.default_dQ = 0.0001;
cross.default_threshold = Vt;
cross.default_detect_up = false;
expect(sim.models.can_alloc(10));
!expect(irt::is_success(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment