Skip to content

Commit

Permalink
Fix flaky transmission_interface tests by making them deterministic. (r…
Browse files Browse the repository at this point in the history
  • Loading branch information
sgmurray authored Aug 13, 2024
1 parent a1ad523 commit ace8416
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 @@ -289,7 +289,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(static_cast<unsigned int>(time(nullptr)));
srand(seed);
}
double operator()()
{
Expand Down

0 comments on commit ace8416

Please sign in to comment.