Provide a generic way to receive zmq updates for lidar and slam.

This commit is contained in:
Piv
2020-03-22 19:01:40 +10:30
parent dc832d8a5d
commit 03f6c2b9f7
12 changed files with 97 additions and 75 deletions

View File

@@ -0,0 +1,107 @@
package com.example.carcontroller.LIDAR;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import com.example.carcontroller.PersonTrackingGrpc;
public class LidarView extends SurfaceView implements Runnable {
private boolean running;
private Thread lidarThread;
private SurfaceHolder holder;
PersonTrackingGrpc.PersonTrackingBlockingStub stub;
private int mBitmapX, mBitmapY, mViewWidth, mViewHeight;
private Bitmap mBitmap;
public LidarView(Context context) {
super(context);
}
public LidarView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public LidarView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
float x = event.getX();
float y = event.getY();
// Get the group that was selected and select on the grpc controller.
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
break;
}
return true;
}
@Override
public void run() {
Canvas canvas;
while (running) {
if (holder.getSurface().isValid()) {
canvas = holder.lockCanvas();
canvas.save();
// Get the updated points from the raspberry pi.
// Iterate through every point (hist point) and draw to the canvas.
}
}
}
public void pause() {
running = false;
try {
lidarThread.join();
} catch (InterruptedException e) {
}
}
public void resume() {
lidarThread = new Thread(this);
lidarThread.start();
running = true;
}
private static class Point {
private double x;
private double y;
private Point(double x, double y) {
this.x = x;
this.y = y;
}
static Point fromXY(double x, double y) {
return new Point(x, y);
}
static Point fromHist(double distance, double angle) {
return fromHist(distance, angle, new Point(0, 0));
}
static Point fromHist(double distance, double angle, Point offset) {
return new Point(distance * Math.sin(angle) + offset.x, distance * Math.cos(angle) + offset.y);
}
}
}