Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge 7 -> 8 #2456

Merged
merged 10 commits into from
Jun 27, 2024
5 changes: 5 additions & 0 deletions include/gz/sim/components/Gravity.hh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ namespace components
/// \brief Store the gravity acceleration.
using Gravity = Component<math::Vector3d, class GravityTag>;
GZ_SIM_REGISTER_COMPONENT("gz_sim_components.Gravity", Gravity)

/// \brief Store the gravity acceleration.
using GravityEnabled = Component<bool, class GravityEnabledTag>;
GZ_SIM_REGISTER_COMPONENT(
"gz_sim_components.GravityEnabled", GravityEnabled)
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/Conversions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,10 @@ msgs::Geometry gz::sim::convert(const sdf::Geometry &_in)
}
}
}
else if (_in.Type() == sdf::GeometryType::EMPTY)
{
out.set_type(msgs::Geometry::EMPTY);
}
else
{
gzerr << "Geometry type [" << static_cast<int>(_in.Type())
Expand Down
10 changes: 10 additions & 0 deletions src/Conversions_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1203,3 +1203,13 @@ TEST(Conversions, MsgsPluginToSdf)
EXPECT_EQ(innerXml, sdfPlugins[1].Contents()[0]->ToString(""));
EXPECT_EQ(innerXml2, sdfPlugins[1].Contents()[1]->ToString(""));
}

/////////////////////////////////////////////////
TEST(Conversions, GeometryEmpty)
{
sdf::Geometry geometry;
geometry.SetType(sdf::GeometryType::EMPTY);

auto geometryMsg = convert<msgs::Geometry>(geometry);
EXPECT_EQ(msgs::Geometry::EMPTY, geometryMsg.type());
}
2 changes: 1 addition & 1 deletion src/ModelCommandAPI_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ TEST(ModelCommandAPI, GZ_UTILS_TEST_DISABLED_ON_MAC(RgbdCameraSensor))
// Run without blocking.
server.Run(false, 0, false);

// Tested command: gz model -m altimeter_mode -l link -s altimeter_sensor
// Tested command: gz model -m rgbd_camera -l rgbd_camera_link -s rgbd_camera
{
const std::string cmd = kGzModelCommand
+ "-m rgbd_camera -l rgbd_camera_link -s rgbd_camera";
Expand Down
7 changes: 7 additions & 0 deletions src/SdfEntityCreator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,13 @@ Entity SdfEntityCreator::CreateEntities(const sdf::Link *_link)
linkEntity, components::WindMode(_link->EnableWind()));
}

if (!_link->EnableGravity())
{
// If disable gravity, create a GravityEnabled component to the entity
this->dataPtr->ecm->CreateComponent(
linkEntity, components::GravityEnabled(false));
}

// Visuals
for (uint64_t visualIndex = 0; visualIndex < _link->VisualCount();
++visualIndex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,12 +405,11 @@ void LogicalAudioSensorPluginPrivate::CreateAudioSource(
};

// create services for this source
const auto fullName = scopedName(entity, _ecm);
auto validName = transport::TopicUtils::AsValidTopic(fullName);
const auto validName = topicFromScopedName(entity, _ecm, false);
if (validName.empty())
{
gzerr << "Failed to create valid topics with entity scoped name ["
<< fullName << "]" << std::endl;
<< scopedName(entity, _ecm) << "]" << std::endl;
return;
}
if (!this->node.Advertise(validName + "/play", playSrvCb))
Expand Down Expand Up @@ -504,7 +503,7 @@ void LogicalAudioSensorPluginPrivate::CreateMicrophone(

// create the detection publisher for this microphone
auto pub = this->node.Advertise<msgs::Double>(
scopedName(entity, _ecm) + "/detection");
topicFromScopedName(entity, _ecm, false) + "/detection");
if (!pub)
{
gzerr << "Error creating a detection publisher for microphone "
Expand Down
47 changes: 46 additions & 1 deletion src/systems/physics/Physics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,14 @@ class gz::sim::systems::PhysicsPrivate
public: struct SolverFeatureList : gz::physics::FeatureList<
gz::physics::Solver>{};

//////////////////////////////////////////////////
// CollisionPairMaxContacts
/// \brief Feature list for setting and getting the max total contacts for
/// collision pairs
public: struct CollisionPairMaxContactsFeatureList :
gz::physics::FeatureList<
gz::physics::CollisionPairMaxContacts>{};

//////////////////////////////////////////////////
// Nested Models

Expand All @@ -647,7 +655,8 @@ class gz::sim::systems::PhysicsPrivate
NestedModelFeatureList,
CollisionDetectorFeatureList,
SolverFeatureList,
WorldModelFeatureList
WorldModelFeatureList,
CollisionPairMaxContactsFeatureList
>;

/// \brief A map between world entity ids in the ECM to World Entities in
Expand Down Expand Up @@ -1026,6 +1035,33 @@ void PhysicsPrivate::CreateWorldEntities(const EntityComponentManager &_ecm,
}
}

auto physicsComp =
_ecm.Component<components::Physics>(_entity);
if (physicsComp)
{
auto maxContactsFeature =
this->entityWorldMap.EntityCast<
CollisionPairMaxContactsFeatureList>(_entity);
if (!maxContactsFeature)
{
static bool informed{false};
if (!informed)
{
gzdbg << "Attempting to set physics options, but the "
<< "phyiscs engine doesn't support feature "
<< "[CollisionPairMaxContacts]. "
<< "Options will be ignored."
<< std::endl;
informed = true;
}
}
else
{
maxContactsFeature->SetCollisionPairMaxContacts(
physicsComp->Data().MaxContacts());
}
}

// World Model proxy (used for joints directly under <world> in SDF)
auto worldModelFeature =
this->entityWorldMap.EntityCast<WorldModelFeatureList>(_entity);
Expand Down Expand Up @@ -1287,6 +1323,15 @@ void PhysicsPrivate::CreateLinkEntities(const EntityComponentManager &_ecm,
link.SetInertial(inertial->Data());
}

// get link gravity
const components::GravityEnabled *gravityEnabled =
_ecm.Component<components::GravityEnabled>(_entity);
if (nullptr != gravityEnabled)
{
// gravityEnabled set in SdfEntityCreator::CreateEntities()
link.SetEnableGravity(gravityEnabled->Data());
}

auto constructLinkFeature =
this->entityModelMap.EntityCast<ConstructSdfLinkFeatureList>(
_parent->Data());
Expand Down
3 changes: 1 addition & 2 deletions src/systems/pose_publisher/PosePublisher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,7 @@ void PosePublisher::Configure(const Entity &_entity,
this->dataPtr->usePoseV =
_sdf->Get<bool>("use_pose_vector_msg", this->dataPtr->usePoseV).first;

std::string poseTopic = scopedName(_entity, _ecm) + "/pose";
poseTopic = transport::TopicUtils::AsValidTopic(poseTopic);
std::string poseTopic = topicFromScopedName(_entity, _ecm, false) + "/pose";
if (poseTopic.empty())
{
poseTopic = "/pose";
Expand Down
Loading