Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in latest versions for Android? #2500

Open
rrajivram opened this issue Jan 27, 2025 · 7 comments
Open

Bug in latest versions for Android? #2500

rrajivram opened this issue Jan 27, 2025 · 7 comments

Comments

@rrajivram
Copy link

Using mavsdk-2.1.0 and mavsdk-server-2.1.5 and Ardupilot SITL as the backend on an IP port I cannot get telemetry data on Android. Keeps telling me its retrying when I subscribe for position data. The only code I'm using beside server.run() and new System() is this in my main activity.kt :
fun runServer() {
MavsdkEventQueue.executor().execute({
val address = "tcp://192.168.29.118:5763"
val port = server.run(address)
Log.d(TAG, "port is $port")
if(port == 0) {
Log.e(TAG,"Unable to start server")
return@execute
}
drone = System("127.0.0.1",port)
isRunning = true
buttonText= "Destroy"
Log.i(TAG,"Server started")
setupSubscriptions()
})
}

@SuppressLint("CheckResult")
fun setupSubscriptions() {

    
    val altitude = drone.telemetry.position.subscribeOn(Schedulers.io())
        .observeOn(Schedulers.single())
        .subscribe({
            Log.d(TAG,"info : $it")
            Log.d(TAG,"Lat = " + it.latitudeDeg + ", Lon= " + it.longitudeDeg)
            latText = "   " + it.latitudeDeg
            longText = "   " + it.longitudeDeg
        }, Throwable::printStackTrace)
}

I've validated that QGC and mavproxy are able to both communicate with the SITL. When I change the mavsdk and server versions to 2.0 , then this works perfectly.

@julianoes
Copy link
Collaborator

mavsdk-server-2.1.5 seems quite old? Any chance you can try latest?

Do you have an example for me to test this with?

@rrajivram
Copy link
Author

rrajivram commented Jan 28, 2025 via email

@JonasVautherin
Copy link
Collaborator

Does it detect a mavlink system? Does your drone report receiving messages from MAVSDK over TCP?

@rrajivram
Copy link
Author

rrajivram commented Jan 28, 2025 via email

@rrajivram
Copy link
Author

And now its stopped working ; tried both version 1.2 and version 2.0. The entire source code is below :
`package com.example.greeting

import android.annotation.SuppressLint
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.example.greeting.ui.theme.GreetingTheme
import android.util.Log
import androidx.compose.foundation.layout.Row
import androidx.compose.material3.Button
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import io.mavsdk.MavsdkEventQueue;
import io.mavsdk.System;
import io.mavsdk.mavsdkserver.MavsdkServer;
import io.mavsdk.telemetry.Telemetry
import io.mavsdk.telemetry.Telemetry.Position
import io.reactivex.disposables.Disposable
import io.reactivex.Flowable;
import io.reactivex.functions.Consumer
import io.reactivex.functions.Function;
import io.reactivex.schedulers.Schedulers;
import kotlinx.coroutines.flow.Flow

class MainActivity : ComponentActivity() {
private val TAG = "MainActivity"

private val viewModel by viewModels<DroneModel>()
private val server = MavsdkServer()
private lateinit var drone: System
private var isRunning = false
private var disposables = mutableListOf<Disposable>()

var buttonText by  mutableStateOf("Start")
var altitudeText by mutableStateOf("AL")
var latText by mutableStateOf("LA")
var longText by mutableStateOf("LO")

@SuppressLint("QueryPermissionsNeeded")
override fun onCreate(savedInstanceState: Bundle?) {
    java.lang.System.setProperty("org.slf4j.simpleLogger.defaultLogLevel","Trace")
    Log.d(TAG,"in on create")
    super.onCreate(savedInstanceState)
    enableEdgeToEdge()
    setContent {
        GreetingTheme {
            Column(
                modifier = Modifier.fillMaxSize(),
                horizontalAlignment = Alignment.CenterHorizontally,
                verticalArrangement = Arrangement.Center
            ) {
                Row() {
                    Button(onClick = {
                        runOrDestroyServer()
                    }) {
                        Text(buttonText)
                    }
                }
                Row() {
                    Column {
                        Text("Altitude")
                    }
                    Column {
                        Text(altitudeText)
                    }
                }
                Row() {
                    Column {
                        Text("Latitude")
                    }
                    Column {
                        Text(latText)
                    }
                }
                Row() {
                    Column {
                        Text("Longitude")
                    }
                    Column {
                        Text(longText)
                    }
                }

            }
        }

    }
}

fun runOrDestroyServer() {
    if(isRunning) {
        stopServer()
    } else {
        runServer()
    }
}

fun runServer() {
    MavsdkEventQueue.executor().execute({
        val address = "tcp://192.168.29.118:5763"
        val port = server.run(address)
        Log.d(TAG, "port is $port")
        if(port == 0) {
            Log.e(TAG,"Unable to start server")
            return@execute
        }
        drone = System("127.0.0.1",port)
        isRunning = true
        buttonText= "Destroy"
        Log.i(TAG,"Server started")
        setupSubscriptions()
    })
}

@SuppressLint("CheckResult")
fun setupSubscriptions() {


    val altitude = drone.telemetry.position.subscribeOn(Schedulers.io())
        .observeOn(Schedulers.single())
        .subscribe({
            Log.d(TAG,"info : $it")
            Log.d(TAG,"Lat = " + it.latitudeDeg + ", Lon= " + it.longitudeDeg)
            latText = "   " + it.latitudeDeg
            longText = "   " + it.longitudeDeg
        }, Throwable::printStackTrace)


}

@SuppressLint("CheckResult")
fun stopServer() {
    if(!isRunning) {
        return
    }
    MavsdkEventQueue.executor().execute( {
        for(d in disposables ){
            d.dispose()
        }
        disposables.clear()
        drone.action.disarm().subscribe({},Throwable::printStackTrace)
        Thread.sleep(2000)
        drone.dispose()
        server.stop()

        isRunning = false
        buttonText = "Start"
    })
}

override fun onStart() {
    super.onStart()
    println("On start")
}

override fun onPause() {
    super.onPause()
    println("On Pause")
}

override fun onStop() {
    super.onStop()
    println("On Stop")
}

override fun onRestart() {
    super.onRestart()
    println("On Restart")
}

override fun onDestroy() {
    super.onDestroy()
    println("On Destroy")
}

override fun onResume() {
    super.onResume()
    println("On Resume")
}

}

`

Here are the log messages I'm seeing:
2025-01-28 10:45:58.089 6832-6892 Mavsdk com.example.greeting I MAVSDK version: v2.12.2
2025-01-28 10:45:58.090 6832-6892 MAVSDK-Server com.example.greeting D Running mavsdk_server with connection url: tcp://192.168.29.118:5763
2025-01-28 10:45:58.090 6832-6892 Mavsdk com.example.greeting I Waiting to discover system on tcp://192.168.29.118:5763...
2025-01-28 10:45:58.107 6832-6896 Mavsdk com.example.greeting D New system ID: 1 Comp ID: 1
2025-01-28 10:45:58.107 6832-6896 Mavsdk com.example.greeting D Component Autopilot (1) added.
2025-01-28 10:45:58.107 6832-6896 Mavsdk com.example.greeting W Vehicle type changed (new type: 2, old type: 0)
2025-01-28 10:45:58.107 6832-6896 Mavsdk com.example.greeting D Discovered 1 component(s)
2025-01-28 10:45:58.108 6832-6894 Mavsdk com.example.greeting I System discovered
2025-01-28 10:45:58.115 6832-6892 Mavsdk com.example.greeting I Server started
2025-01-28 10:45:58.115 6832-6892 Mavsdk com.example.greeting I Server set to listen on 0.0.0.0:35297
2025-01-28 10:45:58.115 6832-6892 MAVSDK-Server com.example.greeting D mavsdk_server is now running, listening on port 35297
2025-01-28 10:45:58.113 6832-6832 mavsdk-event-qu com.example.greeting W type=1400 audit(0.0:3935): avc: denied { read } for name="somaxconn" dev="proc" ino=496700 scontext=u:r:untrusted_app:s0:c190,c256,c512,c768 tcontext=u:object_r:proc_net:s0 tclass=file permissive=0 app=com.example.greeting
2025-01-28 10:45:58.115 6832-6892 MainActivity com.example.greeting D port is 35297
2025-01-28 10:45:58.118 6832-6892 MainActivity com.example.greeting I Server started
2025-01-28 10:45:58.128 6832-6892 System.err com.example.greeting W SLF4J(W): No SLF4J providers were found.
2025-01-28 10:45:58.128 6832-6892 System.err com.example.greeting W SLF4J(W): Defaulting to no-operation (NOP) logger implementation
2025-01-28 10:45:58.128 6832-6892 System.err com.example.greeting W SLF4J(W): See https://www.slf4j.org/codes.html#noProviders for further details.
2025-01-28 10:45:58.191 6832-6917 TrafficStats com.example.greeting D tagSocket(100) with statsTag=0xffffffff, statsUid=-1
2025-01-28 10:45:58.410 6832-6896 Mavsdk com.example.greeting D New system ID: 255 Comp ID: 230
2025-01-28 10:45:58.410 6832-6896 Mavsdk com.example.greeting D Component Unsupported component (230) added.
2025-01-28 10:45:58.410 6832-6896 Mavsdk com.example.greeting D Discovered 1 component(s)
2025-01-28 10:45:59.429 6832-6921 ProfileInstaller com.example.greeting D Installing profile for com.example.greeting
2025-01-28 10:46:07.967 6832-6877 EGL_emulation com.example.greeting D app_time_stats: avg=202.23ms min=1.90ms max=9099.12ms count=49

@JonasVautherin
Copy link
Collaborator

Yes. I tried both arm and disarm commands and they worked fine.

This sounds like mavlink messages sent by MAVSDK are received by the autopilot, but mavlink messages sent by the autopilot are not received by MAVSDK. Because you use a TCP connection, I don't think it would be a problem there (usually that happens with UDP) 🤔.

Are you sure that you don't have multiple clients competing on the connection? Not sure how Ardupilot implements TCP support. Did you make your tests when only MAVSDK and Ardupilot are running, and not pymavlink or QGC in parallel?

@rrajivram
Copy link
Author

rrajivram commented Jan 28, 2025 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants