Finish off SlamController
This commit is contained in:
@@ -13,9 +13,10 @@ import com.example.carcontroller.R;
|
|||||||
public class SlamController extends AppCompatActivity implements SeekBar.OnSeekBarChangeListener {
|
public class SlamController extends AppCompatActivity implements SeekBar.OnSeekBarChangeListener {
|
||||||
|
|
||||||
|
|
||||||
SeekBar steeringSlider;
|
private SeekBar steeringSlider;
|
||||||
SeekBar throttleSlider;
|
private SeekBar throttleSlider;
|
||||||
private static PiLoader grpcController;
|
private static PiLoader grpcController;
|
||||||
|
private SlamView slamView;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@@ -30,6 +31,7 @@ public class SlamController extends AppCompatActivity implements SeekBar.OnSeekB
|
|||||||
if (throttleSlider != null) {
|
if (throttleSlider != null) {
|
||||||
throttleSlider.setOnSeekBarChangeListener(this);
|
throttleSlider.setOnSeekBarChangeListener(this);
|
||||||
}
|
}
|
||||||
|
slamView = findViewById(R.id.slamView);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -74,17 +76,20 @@ public class SlamController extends AppCompatActivity implements SeekBar.OnSeekB
|
|||||||
}
|
}
|
||||||
// Should call the equivalent of the load method either here or in the loader.
|
// Should call the equivalent of the load method either here or in the loader.
|
||||||
grpcController.start();
|
grpcController.start();
|
||||||
|
slamView.resume();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
grpcController.stop();
|
grpcController.stop();
|
||||||
|
slamView.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStop() {
|
protected void onStop() {
|
||||||
super.onStop();
|
super.onStop();
|
||||||
grpcController.stop();
|
grpcController.stop();
|
||||||
|
slamView.stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,10 @@ package com.example.carcontroller.SLAM;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.Canvas;
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.graphics.Paint;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.SurfaceHolder;
|
import android.view.SurfaceHolder;
|
||||||
import android.view.SurfaceView;
|
import android.view.SurfaceView;
|
||||||
@@ -13,12 +17,12 @@ import com.google.protobuf.ByteString;
|
|||||||
|
|
||||||
public class SlamView extends SurfaceView implements SlamUpdater.MapChangedListener {
|
public class SlamView extends SurfaceView implements SlamUpdater.MapChangedListener {
|
||||||
|
|
||||||
SlamUpdater slam;
|
private SlamUpdater slam;
|
||||||
Thread mapThread;
|
private Thread mapThread;
|
||||||
Context context;
|
private Context context;
|
||||||
private int width;
|
private int width;
|
||||||
private int height;
|
|
||||||
private SurfaceHolder surfaceHolder;
|
private SurfaceHolder surfaceHolder;
|
||||||
|
private Paint paint;
|
||||||
|
|
||||||
public SlamView(Context context) {
|
public SlamView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
@@ -44,6 +48,9 @@ public class SlamView extends SurfaceView implements SlamUpdater.MapChangedListe
|
|||||||
String port = prefs.getString("zmqPort", "5050");
|
String port = prefs.getString("zmqPort", "5050");
|
||||||
slam = new ZmqSlamUpdater(host, port);
|
slam = new ZmqSlamUpdater(host, port);
|
||||||
slam.addMapChangedListener(this);
|
slam.addMapChangedListener(this);
|
||||||
|
surfaceHolder = getHolder();
|
||||||
|
paint = new Paint();
|
||||||
|
paint.setColor(Color.BLUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -66,6 +73,27 @@ public class SlamView extends SurfaceView implements SlamUpdater.MapChangedListe
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mapChanged(ByteString map, SlamLocation location) {
|
public void mapChanged(ByteString map, SlamLocation location) {
|
||||||
|
if (surfaceHolder.getSurface().isValid()) {
|
||||||
|
Canvas canvas = surfaceHolder.lockCanvas();
|
||||||
|
canvas.save();
|
||||||
|
canvas.drawColor(Color.WHITE);
|
||||||
|
// Using width as we want square.
|
||||||
|
Bitmap bitmap = Bitmap.createBitmap(width, width, Bitmap.Config.ALPHA_8);
|
||||||
|
for (int i = 0; i < width; i++) {
|
||||||
|
for (int j = 0; j < width; j++) {
|
||||||
|
// 0-255 is appropriate for the config used.
|
||||||
|
bitmap.setPixel(i, j, map.byteAt(i * width + j));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
canvas.drawBitmap(bitmap, 0, 0, paint);
|
||||||
|
canvas.restore();
|
||||||
|
surfaceHolder.unlockCanvasAndPost(canvas);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onSizeChanged(int w, int b, int oldW, int oldB) {
|
||||||
|
super.onSizeChanged(w, b, oldW, oldB);
|
||||||
|
width = w;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ public class ZmqSlamUpdater extends SlamUpdater {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void init() {
|
protected void init() {
|
||||||
|
super.init();
|
||||||
context = new ZContext();
|
context = new ZContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user