/// <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. /// Pass this argument as 0 if the product ID is unknown at this time. /// </param> public SmcSettings(UInt16 productId) { this.productId = productId; rc1 = SmcChannelSettings.defaultRCSettings(); rc2 = SmcChannelSettings.defaultRCSettings(); analog1 = SmcChannelSettings.defaultAnalogSettings(); analog2 = SmcChannelSettings.defaultAnalogSettings(); forwardLimits = new SmcMotorLimits(); reverseLimits = new SmcMotorLimits(); if (productId == 0xA5 || productId == 0xA9) { // For the versions with 40V MOSFETs: highVinShutoffMv = 35000; } else { // For the versions with 30V MOSFETs: highVinShutoffMv = 25000; } switch (productId) { case 0xA3: currentLimit = 921; break; case 0xA5: currentLimit = 1096; break; default: case 0xA7: currentLimit = 776; break; case 0xA9: currentLimit = 1153; break; } }
private static void fixMotorLimits(SmcMotorLimits ml, string directionName, List <String> warnings) { if (ml.maxSpeed > 0 && ml.startingSpeed > ml.maxSpeed) { warnings.Add("The " + directionName + " max speed was non-zero and smaller than the " + directionName + " starting speed. " + "The " + directionName + " max speed will be changed to 0 and the motor will not be " + "able to drive in the " + directionName + " direction."); ml.maxSpeed = 0; } if (ml.maxSpeed > 3200) { warnings.Add("The " + directionName + " max speed was greater than 3200 (100%) so it will be changed to 3200."); ml.maxSpeed = 3200; } if (ml.maxAcceleration > 3200) { warnings.Add("The " + directionName + " max acceleration was greater than 3200 so it will be changed to 3200."); ml.maxAcceleration = 3200; } if (ml.maxDeceleration > 3200) { warnings.Add("The " + directionName + " max deceleration was greater than 3200 so it will be changed to 3200."); ml.maxDeceleration = 3200; } }
private static void writeMotorLimits(StreamWriter sw, string name, SmcMotorLimits ml) { writeU32(sw, name + "_max_speed", ml.maxSpeed); writeU32(sw, name + "_max_acceleration", ml.maxAcceleration); writeU32(sw, name + "_max_deceleration", ml.maxDeceleration); writeU32(sw, name + "_brake_duration", ml.brakeDuration); writeU32(sw, name + "_starting_speed", ml.startingSpeed); }
/// <summary> /// Compares this object to another to see if they have the same values. /// </summary> public override bool Equals(object x) { SmcMotorLimits s = x as SmcMotorLimits; if (s == null) { return(false); } return(this.convertToStruct().Equals(s.convertToStruct())); }
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; }