20from motor
import Motor
21from encoder
import Encoder
22from pyb
import Timer, Pin, UART, ExtInt, I2C
23from data_collector
import data_collector
25from motor_encoder_left_class
import motor_encoder_left_class
26from motor_encoder_right_class
import motor_encoder_right_class
27from controller
import Controller
28from control_task
import control_task
29from line_sensor
import Line_Sensor
30from ir_sensor
import IR_Sensor
31from line_task
import line_task
33from imu_task
import imu_task
34from observer
import observer
35from pathing_plan_task
import pathing_plan
36from bump_task
import Bump_Task
37from bump__sensor
import Bump_Sensor
89automatic_mode =
task_share.Share(
'b', thread_protect =
False, name =
"automatic_mode" )
107velocity =
task_share.Queue(
'f', 50, thread_protect =
False, overwrite =
False, name =
"velocity")
108velocity2 =
task_share.Queue(
'f', 50, thread_protect =
False, overwrite =
False, name =
"velocity2")
110position =
task_share.Queue(
'f', 50, thread_protect =
False, overwrite =
False, name =
"position")
112times =
task_share.Queue(
'l', 50, thread_protect =
False, overwrite =
False, name =
"times")
117tim1 = Timer(1, prescaler=0, period=65535)
118tim3 = Timer(3, prescaler=0, period=65535)
119tim4 = Timer(4, freq=20000)
121my_motor_Left =
Motor(Pin.cpu.B7, Pin.cpu.C13, Pin.cpu.C14, tim4, 1)
122encoder_Right =
Encoder(tim3, Pin.cpu.C6, Pin.cpu.C7)
124my_motor_Right =
Motor(Pin.cpu.B6, Pin.cpu.B10, Pin.cpu.A10, tim4, 2)
125encoder_Left =
Encoder(tim1, Pin.cpu.A8, Pin.cpu.A9)
127bump_sensor_right =
Bump_Sensor(Pin.cpu.B13, Pin.cpu.B3, Pin.cpu.B5)
128bump_sensor_left =
Bump_Sensor(Pin.cpu.B11, Pin.cpu.B15, Pin.cpu.B14)
144line_sensor_obj =
Line_Sensor(ir1, ir2, ir3, ir4, ir5, ir6, ir7, ir8, ir9, ir10, ir11, ir12, ir13)
146uart_obj = UART(5, 115200)
147uart_obj.init(115200, bits=8, parity =
None, stop = 1, timeout = 50)
150i2c_obj = I2C(1,I2C.CONTROLLER,baudrate = 400000)
156controller_obj_left =
Controller(.2,1.95,1, ERR_SAT_LEFT, EFF_SAT_LEFT)
157controller_obj_right =
Controller(.2,1.95,1, ERR_SAT_RIGHT, EFF_SAT_RIGHT)
158controller_obj_line =
Controller(150, 10, 1, ERR_SAT_LINE, EFF_SAT_LINE)
159controller_obj_yaw =
Controller(.8,.3,1, ERR_SAT_YAW, EFF_SAT_YAW)
166ui_obj =
ui(testing_flg, m_state_l, m_state_r, position, velocity, times, PWM_l, PWM_r, delay, uart_obj, fwd_ref, arc_ref, piv_ref, c_state, velocity2, need_Calibrate, ready_Black, ready_White, automatic_mode, imu_flg)
167data_collector_obj =
data_collector(testing_flg, position, velocity, times, position_l, velocity_l, position_r, velocity_r, velocity2)
168control_task_obj =
control_task(fwd_ref, arc_ref, piv_ref, c_state, controller_obj_left, controller_obj_right, position_l, velocity_l, position_r, velocity_r, PWM_l, PWM_r, encoder_Right, encoder_Left, m_state_l, m_state_r, centroid, controller_obj_line, automatic_mode, line_sensor_obj, need_Calibrate, yaw, centroid_goal, yaw_goal, controller_obj_yaw)
169line_task_obj =
line_task(line_sensor_obj, l_state, need_Calibrate, ready_Black, ready_White,centroid)
170imu_task_obj =
imu_task(imu_obj, imu_flg, yaw, yaw_velocity)
171observer_obj =
observer(position_l, position_r, yaw, yaw_velocity, PWM_l, PWM_r, velocity_l, velocity_r, total_dist)
172pathing_obj =
pathing_plan(total_dist, automatic_mode, c_state, fwd_ref, piv_ref, yaw, centroid_goal, yaw_goal, bump_on_off, bump_flg)
173bump_obj =
Bump_Task(c_state, bump_sensor_right, bump_sensor_left, bump_on_off, bump_flg)
178task1 =
cotask.Task(data_collector_obj.run, name=
"data_collector", priority=2, period=18, profile=
True, trace=
False, shares=())
179task2 =
cotask.Task(motor_Left_class.run, name=
"motor_encoder_left", priority=7, period=13, profile=
True, trace=
False, shares=())
180task3 =
cotask.Task(motor_Right_class.run, name=
"motor_encoder_right", priority=7, period=13, profile=
True, trace=
False, shares=())
181task4 =
cotask.Task(ui_obj.run, name=
"ui", priority=1, period=1, profile=
True, trace=
False, shares=())
182task5 =
cotask.Task(control_task_obj.run, name=
"control_task", priority=6, period=15, profile =
True, trace=
False, shares=())
183task6 =
cotask.Task(line_task_obj.run, name=
"line_task", priority = 5, period = 22, profile =
True, trace =
False, shares=())
184task7 =
cotask.Task(imu_task_obj.run, name =
"imu_task", priority = 6, period = 20, profile=
True, trace=
False, shares = ())
185task8 =
cotask.Task(observer_obj.run, name =
"observer", priority = 4, period = 20, profile =
True, trace =
False, shares = ())
186task9 =
cotask.Task(pathing_obj.run, name=
"pathing", priority = 3, period = 30, profile =
True, trace =
False, shares = ())
187task10 =
cotask.Task(bump_obj.run, name =
"bump task", priority = 2, period = 50, profile =
True, trace =
False, shares=())
192cotask.task_list.append(task1)
193cotask.task_list.append(task2)
194cotask.task_list.append(task3)
195cotask.task_list.append(task4)
196cotask.task_list.append(task5)
197cotask.task_list.append(task6)
198cotask.task_list.append(task7)
199cotask.task_list.append(task8)
200cotask.task_list.append(task9)
201cotask.task_list.append(task10)
208 cotask.task_list.pri_sched()
210except KeyboardInterrupt:
212 print(
"\nProfiler results:")
213 print(cotask.task_list)
Initializes Bump sensors.
Collision detector for cooperative scheduler.
This file contains a class to create a control_task object which is compatible with the cotask schedu...
This file contains a class to create a PID Controller object.
Implements multitasking with scheduling and some performance logging.
Collects data from shares.
The IR_Sensor class is an object for each individual ir sensor on our line sensor.
Line_Sensor class which will calibrate the sensors, read data from the entire line,...
line_task class that can be initialized to be run with the cotask scheduler.
Left Motor Encoder Class.
Right Motor Encoder Class.
Observer task object compatible with the cotask scheduler.
Pathing plan task class for ROMI navigation.
A queue which is used to transfer data from one task to another.
An item which holds data to be shared between tasks.
Initializes User Interface.