0% found this document useful (0 votes)
33 views

Timingmotor Final

This module controls the timing and vibration motors. It initializes the motors, runs their state machines, and changes the vibration motor's state. The module variables track the current state, priority, and pulse width. It contains functions to initialize the timing motor, post events to its queue, run its state machine, and change the vibration motor's state. The state machine handles events to start, reset, and timeout the motor's timing and transitions between initialization, waiting, timing, and replay states.

Uploaded by

api-340769184
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

Timingmotor Final

This module controls the timing and vibration motors. It initializes the motors, runs their state machines, and changes the vibration motor's state. The module variables track the current state, priority, and pulse width. It contains functions to initialize the timing motor, post events to its queue, run its state machine, and change the vibration motor's state. The state machine handles events to start, reset, and timeout the motor's timing and transitions between initialization, waiting, timing, and replay states.

Uploaded by

api-340769184
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

TIMING AND VIBRATION MOTORS MODULE

Controls events and functionality for both motors


MODULE VARIABLES
CurrentState
MyPriority
PulseWidth

Current state of this service


ES_Framework priority
Pulse width for motor PWMs

InitTimingMotor
Parameters:
priority number of this service
Returns:
success/failure
Local Variables: Pseudo-code:
Takes a priority number, returns True
Initialize the PWM port
Initialize the period of the timing motor
Set the CurrentState to InitTM
Enable the port and the pin for the vibration motor
Make pin digital and output
Post Event ES_INIT to TimingMotor queue
PostTimingMotor
Parameters:
Returns:
Local Variables: Pseudo-code:
ES_PostToService
Return success/failure
RunTimingMotorSM
Parameters:
ThisEvent
Event we are handling
Returns:
ReturnEvent ES_NO_EVENT if no errors
Local Variables: ReturnEvent ES_Event to return (ES_NO_EVENT if no errors)
Pseudo-code:
Switch CurrentState
CurrentState is InitTM
Put motor into initial position
Put vibration motor initially off
Set CurrentState to WaitForStart
CurrentState is WaitForStart
IF ThisEvent is WAITING
Set the position of the motor to the max position
Set the timing motor timer for one second
ELSE IF ThisEvent is RESET
Set PulseWidth to initial value of pulse width
Set the motor to PulseWidth
Stop the current timer
Set CurrentState to timing

ELSE IF ThisEvent is ES_Timeout and EventParam is TIMING_MOTOR_TIMER


Set static variable reverse to true
IF reverse is true
Set the motor position to minimum
Restart the timing motor timer for one second
Set reverse to false
ELSE
Set the motor position to maximum
Restart the timing motor timer for one second
Set reverse to true
END IF
END IF
CurrentState is Timing
IF ThisEvent is START
OR IF ThisEvent is ES_TIMEOUT and EventParam is TIMING_MOTOR_TIMER
IF the motor hasnt reached the min position
Set the pulse width to current value of PulseWidth
Start timer for one second
Decrement PulseWidth by INCREMENT constant
ELSE
Set the PulseWidth to the maximum value
Set the pulse width of motor
Set CurrentState to Replay
END IF
END IF
CurrentState is Replay
IF ThisEvent is WAITING
Set current state to WaitForStart
Post WAITING event to TimingMotor
END IF
END Switch
ChangeVibrationMotor
Parameters:
change
What to change vibration motor to (on/off)
Returns:
Local Variables: Pseudo-code:
IF change is vibration motor on
Set the vibration pin HI
ELSE IF change is vibration motor off
Set the vibration pin LO
END IF

You might also like