public async Task <EepromConfiguration> CalculateConfig(EepromConfigurationInput param) { using (var scope = CreateScope()) { var paramUri = new UriQueryBuilder(); paramUri.Add("teeth", param.Teeth) .Add("toothSizeInMm", param.ToothSizeInMm) .Add("microSteps", param.MicroSteps) .Add("stepsPerRotation", param.StepsPerRotation) .Add("estimatedRotationSpeed", param.EstimatedRotationSpeed) .Add("timeToAcc", param.TimeToAcc) .Add("timeToDec", param.TimeToDec); HttpResponseMessage response = await scope.Instance.GetAsync(CreatePathBuilder().AddQuery(paramUri).Build()); if (response.IsSuccessStatusCode) { EepromConfiguration value = await response.Content.ReadAsAsync <EepromConfiguration>(); return(value); } return(null); } }
public async Task <EepromConfiguration> CalculateConfig(EepromConfigurationInput param) { using (HttpClient client = CreateHttpClient()) { string paramuri = $"teeth={param.Teeth}&toothsizeInMm={param.ToothsizeinMm}µsteps={param.Microsteps}&stepsPerRotation={param.StepsPerRotation}&estimatedRotationSpeed={param.EstimatedRotationSpeed}&timeToAcc={param.TimeToAcc}&timeToDec={param.TimeToDec}"; HttpResponseMessage response = await client.GetAsync(_api + "/" + paramuri); if (response.IsSuccessStatusCode) { EepromConfiguration value = await response.Content.ReadAsAsync <EepromConfiguration>(); return(value); } } return(null); }
public async Task <EepromConfiguration> CalculateConfig(EepromConfigurationInput param) { var result = new EepromConfiguration(); double acc_corr = 1.0615; double jerkFactor = 25; result.StepsPerRotation = param.MicroSteps * (uint)param.StepsPerRotation; result.DistancePerRotationInMm = param.Teeth * param.ToothSizeInMm; if (Math.Abs(result.DistancePerRotationInMm) > double.Epsilon) { result.StepsPerMm = result.StepsPerRotation / result.DistancePerRotationInMm; result.DistancePerStepInMm = result.DistancePerRotationInMm / result.StepsPerRotation; } result.EstimatedMaxStepRate = result.StepsPerRotation * param.EstimatedRotationSpeed; result.EstimatedMaxSpeedInMmSec = result.DistancePerRotationInMm * param.EstimatedRotationSpeed; result.EstimatedMaxSpeedInMmMin = result.EstimatedMaxSpeedInMmSec * 60.0; if (Math.Abs(param.TimeToAcc) > double.Epsilon) { result.EstimatedAccelerationInMmSec2 = result.EstimatedMaxSpeedInMmSec / param.TimeToAcc; result.EstimatedAcc = Math.Sqrt(result.EstimatedMaxStepRate / param.TimeToAcc) * acc_corr; result.EstimatedAccelerationDistToMaxSpeedInMm = result.EstimatedAccelerationInMmSec2 * param.TimeToAcc * param.TimeToAcc; } if (Math.Abs(param.TimeToDec) > double.Epsilon) { result.EstimatedDecelerationInMmSec2 = result.EstimatedMaxSpeedInMmSec / param.TimeToDec; result.EstimatedDec = Math.Sqrt(result.EstimatedMaxStepRate / param.TimeToDec) * acc_corr; result.EstimatedDecelerationDistFromMaxSpeedInMm = result.EstimatedDecelerationInMmSec2 * param.TimeToDec * param.TimeToDec; } result.EstimatedJerkSpeed = result.EstimatedMaxStepRate / jerkFactor; result.MaxStepRate = (uint)Math.Round(result.EstimatedMaxStepRate, 0); result.Acc = (ushort)Math.Round(result.EstimatedAcc, 0); result.Dec = (ushort)Math.Round(result.EstimatedDec, 0); result.JerkSpeed = (uint)Math.Round(result.EstimatedJerkSpeed, 0); result.StepsPerMm1000 = (float)(result.StepsPerMm / 1000.0); return(await Task.FromResult(result)); }