; 18649 Spring 2010
; group 7
; Justin Ray/justinr2
; other names would go here
; vendpositioncontrol_2.mf

;unit test for coin control

;definitions for inputs
;period and ID for mCoinCount
#DEFINE COIN_COUNT_PER 100ms
#DEFINE COIN_COUNT_CAN_ID 0x0A583C00
;period and ID for mVendMotor
#DEFINE VEND_PER 50ms
#DEFINE VEND_CAN_ID 0x08C81400
;period and ID for mVendPosition 
#DEFINE VEND_POS_PER 50ms
#DEFINE VEND_POS_1_CAN_ID 0x08640A00
#DEFINE VEND_POS_5_CAN_ID 0x08640A04
#DEFINE VEND_POS_8_CAN_ID 0x08640A07
;period and ID for mButton 
#DEFINE BUTTON_PER 100ms
#DEFINE BUTTON_1_CAN_ID 0x09902800
#DEFINE BUTTON_5_CAN_ID 0x09902804
#DEFINE BUTTON_8_CAN_ID 0x09902807
 

;definitions for outputs (output periods are determined by the setting in the .cf file)
#DEFINE VEND_MOTOR_CAN_ID 0x092C1E00

;set input initial value
0.0s I COIN_COUNT_PER N COIN_COUNT_CAN_ID CoinCount = 0
0.0s I VEND_PER N VEND_CAN_ID Vend = false
0.0s I VEND_POS_PER N VEND_POS_1_CAN_ID VendPosition 1 = false
0.0s I VEND_POS_PER N VEND_POS_5_CAN_ID VendPosition 5 = false
0.0s I VEND_POS_PER N VEND_POS_8_CAN_ID VendPosition 8 = true
0.0s I BUTTON_PER N BUTTON_1_CAN_ID Button 1 = false
0.0s I BUTTON_PER N BUTTON_5_CAN_ID Button 5 = false
0.0s I BUTTON_PER N BUTTON_8_CAN_ID Button 8 = false

;#state 'S5.1 IDLE'
0.2s A F VendMotor : direction == STOP
0.2s A N VEND_MOTOR_CAN_ID VendMotor : getDirection == STOP

;#transition 'T5.1'
1.0s I COIN_COUNT_PER N COIN_COUNT_CAN_ID CoinCount = 2
1.0s I BUTTON_PER N BUTTON_5_CAN_ID Button 5 = true 

;set position sensor 8 false
1.1s I VEND_POS_PER N VEND_POS_8_CAN_ID VendPosition 8 = false
;set button false - this is not a normal operating input, but is intended to test the safety condition that we stop at the end of the track regardless. 
1.1s I BUTTON_PER N BUTTON_5_CAN_ID Button 5 = false

;#state 'S5.2 MOVE'
1.3s A F VendMotor : direction == LEFT
1.3s A N VEND_MOTOR_CAN_ID VendMotor : getDirection == LEFT

;set position 5 true and verify that we don't stop there
2.0s I VEND_POS_PER N VEND_POS_5_CAN_ID VendPosition 5 = true
2.10s I VEND_POS_PER N VEND_POS_5_CAN_ID VendPosition 5 = false

;#state 'S5.2 MOVE'
2.2s A F VendMotor : direction == LEFT
2.2s A N VEND_MOTOR_CAN_ID VendMotor : getDirection == LEFT

;#transition 'T5.2'
3.0s I VEND_POS_PER N VEND_POS_1_CAN_ID VendPosition 1 = true

;#state 'S5.1 IDLE'
3.2s A F VendMotor : direction == STOP
3.2s A N VEND_MOTOR_CAN_ID VendMotor : getDirection == STOP







