Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge jagheterfredrik to apk-method branch #3

Open
wants to merge 54 commits into
base: apk-method
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
b6283f1
android stuff
jagheterfredrik Oct 9, 2024
c53b424
a good chunk
jagheterfredrik Oct 9, 2024
22fd2e0
some more
jagheterfredrik Oct 9, 2024
adf63ab
all running
jagheterfredrik Oct 9, 2024
5481ce7
fixes
jagheterfredrik Oct 9, 2024
31b9e77
stuff
jagheterfredrik Oct 13, 2024
76c0d45
bump panda, all working
jagheterfredrik Oct 14, 2024
bca6ef8
non-root
jagheterfredrik Oct 14, 2024
27e1b80
restartability
jagheterfredrik Oct 15, 2024
a50f682
latest n' gratest
jagheterfredrik Oct 28, 2024
2f44ca7
default camera values for now
jagheterfredrik Oct 28, 2024
ea14b7b
remove cruft
jagheterfredrik Oct 28, 2024
46451cb
roll back to modelparsed
jagheterfredrik Oct 29, 2024
7fb33a5
dump latest
jagheterfredrik Nov 1, 2024
b4c0a62
stuff
jagheterfredrik Nov 1, 2024
d84b591
change python package name
jagheterfredrik Nov 2, 2024
370c368
add pandaflashpoc
jagheterfredrik Nov 3, 2024
311f945
pandaflash
jagheterfredrik Nov 4, 2024
10a8d82
dump latest
jagheterfredrik Nov 5, 2024
b1ec77c
pandaflash
jagheterfredrik Nov 5, 2024
5721e7b
add flashing
jagheterfredrik Nov 5, 2024
547f841
clean up dependencies
jagheterfredrik Nov 6, 2024
71a6b2d
:build in docker
jagheterfredrik Nov 5, 2024
2841616
add settings to flowy
jagheterfredrik Nov 6, 2024
d6985fe
submodules please
jagheterfredrik Nov 6, 2024
2aa2df4
use kgsl directly?
jagheterfredrik Nov 6, 2024
e377dee
clean out binaries
jagheterfredrik Nov 6, 2024
9de99f0
json11, name and kj path fix
jagheterfredrik Nov 6, 2024
2bb0e02
more lib fixes
jagheterfredrik Nov 6, 2024
1fb0485
finishing touches
jagheterfredrik Nov 6, 2024
1b4cee6
finishing touches 2
jagheterfredrik Nov 6, 2024
14fd849
finishing touches 3
jagheterfredrik Nov 6, 2024
3f9559e
instructions and opencl for linking
jagheterfredrik Nov 6, 2024
8f0033d
update readme
jagheterfredrik Nov 6, 2024
ff723e7
make libs a build artifact
jagheterfredrik Nov 6, 2024
df1cd8d
Update build.yml
jagheterfredrik Nov 7, 2024
79498f6
clean up
jagheterfredrik Nov 7, 2024
f6b4f13
build info
jagheterfredrik Nov 7, 2024
60db6dd
libusb fix
jagheterfredrik Nov 7, 2024
8dfa057
less noisy buildozer
jagheterfredrik Nov 7, 2024
3f91e54
revert to jniconvert
jagheterfredrik Nov 7, 2024
69d26f1
remove unused permissions
jagheterfredrik Nov 7, 2024
b656845
cleanup pandad
jagheterfredrik Nov 8, 2024
d45e5aa
Update README.md
jagheterfredrik Nov 8, 2024
b7098d6
match docker uid/guid to host
jagheterfredrik Nov 8, 2024
e7f5596
use scripts in CI
jagheterfredrik Nov 8, 2024
4fd0100
allow for non-tty builds
jagheterfredrik Nov 8, 2024
b89e6c6
api 31?
jagheterfredrik Nov 8, 2024
4ebd06c
build tweaks
jagheterfredrik Nov 8, 2024
43581cb
no fancy user stuff
jagheterfredrik Nov 8, 2024
bb6c7e4
less user stuff
jagheterfredrik Nov 8, 2024
30cf634
backport missing rate reduction from flowy
jagheterfredrik Nov 10, 2024
bf4686e
check for both panda vendor IDs and product IDs
andiradulescu Feb 15, 2025
9ea918e
Merge pull request #2 from andiradulescu/panda-support-all-ids
jagheterfredrik Mar 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
roll back to modelparsed
  • Loading branch information
jagheterfredrik committed Oct 29, 2024
commit 46451cb50ca97c3e4561790a805f51a49f0977d3
15 changes: 2 additions & 13 deletions android/src/main/java/ai.flow.android/sensor/CameraManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,14 @@
import ai.flow.common.utils;
import ai.flow.definitions.Definitions;
import ai.flow.modeld.ModelExecutor;
import ai.flow.modeld.ModelExecutorF3;
import ai.flow.modeld.messages.MsgFrameData;
import ai.flow.sensor.SensorInterface;
import ai.flow.sensor.messages.MsgFrameBuffer;

import android.annotation.SuppressLint;
import android.content.Context;
import android.hardware.camera2.CameraCaptureSession;
import android.hardware.camera2.CameraCharacteristics;
import android.hardware.camera2.CameraMetadata;
import android.hardware.camera2.CaptureRequest;
import android.hardware.camera2.CaptureResult;
import android.hardware.camera2.TotalCaptureResult;
import android.hardware.camera2.params.MeteringRectangle;
import android.hardware.camera2.params.TonemapCurve;
import android.os.Build;
Expand All @@ -32,18 +27,14 @@
import androidx.camera.camera2.interop.Camera2CameraControl;
import androidx.camera.camera2.interop.Camera2CameraInfo;
import androidx.camera.camera2.interop.Camera2Interop;
import androidx.camera.camera2.interop.CaptureRequestOptions;
import androidx.camera.camera2.interop.ExperimentalCamera2Interop;
import androidx.camera.core.*;
import androidx.camera.core.impl.CameraCaptureResult;
import androidx.camera.core.impl.utils.ExifData;
import androidx.camera.lifecycle.ProcessCameraProvider;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import com.google.common.util.concurrent.ListenableFuture;

import messaging.ZMQPubHandler;
import org.capnproto.PrimitiveList;
import org.opencv.core.Core;

import java.nio.ByteBuffer;
Expand All @@ -54,13 +45,11 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;

import static ai.flow.android.sensor.Utils.fillYUVBuffer;
import static ai.flow.common.transformations.Camera.CAMERA_TYPE_ROAD;

import androidx.camera.camera2.Camera2Config;
import androidx.camera.core.CameraProvider;
import androidx.camera.core.CameraXConfig;


Expand Down Expand Up @@ -303,8 +292,8 @@ private void bindUseCases(@NonNull ProcessCameraProvider cameraProvider) {
CameraRequests.setCaptureRequestOption(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON);
CameraRequests.setCaptureRequestOption(CaptureRequest.COLOR_CORRECTION_MODE, CaptureRequest.COLOR_CORRECTION_MODE_FAST);
CameraRequests.setCaptureRequestOption(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, new Range<>(20, 20));
// CameraRequests.setCaptureRequestOption(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_OFF);
// CameraRequests.setCaptureRequestOption(CaptureRequest.LENS_FOCUS_DISTANCE, 0f);
CameraRequests.setCaptureRequestOption(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_OFF);
CameraRequests.setCaptureRequestOption(CaptureRequest.LENS_FOCUS_DISTANCE, 0f);
ImageAnalysis imageAnalysis = builder.build();
imageAnalysis.setAnalyzer(ContextCompat.getMainExecutor(context), myAnalyzer);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public ModelparsedManager(Context ctx) {

public void start() {
System.out.println("Modelparsed was called, starting services!");
// ServiceModelparsed.start(ctx);
ServiceModelparsed.start(ctx);
// Context ctx = this.ctx
// new java.util.Timer().schedule(
// new java.util.TimerTask() {
Expand Down
20 changes: 20 additions & 0 deletions android/src/main/java/ai.flow.android/sensor/Utils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package ai.flow.android.sensor;

import android.media.Image;

import androidx.camera.core.ImageProxy;

import java.nio.ByteBuffer;
Expand All @@ -22,4 +24,22 @@ public static void fillYUVBuffer(ImageProxy image, ByteBuffer yuvBuffer){
yuvBuffer.put(vPlane.getBuffer());
}
}

public static void fillYUVBuffer(Image image, ByteBuffer yuvBuffer){
yuvBuffer.rewind();
Image.Plane yPlane = image.getPlanes()[0];
yuvBuffer.put(yPlane.getBuffer());

// interleaved uv pixels, nv12 or nv21
if (image.getPlanes()[1].getPixelStride() == 2) {
Image.Plane uvPlane = image.getPlanes()[2];
yuvBuffer.put(uvPlane.getBuffer());
}
else{
Image.Plane uPlane = image.getPlanes()[1];
Image.Plane vPlane = image.getPlanes()[2];
yuvBuffer.put(uPlane.getBuffer());
yuvBuffer.put(vPlane.getBuffer());
}
}
}
17 changes: 10 additions & 7 deletions common/java/ai.flow.common/transformations/Camera.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@ public class Camera {

public static final boolean FORCE_TELE_CAM_F3 = false;

// lots of important stuff calculated from this
// current set to LG G8 wide camera
public static float
FocalX = 630f,
FocalY = 630f,
CenterX = 640f,
CenterY = 360f;
FocalX = 538f,
FocalY = 538f,
CenterX = 640f, //632
CenterY = 360f; //358

public static int UseCameraID = 0;
// Camera 2
// MATRIX: [538.2648047477589, 0, 635.4029785884212;
//0, 538.3225487046863, 348.6366566852139;
//0, 0, 1]

public static int UseCameraID = 2;

// everything autocalculated below
public static float actual_cam_focal_length = (FocalX + FocalY) * 0.5f;
Expand Down
6 changes: 6 additions & 0 deletions selfdrive/modeld/java/ai.flow.modeld/CommonModelF2.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,16 @@ public class CommonModelF2 {
public static final int SIZE_ModelOutputMeta = 352 / 4;
public static final int SIZE_ModelOutputPose = 48 / 4;
public static final int SIZE_ModelOutputLinesXY = 1056 / 4;

public static final int SIZE_ModelOutputWideFromDeviceEuler = 24 / 4;
public static final int SIZE_ModelOutputRoadTransform = 48 / 4;
public static final int SIZE_LateralAction = 4 / 4;

public static final int SIZE_ModelOutputStopLinePrediction = 68 / 4;
public static final int SIZE_Total = SIZE_ModelOutputPlans + SIZE_ModelOutputLaneLines + SIZE_ModelOutputRoadEdges +
SIZE_ModelOutputLeads + SIZE_ModelOutputMeta +
SIZE_ModelOutputPose;
// + SIZE_ModelOutputWideFromDeviceEuler + SIZE_ModelOutputRoadTransform + SIZE_LateralAction;
public static final int SIZE_ModelOutputLeadPrediction = 204 / 4;
public static final int DESIRE_LEN = 8;
public static final int STOP_LINE_MHP_N = 3;
Expand Down
21 changes: 15 additions & 6 deletions selfdrive/modeld/java/ai.flow.modeld/ModelExecutorF3.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import ai.flow.common.transformations.Camera;
import ai.flow.common.utils;
import ai.flow.definitions.Definitions;
import ai.flow.modeld.messages.MsgCameraOdometery;
import ai.flow.modeld.messages.MsgModelRaw;
import ai.flow.modeld.messages.MsgModelDataV2;
import messaging.ZMQPubHandler;
Expand Down Expand Up @@ -71,7 +72,8 @@ public class ModelExecutorF3 extends ModelExecutor {
public final ZMQPubHandler ph = new ZMQPubHandler();
public final ZMQSubHandler sh = new ZMQSubHandler(true);
public MsgModelRaw msgModelRaw = new MsgModelRaw(CommonModelF3.NET_OUTPUT_SIZE);
public MsgModelDataV2 msgModelDataV2 = new MsgModelDataV2();
// public MsgModelDataV2 msgModelDataV2 = new MsgModelDataV2();
// public MsgCameraOdometery msgCameraOdometery = new MsgCameraOdometery();
public Definitions.LiveCalibrationData.Reader liveCalib;

public long start, end;
Expand Down Expand Up @@ -177,10 +179,16 @@ public void ExecuteModel(Definitions.FrameData.Reader wideData, Definitions.Fram
// publish outputs
end = System.currentTimeMillis();

Parser parser = new Parser();
ParsedOutputs parsedOutputs = parser.parser(netOutputs);
msgModelDataV2.fill(parsedOutputs, processStartTimestamp, lastFrameID, 0, 0f, end-start, end-start);
ph.publishBuffer("modelV2", msgModelDataV2.serialize(true));
// Parser parser = new Parser();
// ParsedOutputs parsedOutputs = parser.parser(netOutputs);
// msgModelDataV2.fill(parsedOutputs, processStartTimestamp, lastFrameID, 0, 0f, end-start, end-start);
// msgCameraOdometery.fill(parsedOutputs, processStartTimestamp, lastFrameID);
//
// ph.publishBuffer("modelV2", msgModelDataV2.serialize(true));
// ph.publishBuffer("cameraOdometry", msgCameraOdometery.serialize(true));

msgModelRaw.fill(netOutputs, processStartTimestamp, lastFrameID, 0, 0f, end - start);
ph.publishBuffer("modelRaw", msgModelRaw.serialize(true));

// compute runtime stats every 10 runs
timePerIt += end - processStartTimestamp;
Expand Down Expand Up @@ -221,7 +229,8 @@ public void init(){
navfeaturesNDArr = Nd4j.zeros(navFeaturesTensorShape);
navinstructNDArr = Nd4j.zeros(navInstructionsTensorShape);

ph.createPublishers(Arrays.asList("modelV2"));
// ph.createPublishers(Arrays.asList("modelV2", "cameraOdometry"));
ph.createPublishers(Arrays.asList("modelRaw"));
sh.createSubscribers(Arrays.asList("pulseDesire", "liveCalibration", "lateralPlan"));

inputShapeMap.put("input_imgs", imgTensorShape);
Expand Down
4 changes: 4 additions & 0 deletions selfdrive/modeld/java/ai.flow.modeld/ParsedOutputs.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public class ParsedOutputs {
public float[] transStd;
public float[] rot;
public float[] rotStd;
// public float[] wideFromDeviceEuler;
// public float[] roadTransform;
// public float[] action;

public ParsedOutputs(){
this.initLanes();
Expand Down Expand Up @@ -86,6 +89,7 @@ public void initCameraOdometery(){
transStd = new float[3];
rot = new float[3];
rotStd = new float[3];
// wideFromDeviceEuler = new float[2];
}

public void initLeads(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ public class MsgCameraOdometery extends MessageBase {
public PrimitiveList.Float.Builder rotStd;
public PrimitiveList.Float.Builder trans;
public PrimitiveList.Float.Builder transStd;
// public PrimitiveList.Float.Builder wideFromDeviceEuler;
// public PrimitiveList.Float.Builder wideFromDeviceEulerStd;
// public PrimitiveList.Float.Builder roadTransformTrans;
// public PrimitiveList.Float.Builder roadTransformTransStd;

public MsgCameraOdometery(ByteBuffer rawMessageBuffer) {
super(rawMessageBuffer);
Expand All @@ -39,6 +43,10 @@ private void initFields(){
rotStd = odometry.initRotStd(3);
trans = odometry.initTrans(3);
transStd = odometry.initTransStd(3);
// wideFromDeviceEuler = odometry.initWideFromDeviceEuler(3);
// wideFromDeviceEulerStd = odometry.initWideFromDeviceEulerStd(3);
// roadTransformTrans = odometry.initRoadTransformTrans(3);
// roadTransformTransStd = odometry.initRoadTransformTransStd(3);
}

public void fill(ParsedOutputs parsed, long timestamp, int frameId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ public void render(float delta) {
byte[] cameraMatrixBuffer = MatToByte(calibrator.cameraMatrix);
byte[] distortionCoefficientsBuffer = MatToByte(calibrator.distortionCoefficients);

System.out.println("MATRIX: " + calibrator.cameraMatrix.dump());

params.put(intrinsicParamName, cameraMatrixBuffer);
params.put(distortionParamName, distortionCoefficientsBuffer);

Expand Down
4 changes: 2 additions & 2 deletions selfdrive/ui/java/ai.flow.app/Draw.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public class Draw {
public static final float LEAD_Y_SCALE = 10f;

public static Matrix4 cam_intrinsics = new Matrix4(new float[] {
630.f, 0.0f, 0.0f, 0.f,
0.0f, 630.f, 0.0f, 0.f,
538.f, 0.0f, 0.0f, 0.f,
0.0f, 538.f, 0.0f, 0.f,
640.0f, 360.0f, 1.0f, 0.f,
0.f, 0.f, 0.f, 0.f
});
Expand Down