Publish command via Websocket in Java


#1

Was able to setup topic’s and subscribe to Telemtry endpoints using FlytSDK via websocket without any issues.
Things are harder now that I want to switch from Rest driven request do websocket.
I want to trigger the ‘takeoff’ command via websocket in order to wait for the finished result.

The topic instantiation looks like:
val t = Topic(ros,"/flytsim/navigation/take_off",“core_api/TakeOff”,2000)
later on int the code I try to publish my request via:
t.publish(“payload”)

Flytsim Docker prompts:
flytsim ==> “publish: Cannot infer topic type for topic /flytsim/navigation/take_off as it is not yet advertised”

Everything compiles and as mentioned before, I can subscribe to topics and process feedback via callbacks. What I am not getting clearly is how to send commands over and wait for a proper result.

Thanks for your help


#2

Hi @tmaus,

instead of calling publish() function, there should be a service().
I will update this thread once I go through the SDK again.


#3

Unfortunately,

TakeOff is a ROS Service call and cannot be called via ‘publish’ function as it is only for ROS Topics.

The SDK does not have the above call definition.
Handling Service response has still not been coded yet.

But one can define the following function:

public void callService(String service_name, JSONObject req, CallbackRos cb) {
this.ros.registerTopicCallback(service_name, cb);
this.callbacks.add(cb);
this.call = new JSONObject();
try {
this.call.put(“op”, “call_service”);
this.call.put(“service”, service_name);
this.call.put(“args”, req);
} catch (JSONException error) {
;
}
this.ros.call(this.call);
}

This would call the service but not fetch the response.
Please refer this guide for more details.


#4

I will try to update SDK and add this feature, but I cannot mention a timeline for this.