mavlink / MAVSDK-Java

MAVSDK client for Java.
73 stars 42 forks source link

run Mavsdk issue #139

Closed Zxr1230 closed 10 months ago

Zxr1230 commented 1 year ago

When I am trying to run the Mavsdk in the android-client example, it always stops at this line. I wonder why it doesn't go to the next line - drone system. Thank you! image

divyanshupundir commented 1 year ago

Hello @Zxr1230.

That is by design. Basically, the server blocks till it gets the flight controller's heartbeat. Only after that it starts the GRPC server to which the System client connects.

divyanshupundir commented 1 year ago

So you'll see the next line running once the flight controller's heartbeat is sent to the server input address.

Zxr1230 commented 1 year ago

Hello @Zxr1230.

That is by design. Basically, the server blocks till it gets the flight controller's heartbeat. Only after that it starts the GRPC server to which the System client connects.

Thank you for helping! Am I able to see if the Mavsdk server successfully connects with the receiving unit of the ground controller? If not, it will never receive a heartbeat, right?

divyanshupundir commented 1 year ago

I'm sorry, I'm not able to understand the question correctly. Can you give more details?

Zxr1230 commented 1 year ago

I'm sorry, I'm not able to understand the question correctly. Can you give more details?

Sure, in order to receive a heartbeat, the device installed with Mavsdk needs to have a receiving unit hardware such as an antenna right? Does the Mavsdk need to successfully connect with that thing first? Thank you!

divyanshupundir commented 1 year ago

Yes, you can send data to your phone over UDP, TCP. For serial connection you can go through this issue. Here we have discussed different solutions to getting data over serial.

Zxr1230 commented 1 year ago

Yes, you can send data to your phone over UDP, TCP. For serial connection you can go through this issue. Here we have discussed different solutions to getting data over serial.

Thank you! I am using a Herelink ground controller(an Android device and it's UDP) to communicate with the drone. Do I need to make sure that the Mavsdk can use the UDP? Does it need a correct IP address or port number?

divyanshupundir commented 1 year ago

Yes, on a Herelink, you can run the MAVSDK server with the default run() function and it will get the heartbeat.

Herelink basically creates a UDP client that emits data to 14550 port. By default, the MAVSDK server creates a UDP server at using the 14550 port.

Zxr1230 commented 1 year ago

Yes, on a Herelink, you can run the MAVSDK server with the default run() function and it will get the heartbeat.

Herelink basically creates a UDP client that emits data to 14550 port. By default, the MAVSDK server creates a UDP server at using the 14550 port.

Thank you! I found the port number might be 14552. Do I use run("udp://:14552")? Or it should be a different format.

divyanshupundir commented 1 year ago

Please try that. It should work.

Zxr1230 commented 1 year ago

Please try that. It should work.

I tried the default which is 14540 and I also tried 14550 and 14552, but none works. Any other address I should check? Thank you! image

divyanshupundir commented 1 year ago

@Zxr1230 sorry for not being able to reply.

The MavsdkServer.run() function takes two parameters.

The System object also takes two parameters.

So doing something like this should work:

MavsdkServer.run("udp://:14550", 50051);

System system = new System("localhost", 50051);
Zxr1230 commented 1 year ago

@Zxr1230 sorry for not being able to reply.

The MavsdkServer.run() function takes two parameters.

  • systemAddress: The address where the server listens for drone data. This can be a UDP address for example "udp://:14550"
  • mavsdkServerPort: This can be considered as an output port of the server to which a System object gets connected to.

The System object also takes two parameters.

  • host: Basically the address where you're expecting the server to be running. In the case of Android, it's the same device so "localhost" or "127.0.0.1" will work
  • port: This is practically the same value as mavsdkServerPort

So doing something like this should work:

MavsdkServer.run("udp://:14550", 50051);

System system = new System("localhost", 50051);

No problem, thank you very much for helping me with this! I tried run("udp://:14540", 50051); run("udp://:14550", 50051); and run("udp://:14552", 50051); but I still can't get to the next line drone = new System(BACKEND_IP_ADDRESS, mavsdkServerPort);

Should I skip MavsdkServer.run and directly give value to the new System(BACKEND_IP_ADDRESS, mavsdkServerPort);? Or I might have a different mavsdkServerPort number?

divyanshupundir commented 1 year ago

Have you added internet permissions to your app's Manifest? To use TCP or UDP ports, you need to give those permissions.

Zxr1230 commented 1 year ago

Have you added internet permissions to your app's Manifest? To use TCP or UDP ports, you need to give those permissions.

I did. This looks correct, right? Do I need to let the Herelink controller connect to the internet? Thank you! image

divyanshupundir commented 1 year ago

No you don't need to connect it to the internet.

Hmm... It is quite strange. Can you try to find out what port QGC is using on the Herelink?

Apart from this, can you try running the app on your phone and connect to Herelink's hotspot? Basically this setup.

Zxr1230 commented 1 year ago

No you don't need to connect it to the internet.

Hmm... It is quite strange. Can you try to find out what port QGC is using on the Herelink?

Apart from this, can you try running the app on your phone and connect to Herelink's hotspot? Basically this setup.

Thank you! Do you mean install the app on an Android phone and connect the app to the Herelink ground controller rather than the drone?

divyanshupundir commented 1 year ago

A little more clear way to say that would be:

Flight controller -> Herelink Air Unit -> Herelink Ground Unit -> Phone (connected to Herelink Ground Unit WiFi Hotspot)

Zxr1230 commented 11 months ago

No you don't need to connect it to the internet.

Hmm... It is quite strange. Can you try to find out what port QGC is using on the Herelink?

Apart from this, can you try running the app on your phone and connect to Herelink's hotspot? Basically this setup.

Rather than the QGC, my friend has a simple app in C# that can send and receive heartbeats from the drone I am trying to connect. Here is the screenshot of the source code about the port number. I tried run("udp://:14552", 50051) but it didn't work. Don't know if this can give you some hints why it doesn't work. Thank you!

image image

divyanshupundir commented 11 months ago

I'm sorry, I'm not able to understand what's happening in this code snippet 😅.

But shouldn't you be using UDP Server instead of Client?

Zxr1230 commented 11 months ago

I'm sorry, I'm not able to understand what's happening in this code snippet 😅.

But shouldn't you be using UDP Server instead of Client?

No problem, my friend said the UDP server is already active on the Herelink so he uses the UDP client to connect with the UDP server in the Herelink ground unit to read or write via the Herelink ground unit radio. Does he understand it correctly? His app works though. Thanks!

divyanshupundir commented 11 months ago

If that's the case then you can try running the MAVSDK server in UDP client mode:

MavsdkServer.run("udp://<address>:<port>", 50051);

System system = new System("localhost", 50051);
Zxr1230 commented 11 months ago

If that's the case then you can try running the MAVSDK server in UDP client mode:

MavsdkServer.run("udp://<address>:<port>", 50051);

System system = new System("localhost", 50051);

Thank you! Do you mean like this? MavsdkServer.run("udp://192.168.42.129:14552", 50051); and the second line same as before

Zxr1230 commented 11 months ago

A little more clear way to say that would be:

Flight controller -> Herelink Air Unit -> Herelink Ground Unit -> Phone (connected to Herelink Ground Unit WiFi Hotspot)

I tried mavsdkServer.run("udp://:14550", 50051); It did make the connection and went to the next line. Regardless of whether the drone is turned on or not, it can make the connection. It connected with the Herelink Ground Unit, not the drone, right? Thank you!