def Drone_land(signal_recieved, frame):

    drone.stop_piloting()
    time.sleep(3)
    Drone_Actn(11, drone)
    print("Simulation Exited")
    sys.exit(0)
def callback(data):
    x0 = data

    global drone
    Dr_IP = "192.168.42.1"  # Real Drone
    Dr_cl = Anafi_drone(Dr_IP)
    drone = Dr_cl.drone

    x0 = 11
    # Gains
    gn_mat = [3.5, 8.5, 4, 6, 1, 2]
    X_Tar = [0, 0, 1.3]
    Vran = 1.33

    if x0 <= 8:
        acn = [
            "Take off", "Mapping", "Go to 0,0,1.5", "Go Home and point out",
            "Track Center", "Circle Origin", "Gimbal Up +45",
            "Gimbal Down -45", "Yaw CW", "Yaw CCW", "Land", "Exit"
        ]
        print(colored(('Starting action: ' + acn[x0 - 1] + '\n'), "green"))
        X_Ref = Drone_Actn(x0, drone)
        if x0 == 2:
            Drone_Map_Opn2(Dr_cl, X_Ref, X_Tar, Vran)
        elif x0 == 3:
            Drone_Line_Track(Dr_cl, X_Ref)
        elif x0 == 4:
            Drone_Move_Orient(Dr_cl, X_Ref)
        elif x0 == 5:
            Drone_Center_Track(Dr_cl, X_Ref)
        elif x0 == 6:
            Drone_Circle(Dr_cl, X_Ref)
        elif x0 == 7:
            gimbal_target(drone, 45)
        elif x0 == 8:
            gimbal_target(drone, -45)

        x0, c = Print_Drone_Actns(acn, acn_N)

    else:
        print(
            colored(('Invalid action selected, please select again! \n'),
                    "red"))
def callback(data):
    global Dr_cl
    global drone
    #rospy.loginfo("DATA RECIEVED:", data)
    print("DATA:", data.data)
    x0 = data.data



    
    # Gains
    gn_mat = [3.5, 8.5, 4, 6, 1, 2]
    X_Tar  = [0, 0, 1.3]
    Vran = 1.33

    acn_N = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 20]
    acn   = ["Take off", "Mapping", "Go to 0,0,1.5", "Go Home and point out", "Track Center","Circle Origin","Gimbal Up +45", "Gimbal Down -45", "Yaw CW", "Yaw CCW", "Land", "Exit" ]

    if x0<=20:
        print( colored( ('Starting action: ' +  acn[x0-1] + '\n'), "green") )
        X_Ref = Drone_Actn(x0, drone)

        if x0==2:
            Drone_Map_Opn2(Dr_cl, X_Ref, X_Tar, Vran)
        elif x0==3:
            Drone_Line_Track(Dr_cl, X_Ref)
        elif x0==4:
            Drone_Move_Orient(Dr_cl, X_Ref)
        elif x0==5:
            Drone_Center_Track(Dr_cl, X_Ref)
        elif x0==6:
            Drone_Circle(Dr_cl, X_Ref)
        elif x0==7:
            gimbal_target(drone, 45)
        elif x0==8:
            gimbal_target(drone, -45)

        # x0, c = Print_Drone_Actns(acn,  acn_N)

    else:
        print( colored( ('Invalid action selected, please select again! \n'), "red" ))
        acn = [
            "Take off", "Mapping", "Go to 0,0,1.5", "Go Home and point out",
            "Track Center", "Circle Origin", "Gimbal Up +45",
            "Gimbal Down -45", "Yaw CW", "Yaw CCW", "Land", "Exit"
        ]
        n_actn = len(acn)

        while (x0 < 20):

            if x0 <= n_actn:

                print('\x1bc')
                print(
                    colored(('Starting action: ' + acn[x0 - 1] + '\n'),
                            "green"))
                X_Ref = Drone_Actn(x0, drone)
                if x0 == 2:
                    Drone_Map_Opn2(Dr_cl, X_Ref, X_Tar, Vran)
                elif x0 == 3:
                    Drone_Line_Track(Dr_cl, X_Ref)
                elif x0 == 4:
                    Drone_Move_Orient(Dr_cl, X_Ref)
                elif x0 == 5:
                    Drone_Center_Track(Dr_cl, X_Ref)
                elif x0 == 6:
                    Drone_Circle(Dr_cl, X_Ref)
                elif x0 == 7:
                    gimbal_target(drone, 45)
                elif x0 == 8:
                    gimbal_target(drone, -45)