예제 #1
0
 private static void parseChannel(Tag tag, SmcChannel channel, string name, SmcChannelSettings cs, List <string> warnings)
 {
     if (assertChild(tag, name, warnings))
     {
         Tag channelTag = tag.children[name];
         parseBool(channelTag, "Invert", ref cs.invert, warnings);
         if (assertValue(channelTag, "AlternateUse", warnings))
         {
             try
             {
                 cs.alternateUse = (SmcChannelAlternateUse)Enum.Parse(typeof(SmcChannelAlternateUse), channelTag.values["AlternateUse"]);
             }
             catch
             {
                 warnings.Add("Invalid AlternateUse value \"" + channelTag.values["AlternateUse"] + "\".");
             }
         }
         if (channel.type() == SmcChannelType.Analog && assertValue(channelTag, "PinMode", warnings))
         {
             try
             {
                 cs.pinMode = (SmcPinMode)Enum.Parse(typeof(SmcPinMode), channelTag.values["PinMode"]);
             }
             catch
             {
                 warnings.Add("Invalid PinMode value \"" + channelTag.values["PinMode"] + "\".");
             }
         }
         parseU8(channelTag, "ScalingDegree", ref cs.scalingDegree, warnings);
         parseRange(channelTag, "Error", ref cs.errorMin, ref cs.errorMax, warnings);
         parseRange(channelTag, "Input", ref cs.inputMin, ref cs.inputMax, warnings);
         parseRange(channelTag, "InputNeutral", ref cs.inputNeutralMin, ref cs.inputNeutralMax, warnings);
     }
 }
예제 #2
0
        /// <summary>
        /// Compares this object to another and sees if they have the same values.
        /// </summary>
        public override bool Equals(object x)
        {
            SmcChannelSettings s = x as SmcChannelSettings;

            if (s == null)
            {
                return(false);
            }
            return(this.convertToStruct().Equals(s.convertToStruct()));
        }
예제 #3
0
파일: Smc.cs 프로젝트: lukazikus/mmc
        /// <summary>
        /// Fixes certain thigns about a setttings object so that it doesn't make the device
        /// do something invalid.
        /// For each thing that gets fixed, a warning is added to the warnings list that is passed in.
        /// </summary>
        /// <param name="newSettings">The settings to fix.</param>
        /// <param name="warnings">A list of warnings.  This function will add items to the list.</param>
        /// <param name="productId">The product ID of the device these settings will be used for.
        /// If unknown, this argument should be 0.</param>
        public static void fixSettings(SmcSettings newSettings, List <string> warnings, UInt16 productId)
        {
            if (newSettings.overTempMax < newSettings.overTempMin)
            {
                warnings.Add("The over-temperature minimum was lower than the over-temperature maximum.  " +
                             "Both settings will be set to " + Smc.temperatureToString(newSettings.overTempMax) + " so the motor will shut off at that temperature.");
                newSettings.overTempMin = newSettings.overTempMax;
            }

            if (newSettings.lowVinStartupMv < newSettings.lowVinShutoffMv)
            {
                if (newSettings.lowVinShutoffMv + 500 > UInt16.MaxValue)
                {
                    newSettings.lowVinStartupMv = UInt16.MaxValue;
                }
                else
                {
                    newSettings.lowVinStartupMv = (UInt16)(newSettings.lowVinShutoffMv + 500);
                }
                warnings.Add("The Low VIN Startup voltage was lower than the Low VIN Shutoff voltage (" + newSettings.lowVinShutoffMv / (decimal)1000 + " V).  " +
                             "The Low VIN Startup voltage will be changed to " + newSettings.lowVinStartupMv / (decimal)1000 + " V.");
            }

            if (newSettings.highVinShutoffMv < newSettings.lowVinStartupMv)
            {
                newSettings.highVinShutoffMv = (new SmcSettings(productId).highVinShutoffMv);
                warnings.Add("The High VIN Shutoff voltage was lower than the Low VIN Startup voltage (" + newSettings.lowVinStartupMv / (decimal)1000 + " V).  " +
                             "The High VIN Shutoff voltage will be changed to " + newSettings.highVinShutoffMv / (decimal)1000 + " V.");
            }

            // Prevent the channel scaling values from being out of order (it's okay if they are equal)
            foreach (SmcChannel channel in Smc.channels)
            {
                SmcChannelSettings cs = newSettings.getChannelSettings(channel);
                if (cs.errorMin > cs.inputMin ||
                    cs.inputMin > cs.inputNeutralMin ||
                    cs.inputNeutralMin > cs.inputNeutralMax ||
                    cs.inputNeutralMax > cs.inputMax ||
                    cs.inputMax > cs.errorMax)
                {
                    warnings.Add("The scaling values for " + channel.name() + " are out of order.  They will be reset to their default settings.");

                    SmcChannelSettings defaults = SmcChannelSettings.defaults(channel);
                    cs.errorMin        = defaults.errorMin;
                    cs.inputMin        = defaults.inputMin;
                    cs.inputNeutralMin = defaults.inputNeutralMin;
                    cs.inputNeutralMax = defaults.inputNeutralMax;
                    cs.inputMax        = defaults.inputMax;
                    cs.errorMax        = defaults.errorMax;
                }
            }

            fixMotorLimits(newSettings.forwardLimits, "forward", warnings);
            fixMotorLimits(newSettings.reverseLimits, "reverse", warnings);
        }
예제 #4
0
 /// <summary>
 /// Returns the default settings for the given channel.
 /// </summary>
 /// <param name="channel"></param>
 /// <returns></returns>
 public static SmcChannelSettings defaults(SmcChannel channel)
 {
     if (channel.type() == SmcChannelType.Analog)
     {
         return(SmcChannelSettings.defaultAnalogSettings());
     }
     else
     {
         return(SmcChannelSettings.defaultRCSettings());
     }
 }
예제 #5
0
        /// <summary>
        /// Returns the default settings for Analog channels.
        /// </summary>
        public static SmcChannelSettings defaultAnalogSettings()
        {
            var cs = new SmcChannelSettings();

            cs.errorMin = 0;
            cs.errorMax = 4095;

            cs.inputMin = 40;
            cs.inputMax = 4055;

            cs.inputNeutralMin = 2015;
            cs.inputNeutralMax = 2080;
            return(cs);
        }
예제 #6
0
        /// <summary>
        /// Returns the default settings for RC channels.
        /// </summary>
        public static SmcChannelSettings defaultRCSettings()
        {
            var cs = new SmcChannelSettings();

            cs.errorMin = 500 * 4;
            cs.errorMax = 2500 * 4;

            cs.inputMin = 1000 * 4;
            cs.inputMax = 2000 * 4;

            cs.inputNeutralMin = 1475 * 4;
            cs.inputNeutralMax = 1525 * 4;

            return(cs);
        }
예제 #7
0
        /// <summary>
        /// Constructs a new SmcSettings object that has the default settings for a particular product.
        /// </summary>
        /// <param name="productId">The product ID of the device.  This determines the initial value of
        /// some product-dependent parameters like highVinShutoffMv.  Pass this argument as 0 if the
        /// product ID is unknown at this time.
        /// </param>
        public SmcSettings(UInt16 productId)
        {
            rc1           = SmcChannelSettings.defaultRCSettings();
            rc2           = SmcChannelSettings.defaultRCSettings();
            analog1       = SmcChannelSettings.defaultAnalogSettings();
            analog2       = SmcChannelSettings.defaultAnalogSettings();
            forwardLimits = new SmcMotorLimits();
            reverseLimits = new SmcMotorLimits();

            if (productId == 0x99 || productId == 0x9D)
            {
                // For the versions with 40V MOSFETs:
                this.highVinShutoffMv = 35000;
            }
            else
            {
                // For the versions with 30V MOSFETs:
                this.highVinShutoffMv = 25000;
            }
        }
예제 #8
0
 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);
 }
예제 #9
0
 private static void WriteElementChannelSettings(this XmlWriter writer, SmcChannel channel, SmcChannelSettings cs)
 {
     writer.WriteStartElement(channel.ToString());
     writer.WriteElementString("AlternateUse", cs.alternateUse.ToString());
     if (channel.type() == SmcChannelType.Analog)
     {
         writer.WriteElementString("PinMode", cs.pinMode.ToString());
     }
     writer.WriteElementBool("Invert", cs.invert);
     writer.WriteElementU32("ScalingDegree", cs.scalingDegree);
     writer.WriteElementRange("Error", cs.errorMin, cs.errorMax);
     writer.WriteElementRange("Input", cs.inputMin, cs.inputMax);
     writer.WriteElementRange("InputNeutral", cs.inputNeutralMin, cs.inputNeutralMax);
     writer.WriteEndElement();
 }
예제 #10
0
 private static void parseChannel(Tag tag, SmcChannel channel, string name, SmcChannelSettings cs, List<string> warnings)
 {
     if (assertChild(tag, name, warnings))
     {
         Tag channelTag = tag.children[name];
         parseBool(channelTag, "Invert", ref cs.invert, warnings);
         if (assertValue(channelTag, "AlternateUse", warnings))
         {
             try
             {
                 cs.alternateUse = (SmcChannelAlternateUse)Enum.Parse(typeof(SmcChannelAlternateUse), channelTag.values["AlternateUse"]);
             }
             catch
             {
                 warnings.Add("Invalid AlternateUse value \"" + channelTag.values["AlternateUse"] + "\".");
             }
         }
         if (channel.type() == SmcChannelType.Analog && assertValue(channelTag, "PinMode", warnings))
         {
             try
             {
                 cs.pinMode = (SmcPinMode)Enum.Parse(typeof(SmcPinMode), channelTag.values["PinMode"]);
             }
             catch
             {
                 warnings.Add("Invalid PinMode value \"" + channelTag.values["PinMode"] + "\".");
             }
         }
         parseU8(channelTag, "ScalingDegree", ref cs.scalingDegree, warnings);
         parseRange(channelTag, "Error", ref cs.errorMin, ref cs.errorMax, warnings);
         parseRange(channelTag, "Input", ref cs.inputMin, ref cs.inputMax, warnings);
         parseRange(channelTag, "InputNeutral", ref cs.inputNeutralMin, ref cs.inputNeutralMax, warnings);
     }
 }
예제 #11
0
        /// <summary>
        /// Returns the default settings for RC channels.
        /// </summary>
        public static SmcChannelSettings defaultRCSettings()
        {
            var cs = new SmcChannelSettings();
            cs.errorMin = 500 * 4;
            cs.errorMax = 2500 * 4;

            cs.inputMin = 1000 * 4;
            cs.inputMax = 2000 * 4;

            cs.inputNeutralMin = 1475 * 4;
            cs.inputNeutralMax = 1525 * 4;

            return cs;
        }
예제 #12
0
 /// <summary>
 /// Changes the settings for a specified channel.
 /// </summary>
 /// <param name="settings">The settings of the device. This object will be modified.</param>
 /// <param name="channel">Specifies the channel to change.</param>
 /// <param name="channelSettings">The new settings for the channel.</param>
 public static void setChannelSettings(this SmcSettings settings, SmcChannel channel, SmcChannelSettings channelSettings)
 {
     switch (channel)
     {
         case SmcChannel.Analog1: settings.analog1 = channelSettings; break;
         case SmcChannel.Analog2: settings.analog2 = channelSettings; break;
         case SmcChannel.Rc1: settings.rc1 = channelSettings; break;
         case SmcChannel.Rc2: settings.rc2 = channelSettings; break;
         default: throw new Exception("Unknown Channel: " + channel.ToString());
     }
 }
예제 #13
0
 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);
 }
예제 #14
0
        /// <summary>
        /// Constructs a new SmcSettings object that has the default settings for a particular product.
        /// </summary>
        /// <param name="productId">The product ID of the device.  This determines the initial value of
        /// some product-dependent parameters like highVinShutoffMv.  Pass this argument as 0 if the
        /// product ID is unknown at this time.
        /// </param>
        public SmcSettings(UInt16 productId)
        {
            rc1 = SmcChannelSettings.defaultRCSettings();
            rc2 = SmcChannelSettings.defaultRCSettings();
            analog1 = SmcChannelSettings.defaultAnalogSettings();
            analog2 = SmcChannelSettings.defaultAnalogSettings();
            forwardLimits = new SmcMotorLimits();
            reverseLimits = new SmcMotorLimits();

            if (productId == 0x99 || productId == 0x9D)
            {
                // For the versions with 40V MOSFETs:
                this.highVinShutoffMv = 35000;
            }
            else
            {
                // For the versions with 30V MOSFETs:
                this.highVinShutoffMv = 25000;
            }
        }
예제 #15
0
 private static void WriteElementChannelSettings(this XmlWriter writer, SmcChannel channel, SmcChannelSettings cs)
 {
     writer.WriteStartElement(channel.ToString());
     writer.WriteElementString("AlternateUse", cs.alternateUse.ToString());
     if (channel.type() == SmcChannelType.Analog)
     {
         writer.WriteElementString("PinMode", cs.pinMode.ToString());
     }
     writer.WriteElementBool("Invert", cs.invert);
     writer.WriteElementU32("ScalingDegree", cs.scalingDegree);
     writer.WriteElementRange("Error", cs.errorMin, cs.errorMax);
     writer.WriteElementRange("Input", cs.inputMin, cs.inputMax);
     writer.WriteElementRange("InputNeutral", cs.inputNeutralMin, cs.inputNeutralMax);
     writer.WriteEndElement();
 }
예제 #16
0
파일: Channels.cs 프로젝트: lukazikus/mmc
        /// <summary>
        /// Changes the settings for a specified channel.
        /// </summary>
        /// <param name="settings">The settings of the device. This object will be modified.</param>
        /// <param name="channel">Specifies the channel to change.</param>
        /// <param name="channelSettings">The new settings for the channel.</param>
        public static void setChannelSettings(this SmcSettings settings, SmcChannel channel, SmcChannelSettings channelSettings)
        {
            switch (channel)
            {
            case SmcChannel.Analog1: settings.analog1 = channelSettings; break;

            case SmcChannel.Analog2: settings.analog2 = channelSettings; break;

            case SmcChannel.Rc1: settings.rc1 = channelSettings; break;

            case SmcChannel.Rc2: settings.rc2 = channelSettings; break;

            default: throw new Exception("Unknown Channel: " + channel.ToString());
            }
        }
예제 #17
0
        /// <summary>
        /// Returns the default settings for Analog channels.
        /// </summary>
        public static SmcChannelSettings defaultAnalogSettings()
        {
            var cs = new SmcChannelSettings();
            cs.errorMin = 0;
            cs.errorMax = 4095;

            cs.inputMin = 40;
            cs.inputMax = 4055;

            cs.inputNeutralMin = 2015;
            cs.inputNeutralMax = 2080;
            return cs;
        }