Pen Plotter Project
main.py File Reference

Main file for pen plotter robot which is run by the user. More...

Functions

def main.task_data_collect ()
 Collects X/Y data from HPGL drawing and converts into readable commands for rotational/radial/servo motors. More...
 
def main.stop_motors ()
 Stops rotational and radial motors; used at the end of main.py program.
 
def main.task_rot_motor ()
 Rotational motor task drives the motor to specified setpoint and repeats the process with new setpoints until there are none left. More...
 
def main.task_rad_motor ()
 Radial motor task drives the motor to specified setpoint and repeats the process with new setpoints until there are none left. More...
 
def main.task_servo ()
 Sends a PWM signal to the servo to make the pen go up or down based on whether the converted HPGL command is a 1 or 0.
 

Variables

int main.ticks_per_rev = 256*2*16
 Ticks.
 
float main.r = 0.375/2
 
int main.S0_DATA_INIT = 0
 
int main.S1_COLLECT_DATA = 1
 
int main.S2_CONVERT_DATA = 2
 
int main.S0_INIT = 0
 
int main.S1_START = 1
 
int main.S2_DRIVE_MOTOR = 2
 
int main.S3_CHANGE_SETPOINT = 3
 
int main.S4_STOP = 4
 
int main.S0_SERVO_INIT = 0
 
int main.S1_PEN_UP = 1
 
int main.S2_PEN_DOWN = 2
 
 main.q_theta_rad
 
 main.q_theta_rot
 
 main.q_servo
 
 main.file_name = input('Enter HPGL filename: ')
 
 main.task_rot
 
 main.task_rad
 
 main.task_srvo
 

Detailed Description

Main file for pen plotter robot which is run by the user.

The program begins by creating state variables, queues, and asking the user for HPGL filename. Once the user inputs the filename, our data collection task is run to put all the setpoint values for respective radial/angular/and servo motor into queues. The task functions for each motor are then created as objects using cotask and appended to a list. This list is then continuously run until there are no setpoint values left in each queue. Finally, the motors are turned off and a print statement lets the user know the program is over.

Author
Christian Clephan
Kyle McGrath
Date
02-Jan-2022

Function Documentation

◆ task_data_collect()

def main.task_data_collect ( )

Collects X/Y data from HPGL drawing and converts into readable commands for rotational/radial/servo motors.

Opens file specified by the user and converts HPGL standard commands to readable code to be put in a queue and read by other tasks as setpoint values for motor control. X/Y coordinates are converted to polar coordinates in revolutions for respective motors to spin. Finally, the setpoints in revolutions for DC motors and up or down commands for pen are put into their resepctive queues.

◆ task_rad_motor()

def main.task_rad_motor ( )

Radial motor task drives the motor to specified setpoint and repeats the process with new setpoints until there are none left.

First the radial motor/encoder pins are initialized and created as objects along with a controller. Next, the encoder is zeroed and a timer is started for which a motor will be driven to a setpoint by a controller which constantly updates and sends duties to the motor based on position control. After 1 second another setpoint value is given to the controller for which the motor is driven again. This is repeated until there are no setpoint values left in the queue and the motor is stopped.

◆ task_rot_motor()

def main.task_rot_motor ( )

Rotational motor task drives the motor to specified setpoint and repeats the process with new setpoints until there are none left.

First the rotational motor/encoder pins are initialized and created as objects along with a controller. Next, the encoder is zeroed and a timer is started for which a motor will be driven to a setpoint by a controller which constantly updates and sends duties to the motor based on position control. After 1 second another setpoint value is given to the controller for which the motor is driven again. This is repeated until there are no setpoint values left in the queue and the motor is stopped.

Variable Documentation

◆ q_servo

main.q_servo
Initial value:
1= task_share.Queue ('b', size = 400, thread_protect = False, overwrite = False,
2 name = "Queue Servo")
A queue which is used to transfer data from one task to another.
Definition: task_share.py:68

◆ q_theta_rad

main.q_theta_rad
Initial value:
1= task_share.Queue ('f', size = 400, thread_protect = False, overwrite = False,
2 name = "Queue Theta Radial")

◆ q_theta_rot

main.q_theta_rot
Initial value:
1= task_share.Queue ('f', size = 400, thread_protect = False, overwrite = False,
2 name = "Queue Theta Rotational")

◆ task_rad

main.task_rad
Initial value:
1= cotask.Task (task_rad_motor, name = 'Task Radial Motor', priority = 1,
2 period = 500, profile = True, trace = False)
Implements multitasking with scheduling and some performance logging.
Definition: cotask.py:24

◆ task_rot

main.task_rot
Initial value:
1= cotask.Task (task_rot_motor, name = 'Task Rotational Motor', priority = 1,
2 period = 500, profile = True, trace = False)

◆ task_srvo

main.task_srvo
Initial value:
1= cotask.Task (task_servo, name = 'Task Servo', priority = 0,
2 period = 500, profile = True, trace = False)