BallHoldLoad (Pseudo code)
Defines –
AngleZero 213 (Servo calibration)
AngleIncrement 17 (Servo calibration for 60 degrees)
Global variables-
Boolean ballsLoaded[5] (Set to TRUE, TRUE, TRUE, TRUE, TRUE at initialize to represent 5 balls starting)
Int position[8] = (Set to AngleZero, AngleZero-AngleIncrement, … AngleZero-7AngleIncrement)
RunBallSM
Static int i (to keep track of which ball we are loading)
On Entry,
Set i to 0
Set BallSpinServo to Position 1
Start Timer 6 with 1000 ms
If Timer 6 timed out,
If i is 0, activate the emitter
If i is less than 5,
Get the color, and for the next part use our color for get disable functions (from power station)
If the power station is not disabled
Set ball spin servo to Position i+1
Set Timer 6 to 3000 ms and start it
Set ballsLoaded[i] to TRUE
Increment i
changeAmmo(1) for MasterSM to keep track of balls
else if power station is disabled and I >= 2 (more than 2 balls already)
Set emitter to 0, and post LoadingFinished to MasterSM
else if power station is disabled and i < 2
Reset timer 6 to 500 ms and start it
Else if i >= 5,
We are finished loading balls, so setEmitter to 0
Post LoadingFinished to MasterSM’
StartBallSM
RunBallSM with the event passed in
loadShooter
Check positions of ballsLoaded in decreasing order (4, 3, 2, 1, 0)
If ballsLoaded of that number is true,
Set BallSpinServo to Position[i] (To drop ball out)
Set ballsLoaded[i] to FALSE
Return to stop searching since ball was loaded
AngleZero 213 (Servo calibration)
AngleIncrement 17 (Servo calibration for 60 degrees)
Global variables-
Boolean ballsLoaded[5] (Set to TRUE, TRUE, TRUE, TRUE, TRUE at initialize to represent 5 balls starting)
Int position[8] = (Set to AngleZero, AngleZero-AngleIncrement, … AngleZero-7AngleIncrement)
RunBallSM
Static int i (to keep track of which ball we are loading)
On Entry,
Set i to 0
Set BallSpinServo to Position 1
Start Timer 6 with 1000 ms
If Timer 6 timed out,
If i is 0, activate the emitter
If i is less than 5,
Get the color, and for the next part use our color for get disable functions (from power station)
If the power station is not disabled
Set ball spin servo to Position i+1
Set Timer 6 to 3000 ms and start it
Set ballsLoaded[i] to TRUE
Increment i
changeAmmo(1) for MasterSM to keep track of balls
else if power station is disabled and I >= 2 (more than 2 balls already)
Set emitter to 0, and post LoadingFinished to MasterSM
else if power station is disabled and i < 2
Reset timer 6 to 500 ms and start it
Else if i >= 5,
We are finished loading balls, so setEmitter to 0
Post LoadingFinished to MasterSM’
StartBallSM
RunBallSM with the event passed in
loadShooter
Check positions of ballsLoaded in decreasing order (4, 3, 2, 1, 0)
If ballsLoaded of that number is true,
Set BallSpinServo to Position[i] (To drop ball out)
Set ballsLoaded[i] to FALSE
Return to stop searching since ball was loaded