SCARA Robot Term Project
main.py File Reference

Reads ADC pin on Nucleo and saves data in queue. More...

Functions

def main.position_check ()
 checks the current positon before getting the next coordinate More...
 
def main.motor1_func ()
 instantiates motor 1 object More...
 
def main.motor2_func ()
 instantiates motor 2 object More...
 
def main.ISR_SCREEN (IRQ_src)
 sets interrupt every millisecond where ADC value is read More...
 

Variables

list main.xypos = []
 
 main.theta1 = task_share.Share('f', thread_protect = False, name = "Motor Angle 1")
 
 main.theta2 = task_share.Share('f', thread_protect = False, name = "Motor Angle 2")
 
 main.next_theta1 = task_share.Share('f', thread_protect = False, name = "Subsequent Motor Angle 1")
 
 main.next_theta2 = task_share.Share('f', thread_protect = False, name = "Subsequent Motor Angle 2")
 
 main.list_theta1
 
 main.list_theta2
 
 main.next_x
 
 main.next_y
 
 main.ENA = pyb.Pin (pyb.Pin.board.PA10, pyb.Pin.OUT_PP)
 
 main.IN1 = pyb.Pin (pyb.Pin.board.PB4, pyb.Pin.OUT_PP)
 
 main.IN2 = pyb.Pin (pyb.Pin.board.PB5, pyb.Pin.OUT_PP)
 
 main.tim3 = pyb.Timer (3, freq=20000)
 
 main.ENB = pyb.Pin (pyb.Pin.board.PC1, pyb.Pin.OUT_PP)
 
 main.IN3 = pyb.Pin (pyb.Pin.board.PA0, pyb.Pin.OUT_PP)
 
 main.IN4 = pyb.Pin (pyb.Pin.board.PA1, pyb.Pin.OUT_PP)
 
 main.tim5 = pyb.Timer (5, freq=20000)
 
 main.mot1 = motor_drv.MotorDriver(ENA, IN1, IN2, tim3)
 
 main.enc1 = EncoderReader.EncoderReader(1)
 
 main.controller1 = controlloop.ClosedLoop(10, 0)
 
 main.mot2 = motor_drv.MotorDriver(ENB, IN3, IN4, tim5)
 
 main.enc2 = EncoderReader.EncoderReader(2)
 
 main.controller2 = controlloop.ClosedLoop(10, 0)
 
 main.pinC2 = pyb.Pin (pyb.Pin.board.PC2, pyb.Pin.IN)
 
 main.pinC3 = pyb.Pin (pyb.Pin.board.PC3, pyb.Pin.IN)
 
 main.pinC0 = pyb.Pin(pyb.Pin.board.PC0, pyb.Pin.OUT_PP)
 
 main.pinB3 = pyb.Pin(pyb.Pin.board.PB3, pyb.Pin.IN)
 
 main.tim1 = pyb.Timer (1, freq=100)
 
 main.filename = user_task.run()
 
 main.coord_values = x_yimport.x_yimport(filename)
 
 main.x = coord_values[0]
 
 main.y = coord_values[1]
 
int main.constant = 8384/(2*3.1415)*20/110
 
 main.output_kin = kinematics.inv_kinematics(x[i], y[i])
 
 main.mot_task1
 
 main.mot_task2
 
 main.pos_checker3
 
 main.vcp = pyb.USB_VCP ()
 

Detailed Description

Reads ADC pin on Nucleo and saves data in queue.

An adapted main file from basic_tasks.py.

This file instantiates the output and analog read out pins. The ADC pin value is read every millisecond then the corresponding data entry gets added to the queue.

Author
Jeremy Baechler
Kendall Chappell
Matthew Wimberley
Date
16-Feb-2022

This file contains a demonstration program that runs some tasks, an inter-task shared variable, and a queue. There are 3 tasks that run our SCARA robot and we added motor control functions that act as the scheduler.

Author
Jeremy Baechler
Kendall Chappell
Matthew Wimberley
Date
31-Jan-2022

Function Documentation

◆ ISR_SCREEN()

def main.ISR_SCREEN (   IRQ_src)

sets interrupt every millisecond where ADC value is read

Once data is collected for one second, "Stop Transmission" line is sent where CTRL-C and CTRL-D commands are sent over serial communication.

Parameters
IRQ_srcThe cause of the interrupt

◆ motor1_func()

def main.motor1_func ( )

instantiates motor 1 object

This function reads the encoder data, which the controller uses to find the new PWM, which then sets the new motor speed.

◆ motor2_func()

def main.motor2_func ( )

instantiates motor 2 object

This function reads the encoder data, which the controller uses to find the new PWM, which then sets the new motor speed.

◆ position_check()

def main.position_check ( )

checks the current positon before getting the next coordinate

Using the shared values of theta1 and theta2, we know what our next setpoint values are after performing inverse kinematics on the x and y coordinates to obtain the theta1 and theta2 values. We then check to see if the motors have been at the same setpoint, at which point the next theta values will be fed in.

Variable Documentation

◆ list_theta1

main.list_theta1
Initial value:
1= task_share.Queue('f', 100, thread_protect = False, overwrite = False,
2 name = 'theta1-coordinates')
A queue which is used to transfer data from one task to another.
Definition: task_share.py:93

◆ list_theta2

main.list_theta2
Initial value:
1= task_share.Queue('f', 100, thread_protect = False, overwrite = False,
2 name = 'theta2-coordinates')

◆ mot_task1

main.mot_task1
Initial value:
1= cotask.Task (motor1_func, name = 'MotorTask_1', priority = 1,
2 period = 10, profile = True, trace = False)
Implements multitasking with scheduling and some performance logging.
Definition: cotask.py:61

◆ mot_task2

main.mot_task2
Initial value:
1= cotask.Task (motor2_func, name = 'MotorTask_2', priority = 1,
2 period = 10, profile = True, trace = False)

◆ next_x

main.next_x
Initial value:
1= task_share.Queue('f', 100, thread_protect = False, overwrite = False,
2 name = 'x-coordinates')

◆ next_y

main.next_y
Initial value:
1= task_share.Queue('f', 100, thread_protect = False, overwrite = False,
2 name = 'y-coordinates')

◆ pos_checker3

main.pos_checker3
Initial value:
1= cotask.Task (position_check, name = 'Position_Checker', priority = 2,
2 period = 5, profile = True, trace = False)