mavlink / MAVSDK-Java

MAVSDK client for Java.
73 stars 42 forks source link

I get `TIMEOUT: Timeout` when uploading my rover's mission #166

Closed Sefibrah closed 3 months ago

Sefibrah commented 3 months ago

I am losing hope. I've been desperately searching about this, but nothing useful is coming up.

I have a SITL ArduRover, and my Android device (Redmi Note 8) running my own lil' Android app, and I manage to connect them through UDP perfectly. I am subscribing to the SITL Rover's position and battery value changes, and I display them on the device screen reactively. That's running smoothly.

The problem is this: I can't upload a damn mission! I am getting timeout errors after roughly 1-3 seconds passing! Is this normal?

To make matters worse, I used QGC to upload a mission to my SITL Rover, and that worked smoothly. I downloaded the mission plan file, tried to copy it to the best of my abilities, but it's failing too...

Anyway, I hope that the information below will give you enough context to help me...

Here are my dependencies:

implementation 'io.mavsdk:mavsdk:2.0.1'
implementation 'io.mavsdk:mavsdk-server:2.0.0'

Here's my code, heavily inspired by this method from source code:

public void doSomeMission() {
  List<MissionRaw.MissionItem> missionItems = new ArrayList<>();
  missionItems.add(generateMissionItem(0, 0, 16, 1, -35.3632621, 149.1652374, 585));

  // takeoff mission item, but I am Mr. rover, i don't need takeoff...
  // missionItems.add(generateMissionItem(1, 3, 22, 0, 0, 0, 0));

  missionItems.add(generateMissionItem(1, 3, 16, 0, -35.36279934, 149.16518583, 50));
  missionItems.add(generateMissionItem(2, 3, 16, 0, -35.36279844, 149.16578784, 50));
  missionItems.add(generateMissionItem(3, 3, 16, 0, -35.36321925, 149.16578136, 50));

  missionItems.add(generateMissionItem(4, 3, 20, 0, 0, 0, 0));
  Log.d(TAG, "Uploading and starting mission...");

  if(mRover != null) {
    mRover.getMissionRaw().uploadMission(missionItems)
        .doOnComplete(() -> Log.d(TAG, "Upload succeeded"))
        .doOnError(throwable -> Log.e(TAG, "Failed to upload the mission", throwable))
      .andThen(mRover.getAction().arm()
        .onErrorComplete())
      .andThen(mRover.getMissionRaw().startMission()
        .doOnComplete(() -> Log.d(TAG, "Mission started"))
        .doOnError(throwable -> Log.e(TAG, "Failed to start the mission", throwable)))
      .subscribe(() -> {
      }, throwable -> {
      });
  } else {
    Log.d(TAG, "Rover is not yet initialized!");
  }
}

public static MissionRaw.MissionItem generateMissionItem(int seq, int frame, int command, int current, double latitudeDeg, double longitudeDeg, float alt) {
  int intLatitudeDeg = (int) (latitudeDeg * 10000000);
  int intLongitudeDeg = (int) (longitudeDeg * 10000000);
  return new MissionRaw.MissionItem(seq, frame, command, current, 1, 0f, 0f, 0f, 0f, intLatitudeDeg, intLongitudeDeg, alt, 0);
}

Here's the error message I receive:

E  Failed to upload the mission
  io.mavsdk.mission_raw.MissionRaw$MissionRawException: TIMEOUT: Timeout
  at io.mavsdk.mission_raw.MissionRaw$1.onNext(MissionRaw.java:497)
  at io.mavsdk.mission_raw.MissionRaw$1.onNext(MissionRaw.java:490)
  at io.grpc.stub.ClientCalls$StreamObserverToCallListenerAdapter.onMessage(ClientCalls.java:468)
  at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1MessagesAvailable.runInternal(ClientCallImpl.java:667)
  at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1MessagesAvailable.runInContext(ClientCallImpl.java:654)
  at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:37)
  at io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:133)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
  at java.lang.Thread.run(Thread.java:923)

I am writing this in hopes of help, as I am genuinely on the edge of losing my mind! Thanks to anyone who helps, and I apologise for tagging you @JonasVautherin, but you did mention that you have a lot of experience with MissionRaw and that you know people who use it, so I wanted to bring this to your attention first. Please forgive me.

Best Regards, Ibrahim Sefer

julianoes commented 3 months ago

What's running on the rover? PX4 or ArduRover?

Sefibrah commented 3 months ago

ArduRover! e.g. I use cd ~/ardupilot/Rover && sim_vehicle.py --map --console --model JSON -D --out udpin:192.168.1.100:14550 -f gazebo-rover to boot it up.

julianoes commented 3 months ago

Ok, do you get the mavsdk_server log output? If so, can you set the env variable MAVSDK_MISSION_TRANSFER_DEBUGGING=1? That might give you more info.

Sefibrah commented 3 months ago

Where do I put that @julianoes? Tried searching for it, couldn't find explanations or examples of it...

Are you perhaps talking about these logs from LogCat:

2024-06-24 12:27:44.572  7994-8173  Mavsdk                  io.ionic.starter                     W  timeout: retries exceeded
2024-06-24 12:27:44.605  7994-8186  LOG_RoverM...munication io.ionic.starter                     E  Failed to upload the mission
                                                                                                    io.mavsdk.mission_raw.MissionRaw$MissionRawException: TIMEOUT: Timeout
                                                                                                        at io.mavsdk.mission_raw.MissionRaw$1.onNext(MissionRaw.java:497)
                                                                                                        at io.mavsdk.mission_raw.MissionRaw$1.onNext(MissionRaw.java:490)
                                                                                                        at io.grpc.stub.ClientCalls$StreamObserverToCallListenerAdapter.onMessage(ClientCalls.java:468)
                                                                                                        at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1MessagesAvailable.runInternal(ClientCallImpl.java:667)
                                                                                                        at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1MessagesAvailable.runInContext(ClientCallImpl.java:654)
                                                                                                        at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:37)
                                                                                                        at io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:133)
                                                                                                        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
                                                                                                        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
                                                                                                        at java.lang.Thread.run(Thread.java:923)
2024-06-24 12:27:52.886  7994-8175  Mavsdk                  io.ionic.starter                     D  MAVLink: warning: Mission upload timeout
2024-06-24 12:27:52.886  7994-8120  Mavsdk                  io.ionic.starter                     D  MAVLink: warning: Mission upload timeout

or perhaps these logs from the sim_vehicle.py --console thing:

Got MISSION_ACK: TYPE_MISSION: OPERATION_CANCELLED
AP: Mission upload timeout

or perhaps I just need to put that environment variable in my .zshrc or .bashrc?

Sefibrah commented 3 months ago

I've noticed that it could be due to connection issues. Apparently, receiving data is not the same as sending data, right? They have their separate ports, or addresses? Does that mean that when I do this combination:

private void initializeServerAndRover(@NonNull String systemAddress) {
    MavsdkEventQueue.executor().execute(() -> {
          mMavsdkServer = new MavsdkServer();
          int mavsdkServerPort = mMavsdkServer.run("udp://192.168.1.100:14550");

          mRover = new io.mavsdk.System("localhost", mavsdkServerPort);
          Log.d(TAG, "Rover is initialized!");

          // other stuff
    });
}

followed by

sim_vehicle.py -D -f gazebo-rover --model JSON --out udpin:192.168.1.100:14550 --map --console

I only really account for the RECEPTION of data, but when I try to send data (like my mission), I get TIMEOUT: Timeout very quickly. Could this be it? Or am I completely misinterpreting this...

EDIT:

I don't think this is the issue, I was able to send mRover.getAction().arm().subscribe() and it armed my rover... So the connection is both ways, but not for bloody missions...

Sefibrah commented 3 months ago

MAVSDK_MISSION_TRANSFER_DEBUGGING=1

Is this a Docker env? I am not using Docker? Just ArduRover, my laptop, and my phone.

Sefibrah commented 3 months ago

I think I have the same issue as this guy did here, but he says that it's fixed for him?

chehrlic commented 3 months ago

I explictly wrote what I've done - I've updated MAVSDK as https://github.com/mavlink/MAVSDK/commit/30d2693417fe2afdfe494ace3e0f5b8ee5331f03 fixes the issue...

Sefibrah commented 3 months ago

But I am using implementation 'io.mavsdk:mavsdk-server:2.0.0' instead of mavsdk_server from brew install mavsdk like you... I guess I need to wait for the update here as well? @julianoes @JonasVautherin when's the update? Or maybe you can guide me on helping you push this fix that @chehrlic mentioned? Or maybe it's already inside, I just don't know how to access it?

Sefibrah commented 3 months ago

I posted a PR @julianoes @JonasVautherin, please check it 😭

Sefibrah commented 3 months ago

Tried running the mavsdk_server locally on v2.12.2, and the mission got through! So I guess that the issue is fixed. Please accept my PR.

Sefibrah commented 3 months ago

All that's left is just for the maintainers to push the PR to Maven, so I'll close this issue...