void CmdGearingP(int anArg) { PrinterMotor currentMotor = m_motors[m_motor]; Text.Log(string.Format("Motor {0}'s gearing is {1}:{2}", m_motor, currentMotor.gearingNumerator, currentMotor.gearingDenominator)); }
/// <summary> /// Clones this instance. /// </summary> public virtual PrinterMotor Clone() { PrinterMotor result = new PrinterMotor(); Populate(result); return(result); }
TickProfile(Arc sourceArc, int stepToTickRate, int tickRate) { Contract.Assert(tickRate > 0, @"Zero tick rate for {0}.", sourceArc); motor = sourceArc.motor; size = sourceArc.motor.stepSize; direction = sourceArc.direction; stepRate = tickRate; // Sync the start with the platform conversion rate. startTick = sourceArc.startStep * stepToTickRate; // Figure out how many steps we can actually take at our rate. int stepsAvailable = Mathf.FloorToInt((float)(sourceArc.length * stepToTickRate) / (float)tickRate); tickLength = stepsAvailable * tickRate; // If we were supposed to take a step in the arc, // try to take at least one step. if (sourceArc.length > 0) { tickLength = Mathf.Max(1, tickLength); } Contract.Assert(tickLength % tickRate == 0 || tickLength < tickRate, @"Non-integral tick rate for {0} from {1}.", this, sourceArc); Contract.Assert((sourceArc.length == 0 && tickLength == 0) || (tickLength > 0), @"Should take at least one tick step for {0} => {1}", sourceArc, this); }
/// <summary> /// Initializes a new instance of the <see cref="Arc"/> class. /// </summary> /// <param name='aMaterial'> /// A material id. /// </param> /// <param name='aStartStep'> /// A start step. /// </param> public Arc(int aMaterial, int aStartStep) { motor = null; material = aMaterial; startStep = aStartStep; endStep = kNotInitialized; direction = StepDirection.Unknown; hasVariableStepRate = false; }
/// <summary> /// Initializes a new instance of the <see cref="Arc"/> class. /// </summary> /// <param name='anId'> /// An extruder identifier. /// </param> /// <param name='aStartStep'> /// A start step. /// </param> public Arc(PrinterMotor aMotor, int aStartStep) { motor = aMotor; startStep = aStartStep; endStep = kNotInitialized; material = kNotInitialized; direction = aMotor.stepDirection; hasVariableStepRate = false; }
/// <summary> /// Çlones an instance of the <see cref="Arc"/> class. /// </summary> /// <param name='aSource'> /// A source. /// </param> public Arc(Arc aSource) { motor = aSource.motor; startStep = aSource.startStep; endStep = aSource.endStep; material = aSource.material; direction = aSource.direction; hasVariableStepRate = false; }
public MotorRateMover(MotorRateMover aMover, int aGlobalStart) { motor = aMover.motor; direction = aMover.direction; size = aMover.size; stepRate = aMover.stepRate; globalStartStep = aGlobalStart; stepCount = aMover.stepCount; }
public MotorRateMover(PrinterMotor aMotor, StepDirection aDirection, StepSize aSize, int aRate, int aGlobalStepStart, int totalStepCount) { motor = aMotor; direction = aDirection; size = aSize; stepRate = aRate; globalStartStep = aGlobalStepStart; stepCount = totalStepCount; }
/// <summary> /// Enqueues a copy of the vertical track arc to move one layer. /// </summary> /// <param name='forMotor'> /// The motor to move. /// </param> /// <param name='toQueue'> /// The queue to fill. /// </param> void NextLayer(PrinterMotor forMotor, List <Arc> toQueue) { Arc anArc = new Arc(m_vertTrackArc); anArc.motor = forMotor; forMotor.Step(anArc.length); toQueue.Add(anArc); Contract.Assert(toQueue.Count == 1, @"Expected 1, not {0} vertical arc{1}", toQueue.Count, Text.S(toQueue.Count)); }
/// <summary> /// Clones this instance. /// </summary> public void Populate(PrinterMotor result) { result.id = id; result.gearingNumerator = gearingNumerator; result.gearingDenominator = gearingDenominator; result.stepSize = stepSize; result.stepDirection = stepDirection; result.stepRate = stepRate; result.stepCounter = stepCounter; //result.maxAccelInStepsPerSec = maxAccelInStepsPerSec; }
public TickProfile(TickProfile source, int aStartTick) { motor = source.motor; size = source.size; direction = source.direction; stepRate = source.stepRate; startTick = aStartTick; tickLength = source.tickLength; // NOTE: Negative tick profiles are OK // when pressurizing, so we don't // check for negative start ticks. Contract.Assert(tickLength >= 0, @"Negative tick length."); Contract.Assert(motor != null, @"No motor assigned to tick profile."); Contract.Assert(direction != StepDirection.Unknown, @"Unknown step direction."); }
static int ApplyPressure(PrinterMotor forMotor, StepDirection inDirection, int usingPressureSteps, int usingPlatformRotation, List <TickProfile> toList) { Contract.Assert(usingPressureSteps <= kPressureSteps, @"Requested {0} pressure steps; maximum is {1}.", usingPressureSteps, kPressureSteps); // NOTE: We don't know how many steps it'll take to // accelerate over usingPressureSteps. So we need // to treat everything as if it stepped from // [0, usingPressureSteps) and then scale the // resulting ticks by anArc.startingStep. Arc pressureArc = new Arc(forMotor, 0); pressureArc.startStep = 0; pressureArc.endStep = usingPressureSteps; pressureArc.direction = inDirection; PrinterExtruder extruder = (PrinterExtruder)forMotor; if (inDirection == StepDirection.Ccw) { extruder.pressureRequired -= usingPressureSteps; Contract.Assert(extruder.pressureRequired >= 0, @"Pressurized more than {0} steps.", kPressureSteps); } else { extruder.pressureRequired += usingPressureSteps; Contract.Assert(extruder.pressureRequired <= kPressureSteps, @"Motor {0} required pressure of {1} exceeds max of {2}.", extruder.id, extruder.pressureRequired, kPressureSteps); } int ticksTaken = Accelerate(pressureArc, usingPlatformRotation, toList); Contract.Assert(ticksTaken > 0, @"Non-positive ticks taken over {0} step{1}.", ticksTaken, Text.S(ticksTaken)); return(ticksTaken); }
public TickProfile(PrinterMotor aMotor, StepSize aSize, StepDirection aDirection, int aStepRate, int aStartTick, int aTickLength) { Contract.Assert(aMotor != null, @"Tried to assign null motor to tick profile."); Contract.Assert(aDirection != StepDirection.Unknown, @"Tried to assign unknown direction to tick profile."); Contract.Assert(aStepRate >= 0, @"Negative step rate of {0}.", aStepRate); // NOTE: Negative tick profiles are OK // when pressurizing, so we don't // check for negative start ticks. motor = aMotor; size = aSize; direction = aDirection; stepRate = aStepRate; startTick = aStartTick; tickLength = aTickLength; }
public static int CompleteDepressurization(PrinterMotor forMotor, int overSteps, int usingPlatformStepRate, List <TickProfile> toList) { // No depressure remaining? Don't care, then. if (overSteps < 1) { return(0); } int ticksTaken = ApplyPressure(forMotor, StepDirection.Cw, overSteps, usingPlatformStepRate, toList); Contract.Assert(ticksTaken > 0, @"No ticks required for depressurizing {0} by {1} step{2}.", forMotor.id, overSteps, Text.S(overSteps)); Contract.Assert(toList[0].startTick == 0, @"Depressure {0} doesn't start at 0.", toList[0]); // How long we actually took to depresurize, worst case. return(Mathf.CeilToInt((float)ticksTaken / (float)usingPlatformStepRate)); }
void StepMotors() { //Text.Log(string.Format("Steps remaining: {0}, {1}", m_motorSteps[0], m_motorSteps[1])); for (int aMotorId = 0; aMotorId < m_motors.Length; ++aMotorId) { PrinterMotor aMotor = m_motors[aMotorId]; if (aMotor.stepRate == 0) { continue; } --aMotor.stepCounter; if (aMotor.stepCounter == 0) { aMotor.stepCounter = aMotor.stepRate; m_motorSteps[aMotorId] = 1; } } bool hasMoved = false; for (int aMotorId = 0; aMotorId < kExtruderBase; ++aMotorId) { if (m_motorSteps[aMotorId] > 0) { m_motors[aMotorId].Step(); --m_motorSteps[aMotorId]; hasMoved = true; } } for (int aMotorId = kExtruderBase; aMotorId < m_motorSteps.Length; ++aMotorId) { if (m_motorSteps[aMotorId] > 0) { m_motors[aMotorId].Step(); --m_motorSteps[aMotorId]; Extrude((PrinterExtruder)m_motors[aMotorId]); hasMoved = false; } } if (hasMoved && !onlyCollectExtruded) { PrinterExtruder anExtruder = (PrinterExtruder)m_motors[4]; float relativePosition = m_simulation.platformRadiusInMm - (float)m_simulation.horizTrack.position; float distFromCenter = anExtruder.DistanceFromPlatCenterInMm(relativePosition); float angleInRad = m_simulation.platform.rotationInDegrees * Mathf.Deg2Rad; Vector4 point = new Vector4(distFromCenter * Mathf.Cos(angleInRad) + m_simulation.platformRadiusInMm, -m_trans.position.y, distFromCenter * Mathf.Sin(angleInRad), 4); movementWithoutExtrusion.Add(point); } m_globalSteps = (m_globalSteps + 1) & 0xFFFFFFFF; Vector3 platformPosition = new Vector3(-(float)m_simulation.horizTrack.position, (float)m_simulation.vertTrack[0].position, 0); m_trans.position = platformPosition; m_trans.rotation = Quaternion.Euler(0, m_simulation.platform.rotationInDegrees, 0); }
public int UpdateState(TickProfile fromProfile, List <TxPacket> forList) { int targetMotorId = fromProfile.motor.id; PrinterMotor targetMotor = targetMotorId < kBaseMotors ? GetBaseMotor(targetMotorId) : extruders[targetMotorId - kBaseMotors]; Contract.Assert(targetMotor.id == targetMotorId, @"Found motor {0} but id isn't {1}.", targetMotor, targetMotorId); bool shouldSendDirection = targetMotor.stepDirection != fromProfile.direction; bool shouldSendStepSize = targetMotor.stepSize != fromProfile.size; bool shouldSendStepRate = targetMotor.stepRate != fromProfile.stepRate; if (shouldSendDirection || shouldSendStepSize || shouldSendStepRate) { if (currentMotorId != targetMotorId) { // Select the motor; note that we don't change the stack. if (lastEnqueuedPacket != null && lastEnqueuedPacket.aCmd == GanglionCommand.StepRate) { lastEnqueuedPacket.aCmd = kStepRateMotor[targetMotorId]; } else { lastEnqueuedPacket = new TxPacket(kMotorToCommand[targetMotorId]); forList.Add(lastEnqueuedPacket); } currentMotorId = targetMotorId; } Contract.Assert(currentMotorId == targetMotor.id, @"Motor id mismatch: {0} != {1}", currentMotorId, targetMotor.id); if (shouldSendDirection) { lastEnqueuedPacket = new TxPacket(fromProfile.direction == StepDirection.Ccw ? GanglionCommand.CounterClockwise : GanglionCommand.Clockwise); forList.Add(lastEnqueuedPacket); targetMotor.stepDirection = fromProfile.direction; } if (shouldSendStepSize) { int ganglionSize = kStepConversion[fromProfile.size]; lastEnqueuedPacket = new TxPacket(GanglionCommand.Value, ganglionSize); forList.Add(lastEnqueuedPacket); lastEnqueuedPacket = new TxPacket(GanglionCommand.StepSize); forList.Add(lastEnqueuedPacket); targetMotor.stepSize = fromProfile.size; m_lastNumberSent = ganglionSize; } if (shouldSendStepRate) { if (fromProfile.stepRate == 0) { if (lastEnqueuedPacket != null && kMotorStop.ContainsKey(lastEnqueuedPacket.aCmd)) { lastEnqueuedPacket.aCmd = kMotorStop[lastEnqueuedPacket.aCmd]; } else { lastEnqueuedPacket = new TxPacket(GanglionCommand.Stop); forList.Add(lastEnqueuedPacket); } } else { if (m_lastNumberSent != fromProfile.stepRate) { lastEnqueuedPacket = new TxPacket(GanglionCommand.Value, fromProfile.stepRate); forList.Add(lastEnqueuedPacket); m_lastNumberSent = fromProfile.stepRate; } lastEnqueuedPacket = new TxPacket(GanglionCommand.StepRate); forList.Add(lastEnqueuedPacket); } targetMotor.stepRate = fromProfile.stepRate; } } Contract.Assert(targetMotor.stepDirection == fromProfile.direction, @"Direction mismatch: {0} != {1}.", targetMotor.stepDirection, fromProfile.direction); Contract.Assert(targetMotor.stepSize == fromProfile.size, @"Step size mismatch: {0} != {1}", targetMotor.stepSize, fromProfile.size); Contract.Assert(targetMotor.stepRate == fromProfile.stepRate, @"Step rate mismatch: {0} != {1}.", targetMotor.stepRate, fromProfile.stepRate); return(m_lastNumberSent); }