Robot Operating System Ros Tutorial (eight) keyboard control

Source: Internet
Author: User
Tags command line

If you have tried the previous example, there is no feeling that every time the robot to move and input instructions in the terminal, this is too cumbersome, there is no way through the keyboard to control the movement of the robot? The answer room of course. I studied several other robot keyboard control code, or some harvest, finally transplanted to the SmartCar, the experiment was successful.

First, create a control pack

First, we create a separate package for keyboard control:

Roscreate-pkg smartcar_teleop rospy geometry_msgs std_msgs roscpp  

If you have forgotten how to build a package, please refer to: http://www.ros.org/wiki/ROS/Tutorials/CreatingPackage

Second, simple message release

In the robot simulation, the main control robot Mobile is in the robot simulation, the main control robot Mobile is Twist () structure, if we program this structure through the program released into topic, nature can control the robot. Let's try the simple Python first.

In the previous simulations, we used a message release at the command line, and now we need to convert these commands into Python code and encapsulate them in a separate node. For the previous command line, we can easily write the following control code under the Smartcar_teleop/scripts folder:

#!/usr/bin/env python  
import roslib roslib.load_manifest (' Smartcar_teleop ')  
import rospy from  
geometry _msgs.msg import Twist from  
std_msgs.msg import String  
      
class Teleop:  
    def __init__ (self):  
        pub = Rospy. Publisher (' Cmd_vel ', Twist)  
        rospy.init_node (' smartcar_teleop ')  
        rate = Rospy. Rate (Rospy.get_param (' ~hz ', 1))  
        self.cmd = None
          
        cmd = Twist ()  
        cmd.linear.x = 0.2 cmd.linear.y
        = 0< C14/>cmd.linear.z = 0
        cmd.angular.z = 0
        cmd.angular.z = 0
        cmd.angular.z = 0.5 self.cmd
      
        = cmd  
        While isn't Rospy.is_shutdown ():  
            str = "Hello World%s"% rospy.get_time ()  
            rospy.loginfo (str)  
            Pub.publish (Self.cmd)  
            Rate.sleep ()  
      
if __name__ = = ' __main__ ': Teleop ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.