16 #include <gtest/gtest.h> 21 const std::string& description)
23 std::stringstream stream;
24 stream <<
"<sdf version='" << SDF_VERSION <<
"'>" << std::endl
25 <<
"<model name='test_model'>" << std::endl
26 <<
"<plugin name='test_plugin' filename='test_file.so'>" << std::endl
28 <<
"</plugin>" << std::endl
29 <<
"</model>" << std::endl
30 <<
"</sdf>" << std::endl;
33 sdfParsed.SetFromString(stream.str());
35 sdf::ElementPtr dynSdf = sdfParsed.Root()->GetElement(
"model")
36 ->GetElement(
"plugin")->GetElement(
"dynamics");
38 std::shared_ptr<gazebo::Dynamics> dyn;
40 CreateDynamics(dynSdf));
45 TEST(ThrusterDynamics, ZeroOrder)
47 std::string description =
49 " <type>ZeroOrder</type> \n" 52 std::shared_ptr<gazebo::Dynamics> dyn;
55 EXPECT_TRUE(dyn != NULL);
56 EXPECT_EQ(dyn->GetType(),
"ZeroOrder");
58 EXPECT_EQ(10.0, dyn->update(10.0, 0.0));
59 EXPECT_EQ(20.0, dyn->update(20.0, 0.2));
62 TEST(ThrusterDynamics, FirstOrder)
64 std::string description =
66 " <type>FirstOrder</type>\n" 67 " <timeConstant>0.5</timeConstant>\n" 70 std::shared_ptr<gazebo::Dynamics> dyn;
73 EXPECT_TRUE(dyn != NULL);
74 EXPECT_EQ(dyn->GetType(),
"FirstOrder");
75 EXPECT_EQ(0.0, dyn->update(0.0, 0));
76 EXPECT_NEAR(1-0.36787944, dyn->update(1.0, 0.5), 1e-5);
79 TEST(ThrusterDynamics, Yoerger)
81 std::string description =
83 " <type>Yoerger</type>\n" 84 " <alpha>0.5</alpha>\n" 88 std::shared_ptr<gazebo::Dynamics> dyn;
91 EXPECT_TRUE(dyn != NULL);
92 EXPECT_EQ(dyn->GetType(),
"Yoerger");
93 EXPECT_EQ(0.0, dyn->update(0.0, 0));
97 TEST(ThrusterDynamics, Bessa)
99 std::string description =
101 " <type>Bessa</type>\n" 102 " <Jmsp>0.5</Jmsp>\n" 109 std::shared_ptr<gazebo::Dynamics> dyn;
112 EXPECT_TRUE(dyn != NULL);
113 EXPECT_EQ(dyn->GetType(),
"Bessa");
114 EXPECT_EQ(0.0, dyn->update(0.0, 0));
119 int main(
int argc,
char **argv)
121 testing::InitGoogleTest(&argc, argv);
122 return RUN_ALL_TESTS();
std::shared_ptr< gazebo::Dynamics > DynamicsFromString(const std::string &description)
TEST(ThrusterDynamics, ZeroOrder)
static DynamicsFactory & GetInstance()
Returns the singleton instance of this factory.
int main(int argc, char **argv)