-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRobotVisionDualUSB.java
More file actions
100 lines (87 loc) · 1.92 KB
/
RobotVisionDualUSB.java
File metadata and controls
100 lines (87 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package org.scotsbots.robotbase;
import org.scotsbots.robotbase.utils.CustomCameraServer;
import edu.wpi.cscore.UsbCamera;
import edu.wpi.cscore.VideoMode.PixelFormat;
import edu.wpi.first.wpilibj.CameraServer;
import edu.wpi.first.wpilibj.vision.USBCamera;
public class RobotVisionDualUSB
{
CustomCameraServer cameraServer;
USBCamera firstCam = null;
USBCamera secondCam = null;
String camName1 = "cam1";
String camName2 = "cam2";
String currCam = "cam2 ";
//boolean isCam1 = true;
public RobotVisionDualUSB(String cam1, String cam2)
{
this.camName1 = cam1;
this.camName2 = cam2;
}
/**
public void switchCameras()
{
if (currCam.equals(camName1))
{
cameraServer.startAutomaticCapture(secondCam);
currCam = camName2;
} else
{
cameraServer.startAutomaticCapture(firstCam);
currCam = camName1;
}
*/
/*
if(isCam1)
{
cameraServer.startAutomaticCapture(secondCam);
currCam = camName2;
isCam1 = false;
}
else
{
cameraServer.startAutomaticCapture(firstCam);
currCam = camName1;
isCam1 = true;
}
*/
public void endCameras()
{
if (firstCam != null)
{
firstCam.closeCamera();
firstCam = null;
}
if (secondCam != null)
{
secondCam.closeCamera();
secondCam = null;
}
}
public void initializeCameras()
{
endCameras();
try
{
firstCam = new USBCamera(camName1);
} catch (Exception e)
{
firstCam = null;
}
try
{
secondCam = new USBCamera(camName2);
} catch (Exception e)
{
secondCam = null;
}
if (cameraServer == null)
{
UsbCamera cameraServer = CameraServer.getInstance().startAutomaticCapture();
cameraServer.setVideoMode(PixelFormat.kMJPEG, 640, 480, 15);
}
currCam = camName1;
UsbCamera cam2 = CameraServer.getInstance().startAutomaticCapture();
cam2.setVideoMode(PixelFormat.kMJPEG, 640, 480, 15);
}
}