ME405: Mechatronics
Project Documentation and Portfolio by Neil Patel
main.py File Reference

A scheduler to manage the tasks needed to balance the ball. More...

Namespaces

 Lab0xFF
 This package contains touchPanel.py, motor.py, encoder.py, main.py, controller.py.
 

Functions

def main.encode_task ()
 A task to update the angle of the motors. More...
 
def main.motor_task ()
 A task to run the motors at the correct duty cycle. More...
 
def main.touch_task ()
 A task to check the balls position on the touch screen. More...
 
def main.ctrl_task ()
 A task to determine the needed Duty cycle according to the sensor data. More...
 
def main.data_task ()
 A task responsible for collecting data and storing it in appropriate format. More...
 
def main.UI_task ()
 A task responsible for interaction between the user and the program. More...
 

Variables

list main.x_vals = []
 List containing the x-axis positions.
 
list main.theta_x_vals = []
 List containing the x-axis angles.
 
list main.x_dot_vals = []
 List containing the x-axis velocities.
 
list main.theta_x_dot_vals = []
 List containing the x-axis angular velocities.
 
list main.y_vals = []
 List containing the y-axis positions.
 
list main.theta_y_vals = []
 List containing the y-axis angles.
 
list main.y_dot_vals = []
 List containing the y-axis velocities.
 
list main.theta_y_dot_vals = []
 List containing the y-axis angular velocities.
 
 main.queue_x
 Initializes the Queues and Task to run the Scheduler. More...
 
 main.queue_y
 
 main.queue_ang
 
 main.queue_vang
 
 main.queue_motor1
 
 main.queue_motor2
 
 main.queue_end
 
 main.task_enc
 Instantiate each task. More...
 
 main.task_mot
 
 main.task_tp
 
 main.task_ctrl
 
int main.debug_count = 0
 Create the task list. More...
 

Detailed Description

A scheduler to manage the tasks needed to balance the ball.

Function Documentation

◆ ctrl_task()

def main.ctrl_task ( )

A task to determine the needed Duty cycle according to the sensor data.

Initializes the Controller objects. Using the previous and current x and y values from the Touch Panel, calculates the velocities and angular velocities. Uses those to calculate the Duty Cycles to input into the motors.

Returns
Does not return anything. Yields the state at the end so that the appropriate state is operated in the next iteration.

◆ data_task()

def main.data_task ( )

A task responsible for collecting data and storing it in appropriate format.

Creates a CSV file and writes into it line-by-line. The line can be formatted to display however many values, but the number of values displayed is directly proportional to memory consumption. So if more values are displayed per line, then the total number of test values will decrease.

Returns
Does not return anything.

◆ encode_task()

def main.encode_task ( )

A task to update the angle of the motors.

Initializes the encoders in the Encoder Object. Updates the encoders and gets the positions of the encoders in a tuple. Uses those values to determine angles and angular velocities.

Returns
Does not return anything. Yields the state at the end so that the appropriate state is operated in the next iteration.

◆ motor_task()

def main.motor_task ( )

A task to run the motors at the correct duty cycle.

Initializes both motors in the Motor object. Checks if any of the motors are in the task queue. If they are, then gets the duty cycle and sets the direction and power to abalnce the ball. If motor is disabled, then clears the fault.

Returns
Does not return anything. Yields the state at the end so that the appropriate state is operated in the next iteration.

◆ touch_task()

def main.touch_task ( )

A task to check the balls position on the touch screen.

Initializes the Touch Panel. Gets the data from the touch panel, puts the data into the task queue to measure the positions and velocities.

Returns
Does not return anything. Yields the state at the end so that the appropriate state is operated in the next iteration.

◆ UI_task()

def main.UI_task ( )

A task responsible for interaction between the user and the program.

Runs the schedular with the chosen scheduling algorithm as soon as a character is sent through the serial port. Quits if another character is sent.

Returns
Does not return anything.

Variable Documentation

◆ debug_count

int main.debug_count = 0

Create the task list.

Run the memory garbage collector to ensure memory is as defragmented as possible before the real-time scheduler is started

◆ queue_ang

main.queue_ang
Initial value:
1 = task_share.Queue ('f', 2, thread_protect = False, overwrite = True,
2  name = "Queue_2")
This class implements a queue which is used to transfer data from one task to another.
Definition: task_share.py:37

◆ queue_end

main.queue_end
Initial value:
1 = task_share.Queue ('f', 1, thread_protect = False, overwrite = True,
2  name = "Queue_6")

◆ queue_motor1

main.queue_motor1
Initial value:
1 = task_share.Queue ('f', 1, thread_protect = False, overwrite = True,
2  name = "Queue_4")

◆ queue_motor2

main.queue_motor2
Initial value:
1 = task_share.Queue ('f', 1, thread_protect = False, overwrite = True,
2  name = "Queue_5")

◆ queue_vang

main.queue_vang
Initial value:
1 = task_share.Queue ('f', 2, thread_protect = False, overwrite = True,
2  name = "Queue_3")

◆ queue_x

main.queue_x
Initial value:
1 = task_share.Queue ('f', 1, thread_protect = False, overwrite = True,
2  name = "Queue_0")

Initializes the Queues and Task to run the Scheduler.

Create Queues to share data between each task.

◆ queue_y

main.queue_y
Initial value:
1 = task_share.Queue ('f', 1, thread_protect = False, overwrite = True,
2  name = "Queue_1")

◆ task_ctrl

main.task_ctrl
Initial value:
1 = cotask.Task (ctrl_task, name = 'Task_ctrl', priority = 2,
2  period = 15, profile = True, trace = False)
This class implements behavior common to tasks in a cooperative multitasking system which runs in Mic...
Definition: cotask.py:49

◆ task_enc

main.task_enc
Initial value:
1 = cotask.Task (encode_task, name = 'Task_enc', priority = 3,
2  period = 40, profile = True, trace = False)

Instantiate each task.

◆ task_mot

main.task_mot
Initial value:
1 = cotask.Task (motor_task, name = 'Task_mot', priority = 2,
2  period = 15, profile = True, trace = False)

◆ task_tp

main.task_tp
Initial value:
1 = cotask.Task (touch_task, name = 'Task_tp', priority = 3,
2  period = 40, profile = True, trace = False)