motor_updater_test.cpp
Go to the documentation of this file.
1 
28 #include <gtest/gtest.h>
29 #include <vector>
30 
31 #define COMMAND_TYPE ETHERCAT_DATA_STRUCTURE_0230_PALM_EDC_COMMAND
32 
34 {
38 };
39 
41 {
42 public:
44  {
45  }
46 
48  {
49  }
50 
51  UpdaterResult check_updates(double tolerancy)
52  {
53  std::vector<generic_updater::UpdateConfig> update_configs_vector;
54 
57  test.when_to_update = -1.0;
58  update_configs_vector.push_back(test);
59 
62  test2.when_to_update = 5.0;
63  update_configs_vector.push_back(test2);
64 
67  test3.when_to_update = 1.0;
68  update_configs_vector.push_back(test3);
69 
71  update_configs_vector, operation_mode::device_update_state::OPERATION);
72 
74  motor_updater.build_command(command);
75 
76  bool git_transmitted = false;
77  bool git_transmitted_once = false;
78 
80  int can_num_transmitted_counter_on_time = 0;
81 
83  ros::Duration time_spent(0.0);
84  ros::Rate r(1000);
85 
86  while (time_spent.toSec() < 7.2)
87  {
88  ros::spinOnce();
89  motor_updater.build_command(command);
90 
91  time_spent = ros::Time::now() - start;
92 
93  if (fabs(time_spent.toSec() - test2.when_to_update) < tolerancy)
94  {
95  if (command->from_motor_data_type == MOTOR_DATA_VOLTAGE)
96  {
97  ROS_INFO_STREAM("Correct data received at time : " << time_spent);
98  git_transmitted = true;
99 
100  if (git_transmitted_once)
101  {
102  git_transmitted_once = false;
103  }
104  else
105  {
106  git_transmitted_once = true;
107  }
108  }
109  }
110 
111  if (command->from_motor_data_type == MOTOR_DATA_CAN_NUM_RECEIVED)
112  {
113  can_num_transmitted_counter++;
114  if (fabs(time_spent.toSec() - (can_num_transmitted_counter * test3.when_to_update)) < tolerancy)
115  {
116  ROS_INFO_STREAM("CAN data received at correct time: " << time_spent);
117  can_num_transmitted_counter_on_time++;
118  }
119  else
120  {
121  ROS_INFO_STREAM("CAN data received too early or too late at time: " << time_spent);
122  }
123  }
124  r.sleep();
125  }
126 
127  UpdaterResult updater_result;
128  updater_result.git_transmitted = git_transmitted;
130  updater_result.can_num_transmitted_counter = can_num_transmitted_counter_on_time;
131 
132  delete command;
133 
134  return updater_result;
135  }
136 };
137 
138 TEST(Utils, motor_updater_freq_low_tolerancy)
139 {
141  UpdaterResult updater_result = mut.check_updates(0.010);
142 
143  EXPECT_TRUE(updater_result.git_transmitted);
144  EXPECT_TRUE(updater_result.git_transmitted_once);
145 
146  EXPECT_EQ(updater_result.can_num_transmitted_counter, 7);
147 }
148 
149 TEST(Utils, motor_updater_freq_medium_tolerancy)
150 {
152  UpdaterResult updater_result = mut.check_updates(0.05);
153 
154  EXPECT_TRUE(updater_result.git_transmitted);
155  EXPECT_TRUE(updater_result.git_transmitted_once);
156 
157  EXPECT_EQ(updater_result.can_num_transmitted_counter, 7);
158 }
159 
160 TEST(Utils, motor_updater_freq_high_tolerancy)
161 {
163  UpdaterResult updater_result = mut.check_updates(0.1);
164 
165  EXPECT_TRUE(updater_result.git_transmitted);
166  EXPECT_TRUE(updater_result.git_transmitted_once);
167 
168  EXPECT_EQ(updater_result.can_num_transmitted_counter, 7);
169 }
170 
171 
172 int main(int argc, char **argv)
173 {
174  ros::init(argc, argv, "sr_edc_ethercat_drivers_test");
175  ros::start();
176 
177  testing::InitGoogleTest(&argc, argv);
178  return RUN_ALL_TESTS();
179 }
180 
181 /* For the emacs weenies in the crowd.
182  Local Variables:
183  c-basic-offset: 2
184  End:
185 */
ROSCPP_DECL void start()
UpdaterResult check_updates(double tolerancy)
TEST(Utils, motor_updater_freq_low_tolerancy)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
MOTOR_DATA_SGL
operation_mode::device_update_state::DeviceUpdateState build_command(CommandType *command)
MOTOR_DATA_CAN_NUM_RECEIVED
ROSLIB_DECL std::string command(const std::string &cmd)
MOTOR_DATA_VOLTAGE
#define COMMAND_TYPE
bool sleep()
#define ROS_INFO_STREAM(args)
int main(int argc, char **argv)
static Time now()
ROSCPP_DECL void spinOnce()


sr_robot_lib
Author(s): Ugo Cupcic, Toni Oliver
autogenerated on Mon Feb 28 2022 23:50:43