@@ -80,11 +80,11 @@ TEST(ParameterTest, integrationClampTest)
80
80
double cmd = 0.0 ;
81
81
82
82
// Test lower limit
83
- cmd = pid.computeCommand (-10.03 , 1.0 * 1e9 );
83
+ cmd = pid.computeCommand (-10.03 , static_cast < uint64_t >( 1.0 * 1e9 ) );
84
84
EXPECT_EQ (-1.0 , cmd);
85
85
86
86
// Test upper limit
87
- cmd = pid.computeCommand (30.0 , 1.0 * 1e9 );
87
+ cmd = pid.computeCommand (30.0 , static_cast < uint64_t >( 1.0 * 1e9 ) );
88
88
EXPECT_EQ (1.0 , cmd);
89
89
}
90
90
@@ -104,13 +104,13 @@ TEST(ParameterTest, integrationClampZeroGainTest)
104
104
double cmd = 0.0 ;
105
105
double pe, ie, de;
106
106
107
- cmd = pid.computeCommand (-1.0 , 1.0 * 1e9 );
107
+ cmd = pid.computeCommand (-1.0 , static_cast < uint64_t >( 1.0 * 1e9 ) );
108
108
pid.getCurrentPIDErrors (pe, ie, de);
109
109
EXPECT_LE (i_min, cmd);
110
110
EXPECT_LE (cmd, i_max);
111
111
EXPECT_EQ (0.0 , cmd);
112
112
113
- cmd = pid.computeCommand (-1.0 , 1.0 * 1e9 );
113
+ cmd = pid.computeCommand (-1.0 , static_cast < uint64_t >( 1.0 * 1e9 ) );
114
114
EXPECT_LE (i_min, cmd);
115
115
EXPECT_LE (cmd, i_max);
116
116
EXPECT_EQ (0.0 , cmd);
@@ -129,16 +129,16 @@ TEST(ParameterTest, integrationAntiwindupTest)
129
129
130
130
double cmd = 0.0 ;
131
131
132
- cmd = pid.computeCommand (-1.0 , 1.0 * 1e9 );
132
+ cmd = pid.computeCommand (-1.0 , static_cast < uint64_t >( 1.0 * 1e9 ) );
133
133
EXPECT_EQ (-1.0 , cmd);
134
134
135
- cmd = pid.computeCommand (-1.0 , 1.0 * 1e9 );
135
+ cmd = pid.computeCommand (-1.0 , static_cast < uint64_t >( 1.0 * 1e9 ) );
136
136
EXPECT_EQ (-1.0 , cmd);
137
137
138
- cmd = pid.computeCommand (0.5 , 1.0 * 1e9 );
138
+ cmd = pid.computeCommand (0.5 , static_cast < uint64_t >( 1.0 * 1e9 ) );
139
139
EXPECT_EQ (0.0 , cmd);
140
140
141
- cmd = pid.computeCommand (-1.0 , 1.0 * 1e9 );
141
+ cmd = pid.computeCommand (-1.0 , static_cast < uint64_t >( 1.0 * 1e9 ) );
142
142
EXPECT_EQ (-1.0 , cmd);
143
143
}
144
144
@@ -155,16 +155,16 @@ TEST(ParameterTest, negativeIntegrationAntiwindupTest)
155
155
156
156
double cmd = 0.0 ;
157
157
158
- cmd = pid.computeCommand (0.1 , 1.0 * 1e9 );
158
+ cmd = pid.computeCommand (0.1 , static_cast < uint64_t >( 1.0 * 1e9 ) );
159
159
EXPECT_EQ (-0.2 , cmd);
160
160
161
- cmd = pid.computeCommand (0.1 , 1.0 * 1e9 );
161
+ cmd = pid.computeCommand (0.1 , static_cast < uint64_t >( 1.0 * 1e9 ) );
162
162
EXPECT_EQ (-0.2 , cmd);
163
163
164
- cmd = pid.computeCommand (-0.05 , 1.0 * 1e9 );
164
+ cmd = pid.computeCommand (-0.05 , static_cast < uint64_t >( 1.0 * 1e9 ) );
165
165
EXPECT_EQ (-0.075 , cmd);
166
166
167
- cmd = pid.computeCommand (0.1 , 1.0 * 1e9 );
167
+ cmd = pid.computeCommand (0.1 , static_cast < uint64_t >( 1.0 * 1e9 ) );
168
168
EXPECT_EQ (-0.2 , cmd);
169
169
}
170
170
@@ -223,7 +223,7 @@ TEST(ParameterTest, gainSettingCopyPIDTest)
223
223
224
224
// Send update command to populate errors -------------------------------------------------
225
225
pid1.setCurrentCmd (10 );
226
- (void ) pid1.computeCommand (20 , 1.0 * 1e9 );
226
+ (void ) pid1.computeCommand (20 , static_cast < uint64_t >( 1.0 * 1e9 ) );
227
227
228
228
// Test copy constructor -------------------------------------------------
229
229
Pid pid2 (pid1);
@@ -291,22 +291,22 @@ TEST(CommandTest, proportionalOnlyTest)
291
291
double cmd = 0.0 ;
292
292
293
293
// If initial error = 0, p-gain = 1, dt = 1
294
- cmd = pid.computeCommand (-0.5 , 1.0 * 1e9 );
294
+ cmd = pid.computeCommand (-0.5 , static_cast < uint64_t >( 1.0 * 1e9 ) );
295
295
// Then expect command = error
296
296
EXPECT_EQ (-0.5 , cmd);
297
297
298
298
// If call again
299
- cmd = pid.computeCommand (-0.5 , 1.0 * 1e9 );
299
+ cmd = pid.computeCommand (-0.5 , static_cast < uint64_t >( 1.0 * 1e9 ) );
300
300
// Then expect the same as before
301
301
EXPECT_EQ (-0.5 , cmd);
302
302
303
303
// If call again doubling the error
304
- cmd = pid.computeCommand (-1.0 , 1.0 * 1e9 );
304
+ cmd = pid.computeCommand (-1.0 , static_cast < uint64_t >( 1.0 * 1e9 ) );
305
305
// Then expect the command doubled
306
306
EXPECT_EQ (-1.0 , cmd);
307
307
308
308
// If call with positive error
309
- cmd = pid.computeCommand (0.5 , 1.0 * 1e9 );
309
+ cmd = pid.computeCommand (0.5 , static_cast < uint64_t >( 1.0 * 1e9 ) );
310
310
// Then expect always command = error
311
311
EXPECT_EQ (0.5 , cmd);
312
312
}
@@ -323,26 +323,26 @@ TEST(CommandTest, integralOnlyTest)
323
323
double cmd = 0.0 ;
324
324
325
325
// If initial error = 0, i-gain = 1, dt = 1
326
- cmd = pid.computeCommand (-0.5 , 1.0 * 1e9 );
326
+ cmd = pid.computeCommand (-0.5 , static_cast < uint64_t >( 1.0 * 1e9 ) );
327
327
// Then expect command = error
328
328
EXPECT_EQ (-0.5 , cmd);
329
329
330
330
// If call again with same arguments
331
- cmd = pid.computeCommand (-0.5 , 1.0 * 1e9 );
331
+ cmd = pid.computeCommand (-0.5 , static_cast < uint64_t >( 1.0 * 1e9 ) );
332
332
// Then expect the integral part to double the command
333
333
EXPECT_EQ (-1.0 , cmd);
334
334
335
335
// Call again with no error
336
- cmd = pid.computeCommand (0.0 , 1.0 * 1e9 );
336
+ cmd = pid.computeCommand (0.0 , static_cast < uint64_t >( 1.0 * 1e9 ) );
337
337
// Expect the integral part to keep the previous command because it ensures error = 0
338
338
EXPECT_EQ (-1.0 , cmd);
339
339
340
340
// Double check that the integral contribution keep the previous command
341
- cmd = pid.computeCommand (0.0 , 1.0 * 1e9 );
341
+ cmd = pid.computeCommand (0.0 , static_cast < uint64_t >( 1.0 * 1e9 ) );
342
342
EXPECT_EQ (-1.0 , cmd);
343
343
344
344
// Finally call again with positive error to see if the command changes in the opposite direction
345
- cmd = pid.computeCommand (1.0 , 1.0 * 1e9 );
345
+ cmd = pid.computeCommand (1.0 , static_cast < uint64_t >( 1.0 * 1e9 ) );
346
346
// Expect that the command is cleared since error = -1 * previous command, i-gain = 1, dt = 1
347
347
EXPECT_EQ (0.0 , cmd);
348
348
}
@@ -359,27 +359,27 @@ TEST(CommandTest, derivativeOnlyTest)
359
359
double cmd = 0.0 ;
360
360
361
361
// If initial error = 0, d-gain = 1, dt = 1
362
- cmd = pid.computeCommand (-0.5 , 1.0 * 1e9 );
362
+ cmd = pid.computeCommand (-0.5 , static_cast < uint64_t >( 1.0 * 1e9 ) );
363
363
// Then expect command = error
364
364
EXPECT_EQ (-0.5 , cmd);
365
365
366
366
// If call again with same error
367
- cmd = pid.computeCommand (-0.5 , 1.0 * 1e9 );
367
+ cmd = pid.computeCommand (-0.5 , static_cast < uint64_t >( 1.0 * 1e9 ) );
368
368
// Then expect command = 0 due to no variation on error
369
369
EXPECT_EQ (0.0 , cmd);
370
370
371
371
// If call again with same error and smaller control period
372
- cmd = pid.computeCommand (-0.5 , 0.1 * 1e9 );
372
+ cmd = pid.computeCommand (-0.5 , static_cast < uint64_t >( 0.1 * 1e9 ) );
373
373
// Then expect command = 0 again
374
374
EXPECT_EQ (0.0 , cmd);
375
375
376
376
// If the error increases, with dt = 1
377
- cmd = pid.computeCommand (-1.0 , 1.0 * 1e9 );
377
+ cmd = pid.computeCommand (-1.0 , static_cast < uint64_t >( 1.0 * 1e9 ) );
378
378
// Then expect the command = change in dt
379
379
EXPECT_EQ (-0.5 , cmd);
380
380
381
381
// If error decreases, with dt = 1
382
- cmd = pid.computeCommand (-0.5 , 1.0 * 1e9 );
382
+ cmd = pid.computeCommand (-0.5 , static_cast < uint64_t >( 1.0 * 1e9 ) );
383
383
// Then expect always the command = change in dt (note the sign flip)
384
384
EXPECT_EQ (0.5 , cmd);
385
385
}
@@ -396,17 +396,17 @@ TEST(CommandTest, completePIDTest)
396
396
397
397
// All contributions are tested, here few tests check that they sum up correctly
398
398
// If initial error = 0, all gains = 1, dt = 1
399
- cmd = pid.computeCommand (-0.5 , 1.0 * 1e9 );
399
+ cmd = pid.computeCommand (-0.5 , static_cast < uint64_t >( 1.0 * 1e9 ) );
400
400
// Then expect command = 3x error
401
401
EXPECT_EQ (-1.5 , cmd);
402
402
403
403
// If call again with same arguments, no error change, but integration do its part
404
- cmd = pid.computeCommand (-0.5 , 1.0 * 1e9 );
404
+ cmd = pid.computeCommand (-0.5 , static_cast < uint64_t >( 1.0 * 1e9 ) );
405
405
// Then expect command = 3x error again
406
406
EXPECT_EQ (-1.5 , cmd);
407
407
408
408
// If call again increasing the error
409
- cmd = pid.computeCommand (-1.0 , 1.0 * 1e9 );
409
+ cmd = pid.computeCommand (-1.0 , static_cast < uint64_t >( 1.0 * 1e9 ) );
410
410
// Then expect command equals to p = -1, i = -2.0 (i.e. - 0.5 - 0.5 - 1.0), d = -0.5
411
411
EXPECT_EQ (-3.5 , cmd);
412
412
}
0 commit comments