Plot Something - ME 405 Term Project
main.py File Reference

This is the main file for Lab 3, it contains a program that runs two motor tasks which includes closed loop control for each motor. More...

Functions

def main.task_motor1 (duty_cycle=0)
 Task which runs the motor, encoder, and controller drivers to control the duty cycle for motor 1. More...
 
def main.task_motor2 (duty_cycle=0)
 Task which runs the motor, encoder, and controller drivers to control the duty cycle for motor 2. More...
 
def main.input_task ()
 Task which runs the non-blocking input object quickly to ensure that keypresses are handled not long after they've occurred.
 
def main.task_user (state=S0_CALIB)
 Task which includes multiple states that guide the user through the use of the pen plotter system. More...
 

Variables

 main.S0_CALIB = const(0)
 State 0 of the user interface task.
 
 main.S1_HELP = const(1)
 State 1 of the user interface task.
 
 main.S2_WAIT_FOR_CHAR = const(2)
 State 2 of the user interface task.
 
 main.S3_READ = const(3)
 State 3 of the user interface task.
 
 main.S4_PLOT = const(4)
 State 4 of the user interface task.
 
 main.nb_in = NB_Input (USB_VCP(), echo=True)
 Variable representing the input to the serial port.
 
 main.encoder_drv1 = encoder_agena_chiu.EncoderDriver(pyb.Pin.cpu.B6, pyb.Pin.cpu.B7, 4)
 A variable that creates a encoder driver for encoder 1.
 
 main.encoder_drv2 = encoder_agena_chiu.EncoderDriver(pyb.Pin.cpu.C6, pyb.Pin.cpu.C7, 8)
 A variable that creates a encoder driver for encoder 2.
 
 main.motor_drv1 = motor_agena_chiu.MotorDriver(pyb.Pin.cpu.A10, pyb.Pin.cpu.B4, pyb.Pin.cpu.B5, 3)
 A variable that creates a motor driver for motor 1.
 
 main.motor_drv2 = motor_agena_chiu.MotorDriver(pyb.Pin.cpu.C1, pyb.Pin.cpu.A0, pyb.Pin.cpu.A1, 5)
 A variable that creates a motor driver for motor 2.
 
 main.controller_1 = controller_agena_chiu.ControllerDriver(0, 0)
 A variable that creates a controller driver for motor 1.
 
 main.controller_2 = controller_agena_chiu.ControllerDriver(0, 0)
 A variable that creates a controller driver for motor 2.
 
 main.hpgl = hpgl_agena_chiu.hpglDriver()
 A variable that creates a hpgl driver to read the hpgl file.
 
 main.move_flag1 = task_share.Share('B', name = 'Movement Flag 1')
 A shared variable that indicates that motor 1 arrived at the desired position.
 
 main.move_flag2 = task_share.Share('B', name = 'Movement Flag 2')
 A shared variable that indicates that motor 2 arrived at the desired position.
 
 main.sol = pyb.Pin(pyb.Pin.cpu.B3, pyb.Pin.OUT_PP)
 
 main.task1
 
 main.task2
 
 main.in_task
 
 main.task_user
 

Detailed Description

This is the main file for Lab 3, it contains a program that runs two motor tasks which includes closed loop control for each motor.

The code was adapted from Dr. Ridgely's basic task example.

Author
Corey Agena
Luisa Chiu
Date
2-9-2022

Function Documentation

◆ task_motor1()

def main.task_motor1 (   duty_cycle = 0)

Task which runs the motor, encoder, and controller drivers to control the duty cycle for motor 1.

Parameters
duty_cycleThe initial cycle of motor 1.

◆ task_motor2()

def main.task_motor2 (   duty_cycle = 0)

Task which runs the motor, encoder, and controller drivers to control the duty cycle for motor 2.

Parameters
duty_cycleThe initial cycle of motor 2.

◆ task_user()

def main.task_user (   state = S0_CALIB)

Task which includes multiple states that guide the user through the use of the pen plotter system.

This includes: calibration, help, read, and plot states.

Parameters
stateThe initial state of the user task.

Variable Documentation

◆ in_task

main.in_task
Initial value:
1= cotask.Task (input_task, name = 'Input Task', priority = 1,
2 period = 50, profile = True, trace = False)
Implements multitasking with scheduling and some performance logging.
Definition: cotask.py:24

◆ task1

main.task1
Initial value:
1= cotask.Task (task_motor1, name = 'Task_Motor1', priority = 2,
2 period = 10, profile = True, trace = False)

◆ task2

main.task2
Initial value:
1= cotask.Task (task_motor2, name = 'Task_Motor2', priority = 2,
2 period = 10, profile = True, trace = False)

◆ task_user

main.task_user
Initial value:
1= cotask.Task (task_user, name = 'User Task', priority = 0,
2 period = 100, profile = True, trace = False)