Skip to content

Commit ffdd36f

Browse files
committed
switching jetpacks
1 parent 471c90e commit ffdd36f

File tree

10 files changed

+134
-9
lines changed

10 files changed

+134
-9
lines changed

photon-core/src/main/java/org/photonvision/common/configuration/PhotonConfiguration.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.photonvision.common.util.SerializationUtils;
3131
import org.photonvision.mrcal.MrCalJNILoader;
3232
import org.photonvision.raspi.LibCameraJNILoader;
33+
//import org.photonvision.jetson.JetsonMipiJNILoader;
3334
import org.photonvision.vision.calibration.UICameraCalibrationCoefficients;
3435
import org.photonvision.vision.camera.QuirkyCamera;
3536
import org.photonvision.vision.processes.VisionModule;
@@ -137,6 +138,11 @@ public Map<String, Object> toHashMap() {
137138
LibCameraJNILoader.isSupported()
138139
? "Zerocopy Libcamera Working"
139140
: ""); // TODO add support for other types of GPU accel
141+
generalSubmap.put(
142+
"cudaAcceleration",
143+
false //JetsonMipiJNILoader.isSupported()
144+
? "Jetson Cuda and mipi Working"
145+
: "");
140146
generalSubmap.put("mrCalWorking", MrCalJNILoader.getInstance().isLoaded());
141147
generalSubmap.put("availableModels", NeuralNetworkModelManager.getInstance().getModels());
142148
generalSubmap.put(

photon-core/src/main/java/org/photonvision/common/logging/PvCSCoreLogger.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public static PvCSCoreLogger getInstance() {
3434
private Logger logger;
3535

3636
private PvCSCoreLogger() {
37-
CameraServerJNI.setLogger(this::logMsg, 7);
37+
CameraServerJNI.setLogger(this::logMsg, 5); // 7 RJS
3838
this.logger = new Logger(getClass(), LogGroup.CSCore);
3939
}
4040

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Copyright (C) Photon Vision.
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
*/
17+
18+
package org.photonvision.jetson;
19+
20+
import java.io.File;
21+
import java.io.FileOutputStream;
22+
import java.io.IOException;
23+
import org.photonvision.common.logging.LogGroup;
24+
import org.photonvision.common.logging.Logger;
25+
26+
/**
27+
* Helper for extracting photon-libcamera-gl-driver shared library files. TODO: Refactor to use
28+
* PhotonJNICommon
29+
*/
30+
public class JetsonMipiJNILoader {
31+
private static boolean libraryLoaded = false;
32+
private static final Logger logger = new Logger(JetsonMipiJNILoader.class, LogGroup.Camera);
33+
34+
public static synchronized void forceLoad() throws IOException {
35+
if (libraryLoaded) return;
36+
37+
var libraryName = "jetsonmipi";
38+
39+
try {
40+
// We always extract the shared object (we could hash each so, but that's a lot of work)
41+
var arch_name = "linuxarm64";
42+
var nativeLibName = System.mapLibraryName(libraryName);
43+
var resourcePath = "/nativelibraries/" + arch_name + "/" + nativeLibName;
44+
var in = LibCameraJNILoader.class.getResourceAsStream(resourcePath);
45+
46+
if (in == null) {
47+
logger.error("Failed to find internal native library at path " + resourcePath);
48+
libraryLoaded = false;
49+
return;
50+
}
51+
52+
// It's important that we don't mangle the names of these files on Windows at least
53+
File temp = new File(System.getProperty("java.io.tmpdir"), nativeLibName);
54+
FileOutputStream fos = new FileOutputStream(temp);
55+
56+
int read = -1;
57+
byte[] buffer = new byte[1024];
58+
while ((read = in.read(buffer)) != -1) {
59+
fos.write(buffer, 0, read);
60+
}
61+
fos.close();
62+
in.close();
63+
64+
System.load(temp.getAbsolutePath());
65+
66+
logger.info("Successfully loaded shared object " + temp.getName());
67+
68+
} catch (UnsatisfiedLinkError e) {
69+
logger.error("Couldn't load shared object " + libraryName, e);
70+
e.printStackTrace();
71+
// logger.error(System.getProperty("java.library.path"));
72+
}
73+
libraryLoaded = true;
74+
}
75+
76+
public static boolean isSupported() {
77+
return libraryLoaded && JetsonMipiJNI.isSupported();
78+
}
79+
}

photon-core/src/main/java/org/photonvision/vision/camera/QuirkyCamera.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,11 @@ public class QuirkyCamera {
8888
CameraQuirk.ArduOV9782Controls),
8989
// Innomaker OV9281
9090
new QuirkyCamera(
91-
0x0c45, 0x636d, "USB Camera", "Innomaker OV9281", CameraQuirk.InnoOV9281Controls));
91+
0x0c45, 0x636d, "USB Camera", "Innomaker OV9281", CameraQuirk.InnoOV9281Controls),
92+
new QuirkyCamera(
93+
-1, -1, "vi-output, ov9281 9-0060", CameraQuirk.InnoOV9281Controls, CameraQuirk.StickyFPS),
94+
new QuirkyCamera(
95+
-1, -1, "vi-output, ov9281 10-0060", CameraQuirk.InnoOV9281Controls, CameraQuirk.StickyFPS));
9296

9397
public static final QuirkyCamera DefaultCamera = new QuirkyCamera(0, 0, "");
9498
public static final QuirkyCamera ZeroCopyPiCamera =

photon-core/src/main/java/org/photonvision/vision/camera/USBCameras/GenericUSBCameraSettables.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public GenericUSBCameraSettables(CameraConfiguration configuration, UsbCamera ca
7474
}
7575

7676
protected void setUpExposureProperties() {
77+
logger.debug("start usb setupexposure");
7778
// Photonvision needs to be able to control absolute exposure. Make sure we can
7879
// first.
7980
var expProp =
@@ -84,10 +85,20 @@ protected void setUpExposureProperties() {
8485
// first.
8586
var autoExpProp = findProperty("exposure_auto", "auto_exposure");
8687

87-
exposureAbsProp = expProp.get();
88-
autoExposureProp = autoExpProp.get();
88+
if(expProp == null) logger.debug("expProp is null");
89+
logger.debug("pre expprop.get");
90+
exposureAbsProp = expProp.get();
91+
logger.debug("post expprop.get");
92+
if(exposureAbsProp == null) logger.debug("exposureAbsProp is null");
93+
94+
if(autoExpProp.isPresent()) {
95+
autoExposureProp = autoExpProp.get();
96+
}
97+
logger.debug("pre getmin");
8998
this.minExposure = exposureAbsProp.getMin();
99+
logger.debug("post getmin");
90100
this.maxExposure = exposureAbsProp.getMax();
101+
logger.debug("end usb setupexposure");
91102
}
92103

93104
public void setAllCamDefaults() {
@@ -113,7 +124,8 @@ public void setAutoExposure(boolean cameraAutoExposure) {
113124
softSet("white_balance_auto_preset", 2); // Auto white-balance disabled
114125
softSet("white_balance_automatic", 0);
115126
softSet("white_balance_temperature", whiteBalanceTemperature);
116-
autoExposureProp.set(PROP_AUTO_EXPOSURE_DISABLED);
127+
if(autoExposureProp != null)
128+
autoExposureProp.set(PROP_AUTO_EXPOSURE_DISABLED);
117129

118130
// Most cameras leave exposure time absolute at the last value from their AE
119131
// algorithm.
@@ -127,7 +139,8 @@ public void setAutoExposure(boolean cameraAutoExposure) {
127139
softSet("iso_sensitivity", 1); // Manual ISO adjustment by default
128140
softSet("white_balance_auto_preset", 1); // Auto white-balance enabled
129141
softSet("white_balance_automatic", 1);
130-
autoExposureProp.set(PROP_AUTO_EXPOSURE_ENABLED);
142+
if(autoExposureProp != null)
143+
autoExposureProp.set(PROP_AUTO_EXPOSURE_ENABLED);
131144
}
132145
}
133146

@@ -145,7 +158,8 @@ public double getMaxExposureRaw() {
145158
public void setExposureRaw(double exposureRaw) {
146159
if (exposureRaw >= 0.0) {
147160
try {
148-
autoExposureProp.set(PROP_AUTO_EXPOSURE_DISABLED);
161+
if(autoExposureProp != null)
162+
autoExposureProp.set(PROP_AUTO_EXPOSURE_DISABLED);
149163

150164
int propVal = (int) MathUtil.clamp(exposureRaw, minExposure, maxExposure);
151165

@@ -216,7 +230,7 @@ public HashMap<Integer, VideoMode> getAllVideoModes() {
216230
// Filter grey modes
217231
if (videoMode.pixelFormat == PixelFormat.kGray
218232
|| videoMode.pixelFormat == PixelFormat.kUnknown) {
219-
continue;
233+
//continue;
220234
}
221235

222236
if (configuration.cameraQuirks.hasQuirk(CameraQuirk.FPSCap100)) {

photon-core/src/main/java/org/photonvision/vision/camera/USBCameras/InnoOV9281CameraSettables.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ public InnoOV9281CameraSettables(CameraConfiguration configuration, UsbCamera ca
2727

2828
@Override
2929
protected void setUpExposureProperties() {
30+
logger.debug("pre super setup");
3031
super.setUpExposureProperties();
32+
logger.debug("post super setup");
3133

3234
// Property limits are incorrect
3335
this.minExposure = 1;

photon-core/src/main/java/org/photonvision/vision/camera/USBCameras/USBCameraSource.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,10 @@ public USBCameraSource(CameraConfiguration config) {
9393

9494
} else {
9595
// Functional camera, set up the frame provider and configure defaults
96+
logger.info("Camera " + camera.getPath() + " might be usable RJS");
9697
usbFrameProvider = new USBFrameProvider(cvSink, settables);
9798
settables.setAllCamDefaults();
99+
logger.info("Camera " + camera.getPath() + " end setAllCamDefaults RJS");
98100
}
99101
}
100102
}
@@ -138,6 +140,7 @@ protected GenericUSBCameraSettables createSettables(
138140
logger.debug("Using Arducam OV9782 Settables");
139141
settables = new ArduOV9782CameraSettables(config, camera);
140142
} else if (quirks.hasQuirk(CameraQuirk.InnoOV9281Controls)) {
143+
logger.debug("Using Innovision OV9782 Settables");
141144
settables = new InnoOV9281CameraSettables(config, camera);
142145
} else if (quirks.hasQuirk(CameraQuirk.See3Cam_24CUG)) {
143146
settables = new See3Cam24CUGSettables(config, camera);
@@ -146,7 +149,9 @@ protected GenericUSBCameraSettables createSettables(
146149
settables = new GenericUSBCameraSettables(config, camera);
147150
}
148151

152+
logger.debug("pre setupexposurepropeties RJS");
149153
settables.setUpExposureProperties();
154+
logger.debug("post setupexposurepropeties RJS");
150155

151156
return settables;
152157
}

photon-core/src/main/java/org/photonvision/vision/processes/VisionSourceManager.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,8 +577,11 @@ private static List<VisionSource> loadVisionSourcesFromCamConfigs(
577577
var newCam = new USBCameraSource(configuration);
578578
if (!newCam.getCameraQuirks().hasQuirk(CameraQuirk.CompletelyBroken)
579579
&& !newCam.getSettables().videoModes.isEmpty()) {
580+
logger.debug("calling cameraSources.add RJS");
580581
cameraSources.add(newCam);
581-
}
582+
} else {
583+
logger.debug("videoModes must be empty RJS");
584+
}
582585
}
583586
}
584587
return cameraSources;

photon-server/src/main/java/org/photonvision/Main.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import org.photonvision.jni.RknnDetectorJNI;
4343
import org.photonvision.mrcal.MrCalJNILoader;
4444
import org.photonvision.raspi.LibCameraJNILoader;
45+
//import org.photonvision.jetson.JetsonMipiJNILoader;
4546
import org.photonvision.server.Server;
4647
import org.photonvision.vision.apriltag.AprilTagFamily;
4748
import org.photonvision.vision.camera.FileVisionSource;
@@ -388,6 +389,13 @@ public static void main(String[] args) {
388389
} catch (IOException e) {
389390
logger.error("Failed to load libcamera-JNI!", e);
390391
}
392+
/*try {
393+
if (Platform.isJetson()) {
394+
JetsonMipiJNILoader.forceLoad();
395+
}
396+
} catch (IOException e) {
397+
logger.error("Faileto load JetsonMipiJNI!", e);
398+
}*/
391399
try {
392400
if (Platform.isRK3588()) {
393401
RknnDetectorJNI.forceLoad();

photon-targeting/src/main/java/org/photonvision/common/hardware/Platform.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ public static boolean isRaspberryPi() {
9999
return currentPlatform.isPi;
100100
}
101101

102+
public static boolean isJetson() {
103+
return Platform.isJetsonSBC();
104+
}
105+
102106
public static String getPlatformName() {
103107
if (currentPlatform.equals(UNKNOWN)) {
104108
return UnknownPlatformString;

0 commit comments

Comments
 (0)