motor_heating_model_test.cpp
Go to the documentation of this file.
00001 #include <gtest/gtest.h>
00002 #include <string.h>
00003 
00004 #include <boost/shared_ptr.hpp>
00005 #include <boost/make_shared.hpp>
00006 
00007 #include "ethercat_hardware/motor_heating_model.h"
00008 
00009 
00010 using ethercat_hardware::MotorHeatingModel;
00011 using ethercat_hardware::MotorHeatingModelParameters;
00012 using ethercat_hardware::MotorHeatingModelParametersEepromConfig;
00013 using ethercat_hardware::MotorHeatingModelCommon;
00014 
00015 
00016 
00021 MotorHeatingModelParameters casterMotorHeatingModelParams()
00022 {
00023   MotorHeatingModelParameters params;
00024   params.housing_to_ambient_thermal_resistance_ = 4.65;
00025   params.winding_to_housing_thermal_resistance_ = 1.93;
00026   params.winding_thermal_time_constant_         = 41.6;
00027   params.housing_thermal_time_constant_         = 1120.0;
00028   params.max_winding_temperature_               = 155.0;
00029   return params;
00030 }
00031 
00032 
00033 
00034 class UpdateFromDowntimeTest : public ::testing::Test
00035 {
00036 protected:
00037   virtual void SetUp()
00038   {
00039     // Motor params (for caster motor)
00040     MotorHeatingModelParameters params( casterMotorHeatingModelParams() );
00041     
00042     boost::shared_ptr<MotorHeatingModelCommon> common = boost::make_shared<MotorHeatingModelCommon>();
00043     common->load_save_files_   = false;
00044     common->update_save_files_ = false;
00045     common->save_directory_    = "/tmp/motor_heating_model";
00046     
00047     // Make two motor heating model objects
00048     model_1_ = boost::make_shared<MotorHeatingModel>(params, "motor_1", "hwid", "actuator_name");
00049     model_2_ = boost::make_shared<MotorHeatingModel>(params, "motor_2", "hwid", "actuator_name");
00050   }
00051 
00052 
00053 public:
00054 
00055   void runUpdate(int cycles, double amblient_temperature)
00056   {
00057     // Simulate each for model for same ammount of time
00058     double interval = 0.001; // 1ms
00059     double downtime = cycles * interval;
00060     double ambient_temperature = 30.0;
00061 
00062     // Sim first model with small timesteps
00063     static const double heating_power = 0.0;
00064     for (int i=0; i<cycles; ++i)
00065     {
00066       model_1_->update(heating_power, ambient_temperature, interval);
00067     }
00068     
00069     // Sim second with update function
00070     model_2_->updateFromDowntime(downtime, ambient_temperature);
00071   }
00072 
00073   boost::shared_ptr<MotorHeatingModel> model_1_;
00074   boost::shared_ptr<MotorHeatingModel> model_2_;
00075 };
00076 
00077 
00078 TEST_F(UpdateFromDowntimeTest, DowntimeUpdate10Seconds)
00079 {
00080   double ambient_temperature = 30.0;
00081   
00082   // Compare resulting temperatures (assert temperatures are within 0.1 degrees Celcius
00083 
00084   int cycles = 1000;
00085 
00086   for (int i=0; i<10; ++i)
00087   {
00088     runUpdate(cycles, ambient_temperature);
00089     EXPECT_TRUE(  std::abs(  model_1_->getWindingTemperature() - model_2_->getWindingTemperature() ) < 0.1 );
00090     EXPECT_TRUE(  std::abs(  model_1_->getHousingTemperature() - model_2_->getHousingTemperature() ) < 0.1 );
00091   }
00092 }
00093 
00094 
00095 TEST_F(UpdateFromDowntimeTest, DowntimeUpdate100Seconds)
00096 {
00097   int cycles = 100 * 1000;
00098   double ambient_temperature = 30.0;
00099   runUpdate(cycles, ambient_temperature);
00100   
00101   // Compare resulting temperatures (assert temperatures are within 0.1 degrees Celcius
00102   EXPECT_TRUE(  std::abs(  model_1_->getWindingTemperature() - model_2_->getWindingTemperature() ) < 0.1 );
00103   EXPECT_TRUE(  std::abs(  model_1_->getHousingTemperature() - model_2_->getHousingTemperature() ) < 0.1 );
00104 }
00105 
00106 
00107 TEST_F(UpdateFromDowntimeTest, DowntimeUpdate1000Seconds)
00108 {
00109   int cycles = 1000 * 1000;
00110   double ambient_temperature = 30.0;
00111   runUpdate(cycles, ambient_temperature);
00112   
00113   // Compare resulting temperatures (assert temperatures are within 0.1 degrees Celcius
00114   EXPECT_TRUE(  std::abs(  model_1_->getWindingTemperature() - model_2_->getWindingTemperature() ) < 0.1 );
00115   EXPECT_TRUE(  std::abs(  model_1_->getHousingTemperature() - model_2_->getHousingTemperature() ) < 0.1 );
00116 }
00117 
00118 
00119 TEST_F(UpdateFromDowntimeTest, DowntimeUpdate10000Seconds)
00120 {
00121   int cycles = 10000 * 1000;
00122   double ambient_temperature = 30.0;
00123   runUpdate(cycles, ambient_temperature);
00124   
00125   // Compare resulting temperatures (assert temperatures are within 0.1 degrees Celcius
00126   EXPECT_TRUE(  std::abs(  model_1_->getWindingTemperature() - model_2_->getWindingTemperature() ) < 0.1 );
00127   EXPECT_TRUE(  std::abs(  model_1_->getHousingTemperature() - model_2_->getHousingTemperature() ) < 0.1 );
00128 }
00129 
00130 
00131 
00132 TEST(MotorHeatingModelParametersEepromConfig, SelfConsistantCRC)
00133 {
00134   MotorHeatingModelParametersEepromConfig config;
00135   memset(&config, 0, sizeof(config));
00136   
00137   config.generateCRC();
00138   
00139   EXPECT_TRUE( config.verifyCRC() );  
00140 }
00141 
00142 
00143 
00144 
00145 // Run all the tests that were declared with TEST()
00146 int main(int argc, char **argv)
00147 {
00148   testing::InitGoogleTest(&argc, argv);
00149   return RUN_ALL_TESTS();
00150 }


ethercat_hardware
Author(s): Rob Wheeler , Derek King
autogenerated on Fri Aug 28 2015 12:09:44