ThrusterDynamics_TEST.cc
Go to the documentation of this file.
1 // Copyright (c) 2016 The UUV Simulator Authors.
2 // All rights reserved.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #include <gtest/gtest.h>
17 
19 
20 std::shared_ptr<gazebo::Dynamics> DynamicsFromString(
21  const std::string& description)
22 {
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
27  << description
28  << "</plugin>" << std::endl
29  << "</model>" << std::endl
30  << "</sdf>" << std::endl;
31 
32  sdf::SDF sdfParsed;
33  sdfParsed.SetFromString(stream.str());
34 
35  sdf::ElementPtr dynSdf = sdfParsed.Root()->GetElement("model")
36  ->GetElement("plugin")->GetElement("dynamics");
37 
38  std::shared_ptr<gazebo::Dynamics> dyn;
40  CreateDynamics(dynSdf));
41 
42  return dyn;
43 }
44 
45 TEST(ThrusterDynamics, ZeroOrder)
46 {
47  std::string description =
48  "<dynamics> \n"
49  " <type>ZeroOrder</type> \n"
50  "</dynamics>";
51 
52  std::shared_ptr<gazebo::Dynamics> dyn;
53  dyn = DynamicsFromString(description);
54 
55  EXPECT_TRUE(dyn != NULL);
56  EXPECT_EQ(dyn->GetType(), "ZeroOrder");
57 
58  EXPECT_EQ(10.0, dyn->update(10.0, 0.0));
59  EXPECT_EQ(20.0, dyn->update(20.0, 0.2));
60 }
61 
62 TEST(ThrusterDynamics, FirstOrder)
63 {
64  std::string description =
65  "<dynamics>\n"
66  " <type>FirstOrder</type>\n"
67  " <timeConstant>0.5</timeConstant>\n"
68  "</dynamics>";
69 
70  std::shared_ptr<gazebo::Dynamics> dyn;
71  dyn = DynamicsFromString(description);
72 
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);
77 }
78 
79 TEST(ThrusterDynamics, Yoerger)
80 {
81  std::string description =
82  "<dynamics> \n"
83  " <type>Yoerger</type>\n"
84  " <alpha>0.5</alpha>\n"
85  " <beta>0.5</beta>\n"
86  "</dynamics>";
87 
88  std::shared_ptr<gazebo::Dynamics> dyn;
89  dyn = DynamicsFromString(description);
90 
91  EXPECT_TRUE(dyn != NULL);
92  EXPECT_EQ(dyn->GetType(), "Yoerger");
93  EXPECT_EQ(0.0, dyn->update(0.0, 0));
94  // TODO: Actually test dynamic behavior
95 }
96 
97 TEST(ThrusterDynamics, Bessa)
98 {
99  std::string description =
100  "<dynamics> \n"
101  " <type>Bessa</type>\n"
102  " <Jmsp>0.5</Jmsp>\n"
103  " <Kv1>0.5</Kv1>\n"
104  " <Kv2>0.5</Kv2>\n"
105  " <Kt>0.5</Kt>\n"
106  " <Rm>0.5</Rm>\n"
107  "</dynamics>";
108 
109  std::shared_ptr<gazebo::Dynamics> dyn;
110  dyn = DynamicsFromString(description);
111 
112  EXPECT_TRUE(dyn != NULL);
113  EXPECT_EQ(dyn->GetType(), "Bessa");
114  EXPECT_EQ(0.0, dyn->update(0.0, 0));
115  // TODO: Actually test dynamic behavior
116 }
117 
118 
119 int main(int argc, char **argv)
120 {
121  testing::InitGoogleTest(&argc, argv);
122  return RUN_ALL_TESTS();
123 }
std::shared_ptr< gazebo::Dynamics > DynamicsFromString(const std::string &description)
1D dynamic models
TEST(ThrusterDynamics, ZeroOrder)
static DynamicsFactory & GetInstance()
Returns the singleton instance of this factory.
Definition: Dynamics.cc:52
int main(int argc, char **argv)


uuv_gazebo_plugins
Author(s): Musa Morena Marcusso Manhaes , Sebastian Scherer , Luiz Ricardo Douat
autogenerated on Thu Jun 18 2020 03:28:24