StepperMotor Module

This software module

  1) Reads input from grapple dial to control the stepper motor

  2) Controls the stepper motor

  3) Keeps track of the number of steps which determines Tom Cruise's position

 

Public Functions:

initStepMotor(howManySteps)

   Update all timing variables to the current time

   Set the motor direction to raise Tom Cruise

   Run the motor for a number of steps specified by the input howManySteps

   Set the motor direction to lower Tom Cruise

   Run the motor to a calibrated start position

   Reset the internal count for motor position to zero

  

   Read the grapple control dial position by calling readDial() which returns a number the ranges 

   from 0 to 1000

   If the dial position is in the neutral position (about middle of the dial range)

     Set a flag that indicates that the dial is in control of the motor

   Else

     Set a flag that the dial must first be in the neutral position before it is allowed to control

     the motor

 

resetStepMotorStatus

   If motor position is zero

     Return  MOTOR_NOT_IN_RANGE_STATUS

   Else

     Set the motor direction to raise Tom Cruise

     Run the motor at a calibrated reset speed

     Return MOTOR_RESETTING_STATUS

 

slowVictoryReset

   If motor position is zero

     Return  MOTOR_NOT_IN_RANGE_STATUS

   Else

     Set the motor direction to raise Tom Cruise

     Run the motor at a calibrated victory speed

     Return MOTOR_RESETTING_STATUS

 

checkStepMotorStatus

   Read in grapple control dial by calling readDial() which returns a value from 0 to 1000

   Based on grapple control dial position, determine commanded grapple direction and speed

   If flag indicates grapple control dial started not in the neutral position

     Ignore grapple control dial input and assume it is reading neutral (not commanding a motor spd)

   Else

     Set a flag indicating that the grapple control dial is now in control of the motor

  

   Calculate speed (which is actually commanded by a wait time)

   Linearize between calibrated min and max wait times (corresponding to max and min speeds of the

   motor) based off the relative position of the control dial from the neutral position

 

   If motor is commanded to raise and motor position is greater than zero OR

      motor is commanded to lower and motor position is less than the calibrated floor position

     Run motor at commanded speed by calling runMotor(cmdWaitTime) which runs the motor at the

     specified speed = 1/cmdWaitTime

 

   If motor position is equal to calibrated floor position

     Return MOTOR_HIT_FLOOR_STATUS

   Else

     If motor position is in the calibrated position window for the computer

       Return  MOTOR_IN_RANGE_STATUS

     Else

       Return  MOTOR_NOT_IN_RANGE_STATUS

 

Module Functions:

runMotor(cmdWaitTime)

   Filter input speed to prevent instantaneous accelerations of the stepper motor

   If cmdWaitTime is greater than the current motor speed (which is actually expressed as a wait

   time because all motor speeds are actually 1/motor wait times)

     Set cmdWaitTime to be one step faster than the current motor speed

   If cmdWaitTime is less than the current motor speed

     Set cmdWaitTime to be one step slower than the current motor speed

 

   Read the current time

   If the current time minus the time when the last motor step was commanded

     Command a step by calling pulseClock()

     Save the current speed for future filtering

     Update the timing variable with the current time

     Update the motor position

 

readDial

   Read in analog dial as number between 0 and 1023, store as myPos

   If myPos is less than calibrated zero position on dial

     Return 0

   Else

     If myPos is greater than the calibrated fully on position

       Return 1000

     Else

       Linearize between two extreme calibrations in the following manner (to avoid floating point

       math):

      myTemp = (1000*((long)myPos-dialLO));

      myCalc = (int)((myTemp)/((dialHI-dialLO)));

      return myCalc;

 

setDir(dir)

   If dir

     Set stepper motor driver direction line to HI

   Else

     Set stepper motor driver direction line to LO                  

 

pulseClock

   Set step command line to HI

   Delay slightly to ensure CLOCK output stays HI for at least 10[us]

   Set step command line to LO