Remove debug stuff, lidar streaming working.

Tracking still not working correctly, due to assign groups not working propery.
This commit is contained in:
Piv
2020-06-02 20:33:01 +09:30
parent 14d3a64c7f
commit 49c1e90c4e
5 changed files with 40 additions and 25 deletions

View File

@@ -2,7 +2,6 @@ package org.vato.carcontroller.LIDAR;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
@@ -44,11 +43,10 @@ public class LidarView extends SurfaceView
private SurfaceHolder surfaceHolder;
private boolean useGrpcStreams;
PersonTrackingGrpc.PersonTrackingStub stub;
private float timeBetweenMessages = 0.01f;
private float timeBetweenMessages;
private Map<Integer, Paint> groupNumPaints = new HashMap<>();
private int mBitmapX, mBitmapY, mViewWidth, mViewHeight;
private Bitmap mBitmap;
private int mViewWidth, mViewHeight, centreX, centreY;
public LidarView(Context context) {
super(context);
@@ -71,6 +69,7 @@ public class LidarView extends SurfaceView
port = prefs.getString("zmqPort", "5050");
String gRPCPort = prefs.getString("port", "50051");
useGrpcStreams = prefs.getBoolean("use_grpc_streams", false);
timeBetweenMessages = prefs.getFloat("lidar_timeout", 0.1f);
if (useGrpcStreams) {
lidar = new GrpcUpdater<>(PointScan.getDefaultInstance().getParserForType(), this);
@@ -121,6 +120,10 @@ public class LidarView extends SurfaceView
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
mViewWidth = w;
mViewHeight = h;
centreX = w / 2;
centreY = h / 2;
}
@Override
@@ -167,8 +170,23 @@ public class LidarView extends SurfaceView
Canvas canvas = surfaceHolder.lockCanvas();
canvas.save();
canvas.drawColor(Color.WHITE);
for (Point point : points.getPointsList().stream().map(Point::fromProtoPoint).collect(
Collectors.toList())) {
// TODO: Do an initial pass to find the max distance, which will be a scale factor for the other points.
double maxDistance = 0;
for (org.vato.carcontroller.Point point : points.getPointsList()) {
if (point.getDistance() > maxDistance) {
maxDistance = point.getDistance();
}
}
final double maxDistanceFinal = maxDistance;
// Apply scaling factor from max distance.
for (Point point : points.getPointsList().stream().map(
point -> org.vato.carcontroller.Point.newBuilder(point).setDistance(
point.getDistance() / maxDistanceFinal * mViewHeight).build()).map(
Point::fromProtoPoint)
.collect(
Collectors.toList())) {
// Now for each point, draw a circle for the point (so it's big enough) in the correct spot,
// and create a colour for that point to paint it correctly.
if (!groupNumPaints.containsKey(point.groupNumber)) {
@@ -178,9 +196,8 @@ public class LidarView extends SurfaceView
point.groupNumber), 1f, 1f}));
groupNumPaints.put(point.groupNumber, paint);
}
// TODO:
canvas.drawCircle((float) point.x, (float) point.y, 5,
canvas.drawCircle((float) point.x + centreX,
(float) point.y + centreY, 5,
Objects.requireNonNull(groupNumPaints
.get(point.groupNumber))); // Can't be null as we just added it.
}
@@ -189,6 +206,7 @@ public class LidarView extends SurfaceView
}
}
/**
* @param groupNumber
* @return
@@ -225,8 +243,8 @@ public class LidarView extends SurfaceView
}
static Point fromHist(double distance, double angle, Point offset) {
return new Point(distance * Math.sin(angle) + offset.x,
distance * Math.cos(angle) + offset.y);
return new Point(distance * Math.sin(Math.toRadians(angle)) + offset.x,
distance * Math.cos(Math.toRadians(angle)) + offset.y);
}
}

View File

@@ -46,6 +46,14 @@
</PreferenceCategory>
<PreferenceCategory>
<EditTextPreference
android:defaultValue="0.1"
android:title="LiDAR time between scan fetches."
app:key="lidar_timeout"
app:useSimpleSummaryProvider="true" />
</PreferenceCategory>
<PreferenceCategory android:title="0MQ SLAM Connection">
<EditTextPreference
android:key="zmqPort"