RESTAPI : Is there any api which gives the current location


#1

Hello,

I am looking for a similar api like Position Setpoint to find the current location. The api Location Position Data that has been given in the documentation is based on Web Socket, but I am developing a native android app so I am not getting a clear idea regarding its implementation.
Can you guide me which api should I used?

Thanks


#2

Pratik,

This is the rest equivalent for local position data [ GET, url : localhost:9090/ros/flytsim/mavro … tion/local ]
But this will fetch the data only once. And to fetch updated data continuously you’ll have to make the rest call in a loop which is not recommended. Hence the websocket implementation which runs on callbacks which automatically tells us when a data is updated.
For easier implementation of the websocket we have used cordova to develop native android apps which uses HTML ,JS for development .(available in documentation).
If you want to develop apps in java then for websocket implementation you can have a look at rojava: wiki.ros.org/rosjava?distro=indigo


#3

Vallabh,

I have tested the local position data api provided by you, but it doesn’t give any response regarding the location. It only returns a response 200 OK. I am sharing a screenshot please have a look and suggest me what should I do to have a local position.

Thanks



#4

Vallabh,

For WebSocket I am using Java WebSockets library. Below is its implementation

private void connectWebSocket() {
URI uri;
try {
uri = new URI(“ws://10.0.1.108:9090/flytsim/mavros/local_position/local”);
} catch (URISyntaxException e) {
e.printStackTrace();
return;
}

    mWebSocketClient = new WebSocketClient(uri) {
        @Override
        public void onOpen(ServerHandshake serverHandshake) {
            Log.i("Websocket", "Opened");
            mWebSocketClient.send("Hello from " + Build.MANUFACTURER + " " + Build.MODEL);
        }

        @Override
        public void onMessage(String s) {
            final String message = s;
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    Log.d("websocket",message);
                }
            });
        }

        @Override
        public void onClose(int i, String s, boolean b) {
            Log.i("Websocket", "Closed " + s);
        }

        @Override
        public void onError(Exception e) {
            Log.i("Websocket", "Error " + e.getMessage());
        }
    };
    mWebSocketClient.connect();
}

Can you suggest how to send the params for local position api.

Thanks


#5

Pratik,
In case of rest calls just use the address and use get method …no parameters

And for websocket its not as straight forward as using a java websocket library. You also need to know the type of ROS based Structure used to make the specific topic to be able to parse the data and also some ros based libraries to recieve the websocket data .
the details of how it is done is in rosjava link provided in the previous posts.


#6

Vallabh,
The rest call without any parameters gives me response Result status 200 OK , but the response is null.
Below is the screen shot.

Thanks.