Home | Tutorials | Wiki | Issues
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to edit grid size using system plugin

Hi,

I would like to edit grid size. I've written simple system plugin to do this, but it's not working for some reason.

When I print out the cell count from grid 0 I get 2000 as expected. But in Gazebo there's no change to default grid size. It's still grid consisting of 20x20 cells.

Here's the code:

#include <gazebo/rendering/rendering.hh>
#include <gazebo/gazebo.hh>
#include <ros/ros.h>

namespace gazebo{
    class GridPlugin : public SystemPlugin {
    public:
        void Load(int /*_argc*/, char ** /*_argv*/){
            this->connections_.push_back(event::Events::ConnectRender(boost::bind(&GridPlugin::Update, this)));
        }
    private:
        void Update(){
            rendering::ScenePtr scene = rendering::get_scene();

            if(!scene || !scene->Initialized()){
                return;
            }

            auto grid = scene->GetGrid(0);
            if(!grid) return;
            grid->SetCellCount(2000);

            ROS_INFO("cell count: %d", scene->GetGrid(0)->GetCellCount());
        }

    private:
        std::vector<event::ConnectionPtr> connections_;
    };

    GZ_REGISTER_SYSTEM_PLUGIN(GridPlugin)
}