motor_heating_model_test.cpp
Go to the documentation of this file.
1 #include <gtest/gtest.h>
2 #include <string.h>
3 
4 #include <boost/shared_ptr.hpp>
5 #include <boost/make_shared.hpp>
6 
8 
9 
14 
15 
16 
22 {
26  params.winding_thermal_time_constant_ = 41.6;
27  params.housing_thermal_time_constant_ = 1120.0;
28  params.max_winding_temperature_ = 155.0;
29  return params;
30 }
31 
32 
33 
34 class UpdateFromDowntimeTest : public ::testing::Test
35 {
36 protected:
37  virtual void SetUp()
38  {
39  // Motor params (for caster motor)
41 
42  boost::shared_ptr<MotorHeatingModelCommon> common = boost::make_shared<MotorHeatingModelCommon>();
43  common->load_save_files_ = false;
44  common->update_save_files_ = false;
45  common->save_directory_ = "/tmp/motor_heating_model";
46 
47  // Make two motor heating model objects
48  model_1_ = boost::make_shared<MotorHeatingModel>(params, "motor_1", "hwid", "actuator_name");
49  model_2_ = boost::make_shared<MotorHeatingModel>(params, "motor_2", "hwid", "actuator_name");
50  }
51 
52 
53 public:
54 
55  void runUpdate(int cycles, double amblient_temperature)
56  {
57  // Simulate each for model for same ammount of time
58  double interval = 0.001; // 1ms
59  double downtime = cycles * interval;
60  double ambient_temperature = 30.0;
61 
62  // Sim first model with small timesteps
63  static const double heating_power = 0.0;
64  for (int i=0; i<cycles; ++i)
65  {
66  model_1_->update(heating_power, ambient_temperature, interval);
67  }
68 
69  // Sim second with update function
70  model_2_->updateFromDowntime(downtime, ambient_temperature);
71  }
72 
75 };
76 
77 
78 TEST_F(UpdateFromDowntimeTest, DowntimeUpdate10Seconds)
79 {
80  double ambient_temperature = 30.0;
81 
82  // Compare resulting temperatures (assert temperatures are within 0.1 degrees Celcius
83 
84  int cycles = 1000;
85 
86  for (int i=0; i<10; ++i)
87  {
88  runUpdate(cycles, ambient_temperature);
89  EXPECT_TRUE( std::abs( model_1_->getWindingTemperature() - model_2_->getWindingTemperature() ) < 0.1 );
90  EXPECT_TRUE( std::abs( model_1_->getHousingTemperature() - model_2_->getHousingTemperature() ) < 0.1 );
91  }
92 }
93 
94 
95 TEST_F(UpdateFromDowntimeTest, DowntimeUpdate100Seconds)
96 {
97  int cycles = 100 * 1000;
98  double ambient_temperature = 30.0;
99  runUpdate(cycles, ambient_temperature);
100 
101  // Compare resulting temperatures (assert temperatures are within 0.1 degrees Celcius
102  EXPECT_TRUE( std::abs( model_1_->getWindingTemperature() - model_2_->getWindingTemperature() ) < 0.1 );
103  EXPECT_TRUE( std::abs( model_1_->getHousingTemperature() - model_2_->getHousingTemperature() ) < 0.1 );
104 }
105 
106 
107 TEST_F(UpdateFromDowntimeTest, DowntimeUpdate1000Seconds)
108 {
109  int cycles = 1000 * 1000;
110  double ambient_temperature = 30.0;
111  runUpdate(cycles, ambient_temperature);
112 
113  // Compare resulting temperatures (assert temperatures are within 0.1 degrees Celcius
114  EXPECT_TRUE( std::abs( model_1_->getWindingTemperature() - model_2_->getWindingTemperature() ) < 0.1 );
115  EXPECT_TRUE( std::abs( model_1_->getHousingTemperature() - model_2_->getHousingTemperature() ) < 0.1 );
116 }
117 
118 
119 TEST_F(UpdateFromDowntimeTest, DowntimeUpdate10000Seconds)
120 {
121  int cycles = 10000 * 1000;
122  double ambient_temperature = 30.0;
123  runUpdate(cycles, ambient_temperature);
124 
125  // Compare resulting temperatures (assert temperatures are within 0.1 degrees Celcius
126  EXPECT_TRUE( std::abs( model_1_->getWindingTemperature() - model_2_->getWindingTemperature() ) < 0.1 );
127  EXPECT_TRUE( std::abs( model_1_->getHousingTemperature() - model_2_->getHousingTemperature() ) < 0.1 );
128 }
129 
130 
131 
133 {
135  memset(&config, 0, sizeof(config));
136 
137  config.generateCRC();
138 
139  EXPECT_TRUE( config.verifyCRC() );
140 }
141 
142 
143 
144 
145 // Run all the tests that were declared with TEST()
146 int main(int argc, char **argv)
147 {
148  testing::InitGoogleTest(&argc, argv);
149  return RUN_ALL_TESTS();
150 }
double winding_thermal_time_constant_
Thermal time constant of motor winding : in seconds.
TEST(MotorHeatingModelParametersEepromConfig, SelfConsistantCRC)
TEST_F(UpdateFromDowntimeTest, DowntimeUpdate10Seconds)
MotorHeatingModelParameters casterMotorHeatingModelParams()
boost::shared_ptr< MotorHeatingModel > model_2_
double winding_to_housing_thermal_resistance_
Thermal resistance between motor winding and motor housing : in C/Watt.
void runUpdate(int cycles, double amblient_temperature)
double housing_thermal_time_constant_
Thermal time constant of motor housing : in seconds.
int main(int argc, char **argv)
double max_winding_temperature_
temperature limit of motor windings : in Celcius
boost::shared_ptr< MotorHeatingModel > model_1_
double housing_to_ambient_thermal_resistance_
Thermal resistance between motor housing and ambient : in C/Watt.


ethercat_hardware
Author(s): Rob Wheeler , Derek King
autogenerated on Thu Mar 4 2021 03:10:21