Skip to content

Commit b16628e

Browse files
committed
Add comments to test cases
1 parent a60cdf7 commit b16628e

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

control_toolbox/test/pid_tests.cpp

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -469,51 +469,62 @@ TEST(CommandTest, integralOnlyTest)
469469

470470
// If initial error = 0, i-gain = 1, dt = 1
471471
cmd = pid.compute_command(-0.5, 1.0);
472-
// Then expect command = 0.0, since the integral contribution is calculated
473-
// with backwards Euler (i.e. it is calculated after the command is computed)
472+
// Then expect command = -0.5
474473
EXPECT_EQ(-0.5, cmd);
475474

476475
// If call again with same arguments
477476
cmd = pid.compute_command(-0.5, 1.0);
477+
// Then expect command = -1 (-0.5+(-0.5))
478478
EXPECT_EQ(-1.0, cmd);
479479

480480
// Call again with no error
481481
cmd = pid.compute_command(0.0, 1.0);
482+
// Then expect command = -1 (-1+0)
482483
EXPECT_EQ(-1.0, cmd);
483484

484485
// Double check that the integral contribution keep the previous command
485486
cmd = pid.compute_command(0.0, 1.0);
487+
// Then expect command = -1 (-1+0)
486488
EXPECT_EQ(-1.0, cmd);
487489

488490
// Finally call again with positive error to see if the command changes in the opposite direction
489491
cmd = pid.compute_command(1.0, 1.0);
492+
// Then expect command = 0 (-1+1)
490493
EXPECT_EQ(0.0, cmd);
491494

492-
// If initial error = 0, i-gain = 1, dt = 1
493-
cmd = pid.compute_command(0.0, 1.0);
494-
EXPECT_EQ(0.0, cmd);
495+
cmd = pid.compute_command(-0.5, 1.0);
496+
// Then expect command = -0.5 (0+(-0.5))
497+
EXPECT_EQ(-0.5, cmd);
498+
495499
// after reset without argument (save_i_term=false)
496500
// we expect the command to be 0 if update is called error = 0
497501
pid.reset();
498502
cmd = pid.compute_command(0.0, 1.0);
503+
// Then expect command = 0
499504
EXPECT_EQ(0.0, cmd);
500505

501506
// If initial error = 0, i-gain = 1, dt = 1
502507
cmd = pid.compute_command(-0.5, 1.0);
508+
// Then expect command = -0.5
503509
EXPECT_EQ(-0.5, cmd);
510+
504511
// after reset with argument (save_i_term=false)
505512
// we expect the command to be 0 if update is called error = 0
506513
pid.reset(false);
507-
cmd = pid.compute_command(-0.5, 1.0);
508-
EXPECT_EQ(-0.5, cmd);
514+
cmd = pid.compute_command(0.0, 1.0);
515+
// Then expect command = 0.0 since it was reset
516+
EXPECT_EQ(0.0, cmd);
509517

510518
// If initial error = 0, i-gain = 1, dt = 1
511-
cmd = pid.compute_command(0.0, 1.0);
519+
cmd = pid.compute_command(-0.5, 1.0);
520+
// Then expect command = -0.5 (-0.5+0)
512521
EXPECT_EQ(-0.5, cmd);
522+
513523
// after reset with save_i_term=true
514524
// we expect still the same command if update is called error = 0
515525
pid.reset(true);
516526
cmd = pid.compute_command(0.0, 1.0);
527+
// Then expect command = -0.5 since reset was called with save_i_term=true
517528
EXPECT_EQ(-0.5, cmd);
518529
}
519530

0 commit comments

Comments
 (0)