Ask Your Question
0

Teleop based control of a custom vehicle

asked 2012-12-19 19:05:31 -0500

incognito gravatar image

updated 2014-01-28 17:14:38 -0500

ngrennan gravatar image

I am making a ground vehicle which can be controlled over wifi signals using a keyboard. So rather than worrying about all the custom interfaces that i would have to create, i though of modifying the turtlebot teleop interface. Any help on how to procede would be great.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
2

answered 2012-12-19 20:51:12 -0500

Peter Listov gravatar image

updated 2012-12-19 20:51:45 -0500

Here is my implementation of teleop for carlike robot. Instead of Twist (whish has 6 variables) I use simple Drive message containing only acceleration and steering angle. Hope it would be helpful somehow.

    #include "ros/ros.h"
#include "drive_base/Drive.h"
#include "sstream"
#include <termios.h>
#include <signal.h>
#include <fcntl.h>


  #define KEYCODE_A 0x61
  #define KEYCODE_D 0x64
  #define KEYCODE_S 0x73
  #define KEYCODE_W 0x77

  class TeleopRoboCVKeyboard
  {
    private:
    drive_base::Drive cmd;

    ros::NodeHandle n_;
    ros::Publisher drive_pub_;

    public:
    void init()
    {


      //Clear out our cmd - these values are roundabout initials

      cmd.Acceleration = 0;
      cmd.Angle = 0;

      drive_pub_ = n_.advertise<drive_base::Drive>("command", 100);

      ros::NodeHandle n_private("~");
    }

    ~TeleopRoboCVKeyboard()   { }
    void keyboardLoop();
  };

  int kfd = 0;
  struct termios cooked, raw;

  void quit(int sig)
  {
    tcsetattr(kfd, TCSANOW, &cooked);
   exit(0);
  }

  int main(int argc, char** argv)
  {
    ros::init(argc, argv, "drive_cmd_publisher");

    TeleopRoboCVKeyboard tpk;
    tpk.init();

    signal(SIGINT,quit);

    tpk.keyboardLoop();

    return(0);
  }

  void TeleopRoboCVKeyboard::keyboardLoop()
  {
    char c;
   bool dirty=false;

    // 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);

    puts("Reading from keyboard");
    puts("---------------------------");
    puts("Use 'WS' to forward/back");
    puts("Use 'AD' to left/right");

    for(;;)
    {
      // get the next event from the keyboard
      if(read(kfd, &c, 1) < 0)
      {
        perror("read():");
        exit(-1);
      }

      switch(c)
      {
        // Walking
      case KEYCODE_W:
    puts("throttle");
        cmd.Acceleration = cmd.Acceleration + 10;
        dirty = true;
        break;
      case KEYCODE_S:
    puts("brake");
        cmd.Acceleration = cmd.Acceleration - 10;
        dirty = true;
        break;
      case KEYCODE_A:
    puts("turn left");
        cmd.Angle = cmd.Angle - 0.1;
        dirty = true;
        break;
      case KEYCODE_D:
    puts("turn right");
        cmd.Angle = cmd.Angle + 0.1;
        dirty = true;
        break; 
      }


      if (dirty == true)
      {
        drive_pub_.publish(cmd);
      }


    }
  }
edit flag offensive delete link more

Comments

You can choose to update only two of the 6 geometry_msgs/Twist parameters (the angular z for the "left and right" and the linear x for the "forward and back")

SL Remy gravatar imageSL Remy ( 2012-12-20 04:55:23 -0500 )edit
4

answered 2012-12-19 19:37:33 -0500

The most convenient option would be to make it controllable via a geometry_msgs/Twist message, with the topic name typically being "/cmd_vel". This way, you can use a lot of options for teleoperation that already follow this convention.

The fast and easy option I often use is the pr2_teleop package. By starting the keyboard teleop node you can quickly move a robot around:

rosrun pr2_teleop teleop_pr2_keyboard
edit flag offensive delete link more

Comments

1

I'm having problem with the drive.h

Marlon Rocha gravatar imageMarlon Rocha ( 2013-04-10 16:07:24 -0500 )edit

After going to the pr2_teleop wiki page, I wasn't able to download the package from the source page. Clicking on the link just shows a blank page.

Quadrobo gravatar imageQuadrobo ( 2014-01-10 02:47:18 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2012-12-19 19:05:31 -0500

Seen: 1,062 times

Last updated: Dec 19 '12