Open Ahmed-Radwan094 opened 4 years ago
package com.github.rosjava_opends.opends;
import java.net.InetAddress; import java.net.URI;
import org.jboss.netty.buffer.ChannelBuffer; import org.ros.exception.RemoteException; import org.ros.exception.RosRuntimeException; import org.ros.exception.ServiceNotFoundException; import org.ros.internal.message.MessageBuffers; import org.ros.namespace.GraphName; import org.ros.node.AbstractNodeMain; import org.ros.node.ConnectedNode; import org.ros.node.DefaultNodeMainExecutor; import org.ros.node.NodeConfiguration; import org.ros.node.NodeMainExecutor; import org.ros.node.service.ServiceClient; import org.ros.node.service.ServiceResponseListener;
import com.google.common.base.Preconditions;
import rosjava_custom_srv.Image_SteeringResponse; import rosjava_custom_srv.Image_SteeringRequest; import rosjava_custom_srv.Image_Steering;
public class Image_Steering_Client extends AbstractNodeMain {
ServiceClient<Image_SteeringRequest, Image_SteeringResponse> serviceClient;
NodeMainExecutor nodeMainExecutor;
float[] Steering_Input = new float [3];
@Override
public GraphName getDefaultNodeName() {
return GraphName.of("rosjava/Image_Steering_client");
}
public void RosRun() {
// Set up the node executer
nodeMainExecutor = DefaultNodeMainExecutor.newDefault();
String host = "";
System.out.print("Ros service client has been added to host: ");
try {
host = InetAddress.getLocalHost().getHostName();
System.out.println(host);
} catch (Exception e) {
System.out.println("Unknown Host");
}
String uri = "http://" + host + ":11311";
URI masteruri = URI.create(uri);
NodeConfiguration srvNodeConfiguration = NodeConfiguration.newPublic(host, masteruri);
// Check if Publisher class correctly instantiated
Preconditions.checkState(this != null);
// execute the node talker (this will run the method onStart of Talker.java)
nodeMainExecutor.execute(this, srvNodeConfiguration);
}
public void Shutdown() {
System.out.println("Node Shutting down");
nodeMainExecutor.shutdown();
}
@Override
public void onStart(final ConnectedNode connectedNode) {
try {
serviceClient = connectedNode.newServiceClient("Image_Steering_Service", Image_Steering._TYPE);
} catch (ServiceNotFoundException e) {
throw new RosRuntimeException(e);
}
}
public void SendRequest(byte[] image) {
if(serviceClient == null) {
return;
}
Image_SteeringRequest request = serviceClient.newMessage();
float [] current_steering= {1.0f,2.0f,3.0f};
request.setCurrentSteering(current_steering);
ChannelBuffer buffer = MessageBuffers.dynamicBuffer();
buffer.writeBytes(image);
request.setImage(buffer);
serviceClient.call(request, new ServiceResponseListener<Image_SteeringResponse>() {
@Override
public void onSuccess(Image_SteeringResponse response) {
Steering_Input = response.getSteering();
System.out.println(Steering_Input.toString());
}
@Override
public void onFailure(RemoteException e) {
//System.out.println("Hi");
throw new RosRuntimeException(e);
}
});
}
public float[] getSteering_Input() {
return Steering_Input;
}
public void setSteering_Input(float[] steering_Input) {
Steering_Input = steering_Input;
}
}
I have succeed to have a service working between rosjava ana python 2.7. Now , I changed to python3+ROS due to certain project requirements. Rosjava is able to send request and receive response for the first time only and then this error is thrown: Exception in thread "pool-2-thread-12" org.ros.exception.RosRuntimeException: org.ros.exception.RemoteException: at com.github.rosjava_opends.opends.Image_Steering_Client$1.onFailure(Image_Steering_Client.java:98) at org.ros.internal.node.service.ServiceResponseHandler$1.run(ServiceResponseHandler.java:65) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) Caused by: org.ros.exception.RemoteException: ... 4 more
can someone help me to solve this issue or tell me is there something i can do to make rosjava better compatible with python3
I am currently working on connecting ROS python and ROS java, where could I find information like some code snippets or some information related to that? Thank you
I have succeed to have a service working between rosjava ana python 2.7. Now , I changed to python3+ROS due to certain project requirements. Rosjava is able to send request and receive response for the first time only and then this error is thrown: Exception in thread "pool-2-thread-12" org.ros.exception.RosRuntimeException: org.ros.exception.RemoteException: at com.github.rosjava_opends.opends.Image_Steering_Client$1.onFailure(Image_Steering_Client.java:98) at org.ros.internal.node.service.ServiceResponseHandler$1.run(ServiceResponseHandler.java:65) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) Caused by: org.ros.exception.RemoteException: ... 4 more
can someone help me to solve this issue or tell me is there something i can do to make rosjava better compatible with python3