Commit 24039675 authored by David Daish's avatar David Daish

Created hacky solution to ghost visual bug

parent 35a24981
......@@ -11,18 +11,34 @@
<specular>1 1 1 0</specular>
<direction>-1 -1 -1</direction>
</light>
<include>
<uri>model://ground_plane</uri>
</include>
<plugin name="plank" filename="libPlankDrop.so">
<plank_num>1</plank_num>
<other_model_num>4</other_model_num>
</plugin>
<include>
<uri>model://ground_plane</uri>
</include>
<model name="dummy_model">
<link name="dummy_link">
<visual name="dummy_visual">
<plugin name="visual_canary_plugin" filename="libVisualCanary.so">
<expected_model_num>5</expected_model_num>
</plugin>
<geometry>
<sphere>
<radius>0.1</radius>
</sphere>
</geometry>
</visual>
</link>
</model>
<physics type="ode">
<real_time_update_rate>0.0</real_time_update_rate>
<max_step_size>0.004</max_step_size> <!-- Note: The higher this number, the faster the sim. -->
<max_step_size>0.008</max_step_size> <!--Note: The higher this number, the faster the sim.-->
</physics>
</world>
</sdf>
......@@ -7,6 +7,8 @@ list(APPEND CMAKE_CXX_FLAGS "${GAZEBO_CXX_FLAGS} -Wall")
add_library(PlankDrop SHARED plank_drop.cc extra_functions.cc)
add_library(CamRecord SHARED cam_record.cc extra_functions.cc)
add_library(VisualCanary SHARED visual_canary.cc)
target_link_libraries(PlankDrop ${GAZEBO_LIBRARIES})
target_link_libraries(CamRecord ${GAZEBO_LIBRARIES})
target_link_libraries(VisualCanary ${GAZEBO_LIBRARIES})
......@@ -122,7 +122,7 @@ sdf::SDFPtr drop_model (std::string model_name)
sdf::ElementPtr model_elm = modelSDF->Root()->GetElement("model");
// Set the model name to be unique
std::string name_suffix = guid();
std::string name_suffix = "-" + guid();
model_elm->GetAttribute("name")->SetFromString(model_name + name_suffix);
// Set the model's pose to a random value
......
......@@ -9,6 +9,7 @@
#include <gazebo/common/common.hh>
#include <gazebo/gazebo.hh>
#include <gazebo/msgs/msgs.hh>
#include <gazebo/transport/transport.hh>
#include "extra_functions.h"
......@@ -46,13 +47,7 @@ class PlankDrop : public WorldPlugin
// Store the time when the simulation starts and should end
double run_start = this->world->SimTime().Double();
this->run_end = run_start + this->run_duration;
// Insert all the run's models
this->inserted_model_names = this->build_sim_run(
this->world,
this->plank_num,
this->other_model_num);
this->run_end = run_start + 1;
// Do a callback to delete models
this->updateConn = event::Events::ConnectWorldUpdateEnd(
......@@ -62,12 +57,16 @@ class PlankDrop : public WorldPlugin
public: void onUpdate ()
{
double the_time = this->world->SimTime().Double();
if (the_time >= this->run_end && !this->sim_has_run)
{
this->sim_runs ++;
std::cout << "Performing run " << this-> sim_runs << std::endl;
this->world->SetPaused(true);
// Tear down current run
this->sim_has_run = true;
this->tear_sim_run();
......@@ -83,6 +82,7 @@ class PlankDrop : public WorldPlugin
double run_start = this->world->SimTime().Double();
this->run_end = run_start + this->run_duration;
this->sim_has_run = false;
this->world->SetPaused(false);
}
// End the program at the max_sim_runs
......@@ -105,7 +105,7 @@ class PlankDrop : public WorldPlugin
{
// Generate the plank model in a pose ready for dropping
sdf::SDFPtr plankSDF = drop_model("plank");
// Insert the model
world->InsertModelSDF(*plankSDF);
......@@ -160,7 +160,7 @@ class PlankDrop : public WorldPlugin
cam->GetElement("pose")->GetValue()->Set(cam_pose_string);
// Set the camera's name to a unique value
std::string name_suffix = guid();
std::string name_suffix = "-" + guid();
cam->GetAttribute("name")->SetFromString("multi-cam" + name_suffix);
// Insert the camera
......@@ -175,11 +175,14 @@ class PlankDrop : public WorldPlugin
public: void tear_sim_run ()
{
for (auto iter = this->inserted_model_names.begin();
iter != this->inserted_model_names.end();
iter++)
if (this->inserted_model_names.size() > 0)
{
this->world->ModelByName(*iter)->Fini();
for (auto iter = this->inserted_model_names.begin();
iter != this->inserted_model_names.end();
iter++)
{
this->world->ModelByName(*iter)->Fini();
}
}
}
......@@ -199,11 +202,12 @@ class PlankDrop : public WorldPlugin
bool sim_has_run = false;
double run_end;
uint32_t teardown_step;
unsigned int sim_runs = 1;
unsigned int max_sim_runs = 30;
unsigned int sim_runs = 0;
unsigned int max_sim_runs = 10;
// Seconds to let the sim run for
double run_duration = 5;
};
......
#include <iostream>
#include <string>
#include <gazebo/common/common.hh>
#include <gazebo/rendering/rendering.hh>
#include <gazebo/gazebo.hh>
namespace gazebo
{
class VisualCanary : public VisualPlugin
{
public: void Load(rendering::VisualPtr _visual, sdf::ElementPtr _sdf)
{
this->scene = _visual->GetScene();
this->updateConn = event::Events::ConnectWorldUpdateEnd(
std::bind(&gazebo::VisualCanary::onUpdate, this));
if (_sdf->HasElement("expected_model_num"))
{
this->expected_visual_num =
this->default_visual_num + _sdf->Get<int>("expected_model_num");
} else
{
gzerr << "Please specify the expected number of models to be inserted at any one time.";
}
}
public: void onUpdate()
{
int visual_count = this->scene->WorldVisual()->GetChildCount();
if (visual_count > this->expected_visual_num)
{
gzerr << "Detected more visuals than expected. Ending Gazebo.";
exit(1);
}
}
private:
// Storing pointers
rendering::ScenePtr scene;
event::ConnectionPtr updateConn;
// The number of visuals that are there at initialisation, and will
// not change over the course of the runs. (ground_plane, Grid0, etc)
int default_visual_num = 6;
// The max number of visuals to be expected at any one time.
int expected_visual_num;
};
GZ_REGISTER_VISUAL_PLUGIN(VisualCanary)
}
......@@ -39,7 +39,7 @@ set so that the docker container can access the host's X-server.
Note that this tends to be a little buggy if the simulation is running at full
speed. You can reduce the speed by reducing the value in the `<max_step_size>`
tag found in the `include/lit_world.world`.
tag found in the `include/lit_world.world` file.
```
xhost +
......
......@@ -36,10 +36,17 @@ ideas for increasing accuracy:
model entirely, and it still didn't change.
- Screw it, I give up. Resolved by ending and restarting the program before
the slowdown gets too bad.
- ~~Sometimes, multiple planks will appear in rendered images. I suspect this
is on account of the simulation running too fast for the teardown to keep
up.~~ The problem appears to have gone, but I have no idea what caused it, nor what
fixed it.
- Sometimes, multiple planks will appear in rendered images.
- It doesn't happen every batch.
- The extra models are not listed with a call to `WorldPtr->Models()`.
- When the issue appears once, it'll appear across all the other images.
Alternatively, it might just appear in most of the other images. It's
hard to tell.
- The extra models can be seen in the depth images.
- The scene does not appear to change, when accessed by `WorldPtr->SceneMsg()`.
- The ghost models can be accessed using `ScenePtr->WorldVisual()->GetChild()`.
- I cannot find the cause, so I have resolved the issue by creating a simple,
hacky system that ends the process if more visuals are detected than expected.
- The NN would have no way to diferentiate the pose differences of a plank that
is symmetrical. The serialisation process needs to limit it to just a few
directions, such that the NN doesn't need to determine the exact pose, just the
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment