Mechatronics Portfolio
Logan Williamson's Mechatronics Portfolio and Documentation Repository
Functions | Variables
Lab0x04_taskUser.py File Reference

Implimentation of User Interface task as an FSM. More...

Functions

def Lab0x04_taskUser.taskUserFcn (taskName, period, zFlag, timDATA, posDATA, delDATA, DATA, speedDATA, faultFlag, duty1, duty2, K_p, setpoint, wFlag)
 A generator to implement the UI task as an FSM. More...
 

Variables

 Lab0x04_taskUser.S0_INIT = micropython.const(0)
 Creates object S0_INIT connected to constant 0. More...
 
 Lab0x04_taskUser.S1_Wait = micropython.const(1)
 Creates object S1_Wait connected to constant 1. More...
 
 Lab0x04_taskUser.S2_zZeroEnc1 = micropython.const(2)
 Creates object S2_zZeroEnc1 connected to constant 2. More...
 
 Lab0x04_taskUser.S3_pPrintPos = micropython.const(3)
 Creates object S3_pPrintPos connected to constant 3. More...
 
 Lab0x04_taskUser.S4_dDelta = micropython.const(4)
 Creates object S4_dDelta connected to constant 4. More...
 
 Lab0x04_taskUser.S5_vVelocity = micropython.const(5)
 Creates object S5_vVelocity connected to constant 5. More...
 
 Lab0x04_taskUser.S6_mDutyCtrl = micropython.const(6)
 Creates object S6_mDutyCtrl connected to constant 6. More...
 
 Lab0x04_taskUser.S7_clrFault = micropython.const(7)
 Creates object S7_clrFault connected to constant 7. More...
 
 Lab0x04_taskUser.S8_gCollectThirtySec = micropython.const(8)
 Creates object S8_gCollectThirtySec connected to constant 8. More...
 
 Lab0x04_taskUser.S9_PrintData = micropython.const(9)
 Creates object S9_PrintData connected to constant 9. More...
 
 Lab0x04_taskUser.S10_testingDataCrunch = micropython.const(10)
 Creates object S10_testingDataCrunch connected to constant 10. More...
 
 Lab0x04_taskUser.S11_wToggleCTRmode = micropython.const(11)
 Creates object S11_wToggleCTRmode connected to constant 11. More...
 
 Lab0x04_taskUser.S12_rStepResponse = micropython.const(12)
 Creates object S12_rStepResponse connected to constant 12. More...
 

Detailed Description

Implimentation of User Interface task as an FSM.

The task uses the USB VCP (Virtual COM Port) to take character input from the user working at a serial terminal such as PuTTY. It uses this input with Finite State Machine logic to determine which functionality should be executed based on that user input. This file works cooperatively with taskEncoder.py to allow both files' functionality to be executed quasi- simultaneously.

Author
Brianna Roberts
Logan Williamson
Date
01/26/2022

Function Documentation

◆ taskUserFcn()

def Lab0x04_taskUser.taskUserFcn (   taskName,
  period,
  zFlag,
  timDATA,
  posDATA,
  delDATA,
  DATA,
  speedDATA,
  faultFlag,
  duty1,
  duty2,
  K_p,
  setpoint,
  wFlag 
)

A generator to implement the UI task as an FSM.

The task runs as a generator function and requires a task name and interval to be specified.

Parameters
taskNameThe name of the task as a string.
periodThe task interval or period specified as an integer number of microseconds.
zFlagShared flag variable which causes FSM to enter zeroing state.
timDATAShared data for the time during a data recording session. This is not currently utilized by taskUser.py (instead, it is immediately fed into DATA); however, this is shared to taskUser for debugging purposes.
posDATAShared data for printing the position of the encoder upon 'p' or 'P' press.
delDATAShared data for printing the delta value of the encoder upon 'd' or 'D' press.
DATAShared data for data recording upon 'g' or 'G' press.
speedDATAShared data for printing the velocity of the encoder upon 't' or 'T' press.
faultFlagShared flag variable for indicating when a fault condition has occurred.
duty1Shared data for controlling the duty cycle of the motor_1 object, effectively controlling its speed.
duty2Shared data for controlling the duty cycle of the motor_2 object, effectively controlling its speed.
K_pShared data for controlling the gain for closed-loop motor control
setpointShared data corresponding to the reference or desired velocity of the motor for closed-loop control.\
wFlagShared flag variable set or reset by the user entering 'w' or 'W' in State 1. This variable is shared with taskMotor and will determine whether taskMotor is in the open-loop or closed-loop control state.
kFlagLocal flag variable used to reserve the character buffer for user to set the closed-loop gain.

Variable Documentation

◆ S0_INIT

Lab0x04_taskUser.S0_INIT = micropython.const(0)

Creates object S0_INIT connected to constant 0.

S0_INIT is used as an initialization state it prints the help interface block and sends FSM to state 1 (S1_Wait)

◆ S10_testingDataCrunch

Lab0x04_taskUser.S10_testingDataCrunch = micropython.const(10)

Creates object S10_testingDataCrunch connected to constant 10.

S10_testingDataCrunch is the state used to collect a sample of velocity data points and use them to compute the average velocity of that set. This duty cycle is then written to posArray and the averaged velocity value is written to velArray before being used to print a dataset representing speed as a function of duty cycle.

◆ S11_wToggleCTRmode

Lab0x04_taskUser.S11_wToggleCTRmode = micropython.const(11)

Creates object S11_wToggleCTRmode connected to constant 11.

S11_wToggleCTRmode state either enables or disables the closed loop control. If it is disabled, the velocity set will be off proportionally to the duty cycle. When it is enabled, the corrected gain will alter the duty cycle to be more accurate.

◆ S12_rStepResponse

Lab0x04_taskUser.S12_rStepResponse = micropython.const(12)

Creates object S12_rStepResponse connected to constant 12.

S12_rStepResponse records the step response of the motor when the user has put the motor in closed-loop control mode and

◆ S1_Wait

Lab0x04_taskUser.S1_Wait = micropython.const(1)

Creates object S1_Wait connected to constant 1.

S1_Wait is used as an wait state. Used to decode what the user is inputting. sends user to respective states given specific keyboard inputs

◆ S2_zZeroEnc1

Lab0x04_taskUser.S2_zZeroEnc1 = micropython.const(2)

Creates object S2_zZeroEnc1 connected to constant 2.

S2_zZeroEnc1 is used as a zeroing state. If user inputs z or Z, they are sent to this state which zero's the encoder from the taskEncoder uses zFlag to communicate between all files

◆ S3_pPrintPos

Lab0x04_taskUser.S3_pPrintPos = micropython.const(3)

Creates object S3_pPrintPos connected to constant 3.

S3_pPrintPos is used as a printing state. If user inputs p or P, they are sent to this state which prints ONE value of the current position from the encoder. uses POS to connect between files

◆ S4_dDelta

Lab0x04_taskUser.S4_dDelta = micropython.const(4)

Creates object S4_dDelta connected to constant 4.

S4_dDelta is used as a delta state. If user inputs d or D, they are sent to this state which prints ONE value of the current delta value from the encoder. uses DEL to connect between files

◆ S5_vVelocity

Lab0x04_taskUser.S5_vVelocity = micropython.const(5)

Creates object S5_vVelocity connected to constant 5.

S5_vVelocity is used as a velocity state. If user inputs v or V, they are sent to this state which prints ONE value of the current velocity value from the encoder. uses speedDATA to connect between files

◆ S6_mDutyCtrl

Lab0x04_taskUser.S6_mDutyCtrl = micropython.const(6)

Creates object S6_mDutyCtrl connected to constant 6.

S6_mDutyCtrl is used to set any and all system parameters which the user may need to control. If user inputs m, M, t, k, or y, they are sent to this state. In this state, the user can input positive or negative numbers, including decimal numbers, for the duty cycle, setpoint, closed-loop gain for various control states related to the operation of the motors.

◆ S7_clrFault

Lab0x04_taskUser.S7_clrFault = micropython.const(7)

Creates object S7_clrFault connected to constant 7.

S7_clrFault is used to check if there is a fault detected by the driver. Uses flag variable with boolean logic. flag used is faultFlag

◆ S8_gCollectThirtySec

Lab0x04_taskUser.S8_gCollectThirtySec = micropython.const(8)

Creates object S8_gCollectThirtySec connected to constant 8.

S8_gCollectThirtySec is used to collect data from encoder continuously for 30 seconds. The values are then printed out all together in an array. If the user decides to end data collection early, they may do this by entering s or S on the keyboard.

◆ S9_PrintData

Lab0x04_taskUser.S9_PrintData = micropython.const(9)

Creates object S9_PrintData connected to constant 9.

S9_PrintData is used to print the compiled data that has been collected from both Encoder data or Testing data.