//private float setpoint_converted; public SetpointData(int deviceID, int mode, Double setpoint) { this.deviceID = deviceID; this.mode = (CTRE.TalonSrx.ControlMode)mode; this.setpoint = setpoint; // setpoint_converted = convertSetpoint(); }
/** spin in this routine forever */ public void RunForever() { /* config our talon, don't continue until it's successful */ int initStatus = SetupConfig(); /* configuration */ while (initStatus != 0) { Instrument.PrintConfigError(); initStatus = SetupConfig(); /* (re)config*/ } /* robot loop */ while (true) { /* get joystick params */ float leftY = -1f * _gamepad.GetAxis(1); bool btnTopLeftShoulder = _gamepad.GetButton(5); bool btnBtmLeftShoulder = _gamepad.GetButton(7); Deadband(ref leftY); /* keep robot enabled if gamepad is connected and in 'D' mode */ if (_gamepad.GetConnectionStatus() == CTRE.UsbDeviceConnection.Connected) { CTRE.Watchdog.Feed(); } /* set the control mode based on button pressed */ if (btnTopLeftShoulder) { _mode = CTRE.TalonSrx.ControlMode.kPercentVbus; } if (btnBtmLeftShoulder) { _mode = CTRE.TalonSrx.ControlMode.kMotionMagic; } /* calc the Talon output based on mode */ if (_mode == CTRE.TalonSrx.ControlMode.kPercentVbus) { float output = leftY; // [-1, +1] percent duty cycle _talon.SetControlMode(_mode); _talon.Set(output); } else if (_mode == CTRE.TalonSrx.ControlMode.kMotionMagic) { float servoToRotation = leftY * 10;// [-10, +10] rotations _talon.SetControlMode(_mode); _talon.Set(servoToRotation); } /* instrumentation */ Instrument.Process(_talon); /* wait a bit */ System.Threading.Thread.Sleep(5); } }
//reads the talons and updates the data public void updateStatusData() { talonCurrent = (talon.GetOutputCurrent()); talonTemperature = (talon.GetTemperature()); talonVoltage = (talon.GetOutputVoltage()); talonSpeed = (talon.GetSpeed()); talonPosition = (talon.GetPosition()); talonSetpoint = (talon.GetSetpoint()); talonForwardLimitReached = talon.IsFwdLimitSwitchClosed() ? 1 : 0; talonReverseLimitReached = talon.IsRevLimitSwitchClosed() ? 1 : 0; controlMode = talon.GetControlMode(); }
/** spin in this routine forever */ public void RunForever() { /* config our talon, don't continue until it's successful */ int initStatus = SetupConfig(); /* configuration */ while (initStatus != 0) { Instrument.PrintConfigError(); initStatus = SetupConfig(); /* (re)config*/ } /* robot loop */ while (true) { /* get joystick params */ float leftY = -1f * _gamepad.GetAxis(1); bool btnTopLeftShoulder = _gamepad.GetButton(5); bool btnBtmLeftShoulder = _gamepad.GetButton(7); Deadband(ref leftY); /* keep robot enabled if gamepad is connected and in 'D' mode */ if (_gamepad.GetConnectionStatus() == CTRE.UsbDeviceConnection.Connected) CTRE.Watchdog.Feed(); /* set the control mode based on button pressed */ if (btnTopLeftShoulder) _mode = CTRE.TalonSrx.ControlMode.kPercentVbus; if (btnBtmLeftShoulder) _mode = CTRE.TalonSrx.ControlMode.kMotionMagic; /* calc the Talon output based on mode */ if (_mode == CTRE.TalonSrx.ControlMode.kPercentVbus) { float output = leftY; // [-1, +1] percent duty cycle _talon.SetControlMode(_mode); _talon.Set(output); } else if (_mode == CTRE.TalonSrx.ControlMode.kMotionMagic) { float servoToRotation = leftY * 10;// [-10, +10] rotations _talon.SetControlMode(_mode); _talon.Set(servoToRotation); } /* instrumentation */ Instrument.Process(_talon); /* wait a bit */ System.Threading.Thread.Sleep(5); } }