Skip to content

Commit

Permalink
Fix flaky transmission_interface tests by making them deterministic. …
Browse files Browse the repository at this point in the history
…(backport #1665) (#1670)
  • Loading branch information
mergify[bot] authored Aug 14, 2024
1 parent 0af922d commit 8a3ac66
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ inline void FourBarLinkageTransmission::actuator_to_joint()

joint_eff[0].set_value(jr[0] * act_eff[0].get_value() * ar[0]);
joint_eff[1].set_value(
jr[1] * (act_eff[1].get_value() * ar[1] - act_eff[0].get_value() * ar[0] * jr[0]));
jr[1] * (act_eff[1].get_value() * ar[1] - jr[0] * act_eff[0].get_value() * ar[0]));
}
}

Expand Down
6 changes: 4 additions & 2 deletions transmission_interface/test/random_generator_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ using std::vector;
/// \brief Generator of pseudo-random double in the range [min_val, max_val].
// NOTE: Based on example code available at:
// http://stackoverflow.com/questions/2860673/initializing-a-c-vector-to-random-values-fast
// Use a user specified seed instead of system time for deterministic tests
struct RandomDoubleGenerator
{
public:
RandomDoubleGenerator(double min_val, double max_val) : min_val_(min_val), max_val_(max_val)
RandomDoubleGenerator(double min_val, double max_val, unsigned int seed = 1234)
: min_val_(min_val), max_val_(max_val)
{
srand(time(nullptr));
srand(seed);
}
double operator()()
{
Expand Down

0 comments on commit 8a3ac66

Please sign in to comment.