akshayvernekar / telloArduino

Open source arudino library for controlling tello through ESP32
32 stars 17 forks source link

void Tello::init() #4

Open TobiasFrahm opened 3 years ago

TobiasFrahm commented 3 years ago

Hello, am I right, that the drone is always initialised? Even if the response.compare("ok") is not true? Is this intended?

void Tello::init()
{
    udpclient = new WiFiUDP();
    //This initializes udp and transfer buffer
    udpclient->begin(COMMAND_PORT);
    isInitialised = true;
    string response = sendCommand("command");
    //if response is other than "ok" then we consider as error 
    if(response.compare("ok"))
    {
        isInitialised = true;
    }
}

Greetings Tobi

akshayvernekar commented 3 years ago

Hi Tobi, Good find , I had originally set it to FALSE but since the response to "command" is sent via UDP the response is sometimes lost, this is the reason I had set the isInitialised flag to TRUE when I carried out my tests . I should probably add a comment there .

Also could you check with your tello and let me know if you are able to get the response consistently ? If yes I will change the flag to False.

TobiasFrahm commented 3 years ago

Hello, thank you for the Reply. I see your point here, I think the loss of Information due to the UDP is a general problem with this tello API... I think something Asynchronous would be needed here, but we are talking about an controlling API of a flying device... We cannot block and wait for the response, but it would be great to be sure that the command was processed by the tello.

But anyways, in this certain case, since this is a init-function, I think it would be OK to do something blocking like this:

string Tello::init()
{
    udpclient = new WiFiUDP();
    //This initializes udp and transfer buffer
    udpclient->begin(COMMAND_PORT);
    string response = "nok":
    u_int8_t cnt = 0;
    while (response.compare("ok")){
        response = sendCommand("command");
        delay(500);
        cnt++;
        if (cnt > 10){
            // just don't block forever
            return "error";
        }
    }

    //if response is other than "ok" then we consider as error 
    if(response.compare("ok"))
    {
        isInitialised = true;
    }
}
TobiasFrahm commented 3 years ago

I observed strange behavior with this. It nearly always works, If i just use it as it was. If I try my approach, it does not even get in the SDK-Mode with or without response... I will play around a bit, maybe I will find an answer!

akshayvernekar commented 3 years ago

I guess I have faced this issue earlier, if you have already sent the command to enter the SDK mode the drone doesn't send Acknowledgement if the command is sent again for the second time . I don't have my Tello currently to verify but i remember facing this issue.