|
19 | 19 |
|
20 | 20 | #include "gz/sim/EntityComponentManager.hh"
|
21 | 21 | #include "gz/sim/Link.hh"
|
| 22 | +#include "gz/sim/Util.hh" |
| 23 | +#include "gz/sim/components/AngularVelocity.hh" |
| 24 | +#include "gz/sim/components/LinearVelocity.hh" |
22 | 25 | #include "gz/sim/components/Link.hh"
|
| 26 | +#include "gz/sim/components/Model.hh" |
23 | 27 | #include "gz/sim/components/Name.hh"
|
24 | 28 | #include "gz/sim/components/ParentEntity.hh"
|
| 29 | +#include "gz/sim/components/Pose.hh" |
25 | 30 | #include "gz/sim/components/Sensor.hh"
|
26 | 31 |
|
27 | 32 | /////////////////////////////////////////////////
|
@@ -139,3 +144,67 @@ TEST(LinkTest, Sensors)
|
139 | 144 | EXPECT_EQ(0u, linkC.Sensors(ecm).size());
|
140 | 145 | EXPECT_EQ(gz::sim::kNullEntity, linkC.SensorByName(ecm, "invalid"));
|
141 | 146 | }
|
| 147 | + |
| 148 | +TEST(LinkTest, EnableVelocityChecksCreatesAdequateWorldComponents) |
| 149 | +{ |
| 150 | + gz::sim::EntityComponentManager ecm; |
| 151 | + |
| 152 | + gz::math::Pose3d modelWorldPose(-1.2, -3.4, -5.6, 0.1, 0.2, 0.3); |
| 153 | + gz::math::Vector3d linkWorldLinvel(0.1, 0.2, -0.3); |
| 154 | + gz::math::Vector3d linkWorldAngvel(0.04, -0.05, 0.06); |
| 155 | + |
| 156 | + auto bodyLinvel = modelWorldPose.Rot().RotateVectorReverse(linkWorldLinvel); |
| 157 | + auto bodyAngvel = modelWorldPose.Rot().RotateVectorReverse(linkWorldAngvel); |
| 158 | + |
| 159 | + // Create a model with a child link |
| 160 | + gz::sim::Entity modelEntity = ecm.CreateEntity(); |
| 161 | + |
| 162 | + ecm.CreateComponent(modelEntity, |
| 163 | + gz::sim::components::Model()); |
| 164 | + ecm.CreateComponent(modelEntity, |
| 165 | + gz::sim::components::Name("model_name")); |
| 166 | + ecm.CreateComponent(modelEntity, |
| 167 | + gz::sim::components::Pose(modelWorldPose)); |
| 168 | + |
| 169 | + gz::sim::Entity linkEntity = ecm.CreateEntity(); |
| 170 | + |
| 171 | + ecm.CreateComponent(linkEntity, |
| 172 | + gz::sim::components::Link()); |
| 173 | + ecm.CreateComponent(linkEntity, |
| 174 | + gz::sim::components::Name("link_name")); |
| 175 | + ecm.CreateComponent(linkEntity, |
| 176 | + gz::sim::components::ParentEntity(modelEntity)); |
| 177 | + ecm.CreateComponent(linkEntity, |
| 178 | + gz::sim::components::Pose()); |
| 179 | + ecm.CreateComponent(linkEntity, |
| 180 | + gz::sim::components::LinearVelocity(bodyLinvel)); |
| 181 | + ecm.CreateComponent(linkEntity, |
| 182 | + gz::sim::components::AngularVelocity(bodyAngvel)); |
| 183 | + |
| 184 | + // The link's world pose should be correctly resolved |
| 185 | + EXPECT_EQ(modelWorldPose, gz::sim::worldPose(linkEntity, ecm)); |
| 186 | + |
| 187 | + gz::sim::Link link(linkEntity); |
| 188 | + |
| 189 | + // Body velocities should be preserved since they were in the ECM already |
| 190 | + EXPECT_EQ(bodyLinvel, |
| 191 | + ecm.Component<gz::sim::components::LinearVelocity>(linkEntity)->Data()); |
| 192 | + EXPECT_EQ(bodyAngvel, |
| 193 | + ecm.Component<gz::sim::components::AngularVelocity>(linkEntity)->Data()); |
| 194 | + EXPECT_EQ(modelWorldPose, link.WorldPose(ecm).value()); |
| 195 | + |
| 196 | + // Enable velocity checks should provide the correct world components |
| 197 | + // if they have not been computed and inserted in the ECM yet |
| 198 | + link.EnableVelocityChecks(ecm, true); |
| 199 | + |
| 200 | + EXPECT_EQ(bodyLinvel, |
| 201 | + ecm.Component<gz::sim::components::LinearVelocity>(linkEntity)->Data()); |
| 202 | + EXPECT_EQ(bodyAngvel, |
| 203 | + ecm.Component<gz::sim::components::AngularVelocity>(linkEntity)->Data()); |
| 204 | + EXPECT_EQ(modelWorldPose, |
| 205 | + link.WorldPose(ecm).value()); |
| 206 | + EXPECT_EQ(linkWorldLinvel, |
| 207 | + link.WorldLinearVelocity(ecm).value()); |
| 208 | + EXPECT_EQ(linkWorldAngvel, |
| 209 | + link.WorldAngularVelocity(ecm).value()); |
| 210 | +} |
0 commit comments