Commit | Line | Data |
---|---|---|
e63d823c ME |
1 | package org.usfirst.frc.team3501.robot; |
2 | ||
3 | import com.ni.vision.NIVision; | |
4 | import com.ni.vision.NIVision.Image; | |
5 | import edu.wpi.first.wpilibj.CameraServer; | |
6 | ||
7 | public class CameraFeeds { | |
8 | private final int intakeCam; | |
9 | private final int climberCam; | |
10 | private int curCam; | |
11 | private Image frame; | |
12 | private CameraServer server; | |
13 | ||
14 | public CameraFeeds() { | |
15 | // Get camera ids by supplying camera name ex 'cam0', found on roborio web | |
16 | // interface | |
17 | intakeCam = NIVision.IMAQdxOpenCamera(Config.CameraFeeds.camNameCenter, | |
18 | NIVision.IMAQdxCameraControlMode.CameraControlModeController); | |
19 | climberCam = NIVision.IMAQdxOpenCamera(Config.CameraFeeds.camNameRight, | |
20 | NIVision.IMAQdxCameraControlMode.CameraControlModeController); | |
21 | curCam = intakeCam; | |
22 | // Img that will contain camera img | |
23 | frame = NIVision.imaqCreateImage(NIVision.ImageType.IMAGE_RGB, 0); | |
24 | // Server that we'll give the img to | |
25 | server = CameraServer.getInstance(); | |
26 | server.setQuality(Config.CameraFeeds.imgQuality); | |
27 | } | |
28 | ||
29 | public void init() { | |
30 | changeCam(intakeCam); | |
31 | } | |
32 | ||
33 | public void run() | |
34 | { | |
a1a9bb70 | 35 | if(/*add test for toggle*/) |
e63d823c ME |
36 | changeCam(intakeCam); |
37 | ||
a1a9bb70 | 38 | if(/*add test for toggle*/) |
e63d823c ME |
39 | changeCam(climberCam); |
40 | ||
41 | updateCam(); | |
42 | } | |
43 | ||
44 | /** | |
45 | * Stop aka close camera stream | |
46 | */ | |
47 | public void end() { | |
48 | NIVision.IMAQdxStopAcquisition(curCam); | |
49 | } | |
50 | ||
51 | /** | |
52 | * Change the camera to get imgs from to a different one | |
53 | * | |
54 | * @param newId | |
55 | * for camera | |
56 | */ | |
57 | public void changeCam(int newId) { | |
58 | NIVision.IMAQdxStopAcquisition(curCam); | |
59 | NIVision.IMAQdxConfigureGrab(newId); | |
60 | NIVision.IMAQdxStartAcquisition(newId); | |
61 | curCam = newId; | |
62 | } | |
63 | ||
64 | /** | |
65 | * Get the img from current camera and give it to the server | |
66 | */ | |
67 | public void updateCam() { | |
68 | NIVision.IMAQdxGrab(curCam, frame, 1); | |
69 | server.setImage(frame); | |
70 | } | |
71 | } |