Arm.c

void Arm_Init(void)

      Initialize MyTimer on Timer 0 PT0 which has a frequency of 3MHz

      Set Timer0 Channel 6 to output compare used by the servo

      Toggle Channel 6 on overflow to create a PWM

      Set servo to home position

      Set stepper to home position

      Turn off both coils in the stepper motor

 

static void StepMotorModule_runMotor(int waitTime, int dir)

      step the motor if waitTime has passed

 

static void stepMotor(int dir)

      Depending on the direction, update the current step in the fullCmds array

      If curStepStage overflows the array, loop back

      Write out the proper voltages to PS2, PS3, PP2, and PP0 depending on the array index value

 

static void pulseServo(unsigned int width)

      Set the pulse width of the rise time on OC of the servo.

            This width determines the servo’s angle

      Save this width as servo_curPos

 

void goToHomePosition(void)

      Set servo’s desired position to home position

      Set stepper’s desired position to home position

 

void goToAttackPosition(void)

      Set servo’s desired position to attack position

      Set stepper’s desired position to attack position

 

void waveArm(void)

      Set stepper’s desired position to attack position

      Set servo’s desired position to out position

      Set the servo’s skip to wave skip

 

char isWaveStopped(void)

      If stepper’s desPos is not equal to stepper’s curPos

            If desPos > curPos

                  runMotor to send the arm out

            If desPos < curPos

                  runMotor to bring the arm in

                        Set the stepper’s waitTime depending on its position

 

      If servo’s desPos is not equal to servo’s curPos

            If desPos < curPos

                  pulseServo to wave out

            If desPos > curPos

                  pulseServo to wave in

 

      When servo gets to the end of the wave, bring the servo back to wave beginning point

 

      Return 1 when curPos == desPos for both stepper and servo

 

void swingArm(int targetNum)

      correlate targetNum with the height (either low or hi) from the TargetHeights array

      if high

            Set stepper’s desPos = highPos

      Else

            Set stepper’s desPos = lowPos

 

char isArmStopped(void)

      if stepper’s desPos is not equal to stepper’s curPos

            if stepper’s desPos > stepper’s curPos

                  runMotor to raise the arm

                  when stepper reaches attackPos, swing the servo out to midPos

                  when stepper reaches highPos, swing the servo out to attack

            else if stepper’s desPos < stepper’s curPos

                  runMotor to bring arm back in

     

      if servo’s desPos is not equal to servo’s curPos

            if servo’s desPos > servo’s curPos

                  pulseServo to bring servo back in

                  when servo reaches midPos, send stepper’s desPos back to attackPos

            else if servo’s desPos < servo’s curPos

                  pulseServo to swing servo out

 

      if servo’s curPos <= servo’s outpos

            send servo back home

 

      Return 1 when curPos == desPos for both stepper and servo