Exemplo n.º 1
0
def key_op():
    #Function that continuously checks for key presses
    """Setup node and twistCommand object. Main ROS loop."""
    #Init node. anonymous=True allows multiple launch with automatically assigned names
    rospy.init_node('key_command', anonymous='True')
    #Set rate to use (in Hz)
    rate = rospy.Rate(50)

    #to stands for tWISTcOMMAND oBJECT
    tco = TwistCommand()

    #Print out directions and current speeds
    command_info = "'w': increment speed_linear;\n's': decrement speed_linear;\n'd': increment speed_angular;\n'a': decrement speed_angular"
    rospy.loginfo(command_info)
    rospy.loginfo("Current speed_linear: " + str(tco.speed_linear))
    rospy.loginfo("Current speed_angular: " + str(tco.speed_angular))

    global twist_msg
    twist_msg = Twist()

    #Boilerplate to get function to read keyboard
    getch = mu._Getch()

    while not rospy.is_shutdown():
        #check for keyboard commands
        key = getch()
        tco.update(key)
        #Wait until it is done
        rate.sleep()
Exemplo n.º 2
0
def main():
    """Function to setup node and loop"""
    #Setup node and object for rate throttling
    rospy.init_node('key_emergency_switch')
    rate = rospy.Rate(50)
    print '     Press "q" to quit.\n'

    #Boilerplate to get function to read keyboard
    getch = mu._Getch()

    #Main ROS loop
    while not rospy.is_shutdown():
        key = getch()
        if key == 'q':
            rospy.loginfo("Shutdown initiated")
            rospy.signal_shutdown(
                'Shutting down initiated by %s' % rospy.get_name())
        rate.sleep()
Exemplo n.º 3
0
    def send(self):
        getch = mu._Getch()  #Runs to recieve key commands
        rate = rospy.Rate(50)
        speed_linear = self.msg.linear.x  #setting up variables specified in HW
        speed_angular = self.msg.angular.z
        while not rospy.is_shutdown():
            key = getch()
            #Runs through all the possibilities for key commands and prints
            if key == 'w':
                if speed_linear < 1.0:
                    speed_linear = speed_linear + 0.2  #increasing linear speed by 0.2
                    rospy.loginfo("New linear speed is %0.1f", speed_linear)
                else:
                    rospy.loginfo("Linear speed is already at maximum, 1.0.")
            elif key == 's':
                if speed_linear > -1.0:
                    speed_linear = speed_linear - 0.2  #decreasing linear speed by 0.2
                    rospy.loginfo("New linear speed is %0.1f", speed_linear)
                else:
                    rospy.loginfo("Linear speed is already at minimum, -1.0.")
            elif key == 'd':
                if speed_angular < 1.0:
                    speed_angular = speed_angular + 0.2  #increasing angular speed by 0.2
                    rospy.loginfo("New angular  speed is %0.1f", speed_angular)
                else:
                    rospy.loginfo("Angular speed is already at maximum, 1.0.")
            elif key == 'a':
                if speed_angular > -1.0:
                    speed_angular = speed_angular - 0.2  #decreasing angular speed by 0.2
                    rospy.loginfo("New angular speed is %0.1f", speed_angular)
                else:
                    rospy.loginfo("Angular speed is already at minimum, -1.0.")
            elif key == 'q':
                rospy.loginfo("Shutdown initiated")
                rospy.signal_shutdown(
                    "Shutting down initiated by key_emergency_switch")
            else:
                pass
#Need to spend the values of the variables back to Twist
            self.msg.linear.x = speed_linear
            self.msg.angular.z = speed_angular
            self.pub.publish(self.msg)  #sends back to Twist
            rate.sleep()
Exemplo n.º 4
0
def main():
    """The node permits to change velocities of the robot through the press of certain keys on your keyboard:
    press:
    w - accelerate/increases linear velocities in front direction
    a - turn left
    s - decelerate/decreases linear velocity in front direction
    d - turn right
    q - quit
    """

    rospy.init_node('key_op', anonymous='True')

    pub = rospy.Publisher('robot_twist', Twist, queue_size=10)

    tmsg = Twist()

    rate = rospy.Rate(50)

    speed = mcm.KeysToVelocities()

    getch = mu._Getch()

    while not rospy.is_shutdown():

        key = getch()

        if key == 'q':

            rospy.loginfo('Shutdown Initiated')
            rospy.signal_shutdown('Shutting down initiated by %s' %
                                  rospy.get_name())

        else:

            speedv = speed.update_speeds(key)

            tmsg.linear.x = speedv[0]
            tmsg.angular.z = speedv[1]
            pub.publish(tmsg)

        rate.sleep()
Exemplo n.º 5
0
def main():
    """Function to setup node and loop"""
    #Setup node and object for rate throttling
    rospy.init_node('key_op')
    rate = rospy.Rate(50)

    pub = rospy.Publisher('robot_twist', Twist, queue_size=10)

    #Boilerplate to get function to read keyboard
    getch = mu._Getch()

    key_to_speed = mcm.KeysToVelocities()
    cmd_vel = Twist()
    print_usage()
    print('Linear Speed: %f | Angular Speed: %f'%(key_to_speed.speed_linear,key_to_speed.speed_angular))
    print('')
    
    #Main ROS loop
    while not rospy.is_shutdown():
        key = getch()

        # Check if exit is commanded
        if key == 'q' or key == 'Q':
            rospy.loginfo("Shutdown initiated")
            rospy.signal_shutdown(
                'Shutting down initiated by %s' % rospy.get_name())
        else:
            key_to_speed.update_speeds(key)
            cmd_vel.linear.x = key_to_speed.speed_linear
            cmd_vel.angular.z = key_to_speed.speed_angular
            print(key_to_speed.action)
            print('Linear Speed: %f | Angular Speed: %f'%(key_to_speed.speed_linear,key_to_speed.speed_angular))
            print('')

            pub.publish(cmd_vel)

        rate.sleep()