Gazebo | Ignition | Community
Ask Your Question
0

Gazebo model interaction without ros

asked 2014-06-24 14:39:28 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

Hello, I just started to learn gazebo. I want to control my model from keyboard. There is a turtlesim example for ros,but Is it possible to take key events from gazebo without using ros?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2014-07-03 14:04:47 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

Hello, Thanks for the suggestions. Finally, I achieved controlling model from the keyboard. I used http://wiki.ros.org/turtlesim example code. I took turtlesim, terminal reading part and added it to update function of my model. In every update, it checks if there is a key press. update function of my code is below.

 // Called by the world update start event
    public: void OnUpdate()
    {
          char c;
        int kfd = 0;
    struct termios cooked, raw;
          // get the console in raw mode                                                              
      tcgetattr(kfd, &cooked);
      memcpy(&raw, &cooked, sizeof(struct termios));
      raw.c_lflag &=~ (ICANON | ECHO);
      // Setting a new line, then end of file                         
      raw.c_cc[VEOL] = 1;
      raw.c_cc[VEOF] = 2;
      tcsetattr(kfd, TCSANOW, &raw);
        struct pollfd pfd = {0,0,0};       /* poll() settings   */
      int pr;                            /* poll() result     */

      pfd.fd = STDIN_FILENO;
      pfd.events = POLLIN;
      pr = poll(&pfd, 1, 100);
      if(pr>0)
      {
        if(read(kfd, &c, 1) < 0)
        {
          perror("read():");
          exit(-1);
        }
        double rad = 1;
            switch(c)
            {
              case KEYCODE_L:
                puts("LEFT");
                this->left_wheel_joint_->SetAngle(0,0);  //joint
                break;
              case KEYCODE_D:
                puts("DOWN");
                this->left_wheel_joint_->SetAngle(0,-rad); //joint
                break;
            }
       }
       else{
        //no key
        }
}
edit flag offensive delete link more
0

answered 2014-06-26 10:37:43 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

Hi,

I haven't tried this yet but maybe one of the following ideas work:

  • Add a GuiOverlay and implement the corresponding functions.(I have no idea how this is done, but this seems to be the cleanest way ;) )
  • Try to access QTEvents via a System plugin qtevents
  • Try to use OIS(This seems to be the standard io system in OGRE) ois ogre tutorial
  • Write an external program (like the teleop app for the turtlesim which does not use ros to read the keyboard) and transport the key events via protobuf messages. Maybe this python module can help to build such a system but I haven't tried it yet... pygazebo

I am not sure if the second and third solutions work without changing the gazebo source code. The last solution will work but would need an external program...

All of those solutions need a model plugin that listens to gazebo messages...

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

Stats

Asked: 2014-06-24 14:39:28 -0500

Seen: 1,580 times

Last updated: Jul 03 '14