2012-11-03 1 views
2

TurtleBot을 프로그래밍하려고하지만 로봇에 대한 자습서가 많이 없으며 작동하는 C++을 직접 작성할 수 없습니다. 키를 누를 때 로봇을 움직이게하기 위해 다른 로봇의 튜토리얼을 사용하려고합니다.TurtleBot ROS Twist를 사용하여 이동

소스 튜토리얼 here 발견 : 난 단지 게시 항목을 수정하는 "/ cmd_vel"에

#include <iostream> 

#include <ros/ros.h> 
#include <geometry_msgs/Twist.h> 

class RobotDriver 
{ 
private: 
    //! The node handle we'll be using 
    ros::NodeHandle nh_; 
    //! We will be publishing to the "/base_controller/command" topic to issue commands 
    ros::Publisher cmd_vel_pub_; 

public: 
    //! ROS node initialization 
    RobotDriver(ros::NodeHandle &nh) 
    { 
    nh_ = nh; 
    //set up the publisher for the cmd_vel topic 
    cmd_vel_pub_ = nh_.advertise<geometry_msgs::Twist>("/cmd_vel", 1); 
    } 

    //! Loop forever while sending drive commands based on keyboard input 
    bool driveKeyboard() 
    { 
    std::cout << "Type a command and then press enter. " 
     "Use '+' to move forward, 'l' to turn left, " 
     "'r' to turn right, '.' to exit.\n"; 

    //we will be sending commands of type "twist" 
    geometry_msgs::Twist base_cmd; 

    char cmd[50]; 
    while(nh_.ok()){ 

     std::cin.getline(cmd, 50); 
     if(cmd[0]!='+' && cmd[0]!='l' && cmd[0]!='r' && cmd[0]!='.') 
     { 
     std::cout << "unknown command:" << cmd << "\n"; 
     continue; 
     } 

     base_cmd.linear.x = base_cmd.linear.y = base_cmd.angular.z = 0; 
     //move forward 
     if(cmd[0]=='+'){ 
     base_cmd.linear.x = 0.25; 
     } 
     //turn left (yaw) and drive forward at the same time 
     else if(cmd[0]=='l'){ 
     base_cmd.angular.z = 0.75; 
     base_cmd.linear.x = 0.25; 
     } 
     //turn right (yaw) and drive forward at the same time 
     else if(cmd[0]=='r'){ 
     base_cmd.angular.z = -0.75; 
     base_cmd.linear.x = 0.25; 
     } 
     //quit 
     else if(cmd[0]=='.'){ 
     break; 
     } 

     //publish the assembled command 
     cmd_vel_pub_.publish(base_cmd); 
    } 
    return true; 
    } 

}; 

int main(int argc, char** argv) 
{ 
    //init the ROS node 
    ros::init(argc, argv, "robot_driver"); 
    ros::NodeHandle nh; 

    RobotDriver driver(nh); 
    driver.driveKeyboard(); 
} 

코드는 컴파일하고 제대로 실행하지만, 명령이 실행될 때 turtlebot가 이동하지 않습니다. 어떤 아이디어?

추가 정보 :

내 Turtlebot 메시지와 함께 제공되는 노트북에있어가 전송되는되지 않을 것으로 보인다 (또는 전달되지 않습니다). 별도의 터미널에서 내가 가진 :

[email protected]:~$ sudo service turtlebot start 
[sudo] password for turtlebot: 
turtlebot start/running, process 1470 
[email protected]:~$ rostopic echo /cmd_vel 

그리고

[email protected]:~$ rostopic pub /cmd_vel geometry_msgs/Twist '[1.0, 0.0, 0.0]' '[0.0, 0.0, 0.0]' 
publishing and latching message. Press ctrl-C to terminate 

정보와 :

[email protected]:~$ rostopic info /cmd_vel 
Type: geometry_msgs/Twist 

Publishers: 
* /rosttopic_2547_1352476947372 (http://turtlebot-0516:40275/) 

Subscribers: 
* /turtlebot_node (http://10.143.7.81:58649/) 
* /rostopic_2278_1352476884936 (http://turtlebot-0516:39291/) 

모든 에코에 대한 출력이 없습니다입니다.

+2

현재이 질문을 더 행운을 얻을 것이다 : HTTP : //answers.ros .org/questions/ – Dunes

답변

1

나는이 게시물이 천 년 된 것을 알고 있지만이 코드를 실행하는 데 아무런 문제가 없습니다. 각 문자가 입력 된 후에 엔터 키를 누르지 않고도 실행하려면 ncurses 라이브러리를 사용해야했습니다.

그냥 모든 사람들에게 이것이 작동한다는 것을 알릴 것이라고 생각했습니다. : P 나는 그것을 사용하여 iRobot을 만들었습니다.

0

sudo service turtlebot stop을 사용하면 자동 초기 설정을 중지하고 roslaunch turtlebot bringup minimal.launch을 사용하여 필요한 최소 설정 만 실행할 수 있습니다. 그런 다음 키보드로 원격 조작을 사용하려면 roslaunch turtlebot_teleop keyboard_teleop.launch으로 시도하십시오.

0

그냥가는 사람에게 Hello World for TurtleBot에 대한 자습서를 작성했습니다.

다른 사람의 경우에는이 머리카락을 꺼내려고 노력하는 것이 좋습니다.

변경 /cmd_vel 내가 사용

cmd_vel_mux/input/teleop에 :

  • 인디고
  • TurtleBot2
+1

링크가 작동하지 않습니다. –

관련 문제