ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Hello,

I have made a couple of very simple modifications to the original script in order to achieve that. What I've done is the following. First, import the Empty message:

import roslib; roslib.load_manifest('teleop_twist_keyboard')
import rospy

from geometry_msgs.msg import Twist
from std_msgs.msg import Empty

Then, create 2 new Publishers, one for landing and the other one for taking off. And create an instance of the Empty message:

if __name__=="__main__":
        settings = termios.tcgetattr(sys.stdin)

    pub = rospy.Publisher('cmd_vel', Twist, queue_size = 1)
    rospy.init_node('teleop_twist_keyboard')
    pub2 = rospy.Publisher('drone/takeoff', Empty, queue_size = 1)
    pub3 = rospy.Publisher('drone/land', Empty, queue_size = 1)
    empty_msg = Empty()

Finally, just add 2 conditions for the new keys:

while(1):
            key = getKey()
            if key in moveBindings.keys():
                x = moveBindings[key][0]
                y = moveBindings[key][1]
                z = moveBindings[key][2]
                th = moveBindings[key][3]
            elif key in speedBindings.keys():
                speed = speed * speedBindings[key][0]
                turn = turn * speedBindings[key][1]

                print vels(speed,turn)
                if (status == 14):
                    print msg
                status = (status + 1) % 15
                    elif key == '1':
                        pub2.publish(empty_msg)
                    elif key == '2':
                        pub3.publish(empty_msg)
            else:
                x = 0
                y = 0
                z = 0
                th = 0
                if (key == '\x03'):
                    break

I have also created a video showing how to do it and testing the script. Hope it helps!

Hello,

I have made a couple of very simple modifications to the original script in order to achieve that. What I've done is the following. First, import the Empty message:

import roslib; roslib.load_manifest('teleop_twist_keyboard')
import rospy

from geometry_msgs.msg import Twist
from std_msgs.msg import Empty

Then, create 2 new Publishers, one for landing and the other one for taking off. And create an instance of the Empty message:

if __name__=="__main__":
        settings = termios.tcgetattr(sys.stdin)

    pub = rospy.Publisher('cmd_vel', Twist, queue_size = 1)
    rospy.init_node('teleop_twist_keyboard')
    pub2 = rospy.Publisher('drone/takeoff', Empty, queue_size = 1)
    pub3 = rospy.Publisher('drone/land', Empty, queue_size = 1)
    empty_msg = Empty()

Finally, just add 2 conditions for the new keys:

while(1):
     key = getKey()
     if key in moveBindings.keys():
         x = moveBindings[key][0]
        moveBindings[key][0]    
        y = moveBindings[key][1]
        moveBindings[key][1]    
        z = moveBindings[key][2]
        moveBindings[key][2]    
        th = moveBindings[key][3]
     elif key in speedBindings.keys():
        speedBindings.keys():   
        speed = speed * speedBindings[key][0]
        speedBindings[key][0]   
        turn = turn * speedBindings[key][1]

         print vels(speed,turn)
        vels(speed,turn)  
        if (status == 14):
             print msg
        msg   
        status = (status + 1) % 15
      elif key == '1':
         pub2.publish(empty_msg)
     elif key == '2':
         pub3.publish(empty_msg)
      else:
         x = 0
        0   
        y = 0
        0   
        z = 0
        0   
        th = 0
        0  
        if (key == '\x03'):
             break

    twist = Twist()
twist.linear.x = x*speed; twist.linear.y = y*speed; twist.linear.z = z*speed;
twist.angular.x = 0; twist.angular.y = 0; twist.angular.z = th*turn
pub.publish(twist)

I have also created a video showing how to do it and testing the script. Hope it helps!