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

fixed thruster.cc undefined behavior #2316

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
9d87652
fixed thruster.cc undefined behaviour
GauravKumar9920 Feb 15, 2024
e023e3d
updating the code to check for the empty modelposes
GauravKumar9920 Feb 17, 2024
5f81ca1
adding a runtime error
GauravKumar9920 Feb 18, 2024
2db4d5d
minor fix
GauravKumar9920 Feb 18, 2024
d3f586c
Added assert false function
GauravKumar9920 Mar 2, 2024
1ad599e
added ASSERT_FALSE stement that's required elsewhere
GauravKumar9920 Mar 18, 2024
3239f41
minor changes
GauravKumar9920 Mar 18, 2024
59a0f5e
Update test/integration/thruster.cc
GauravKumar9920 Mar 19, 2024
be2d152
Fixed all the issues, I Hope
GauravKumar9920 Mar 19, 2024
19ce285
Update test/integration/thruster.cc
GauravKumar9920 Mar 20, 2024
60861c1
Add entity validation to OdometryPublisher (#2326)
Mar 1, 2024
b918724
Add entity and sdf parameters to Server's AddSystem interface (#2324)
g-arjones Mar 5, 2024
8c63d88
Fix wget in maritime tutorials (#2330)
caguero Mar 12, 2024
d56ea91
Add reference to joint_controller.md tutorial. (#2333)
francocipollone Mar 13, 2024
bce4ae2
Prepare for 8.2.0 (#2335)
azeey Mar 15, 2024
1716fe5
Publish step size in world stats topic (#2340)
iche033 Mar 22, 2024
8ca57b4
Check null mesh (#2341)
iche033 Mar 25, 2024
55cd8a6
Fixed turning error in ackermann steering (#2342)
sauk2 Mar 27, 2024
2dcec27
Added mutex to protect stored time variables (#2345)
sauk2 Mar 28, 2024
d580c2d
made the required changes
GauravKumar9920 Mar 30, 2024
0e92da8
Update test/integration/thruster.cc
GauravKumar9920 Apr 1, 2024
5a303ba
Merge branch 'gazebosim:gz-sim8' into gz-sim8
GauravKumar9920 Apr 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.10.2 FATAL_ERROR)
#============================================================================
# Initialize the project
#============================================================================
project(gz-sim8 VERSION 8.1.0)
project(gz-sim8 VERSION 8.2.0)
set (GZ_DISTRIBUTION "Harmonic")

#============================================================================
Expand Down
17 changes: 17 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
## Gazebo Sim 8.x

### Gazebo Sim 8.2.0 (2024-03-14)

1. Add reference to joint_controller.md tutorial.
* [Pull request #2333](https://github.com/gazebosim/gz-sim/pull/2333)

1. Fix wget in maritime tutorials
* [Pull request #2330](https://github.com/gazebosim/gz-sim/pull/2330)

1. Add entity and sdf parameters to Server's AddSystem interface
* [Pull request #2324](https://github.com/gazebosim/gz-sim/pull/2324)

1. Add entity validation to OdometryPublisher
* [Pull request #2326](https://github.com/gazebosim/gz-sim/pull/2326)

1. Fix typo in Joint.hh
* [Pull request #2310](https://github.com/gazebosim/gz-sim/pull/2310)

### Gazebo Sim 8.1.0 (2024-02-06)

1. Add tutorial for using components in systems
Expand Down
48 changes: 48 additions & 0 deletions include/gz/sim/Server.hh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include <gz/sim/Export.hh>
#include <gz/sim/ServerConfig.hh>
#include <gz/sim/SystemPluginPtr.hh>
#include <sdf/Element.hh>
#include <sdf/Plugin.hh>

namespace gz
{
Expand Down Expand Up @@ -225,14 +227,60 @@ namespace gz
const SystemPluginPtr &_system,
const unsigned int _worldIndex = 0);

/// \brief Add a System to the server. The server must not be running when
/// calling this.
/// \param[in] _system system to be added
/// \param[in] _entity Entity of system to be added.
/// If _entity is std::nullopt, it will be added to the world entity.
/// \param[in] _sdf Pointer to the SDF element of a <plugin> tag with
/// configuration options for the system being added.
/// \param[in] _worldIndex Index of the world to query.
/// \return Whether the system was added successfully, or std::nullopt
/// if _worldIndex is invalid.
public: std::optional<bool> AddSystem(
const SystemPluginPtr &_system,
std::optional<Entity> _entity,
std::optional<std::shared_ptr<const sdf::Element>> _sdf,
const unsigned int _worldIndex = 0);

/// \brief Add a System to the server. The server must not be running when
/// calling this.
/// \param[in] _plugin system plugin to be added with any additional XML
/// contents.
/// \param[in] _entity Entity of system to be added.
/// If _entity is std::nullopt, it will be added to the world entity.
/// \param[in] _worldIndex Index of the world to query.
/// \return Whether the system was added successfully, or std::nullopt
/// if _worldIndex is invalid.
public: std::optional<bool> AddSystem(
const sdf::Plugin &_plugin,
std::optional<Entity> _entity,
const unsigned int _worldIndex = 0);

/// \brief Add a System to the server. The server must not be running when
/// calling this.
/// \param[in] _system System to be added
/// \param[in] _worldIndex Index of the world to add to.
/// \return Whether the system was added successfully, or std::nullopt
/// if _worldIndex is invalid.
public: std::optional<bool> AddSystem(
const std::shared_ptr<System> &_system,
const unsigned int _worldIndex = 0);

/// \brief Add a System to the server. The server must not be running when
/// calling this.
/// \param[in] _system System to be added
/// \param[in] _entity Entity of system to be added.
/// If _entity is std::nullopt, it will be added to the world entity.
/// \param[in] _sdf Pointer to the SDF element of a <plugin> tag with
/// configuration options for the system being added
/// \param[in] _worldIndex Index of the world to add to.
/// \return Whether the system was added successfully, or std::nullopt
/// if _worldIndex is invalid.
public: std::optional<bool> AddSystem(
const std::shared_ptr<System> &_system,
std::optional<Entity> _entity,
std::optional<std::shared_ptr<const sdf::Element>> _sdf,
const unsigned int _worldIndex = 0);

/// \brief Get an Entity based on a name.
Expand Down
5 changes: 5 additions & 0 deletions src/MeshInertiaCalculator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ std::optional<gz::math::Inertiald> MeshInertiaCalculator::operator()
// Load the Mesh
gz::common::MeshManager *meshManager = gz::common::MeshManager::Instance();
mesh = meshManager->Load(fullPath);
if (!mesh)
{
gzerr << "Failed to load mesh: " << fullPath << std::endl;
return std::nullopt;
}
std::vector<Triangle> meshTriangles;
gz::math::MassMatrix3d meshMassMatrix;
gz::math::Pose3d centreOfMass;
Expand Down
37 changes: 35 additions & 2 deletions src/Server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,29 @@ std::optional<size_t> Server::SystemCount(const unsigned int _worldIndex) const
//////////////////////////////////////////////////
std::optional<bool> Server::AddSystem(const SystemPluginPtr &_system,
const unsigned int _worldIndex)
{
return this->AddSystem(_system, std::nullopt, std::nullopt, _worldIndex);
}

//////////////////////////////////////////////////
std::optional<bool> Server::AddSystem(const sdf::Plugin &_plugin,
std::optional<Entity> _entity,
const unsigned int _worldIndex)
{
auto system = this->dataPtr->systemLoader->LoadPlugin(_plugin);
if (system)
{
return this->AddSystem(*system, _entity, _plugin.ToElement(), _worldIndex);
}
return false;
}

//////////////////////////////////////////////////
std::optional<bool> Server::AddSystem(
const SystemPluginPtr &_system,
std::optional<Entity> _entity,
std::optional<std::shared_ptr<const sdf::Element>> _sdf,
const unsigned int _worldIndex)
{
// Check the current state, and return early if preconditions are not met.
std::lock_guard<std::mutex> lock(this->dataPtr->runMutex);
Expand All @@ -364,7 +387,7 @@ std::optional<bool> Server::AddSystem(const SystemPluginPtr &_system,

if (_worldIndex < this->dataPtr->simRunners.size())
{
this->dataPtr->simRunners[_worldIndex]->AddSystem(_system);
this->dataPtr->simRunners[_worldIndex]->AddSystem(_system, _entity, _sdf);
return true;
}

Expand All @@ -374,6 +397,16 @@ std::optional<bool> Server::AddSystem(const SystemPluginPtr &_system,
//////////////////////////////////////////////////
std::optional<bool> Server::AddSystem(const std::shared_ptr<System> &_system,
const unsigned int _worldIndex)
{
return this->AddSystem(_system, std::nullopt, std::nullopt, _worldIndex);
}

//////////////////////////////////////////////////
std::optional<bool> Server::AddSystem(
const std::shared_ptr<System> &_system,
std::optional<Entity> _entity,
std::optional<std::shared_ptr<const sdf::Element>> _sdf,
const unsigned int _worldIndex)
{
std::lock_guard<std::mutex> lock(this->dataPtr->runMutex);
if (this->dataPtr->running)
Expand All @@ -384,7 +417,7 @@ std::optional<bool> Server::AddSystem(const std::shared_ptr<System> &_system,

if (_worldIndex < this->dataPtr->simRunners.size())
{
this->dataPtr->simRunners[_worldIndex]->AddSystem(_system);
this->dataPtr->simRunners[_worldIndex]->AddSystem(_system, _entity, _sdf);
return true;
}

Expand Down
41 changes: 36 additions & 5 deletions src/Server_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -625,17 +625,48 @@ TEST_P(ServerFixture, GZ_UTILS_TEST_DISABLED_ON_WIN32(RunOnceUnpaused))
auto mockSystemPlugin = systemLoader.LoadPlugin(sdfPlugin);
ASSERT_TRUE(mockSystemPlugin.has_value());

// Check that it was loaded
const size_t systemCount = *server.SystemCount();
EXPECT_TRUE(*server.AddSystem(mockSystemPlugin.value()));
EXPECT_EQ(systemCount + 1, *server.SystemCount());

// Query the interface from the plugin
auto system = mockSystemPlugin.value()->QueryInterface<sim::System>();
EXPECT_NE(system, nullptr);
auto mockSystem = dynamic_cast<sim::MockSystem*>(system);
EXPECT_NE(mockSystem, nullptr);

Entity entity = server.EntityByName("default").value();
size_t configureCallCount = 0;
auto configureCallback = [&sdfPlugin, &entity, &configureCallCount](
const Entity &_entity,
const std::shared_ptr<const sdf::Element> &_sdf,
EntityComponentManager &,
EventManager &)
{
configureCallCount++;
EXPECT_EQ(entity, _entity);
EXPECT_EQ(sdfPlugin.ToElement()->ToString(""), _sdf->ToString(""));
};

mockSystem->configureCallback = configureCallback;
const size_t systemCount = *server.SystemCount();
EXPECT_TRUE(
*server.AddSystem(
mockSystemPlugin.value(), entity, sdfPlugin.ToElement()
));

// Add pointer
auto mockSystemPtr = std::make_shared<MockSystem>();
mockSystemPtr->configureCallback = configureCallback;
EXPECT_TRUE(*server.AddSystem(mockSystemPtr, entity, sdfPlugin.ToElement()));

// Add an sdf::Plugin
EXPECT_TRUE(*server.AddSystem(sdfPlugin, entity));

// Fail if plugin is invalid
sdf::Plugin invalidPlugin("foo_plugin", "foo::systems::FooPlugin");
EXPECT_FALSE(*server.AddSystem(invalidPlugin, entity));

// Check that it was loaded
EXPECT_EQ(systemCount + 3, *server.SystemCount());
EXPECT_EQ(2u, configureCallCount);

// No steps should have been executed
EXPECT_EQ(0u, mockSystem->preUpdateCallCount);
EXPECT_EQ(0u, mockSystem->updateCallCount);
Expand Down
2 changes: 2 additions & 0 deletions src/SimulationRunner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,8 @@ void SimulationRunner::PublishStats()

msg.set_paused(this->currentInfo.paused);

msgs::Set(msg.mutable_step_size(), this->currentInfo.dt);

if (this->Stepping())
{
// (deprecated) Remove this header in Gazebo H
Expand Down
1 change: 0 additions & 1 deletion src/gui/plugins/apply_force_torque/ApplyForceTorque.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include <mutex>
#include <string>

#include <gz/common/MeshManager.hh>
#include <gz/common/MouseEvent.hh>
#include <gz/gui/Application.hh>
#include <gz/gui/GuiEvents.hh>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1245,7 +1245,14 @@ rendering::GeometryPtr VisualizationCapabilitiesPrivate::CreateGeometry(
gz::common::MeshManager *meshManager =
gz::common::MeshManager::Instance();
descriptor.mesh = meshManager->Load(descriptor.meshName);
geom = this->scene->CreateMesh(descriptor);
if (descriptor.mesh)
{
geom = this->scene->CreateMesh(descriptor);
}
else
{
gzerr << "Failed to load mesh: " << descriptor.meshName << std::endl;
}
scale = _geom.MeshShape()->Scale();
}
else if (_geom.Type() == sdf::GeometryType::HEIGHTMAP)
Expand Down
10 changes: 8 additions & 2 deletions src/rendering/SceneManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -813,8 +813,14 @@ rendering::GeometryPtr SceneManager::LoadGeometry(const sdf::Geometry &_geom,
rendering::MeshDescriptor descriptor;
descriptor.meshName = name;
descriptor.mesh = meshManager->MeshByName(name);

geom = this->dataPtr->scene->CreateMesh(descriptor);
if (descriptor.mesh)
{
geom = this->dataPtr->scene->CreateMesh(descriptor);
}
else
{
gzerr << "Unable to find the polyline mesh: " << name << std::endl;
}
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions src/systems/ackermann_steering/AckermannSteering.cc
Original file line number Diff line number Diff line change
Expand Up @@ -968,11 +968,11 @@ void AckermannSteeringPrivate::UpdateAngle(

double leftSteeringJointAngle =
atan((2.0 * this->wheelBase * sin(ang)) / \
((2.0 * this->wheelBase * cos(ang)) + \
((2.0 * this->wheelBase * cos(ang)) - \
(1.0 * this->wheelSeparation * sin(ang))));
double rightSteeringJointAngle =
atan((2.0 * this->wheelBase * sin(ang)) / \
((2.0 * this->wheelBase * cos(ang)) - \
((2.0 * this->wheelBase * cos(ang)) + \
(1.0 * this->wheelSeparation * sin(ang))));

auto leftSteeringPos = _ecm.Component<components::JointPosition>(
Expand Down
11 changes: 11 additions & 0 deletions src/systems/dvl/DopplerVelocityLogSystem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ class gz::sim::systems::DopplerVelocityLogSystem::Implementation
/// \brief Current simulation time.
public: std::chrono::steady_clock::duration nextUpdateTime{
std::chrono::steady_clock::duration::max()};

/// \brief Mutex to protect current simulation times
public: std::mutex timeMutex;
};

using namespace gz;
Expand Down Expand Up @@ -351,6 +354,8 @@ void DopplerVelocityLogSystem::Implementation::DoPostUpdate(
return true;
});

std::lock_guard<std::mutex> timeLock(this->timeMutex);

if (!this->perStepRequests.empty() || (
!_info.paused && this->nextUpdateTime <= _info.simTime))
{
Expand Down Expand Up @@ -611,6 +616,9 @@ void DopplerVelocityLogSystem::Implementation::OnRender()
}

auto closestUpdateTime = std::chrono::steady_clock::duration::max();

std::lock_guard<std::mutex> timeLock(this->timeMutex);

for (const auto & [_, sensorId] : this->sensorIdPerEntity)
{
gz::sensors::Sensor *sensor =
Expand All @@ -635,6 +643,9 @@ void DopplerVelocityLogSystem::Implementation::OnRender()
void DopplerVelocityLogSystem::Implementation::OnPostRender()
{
GZ_PROFILE("DopplerVelocityLogSystem::Implementation::OnPostRender");

std::lock_guard<std::mutex> timeLock(this->timeMutex);

for (const auto & sensorId : this->updatedSensorIds)
{
auto *sensor =
Expand Down
24 changes: 24 additions & 0 deletions src/systems/odometry_publisher/OdometryPublisher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,21 @@ void OdometryPublisher::PreUpdate(const gz::sim::UpdateInfo &_info,
{
GZ_PROFILE("OdometryPublisher::PreUpdate");

// \TODO(anyone) This is a temporary fix for
// gazebosim/gz-sim#2165 until gazebosim/gz-sim#2217 is resolved.
if (kNullEntity == this->dataPtr->model.Entity())
{
return;
}

if (!this->dataPtr->model.Valid(_ecm))
{
gzwarn << "OdometryPublisher model no longer valid. "
<< "Disabling plugin." << std::endl;
this->dataPtr->model = Model(kNullEntity);
return;
}

// \TODO(anyone) Support rewind
if (_info.dt < std::chrono::steady_clock::duration::zero())
{
Expand All @@ -301,6 +316,15 @@ void OdometryPublisher::PostUpdate(const UpdateInfo &_info,
const EntityComponentManager &_ecm)
{
GZ_PROFILE("OdometryPublisher::PostUpdate");

// \TODO(anyone) This is a temporary fix for
// gazebosim/gz-sim#2165 until gazebosim/gz-sim#2217 is resolved.
if (kNullEntity == this->dataPtr->model.Entity())
{
return;
}


// Nothing left to do if paused.
if (_info.paused)
return;
Expand Down
Loading