Gazebo | Ignition | Community
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Get the dimensions of a generated sdf (box shape)

Good morning, everyone, I am working with a C++ plugin for gz sim garden and trying to get the dimensions (depth, width and height) of a previously spawned box via the service provided by UserCommands.

Using ECM I have done so far and was trying to get the AxisAlignedBox:

// Get the name
boxModelName = _ecm.Component<components::Name>(boxModelEntity)->Data();

// Get the BoxLink of the old box model for the size of the box
boxLinkEntity = _ecm.EntityByComponents(components::Link(), components::ParentEntity(boxModelEntity), components::Name(boxLink));

// Get the AxisAlignedBox component of the old box model
math::AxisAlignedBox boxSize = _ecm.Component<components::AxisAlignedBox>(boxLinkEntity)->Data();
double boxDepthSize = boxSize.XLength();
double boxWidthSize = boxSize.YLength();
double boxHeightSize = boxSize.ZLength();

// Get the pose of the old box model
auto boxPose = _ecm.Component<components::Pose>(boxModelEntity)->Data();
double box_X = boxPose.Pos().X();
double box_Y = boxPose.Pos().Y();
double box_Z = boxPose.Pos().Z();

// Destroy the old box model
_ecm.RequestRemoveEntity(boxModelEntity, true);
gzerr << "Destroying box model " << boxModelName << std::endl;

// Spawn a new box with the same name, label and pose
SpawnBox(boxModelName, boxLabel, box_X, box_Y, box_Z, boxDepthSize, boxWidthSize, boxHeightSize);

Basically I need to recreate the same box as before with the static component set to false, since the change at runtime of the component does not update the physics of the simulation, so the trick I used so far was to remove and create immediately but now I need to generalize the dimensions.

It seems to me a fairly convulsive ride, but I have not yet found another way to get the geometric primitive of the collisions (a simple box).

Thanks a lot!

Get the dimensions of a generated sdf (box shape)

Good morning, everyone, I am working with a C++ plugin for gz sim garden and trying to get the dimensions (depth, width and height) of a previously spawned box via the service provided by UserCommands.

Using ECM I have done so far and was trying to get the AxisAlignedBox:

// Get the name
boxModelName = _ecm.Component<components::Name>(boxModelEntity)->Data();

// Get the BoxLink of the old box model for the size of the box
boxLinkEntity = _ecm.EntityByComponents(components::Link(), components::ParentEntity(boxModelEntity), components::Name(boxLink));

// Get the AxisAlignedBox component of the old box model
math::AxisAlignedBox boxSize = _ecm.Component<components::AxisAlignedBox>(boxLinkEntity)->Data();
double boxDepthSize = boxSize.XLength();
double boxWidthSize = boxSize.YLength();
double boxHeightSize = boxSize.ZLength();

// Get the pose of the old box model
auto boxPose = _ecm.Component<components::Pose>(boxModelEntity)->Data();
double box_X = boxPose.Pos().X();
double box_Y = boxPose.Pos().Y();
double box_Z = boxPose.Pos().Z();

// Destroy the old box model
_ecm.RequestRemoveEntity(boxModelEntity, true);
gzerr << "Destroying box model " << boxModelName << std::endl;

// Spawn a new box with the same name, label and pose
SpawnBox(boxModelName, boxLabel, box_X, box_Y, box_Z, boxDepthSize, boxWidthSize, boxHeightSize);

Basically I need to recreate the same box as before with the static component set to false, since the change at runtime of the component does not update the physics of the simulation, so the trick I used so far was to remove and create immediately but now I need to generalize the dimensions.

It seems to me a fairly convulsive ride, but I have not yet found another way to get the geometric primitive of the collisions (a simple box).

Thanks a lot!