예제 #1
0
 /// <summary>
 /// Calculate and applies next step voltage.
 /// </summary>
 /// <returns>returns true if next step voltage was applied, 
 /// returns false if max or min voltage was exceeded and last voltage remained. </returns>
 public bool MoveSingleStep()
 {
     double oldVoltage = m_currentEMVoltage;
     
     //
     //Calculate next voltage to apply. 
     //the higher the voltage, the more we push the junction (up the voltage->down direction)
     //            
     m_currentEMVoltage -= s_voltInterval*(int)m_direction;            
     
     //
     // if exceedes max or min voltage, pause stepper and return false.
     // else: move and return true. 
     //
     if ( (Math.Abs(m_currentEMVoltage) > s_maxEMVoltage) || (m_currentEMVoltage < s_minEMVoltage) )
     {
         m_direction = StepperDirection.STATIC;
         m_currentEMVoltage = oldVoltage;
         return false;
     }
     else
     {
         AnalogOut(s_analogOutChannel, m_currentEMVoltage);
         return true;
     }
 }
예제 #2
0
 /// <summary>
 /// Reach target voltage on EM.
 /// </summary>
 /// <param name="targetVoltage"></param>
 public void ReachEMVoltageGradually(int delayTime, double targetVoltage)
 {
     //
     // if the current voltage is different than the target
     //
     if (m_currentEMVoltage != targetVoltage)
     {
         //
         // choose direction of motion according to where is the current voltage relative to the target
         // notice: increase in voltage causes DOWN direction motion
         //
         m_direction = ((m_currentEMVoltage - targetVoltage) > 0) ? StepperDirection.UP : StepperDirection.DOWN;
         
         //
         // move until the difference between the current voltage and the target is below zero
         //
         if ((m_currentEMVoltage - targetVoltage) > 0)
         {
             while ((m_currentEMVoltage - targetVoltage) > 0)
             {
                 //
                 //if EM voltage exceeded max value - break. 
                 //
                 if (!MoveSingleStep())
                 {
                     return;
                 }
                 Thread.Sleep(delayTime);
             }
         }
         else
         {
             while ((m_currentEMVoltage - targetVoltage) < 0)
             {
                 //
                 //if EM voltage exceeded max value - break.  
                 //
                 if (!MoveSingleStep())
                 {
                     return;
                 }
                 Thread.Sleep(delayTime);
             }
         }
     }
 }
예제 #3
0
 public void Shutdown()
 {
     m_direction = StepperDirection.STATIC;
     this.SetVoltage(0);
 }
예제 #4
0
 /// <summary>
 /// Move steps by stepper motor with minDelay and Full mode, and shut it down afterwards.
 /// </summary>
 /// <param name="stepperDirection"></param>
 /// <param name="numberOfSteps"></param>
 private void MoveStepsByStepperMotor(StepperDirection stepperDirection, int numberOfSteps)
 {
     m_stepperMotor.Direction = stepperDirection;
     m_stepperMotor.SteppingMode = StepperSteppingMode.FULL;
     m_stepperMotor.Delay = m_stepperMotor.MinDelay;
     m_stepperMotor.MoveMultipleSteps(numberOfSteps);
     m_stepperMotor.Shutdown();
 }
예제 #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:Eto.Forms.StepperEventArgs"/> class.
 /// </summary>
 /// <param name="direction">Direction of the step that the user clicked.</param>
 public StepperEventArgs(StepperDirection direction)
 {
     Direction = direction;
 }
예제 #6
0
        public void StartMoving(StepperDirection dir, int nPos = 1)
        {
            string command = string.Format("move-{0}:{1}", (dir == StepperDirection.CW) ? "cw" : "ccw", nPos.ToString());

            SendCommand(command, waitForReply: true, interimStatus: ArduinoStatus.Moving);
        }