Gazebo | Ignition | Community
Ask Your Question

Setting Goal Position with Gazebo

asked 2015-07-02 23:33:12 -0600

bazzisniper gravatar image

updated 2015-07-03 06:42:29 -0600

Hello, I'm trying to make the mobile robot move autonomously.

Now I want to give a coordinate of goal position to my robot, but I don't know how?

My desired interface is simple like this.

  • click some point in gzclient window
  • then mobile robot starts moving to there.

For this, I think I need to pick the coordinate of the mouse pointer when mouse was clicked.

Is there any way to solve this?

I found this solution but it only extracts position on the client window(not the coordinate of gazebo world).


I could get mouse position in the gazebo world by using gui::MouseEventHandle and Scene::GetFirstContact method. Thank you for answering.

#include <gazebo/math/Rand.hh>
#include <gazebo/gui/GuiIface.hh>
#include <gazebo/rendering/rendering.hh>
#include <gazebo/gazebo.hh>
#include <gazebo/gui/MouseEventHandler.hh>
#include <gazebo/common/MouseEvent.hh>
#include <boost/thread/mutex.hpp>
#include <boost/thread/thread.hpp>

namespace gazebo
    class SystemGUI : public SystemPlugin
        /// \brief Destructor
    public: virtual ~SystemGUI()
            if (this->userCam)

        /// \brief Called after the plugin has been constructed.
    public: void Load(int /*_argc*/, char ** /*_argv*/)
                            boost::bind(&SystemGUI::Update, this)));

            gui::MouseEventHandler::Instance()->AddPressFilter("glwidget", boost::bind(&SystemGUI::OnMousePress, this, _1));

        // \brief Called once after Load
    private: void Init()

        boost::mutex mutexMouseClicked;
        math::Vector2i mouseClicked;
        bool isMouseClicked;
    private: bool OnMousePress(const common::MouseEvent& _event)
            boost::mutex::scoped_lock lock(mutexMouseClicked);
            mouseClicked = _event.pos;
            isMouseClicked = true;
            std::cout<<"Clicked at "<<mouseClicked<<" of screen "<<std::endl;

        /// \brief Called every PreRender event. See the Load function.
    private: void Update()
            if (!this->userCam)
                // Get a pointer to the active user camera
                this->userCam = gui::get_active_camera();
            // Get scene pointer
            rendering::ScenePtr scene = rendering::get_scene();

            // Wait until the scene is initialized.
            if (!scene || !scene->GetInitialized())

            if(isMouseClicked && this->userCam){
                boost::mutex::scoped_lock lock(mutexMouseClicked);
                math::Vector3 position_clicked;
                scene->GetFirstContact(this->userCam, mouseClicked, position_clicked);
                std::cout<<"Clicked at "<<position_clicked<<" of world\n"<<std::endl;
                isMouseClicked = false;

        /// Pointer the user camera.
    private: rendering::UserCameraPtr userCam;

        /// All the event connections.
    private: std::vector<event::ConnectionPtr> connections;

    // Register this plugin with the simulator
edit retag flag offensive close merge delete


I tried nearly the same thing some days ago but for me it seems to steal the Gazebo mouseClick events which makes the 3D viewport unusable is this effect the same for you??

evilBiber gravatar imageevilBiber ( 2015-07-03 08:04:18 -0600 )edit

If you mean that you couldn't navigate in 3D view by **3D viewport unusable** , that was not the case with me. I could navigate the gazebo world as usual.

bazzisniper gravatar imagebazzisniper ( 2015-07-03 22:27:54 -0600 )edit

When I try to compile the code, I am getting the following error. /usr/local/include/OGRE/Paging/OgrePagingPrerequisites.h:32:31: fatal error: OgrePrerequisites.h: No such file or directory #include "OgrePrerequisites.h" I have no clue if I have to install anything. Please, help.

vishnurs gravatar imagevishnurs ( 2017-03-31 07:00:51 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2015-07-03 03:30:05 -0600

AndreiHaidu gravatar image

Try using GetFirstContact from a gui system plugin.

Cheers, Andrei

edit flag offensive delete link more


Great. Thank you so much. I solved problem. :D

bazzisniper gravatar imagebazzisniper ( 2015-07-03 06:37:39 -0600 )edit

Question Tools

1 follower


Asked: 2015-07-02 23:33:12 -0600

Seen: 2,504 times

Last updated: Jul 03 '15