Fix SLAM controller, use PUB instead of PAIR sockets for zmq updater.
This commit is contained in:
@@ -12,9 +12,16 @@ import android.view.SurfaceView;
|
||||
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import com.example.carcontroller.Empty;
|
||||
import com.example.carcontroller.SlamControlGrpc;
|
||||
import com.example.carcontroller.SlamDetails;
|
||||
import com.example.carcontroller.SlamLocation;
|
||||
import com.google.protobuf.ByteString;
|
||||
|
||||
import io.grpc.ManagedChannel;
|
||||
import io.grpc.ManagedChannelBuilder;
|
||||
import io.grpc.stub.StreamObserver;
|
||||
|
||||
public class SlamView extends SurfaceView implements SlamUpdater.MapChangedListener {
|
||||
|
||||
private SlamUpdater slam;
|
||||
@@ -23,6 +30,10 @@ public class SlamView extends SurfaceView implements SlamUpdater.MapChangedListe
|
||||
private int width;
|
||||
private SurfaceHolder surfaceHolder;
|
||||
private Paint paint;
|
||||
private SlamControlGrpc.SlamControlStub stub;
|
||||
private ManagedChannel channel;
|
||||
private int mapSizePixels;
|
||||
private int mapSizeMeters;
|
||||
|
||||
public SlamView(Context context) {
|
||||
super(context);
|
||||
@@ -46,19 +57,43 @@ public class SlamView extends SurfaceView implements SlamUpdater.MapChangedListe
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
String host = prefs.getString("host", "10.0.0.53");
|
||||
String port = prefs.getString("zmqPort", "5050");
|
||||
String gRPCPort = prefs.getString("port", "50051");
|
||||
mapSizePixels = Integer.parseInt(prefs.getString("MAPSIZEPIXELS", "540"));
|
||||
mapSizeMeters = Integer.parseInt(prefs.getString("MAPSIZEMETRES", "10"));
|
||||
slam = new ZmqSlamUpdater(host, port);
|
||||
slam.addMapChangedListener(this);
|
||||
surfaceHolder = getHolder();
|
||||
paint = new Paint();
|
||||
paint.setColor(Color.BLUE);
|
||||
mapThread = new Thread(slam);
|
||||
channel = ManagedChannelBuilder.forAddress(host, Integer.parseInt(gRPCPort)).usePlaintext().build();
|
||||
stub = SlamControlGrpc.newStub(channel);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by MainActivity.onResume() to start a thread.
|
||||
*/
|
||||
public void resume() {
|
||||
mapThread = new Thread(slam);
|
||||
mapThread.start();
|
||||
StreamObserver<Empty> response = new StreamObserver<Empty>() {
|
||||
@Override
|
||||
public void onNext(Empty value) {
|
||||
mapThread.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable t) {
|
||||
// TODO: close the activity,
|
||||
System.out.println(t.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCompleted() {
|
||||
// Don't care.
|
||||
}
|
||||
};
|
||||
// use async grpc method, ZMQ doesn't need to connect straight away.
|
||||
stub.startMapStreaming(SlamDetails.newBuilder().setMapSizePixels(mapSizePixels).setMapSizeMeters(mapSizeMeters).build(), response);
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
|
||||
Reference in New Issue
Block a user