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

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

Functions

def taskUser.taskUserFcn (taskName, period, zFlag, timDATA, posDATA, calDATA, DATA, speedDATA, duty_y, duty_x, K_pi, K_di, K_po, K_do, setpoint_x, setpoint_y, wFlag, cFlag)
 A generator to implement the UI task as an FSM. More...
 

Variables

 taskUser.S0_INIT = micropython.const(0)
 Creates object S0_INIT connected to constant 0. More...
 
 taskUser.S1_Wait = micropython.const(1)
 Creates object S1_Wait connected to constant 1. More...
 
 taskUser.S2_zCalibrate = micropython.const(2)
 Creates object S2_zCalibrate connected to constant 2. More...
 
 taskUser.S3_pPrintPos = micropython.const(3)
 Creates object S3_pPrintPos connected to constant 3. More...
 
 taskUser.S4_vVelocity = micropython.const(4)
 Creates object S4_vVelocity connected to constant 4. More...
 
 taskUser.S5_mDutyCtrl = micropython.const(5)
 Creates object S5_mDutyCtrl connected to constant 5. More...
 
 taskUser.S6_gCollectThirtySec = micropython.const(6)
 Creates object S6_gCollectThirtySec connected to constant 6. More...
 
 taskUser.S7_PrintData = micropython.const(7)
 Creates object S7_PrintData connected to constant 7. More...
 
 taskUser.S8_wToggleCTRmode = micropython.const(8)
 Creates object S8_wToggleCTRmode connected to constant 8. More...
 
 taskUser.charIn = serport.read(1).decode()
 State 8 code - Data Collection State.
 
 taskUser.state = S7_PrintData
 
int taskUser.numPrint = 0
 State 7 code - Printing State Printing for data collection ('g' press) state.
 
int taskUser.numItems = 0
 
bool taskUser.IMU_DataFlag = False
 

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 taskUser.taskUserFcn (   taskName,
  period,
  zFlag,
  timDATA,
  posDATA,
  calDATA,
  DATA,
  speedDATA,
  duty_y,
  duty_x,
  K_pi,
  K_di,
  K_po,
  K_do,
  setpoint_x,
  setpoint_y,
  wFlag,
  cFlag 
)

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
posDATAShared data for printing the position of the encoder upon 'p' or 'P' press. This data represents the angular position readout from a BNO055.BNO055 object in degrees.
calDATAShared data for printing the delta value of the encoder upon 'c' or 'C' 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.
duty_yShared data for controlling the duty cycle of the motor_y object, effectively controlling its speed.
duty_xShared data for controlling the duty cycle of the motor_x object, effectively controlling its speed.
K_piK_pi is the closed loop proportional inner loop gain factor that is input by the user upon 'k' press
K_diK_di is the closed loop derivative inner loop gain factor that is input by the user upon 'd' press
K_poK_po is the closed loop proportional outer loop gain factor that is input by the user upon 'K' press
K_doK_do is the closed loop proportional outer loop gain factor that is input by the user upon 'D' press
setpoint_xsetpoint_x is set at desired x position by user upon press of 'x' or 'X'
setpoint_ysetpoint_y is set at desired y position by user upon press of 'y' or 'Y'
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.
cFlagLocal flag variable used to check if calibration coefficient file exists.

Variable Documentation

◆ S0_INIT

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) it also checks if zFlag is true which will begin manual calibration

◆ S1_Wait

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_zCalibrate

taskUser.S2_zCalibrate = micropython.const(2)

Creates object S2_zCalibrate connected to constant 2.

S2_zCalibrate 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

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 3 values of the current position from the touchpanel (theta_x, theta_y, and theta_z)

◆ S4_vVelocity

taskUser.S4_vVelocity = micropython.const(4)

Creates object S4_vVelocity connected to constant 4.

S4_vVelocity is used as a velocity state. If user inputs v or V, they are sent to this state which prints 3 values of the current velocity from the touchpanel (omega_x, omega_y, and omega_z)

◆ S5_mDutyCtrl

taskUser.S5_mDutyCtrl = micropython.const(5)

Creates object S5_mDutyCtrl connected to constant 5.

S5_mDutyCtrl is used to set any and all system parameters which the user may need to control. If user inputs m, M, k, d, y, or x they are sent to this state. In this state, the user can input positive or negative numbers, including decimal numbers. This will change the duty cycles for motor 1 and 2, K_p and K_d, desired theta_y and theta_x values respectively.

◆ S6_gCollectThirtySec

taskUser.S6_gCollectThirtySec = micropython.const(6)

Creates object S6_gCollectThirtySec connected to constant 6.

S6_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.

◆ S7_PrintData

taskUser.S7_PrintData = micropython.const(7)

Creates object S7_PrintData connected to constant 7.

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

◆ S8_wToggleCTRmode

taskUser.S8_wToggleCTRmode = micropython.const(8)

Creates object S8_wToggleCTRmode connected to constant 8.

S8_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.