/// <summary> /// Determines what the specified channel is used for (e.g. limit switch or /// controlling the motor speed). /// </summary> /// <param name="channel">Specifies the channel.</param> /// <param name="inputMode">The input mode of the device (Serial/USB, Analog, RC).</param> /// <param name="mixingMode">The mixing mode of the device (None, Left, Right).</param> /// <param name="alternateUse">The alternate use setting for the channel.</param> /// <returns>What the channel is used for.</returns> public static SmcChannelUse use(this SmcChannel channel, SmcInputMode inputMode, SmcMixingMode mixingMode, SmcChannelAlternateUse alternateUse) { if (channel.controlsMotorSpeed(inputMode, mixingMode)) { if (channel == SmcChannel.Analog2 || channel == SmcChannel.Rc2) { return(SmcChannelUse.Steering); } else { return(SmcChannelUse.Throttle); } } else { switch (alternateUse) { default: return(SmcChannelUse.None); case SmcChannelAlternateUse.KillSwitch: return(SmcChannelUse.KillSwitch); case SmcChannelAlternateUse.LimitForward: return(SmcChannelUse.LimitForward); case SmcChannelAlternateUse.LimitReverse: return(SmcChannelUse.LimitReverse); } } }
private static void writeInputMode(StreamWriter sw, SmcInputMode mode) { string str = ""; switch (mode) { case SmcInputMode.SerialUsb: str = "serial"; break; case SmcInputMode.RC: str = "rc"; break; case SmcInputMode.Analog: str = "analog"; break; } sw.WriteLine("input_mode: " + str); }
/// <summary> /// Determines whether the specified channel is directly used to control the /// motor speed (i.e. it is a Throttle or Steering input). /// </summary> /// <param name="channel">Specifies the channel.</param> /// <param name="inputMode">The input mode of the device (Serial/USB, Analog, RC).</param> /// <param name="mixingMode">The mixing mode of the device (None, Left, Right).</param> /// <returns>True if and only if the channel controls the motor speed.</returns> public static bool controlsMotorSpeed(this SmcChannel channel, SmcInputMode inputMode, SmcMixingMode mixingMode) { if (inputMode == SmcInputMode.Analog) { return(channel == SmcChannel.Analog1 || (mixingMode != SmcMixingMode.None && channel == SmcChannel.Analog2)); } else if (inputMode == SmcInputMode.RC) { return(channel == SmcChannel.Rc1 || (mixingMode != SmcMixingMode.None && channel == SmcChannel.Rc2)); } else { // inputMode should be serial/USB return(false); } }
internal SmcSettings(UInt16 productId, SmcSettingsStruct s) { this.productId = productId; // [Add-new-settings-here] this.neverSleep = (s.b1 & SmcBoolSettings1.NeverSleep) != 0; this.uartResponseDelay = (s.b1 & SmcBoolSettings1.UartResponseDelay) != 0; this.useFixedBaudRate = (s.b1 & SmcBoolSettings1.UseFixedBaudRate) != 0; this.disableSafeStart = (s.b1 & SmcBoolSettings1.DisableSafeStart) != 0; this.enableI2C = (s.b1 & SmcBoolSettings1.EnableI2C) != 0; this.ignoreErrLineHigh = (s.b1 & SmcBoolSettings1.IgnoreErrLineHigh) != 0; this.tempLimitGradual = (s.b1 & SmcBoolSettings1.TempLimitGradual) != 0; this.ignorePotDisconnect = (s.b1 & SmcBoolSettings1.IgnorePotDisconnect) != 0; this.motorInvert = (s.b1 & SmcBoolSettings1.MotorInvert) != 0; this.coastWhenOff = (s.b1 & SmcBoolSettings1.CoastWhenOff) != 0; this.crcForCommands = (s.b1 & SmcBoolSettings1.CrcForCommands) != 0; this.crcForResponses = (s.b1 & SmcBoolSettings1.CrcForResponses) != 0; this.fixedBaudRateBps = Smc.convertBaudRegisterToBps(s.fixedBaudRateRegister); this.speedUpdatePeriod = s.speedUpdatePeriod; this.commandTimeout = s.commandTimeout; this.serialDeviceNumber = s.serialDeviceNumber; this.overTempCompleteShutoffThreshold = s.overTempCompleteShutoffThreshold; this.overTempNormalOperationThreshold = s.overTempNormalOperationThreshold; this.inputMode = s.inputMode; this.pwmPeriodFactor = s.pwmPeriodFactor; this.mixingMode = s.mixingMode; this.minPulsePeriod = s.minPulsePeriod; this.maxPulsePeriod = s.maxPulsePeriod; this.rcTimeout = s.rcTimeout; this.consecGoodPulses = s.consecGoodPulses; this.vinScaleCalibration = s.vinScaleCalibration; this.lowVinShutoffTimeout = s.lowVinShutoffTimeout; this.lowVinShutoffMv = s.lowVinShutoffMv; this.lowVinStartupMv = s.lowVinStartupMv; this.highVinShutoffMv = s.highVinShutoffMv; this.serialMode = s.serialMode; this.rc1 = new SmcChannelSettings(s.rc1); this.rc2 = new SmcChannelSettings(s.rc2); this.analog1 = new SmcChannelSettings(s.analog1); this.analog2 = new SmcChannelSettings(s.analog2); this.forwardLimits = new SmcMotorLimits(s.forwardLimits); this.reverseLimits = new SmcMotorLimits(s.reverseLimits); this.currentLimit = s.currentLimit; this.currentOffsetCalibration = s.currentOffsetCalibration; this.currentScaleCalibration = s.currentScaleCalibration; }
internal SmcSettings(SmcSettingsStruct s) { // [Add-new-settings-here] this.neverSuspend = s.neverSuspend; this.uartResponseDelay = s.uartResponseDelay; this.useFixedBaudRate = s.useFixedBaudRate; this.disableSafeStart = s.disableSafeStart; this.fixedBaudRateBps = Smc.convertBaudRegisterToBps(s.fixedBaudRateRegister); this.speedUpdatePeriod = s.speedUpdatePeriod; this.commandTimeout = s.commandTimeout; this.serialDeviceNumber = s.serialDeviceNumber; this.crcMode = s.crcMode; this.overTempMin = s.overTempMin; this.overTempMax = s.overTempMax; this.inputMode = s.inputMode; this.pwmMode = s.pwmMode; this.pwmPeriodFactor = s.pwmPeriodFactor; this.mixingMode = s.mixingMode; this.minPulsePeriod = s.minPulsePeriod; this.maxPulsePeriod = s.maxPulsePeriod; this.rcTimeout = s.rcTimeout; this.ignorePotDisconnect = s.ignorePotDisconnect; this.tempLimitGradual = s.tempLimitGradual; this.consecGoodPulses = s.consecGoodPulses; this.motorInvert = s.motorInvert; this.speedZeroBrakeAmount = s.speedZeroBrakeAmount; this.ignoreErrLineHigh = s.ignoreErrLineHigh; this.vinMultiplierOffset = s.vinMultiplierOffset; this.lowVinShutoffTimeout = s.lowVinShutoffTimeout; this.lowVinShutoffMv = s.lowVinShutoffMv; this.lowVinStartupMv = s.lowVinStartupMv; this.highVinShutoffMv = s.highVinShutoffMv; this.serialMode = s.serialMode; this.rc1 = new SmcChannelSettings(s.rc1); this.rc2 = new SmcChannelSettings(s.rc2); this.analog1 = new SmcChannelSettings(s.analog1); this.analog2 = new SmcChannelSettings(s.analog2); this.forwardLimits = new SmcMotorLimits(s.forwardLimits); this.reverseLimits = new SmcMotorLimits(s.reverseLimits); }
/// <summary> /// Determines what the specified channel is used for (e.g. limit switch or /// controlling the motor speed). /// </summary> /// <param name="channel">Specifies the channel.</param> /// <param name="inputMode">The input mode of the device (Serial/USB, Analog, RC).</param> /// <param name="mixingMode">The mixing mode of the device (None, Left, Right).</param> /// <param name="alternateUse">The alternate use setting for the channel.</param> /// <returns>What the channel is used for.</returns> public static SmcChannelUse use(this SmcChannel channel, SmcInputMode inputMode, SmcMixingMode mixingMode, SmcChannelAlternateUse alternateUse) { if (channel.controlsMotorSpeed(inputMode, mixingMode)) { if (channel == SmcChannel.Analog2 || channel == SmcChannel.Rc2) { return SmcChannelUse.Steering; } else { return SmcChannelUse.Throttle; } } else { switch (alternateUse) { default: return SmcChannelUse.None; case SmcChannelAlternateUse.KillSwitch: return SmcChannelUse.KillSwitch; case SmcChannelAlternateUse.LimitForward: return SmcChannelUse.LimitForward; case SmcChannelAlternateUse.LimitReverse: return SmcChannelUse.LimitReverse; } } }
/// <summary> /// Determines whether the specified channel is directly used to control the /// motor speed (i.e. it is a Throttle or Steering input). /// </summary> /// <param name="channel">Specifies the channel.</param> /// <param name="inputMode">The input mode of the device (Serial/USB, Analog, RC).</param> /// <param name="mixingMode">The mixing mode of the device (None, Left, Right).</param> /// <returns>True if and only if the channel controls the motor speed.</returns> public static bool controlsMotorSpeed(this SmcChannel channel, SmcInputMode inputMode, SmcMixingMode mixingMode) { if (inputMode == SmcInputMode.Analog) { return (channel == SmcChannel.Analog1 || (mixingMode != SmcMixingMode.None && channel == SmcChannel.Analog2)); } else if (inputMode == SmcInputMode.RC) { return (channel == SmcChannel.Rc1 || (mixingMode != SmcMixingMode.None && channel == SmcChannel.Rc2)); } else { // inputMode should be serial/USB return false; } }