Skip to content

Commit 095150c

Browse files
committed
Fixed test issue
1 parent a2b63a2 commit 095150c

File tree

3 files changed

+43
-26
lines changed

3 files changed

+43
-26
lines changed

include/cosim.h

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,17 @@ cosim_execution* cosim_execution_create(
149149
cosim_duration stepSize);
150150

151151
/**
152-
* Creates an ecco algorithm
153-
* \param [in] ...
152+
* Creates an ecco algorithm with the specified parameters.
153+
* \param [in] safetyFactor Safety factor
154+
* \param [in] stepSize Initial step size
155+
* \param [in] minStepSize Minimum step size
156+
* \param [in] maxStepSize Maximum step size
157+
* \param [in] minChangeRate Minimum rate of change in step size
158+
* \param [in] maxChangeRate Maximum rate of change in step size
159+
* \param [in] absTolerance Absolute tolerance for deciding mismatch in the residual power
160+
* \param [in] relTolerance Relative tolerance for deciding mismatch in the residual power
161+
* \param [in] pGain Proportional value in the PI controller
162+
* \param [in] iGain Integral value in the PI controller
154163
* \returns A pointer to a new instance of cosim_algorithm
155164
*/
156165
cosim_algorithm* cosim_ecco_algorithm_create(
@@ -166,19 +175,25 @@ cosim_algorithm* cosim_ecco_algorithm_create(
166175
double iGain);
167176

168177
/**
169-
* Creates a power bond between models
170-
* \param [in] ...
178+
* Creates a power bond between two instances of models
179+
* \param [in] Ecco An algorithm instance
180+
* \param [in] index1 Slave index for the first model
181+
* \param [in] v1 The output of the first model
182+
* \param [in] u1 The input of the first model
183+
* \param [in] index2 Slave index Id for the second model
184+
* \param [in] v2 The output of the second model
185+
* \param [in] u2 The input of the second model
171186
* \returns
172187
* 0 on success and -1 on error.
173188
*/
174189
int cosim_ecco_add_power_bond(
175190
cosim_algorithm* algo,
176191
cosim_slave_index m1Index,
177-
cosim_value_reference u1,
178192
cosim_value_reference v1,
193+
cosim_value_reference u1,
179194
cosim_slave_index m2Index,
180-
cosim_value_reference u2,
181-
cosim_value_reference v2);
195+
cosim_value_reference v2,
196+
cosim_value_reference u2);
182197

183198
/**
184199
* Creates a fixed step algorithm

src/cosim.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -298,10 +298,10 @@ cosim_execution* cosim_osp_config_execution_create(
298298

299299
int cosim_ecco_add_power_bond(
300300
cosim_algorithm* algo,
301-
cosim_slave_index m1Index,
301+
cosim_slave_index index1,
302302
cosim_value_reference v1,
303303
cosim_value_reference u1,
304-
cosim_slave_index m2Index,
304+
cosim_slave_index index2,
305305
cosim_value_reference v2,
306306
cosim_value_reference u2)
307307
{
@@ -310,11 +310,11 @@ int cosim_ecco_add_power_bond(
310310
if (!ecco_algorithm) {
311311
throw std::invalid_argument("Invalid algorithm type. Expected ecco_algorithm.");
312312
}
313-
auto v1id = cosim::variable_id{m1Index, cosim::variable_type::real, v1};
314-
auto u1id = cosim::variable_id{m1Index, cosim::variable_type::real, u1};
315-
auto v2id = cosim::variable_id{m2Index, cosim::variable_type::real, v2};
316-
auto u2id = cosim::variable_id{m2Index, cosim::variable_type::real, u2};
317-
ecco_algorithm->add_power_bond(v1id, u2id, v2id, u2id);
313+
auto v1id = cosim::variable_id{index1, cosim::variable_type::real, v1};
314+
auto u1id = cosim::variable_id{index1, cosim::variable_type::real, u1};
315+
auto v2id = cosim::variable_id{index2, cosim::variable_type::real, v2};
316+
auto u2id = cosim::variable_id{index2, cosim::variable_type::real, u2};
317+
ecco_algorithm->add_power_bond(v1id, u1id, v2id, u2id);
318318
return success;
319319
} catch (...) {
320320
handle_current_exception();

tests/ecco_algorithm_multi_bond_test.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#include "mock_slaves/mock_slaves.h"
21
#include <cosim.h>
32

43
#include <math.h>
@@ -47,7 +46,8 @@ int main()
4746
double* cfi = NULL;
4847
double* wfo = NULL;
4948
cosim_time_point* times = NULL;
50-
cosim_step_number * steps = NULL;
49+
cosim_step_number* steps = NULL;
50+
double* diffs = NULL;
5151

5252
cosim_algorithm* ecco_algorithm = cosim_ecco_algorithm_create(
5353
0.8,
@@ -82,12 +82,11 @@ int main()
8282
cosim_slave_index wheelIndex = cosim_execution_add_slave(execution, wheel);
8383
if (wheelIndex < 0) { goto Lerror; }
8484

85-
8685
// IO connections
8786
cosim_value_reference chassisVelOut = 23;
88-
cosim_value_reference wheelVelIn = 7;
89-
cosim_value_reference wheelFOut = 15;
9087
cosim_value_reference chassisFIn = 4;
88+
cosim_value_reference wheelFOut = 15;
89+
cosim_value_reference wheelVelIn = 7;
9190

9291
rc = cosim_execution_connect_real_variables(execution, chassisIndex, chassisVelOut, wheelIndex, wheelVelIn);
9392
if (rc < 0) { goto Lerror; }
@@ -150,14 +149,16 @@ int main()
150149
if (samplesRead < 0) { goto Lerror; }
151150

152151
const float threshold = 1e-4f;
152+
diffs = (double*)malloc(nSamples * sizeof(double));
153+
size_t ptr = 0;
153154
for (int i = 1; i < nSamples; ++i) {
154-
// if (i > nSamples / 2 ) {
155-
// printf("%f, %f, %f, %f\n", cvo[i], cfi[i], wvi[i], wfo[i]);
156-
// printf("%f, %f\n", (cvo[i] * cfi[i]), (wvi[i] * wfo[i]));
157-
// }
158-
const double diff = fabs((cvo[i] * cfi[i]) + (wvi[i] * wfo[i]));
159-
if (diff > threshold) {
160-
fprintf(stderr, "Power bond mismatch at sample %d: %f\n", i, diff);
155+
diffs[ptr++] = fabs((cvo[i] * cfi[i]) - (wvi[i] * wfo[i]));;
156+
}
157+
158+
const size_t offset = 500;
159+
for (size_t i = (nSamples > offset ? nSamples - offset : 0); i < nSamples; i++) {
160+
if (diffs[i] > threshold) {
161+
fprintf(stderr, "Power bond mismatch at sample %lld: %f\n", i, diffs[i]);
161162
goto Lfailure;
162163
}
163164
}
@@ -180,6 +181,7 @@ int main()
180181
free(cfi);
181182
free(wfo);
182183
free(times);
184+
free(diffs);
183185

184186
return exitCode;
185187
}

0 commit comments

Comments
 (0)