public void TestCreateAnalogInputNull() { Assert.Throws<ArgumentNullException>(() => { AnalogGyro input = new AnalogGyro(null); }); }
public void TestCreateExistingAnalogInput() { using (AnalogInput aIn = new AnalogInput(0)) using (AnalogGyro input = new AnalogGyro(aIn)) { Assert.IsTrue(GetGyroData(0).Initialized); } }
public override void RobotInit() { int status = 0; var ret = HALThreads.HAL_SetCurrentThreadPriority(true, 25, ref status); Console.WriteLine(status); Console.WriteLine(ret); Thread cameraThread = new Thread(() => { // Get the USB Camera from the camera server UsbCamera camera = CameraServer.Instance.StartAutomaticCapture(); camera.SetResolution(640, 480); // Get a CvSink. This will capture Mats from the Camera CvSink cvSink = CameraServer.Instance.GetVideo(); // Setup a CvSource. This will send images back to the dashboard CvSource outputStream = CameraServer.Instance.PutVideo("Rectangle", 640, 480); // Mats are very expensive. Let's reuse this Mat. Mat mat = new Mat(); while (true) { // Tell the CvSink to grab a frame from the camera and put it // in the source mat. If there is an error notify the output. if (cvSink.GrabFrame(mat) == 0) { Console.WriteLine("Timeout"); // Send the output the error. outputStream.NotifyError(cvSink.GetError()); // skip the rest of the current iteration continue; } // Put a rectangle on the image Cv2.Rectangle(mat, new Point(100, 100), new Point(400, 400), new Scalar(255, 255, 255), 5); // Give the output stream a new image to display outputStream.PutFrame(mat); } }); cameraThread.IsBackground = true; cameraThread.Start(); servo = new Servo(0); joystick = new Joystick(0); gyro = new AnalogGyro(0); }
public void TestCreationPreCreatedInputNull() { Assert.Throws<ArgumentNullException>(() => { AnalogGyro gyro = new AnalogGyro(null); }); }
//public static List<ErrorData> ErrorList { get; } = new List<ErrorData>(); /* * /// <summary> * /// Gets the can talon. * /// </summary> * /// <param name="id">The identifier.</param> * /// <returns></returns> * public static CanTalonData GetCanTalon(int id) * { * CanTalonData data; * bool retVal = s_canTalon.TryGetValue(id, out data); * if (retVal) * { * //Contains key. Just return it * return data; * } * else * { * //CAN Talon does not exist yet. Return null. * return null; * } * } * * /// <summary> * /// Initializes the can talon. * /// </summary> * /// <param name="id">The identifier.</param> * /// <returns></returns> * public static bool InitializeCanTalon(int id) * { * CanTalonData data; * bool retVal = s_canTalon.TryGetValue(id, out data); * if (retVal) * { * //Contains key. return false saying we did not initialize a new one. * return false; * } * else * { * //Create a new Can Talon data and return true. * data = new CanTalonData(); * s_canTalon.Add(id, data); * OnTalonSRXAddedOrRemoved?.Invoke(id, new TalonSRXEventArgs(true)); * return true; * } * } * * /// <summary> * /// Removes the can talon. * /// </summary> * /// <param name="id">The identifier.</param> * public static void RemoveCanTalon(int id) * { * s_canTalon.Remove(id); * OnTalonSRXAddedOrRemoved?.Invoke(id, new TalonSRXEventArgs(false)); * } * * /// <summary> * /// Gets the PCM. * /// </summary> * /// <param name="id">The identifier.</param> * /// <returns></returns> * public static PCMData GetPCM(int id) * { * PCMData data; * bool retVal = s_pcm.TryGetValue(id, out data); * if (retVal) * { * //Contains key. Just return it * return data; * } * else * { * data = new PCMData(); * s_pcm.Add(id, data); * OnPCMAdded?.Invoke(data, null); * return data; * } * } * * /// <summary> * /// Initializes the PCM. * /// </summary> * /// <param name="id">The identifier.</param> * /// <returns></returns> * public static bool InitializePCM(int id) * { * PCMData data; * bool retVal = s_pcm.TryGetValue(id, out data); * if (retVal) * { * //Contains key. return false saying we did not initialize a new one. * return false; * } * else * { * //Create a new PCM data and return true. * data = new PCMData(); * s_pcm.Add(id, data); * OnPCMAdded?.Invoke(data, null); * return true; * } * } * * /// <summary> * /// Gets the PDP. * /// </summary> * /// <param name="id">The identifier.</param> * /// <returns></returns> * public static PDPData GetPDP(int id) * { * PDPData data; * bool retVal = s_pdp.TryGetValue(id, out data); * if (retVal) * { * //Contains key. Just return it * return data; * } * else * { * data = new PDPData(); * s_pdp.Add(id, data); * OnPDPAdded?.Invoke(data, null); * return data; * } * } * * /// <summary> * /// Initializes a new PDP. * /// </summary> * /// <param name="id">The identifier.</param> * /// <returns>True if new PDP was created, otherwise false</returns> * public static bool InitializePDP(int id) * { * PDPData data; * bool retVal = s_pdp.TryGetValue(id, out data); * if (retVal) * { * //Contains key. return false saying we did not initialize a new one. * return false; * } * else * { * //Create a new PCM data and return true. * data = new PDPData(); * s_pdp.Add(id, data); * OnPDPAdded?.Invoke(data, null); * return true; * } * } * * /// <summary> * /// Occurs on talon SRX added or removed. * /// </summary> * public static event EventHandler<TalonSRXEventArgs> OnTalonSRXAddedOrRemoved; * /// <summary> * /// Occurs when a PCM is added. * /// </summary> * public static event EventHandler OnPCMAdded; * /// <summary> * /// Occurs when a PDP is added. * /// </summary> * public static event EventHandler OnPDPAdded; * */ static SimData() { for (int i = 0; i < HAL_GetNumPCMModules(); i++) { PCM.Add(new HALSimPCMData(i)); } for (int i = 0; i < HAL_GetNumPDPModules(); i++) { PDP.Add(new HALSimPDPData(i)); } for (int i = 0; i < HAL_GetNumAccumulators(); i++) { AnalogGyro.Add(new HALSimAnalogGyroData(i)); } for (int i = 0; i < HAL_GetNumAnalogOutputs(); i++) { AnalogOut.Add(new HALSimAnalogOutData(i)); } for (int i = 0; i < HAL_GetNumAnalogInputs(); i++) { AnalogIn.Add(new HALSimAnalogInData(i)); } for (int i = 0; i < HAL_GetNumAnalogTriggers(); i++) { AnalogTrigger.Add(new HALSimAnalogTriggerData(i)); } for (int i = 0; i < HAL_GetNumDigitalChannels(); i++) { DIO.Add(new HALSimDIOData(i)); } for (int i = 0; i < HAL_GetNumDigitalPWMOutputs(); i++) { DigitalPWM.Add(new HALSimDigitalPWMData(i)); } for (int i = 0; i < 4; i++) { //DigitalGlitchFilter.Add(new DigitalGlitchFilterData()); } for (int i = 0; i < HAL_GetNumPWMChannels(); i++) { PWM.Add(new HALSimPWMData(i)); } for (int i = 0; i < 4; i++) { Relay.Add(new HALSimRelayData(i)); } for (int i = 0; i < 8; i++) { //Counter.Add(new CounterData()); } for (int i = 0; i < 8; i++) { Encoder.Add(new HALSimEncoderData(i)); } for (int i = 0; i < 5; i++) { SPIAccelerometer.Add(new HALSimSPIAccelerometerData(i)); } for (int i = 0; i < 5; i++) { //SPIAccumulator.Add(new SPIAccumulatorData()); } //InitializePDP(0); //ErrorList.Clear(); }