Пример #1
0
    def __init__(self, pin, timer, channel):
        ''' Initializes the infared receiver
        @param pin: pin is a pyb.Pin.board object
            for the interrupt pin that will detect interrupts
            from the IR reciever
        @param timer: timer is the timer the interrupt pin will use
        @param channel: channel is the channel the timer will use
        '''
        #----------------------------------------------------------------------#
        # Allocate memory so that exceptions raised in interrupt service
        # routines can generate useful diagnostic printouts
        # comment this line out after testing
        alloc_emergency_exception_buf(100)
        #----------------------------------------------------------------------#

        # assign the pin as an input pin
        intPin = pyb.Pin(pin, pyb.Pin.IN)

        # channel is the channel the timer will use, specified by the function
        # parameter. Has to be brought to the Class scope because it is used in
        # the irISR callback function
        self.channel = channel
        # Assign the timer a 16-bit period and a prescaler of 79 to collect
        # accurate timestamps. Prescaler of 79 to account for 80Mhz clock speed
        # to output counts as microseconds
        tim = pyb.Timer(timer, prescaler=79, period=0xFFFF)

        # set up the timer object to detect rising and fallingedges
        tim.channel(channel,
                    pyb.Timer.IC,
                    polarity=pyb.Timer.BOTH,
                    pin=intPin,
                    callback=self.irISR)

        # A queue to be used as a buffer for interrupt timestamp data. Buffer
        # size is greater than full pulse count to account for repeat codes
        # that disrupt a full pulse set.
        self.ir_data = task_share.Queue('I',
                                        200,
                                        thread_protect=False,
                                        overwrite=False,
                                        name="ir_data")
        # Data is a class scoped list that is filled with timestamps
        # from the ir_data queue
        self.data = []

        self.address = task_share.Share('I',
                                        thread_protect=False,
                                        name="address")
        self.command = task_share.Share('I',
                                        thread_protect=False,
                                        name="address")
        self.command.put(0)
        self.address.put(0)
        self.task = cotask.Task(self.readInfaredSensorTask,
                                name='Infared Reading Task',
                                priority=5,
                                profile=True,
                                trace=False)
Пример #2
0
def main():

    # Create the tasks. If trace is enabled for any task, memory will be
    # allocated for state transition tracing, and the application will run out
    # of memory after a while and quit. Therefore, use tracing only for
    # debugging and set trace to False when it's not needed
    motor_task = cotask.Task(task_motor,
                             name='motor_task',
                             priority=1,
                             period=1,
                             profile=True,
                             trace=False)

    #   front_sensor_task = cotask.Task (task_front_sensor, name = 'front_sensor_task', priority = 2,
    #                           period = 25, profile = True, trace = False)

    #back_sensor_task = cotask.Task (task_back_sensor, name = 'back_sensor_task', priority = 3,
    #                        period = 25, profile = True, trace = False)

    #right_sensor_task = cotask.Task (task_right_sensor, name = 'right_sensor_task', priority = 4,
    #                        period = 25, profile = True, trace = False)

    #left_sensor_task = cotask.Task (task_left_sensor, name = 'left_sensor_task', priority = 5,
    #                        period = 25, profile = True, trace = False)

    #bluetooth_task = cotask.Task (task_bluetooth, name = 'bluetooth_task', priority = 6,
    #                        period = 25, profile = True, trace = False)

    cotask.task_list.append(motor_task)
    #  cotask.task_list.append (front_sensor_task)
    #cotask.task_list.append (back_sensor_task)
    #cotask.task_list.append (right_sensor_task)
    #cotask.task_list.append (left_sensor_task)
    #cotask.task_list.append (bluetooth_task)

    # A task which prints characters from a queue has automatically been
    # created in print_task.py; it is accessed by print_task.put_bytes()

    # Run the memory garbage collector to ensure memory is as defragmented as
    # possible before the real-time scheduler is started
    gc.collect()

    # Run the scheduler with the chosen scheduling algorithm. Quit if any
    # character is sent through the serial por
    vcp = pyb.USB_VCP()
    while not vcp.any():
        cotask.task_list.pri_sched()

    # Empty the comm port buffer of the character(s) just pressed
    vcp.read()

    # Print a table of task data and a table of shared information data
    print('\n' + str(cotask.task_list) + '\n')
    print(task_share.show_all())
    # print (control_task.get_trace ())
    print('\r\n')
    '''  aye = pyb.I2C(1, pyb.I2C.MASTER)
Пример #3
0
        client.loop_stop()
        yield ()


if __name__ == "__main__":
    print("Skylux Project Main()")
    global motorHandler

    motorHandler = motor_handler()
    mqttClient = skylux_mqtt.initMQTT()

    ##implement way to listen to MQTT

    mqttTask = cotask.Task(mqttControl,
                           name='MQTT_Listener',
                           priority=2,
                           period=1000,
                           profile=True,
                           trace=False)
    fauxmoTask = cotask.Task(fauxmoControl,
                             name="Fauxmo",
                             priority=1,
                             period=100,
                             profile=True,
                             trace=False)

    cotask.task_list.append(mqttTask)
    cotask.task_list.append(fauxmoTask)

    while True:
        cotask.task_list.pri_sched()
Пример #4
0
if __name__ == "__main__":

    print ('\033[2JTesting scheduler in cotask.py\n')

    # Create a share and some queues to test diagnostic printouts
    share0 = task_share.Share ('i', thread_protect = False, name = "Share_0")
    q0 = task_share.Queue ('B', 6, thread_protect = False, overwrite = False,
                           name = "Queue_0")
    q1 = task_share.Queue ('B', 8, thread_protect = False, overwrite = False,
                           name = "Queue_1")

    # Create the tasks. If trace is enabled for any task, memory will be
    # allocated for state transition tracing, and the application will run out
    # of memory after a while and quit. Therefore, use tracing only for 
    # debugging and set trace to False when it's not needed
    motor_task = cotask.Task (task_motor, name = 'motor_task', priority = 1,
                            period = 25, profile = True, trace = False)
    
    front_sensor_task = cotask.Task (task_front_sensor, name = 'front_sensor_task', priority = 2,
                            period = 25, profile = True, trace = False)
    
    back_sensor_task = cotask.Task (task_back_sensor, name = 'back_sensor_task', priority = 3,
                            period = 25, profile = True, trace = False)
    
    right_sensor_task = cotask.Task (task_right_sensor, name = 'right_sensor_task', priority = 4,
                            period = 25, profile = True, trace = False)
    
    left_sensor_task = cotask.Task (task_left_sensor, name = 'left_sensor_task', priority = 5,
                            period = 25, profile = True, trace = False)
    
    cotask.task_list.append (motor_task)
    cotask.task_list.append (front_sensor_task)
Пример #5
0
    ## Hold pitch encoder values
    q8 = task_share.Share('f', thread_protect=False, name="Queue_8")

    ## Hold roll encoder values
    q9 = task_share.Share('f', thread_protect=False, name="Queue_9")

    # Create the tasks. If trace is enabled for any task, memory will be
    # allocated for state transition tracing, and the application will run out
    # of memory after a while and quit. Therefore, use tracing only for
    # debugging and set trace to False when it's not needed

    ## Motor task should be run at least every 22ms for "real time" results
    task1 = cotask.Task(task1_pitch_motor,
                        name='Task_1',
                        priority=2,
                        period=22,
                        profile=True,
                        trace=False)
    ## Motor task should be run at least every 22ms for "real time" results
    task2 = cotask.Task(task2_roll_motor,
                        name='Task_2',
                        priority=2,
                        period=22,
                        profile=True,
                        trace=False)
    ## The IMU read task should as often as the motors to keep consistency between movement
    #  and current angles
    task3 = cotask.Task(task3_imu_read,
                        name='Task_3',
                        priority=3,
                        period=22,
Пример #6
0
                                        thread_protect=False,
                                        overwrite=False,
                                        name="Calibration_Queue")

    # Create the tasks. If trace is enabled for any task, memory will be
    # allocated for state transition tracing, and the application will run out
    # of memory after a while and quit. Therefore, use tracing only for
    # debugging and set trace to False when it's not needed

    #task1 = cotask.Task (task1_fun, name = 'Task_1', priority = 1,
    #period = 1000, profile = True, trace = False)
    #task2 = cotask.Task (task2_fun, name = 'Task_2', priority = 2,
    #period = 100, profile = True, trace = False)
    span_motor_task = cotask.Task(task_span_motor_fun,
                                  name='Span_Motor_Task',
                                  priority=6,
                                  period=10,
                                  profile=True,
                                  trace=False)
    tilt_motor_task = cotask.Task(task_tilt_motor_fun,
                                  name='Tilt_Motor_Task',
                                  priority=6,
                                  period=10,
                                  profile=True,
                                  trace=False)
    interface_task = cotask.Task(task_interface_fun,
                                 name='Interface_Task',
                                 priority=1,
                                 period=100,
                                 profile=True,
                                 trace=False)
    dart_motor_task = cotask.Task(task_dart_motor_fun,
Пример #7
0
    """

    while True:
        # If there's a character in the queue, print it
        if print_queue.any():
            # print (chr (print_queue.get ()), end = '')
            print(print_queue.get(), end='')

        # If there's another character, tell this task to run again ASAP
        if print_queue.any():
            print_task.go()

        yield (0)


## This queue holds characters to be printed when the print task gets around
#  to it.
global print_queue
print_queue = task_share.Queue('B',
                               BUF_SIZE,
                               name="Print_Queue",
                               thread_protect=THREAD_PROTECT,
                               overwrite=False)

## This is the task which schedules printing.
global print_task
print_task = cotask.Task(run, name='Printing', priority=0, profile=PROFILE)

# This line tells the task scheduler to add this task to the system task list
cotask.task_list.append(print_task)
Пример #8
0
                             thread_protect=False,
                             name='Position Control 1')
setpoint1 = task_share.Share('I', thread_protect=False, name='Setpoint 1')
step_rsp1 = task_share.Share('H', thread_protect=False, name='Step Response 1')
get_data1 = task_share.Share('H', thread_protect=False, name='Get Data 1')
pos_ctrl2 = task_share.Share('H',
                             thread_protect=False,
                             name='Position Control 2')
setpoint2 = task_share.Share('I', thread_protect=False, name='Setpoint 2')
step_rsp2 = task_share.Share('H', thread_protect=False, name='Step Response 2')
get_data2 = task_share.Share('H', thread_protect=False, name='Get Data 2')

# Create tasks
motor1_task = cotask.Task(motor1_fun,
                          name='Motor 1',
                          priority=2,
                          period=10,
                          profile=True,
                          trace=False)
cotask.task_list.append(motor1_task)
motor2_task = cotask.Task(motor2_fun,
                          name='Motor 2',
                          priority=2,
                          period=10,
                          profile=True,
                          trace=False)
cotask.task_list.append(motor2_task)
# user_input = cotask.Task(user_input, name='Motor 1', priority=1,
# 						  period=750, profile=True, trace=False)
# cotask.task_list.append(user_input)
manual_control = cotask.Task(manual_control,
                             name='Manual Control',
Пример #9
0
    ####################################################################

    pwm1 = motor_task_func.Motor_Task(20, 1, 5, 3, pyb.Pin.board.PA2, 2)
    pwm2 = motor_task_func.Motor_Task(20, 1, 5, 4, pyb.Pin.board.PA3, 2)
    pwm3 = motor_task_func.Motor_Task(1, 20, 8, 2, pyb.Pin.board.PC8, 2)
    pwm4 = motor_task_func.Motor_Task(1, 20, 8, 1, pyb.Pin.board.PC6, 2)
    # pwm2 = motor_task_func.Motor_Task(500, 5, 1, 3, pyb.Pin.board.PB15, 1)

    ####################################################################
    ############################## TASKS ###############################
    ####################################################################

    #Turret Hub Timing => Timing: 100 ms, Priority 1 (Lowest)
    task0 = cotask.Task(pwm1.mot_fun,
                        name='Task_0',
                        priority=1,
                        period=100,
                        profile=True,
                        trace=False)
    task1 = cotask.Task(pwm2.mot_fun,
                        name='Task_1',
                        priority=1,
                        period=100,
                        profile=True,
                        trace=False)
    task2 = cotask.Task(pwm3.mot_fun,
                        name='Task_2',
                        priority=1,
                        period=100,
                        profile=True,
                        trace=False)
    task3 = cotask.Task(pwm4.mot_fun,
Пример #10
0
    # Create the tasks. If trace is enabled for any task, memory will be
    # allocated for state transition tracing, and the application will run out
    # of memory after a while and quit. Therefore, use tracing only for
    # debugging and set trace to False when it's not needed

    #    #Turret Hub Timing => Timing: 100 ms, Priority 1 (Lowest)
    #    task0 = cotask.Task (turret_hub.turret_hub_fun, name = 'Task_0', priority = 1,
    #                         period = 100, profile = True, trace = False)
    #Pan Encoder => Timing 2 ms, Priority 5(Highest)
    #    task1 = cotask.Task (pan_encoder.enc_fun, name = 'Task_1', priority = 5,
    #                         period = 2, profile = True, trace = False)
    #Tilt IMU => Timing 5 ms (minimum 10 ms, applied 2x SF), Priority 5(Highest)
    task2 = cotask.Task(tilt_IMU.IMU_fun,
                        name='Task_2',
                        priority=5,
                        period=5,
                        profile=True,
                        trace=False)
    #    #Pan Motor => Timing 20 ms, Priority 3 (Medium)
    #    task3 = cotask.Task (pan_motor.mot_fun, name = 'Task_3', priority = 3,
    #                         period = 20, profile = True, trace = False)
    #Tilt Motor => Timing 20 ms, Priority 3 (Medium)
    task4 = cotask.Task(tilt_motor.mot_fun,
                        name='Task_4',
                        priority=3,
                        period=20,
                        profile=True,
                        trace=False)
    #    #Nerf Gun => Timing 200 ms, Priority 1 (Lowest)
    #    task5 = cotask.Task (nerf_gun.gun_fun, name = 'Task_5', priority = 1,
    #                         period = 200, profile = True, trace = False)
Пример #11
0
IRShare = task_share.Share('i')
shareIMU = task_share.Share('f')
shareLine = task_share.Share('i')
encoderR = EncoderDriver('PB6', 'PB7', 4, direction='clockwise')
encoderL = EncoderDriver('PC6', 'PC7', 8, direction='counterclockwise')
controllerR = ClosedLoopDriver(0, 0, .2, 100)
motorR = MotorDriver()
controllerL = ClosedLoopDriver(0, 0, .2, 20)
motorL = MotorDriver('PC1', 'PA0', 'PA1', 5, 100)

if __name__ == "__main__":

    print('\033[2JTesting scheduler in cotask.py\n')
    task1 = cotask.Task(MotorControlTask,
                        name='Task1 MC',
                        priority=6,
                        period=50,
                        profile=True,
                        trace=False)
    task2 = cotask.Task(LineSensorTask,
                        name='Task2 LS',
                        priority=5,
                        period=100,
                        profile=True,
                        trace=False)
    task3 = cotask.Task(IMU_Task,
                        name='Task3 IMU',
                        priority=1,
                        period=50,
                        profile=True,
                        trace=False)
    task4 = cotask.Task(TOF_Task,
Пример #12
0
 enc_1_position = task_share.Share('i',
                                   thread_protect=False,
                                   name="Share_0_enc_1_position")
 enc_2_position = task_share.Share('i',
                                   thread_protect=False,
                                   name="Share_0_enc_2_position")
 Run = task_share.Share('i',
                        thread_protect=False,
                        name="Run_Intertask_Comm_Variable")
 # Create the tasks. If trace is enabled for any task, memory will be
 # allocated for state transition tracing, and the application will run out
 # of memory after a while and quit. Therefore, use tracing only for
 # debugging and set trace to False when it's not needed
 task1 = cotask.Task(Encoder1_fun,
                     name='Task_1',
                     priority=5,
                     period=2,
                     profile=True,
                     trace=False)
 task2 = cotask.Task(MotorCtrl1_fun,
                     name='Task_2',
                     priority=3,
                     period=20,
                     profile=True,
                     trace=False)
 task3 = cotask.Task(Encoder2_fun,
                     name='Task_3',
                     priority=5,
                     period=2,
                     profile=True,
                     trace=False)
 task4 = cotask.Task(MotorCtrl2_fun,
Пример #13
0
        yield (0)


if __name__ == "__main__":
    print('\033[2JTesting scheduler in cotask.py\n')

    share0 = task_share.Share('i', thread_protect=True, name="Share_0")
    qt1 = task_share.Queue('f', 500, thread_protect=True, overwrite=False)
    qp1 = task_share.Queue('f', 500, thread_protect=True, overwrite=False)
    qt2 = task_share.Queue('f', 500, thread_protect=True, overwrite=False)
    qp2 = task_share.Queue('f', 500, thread_protect=True, overwrite=False)
    #used to test different periods and plot the results
    #per = eval(input())
    task1 = cotask.Task(motor1_fun,
                        name='Motor_1',
                        priority=1,
                        period=25,
                        profile=True,
                        trace=False)
    task2 = cotask.Task(motor2_fun,
                        name='Motor_2',
                        priority=2,
                        period=25,
                        profile=True,
                        trace=False)
    cotask.task_list.append(task1)
    cotask.task_list.append(task2)

    gc.collect()
    time = []
    pos = []
Пример #14
0
    # Create the tasks. If trace is enabled for any task, memory will be
    # allocated for state transition tracing, and the application will run out
    # of memory after a while and quit. Therefore, use tracing only for
    # debugging and set trace to False when it's not needed

    #    #Turret Hub Timing => Timing: 100 ms, Priority 1 (Lowest)
    #    task0 = cotask.Task (turret_hub.turret_hub_fun, name = 'Task_0', priority = 1,
    #                         period = 100, profile = True, trace = False)
    #    #Pan Encoder => Timing 2 ms, Priority 5(Highest)
    #    task1 = cotask.Task (pan_encoder.enc_fun, name = 'Task_1', priority = 5,
    #                         period = 2, profile = True, trace = False)
    #Tilt IMU => Timing 5 ms (minimum 10 ms, applied 2x SF), Priority 5(Highest)
    task2 = cotask.Task(tilt_IMU.IMU_fun,
                        name='Task_2',
                        priority=5,
                        period=5,
                        profile=True,
                        trace=False)
    #    #Pan Motor => Timing 20 ms, Priority 3 (Medium)
    #    task3 = cotask.Task (pan_motor.mot_fun, name = 'Task_3', priority = 3,
    #                         period = 20, profile = True, trace = False)
    #    #Tilt Motor => Timing 20 ms, Priority 3 (Medium)
    #    task4 = cotask.Task (tilt_motor.mot_fun, name = 'Task_4', priority = 3,
    #                         period = 20, profile = True, trace = False)
    #    #Nerf Gun => Timing 200 ms, Priority 1 (Lowest)
    #    task5 = cotask.Task (nerf_gun.gun_fun, name = 'Task_5', priority = 1,
    #                         period = 200, profile = True, trace = False)

    #cotask.task_list.append (task0)
    #cotask.task_list.append (task1)
    cotask.task_list.append(task2)
Пример #15
0
                          thread_protect=False,
                          overwrite=False,
                          name="Queue_0")
    q1 = task_share.Queue('B',
                          8,
                          thread_protect=False,
                          overwrite=False,
                          name="Queue_1")

    # Create the tasks. If trace is enabled for any task, memory will be
    # allocated for state transition tracing, and the application will run out
    # of memory after a while and quit. Therefore, use tracing only for
    # debugging and set trace to False when it's not needed
    motor1_task = cotask.Task(task_motor1,
                              name='motor1_task',
                              priority=1,
                              period=25,
                              profile=True,
                              trace=False)
    motor2_task = cotask.Task(task_motor2,
                              name='motor2_task',
                              priority=2,
                              period=25,
                              profile=True,
                              trace=False)
    cotask.task_list.append(motor1_task)
    cotask.task_list.append(motor2_task)

    # A task which prints characters from a queue has automatically been
    # created in print_task.py; it is accessed by print_task.put_bytes()

    # Run the memory garbage collector to ensure memory is as defragmented as
Пример #16
0
    time_elapsed.put(0)    
    
    #setup perception shares
    Line_L = task_share.Share ('i', thread_protect = False, name = "L")
    Line_L.put(1)
    Line_C = task_share.Share ('i', thread_protect = False, name = "C")
    Line_C.put(1)
    Line_R = task_share.Share ('i', thread_protect = False, name = "R")
    Line_R.put(1)
    
    #setup task share and tasks
    
    q0 = task_share.Queue ('B', 6, thread_protect = False, overwrite = False,
                           name = "Queue_0")
    
    task1 = cotask.Task (motor_task_1, name = 'right_motor', priority = 1, 
                         period = 20, profile = True, trace = False)
    
    task2 = cotask.Task (motion_control, name = 'motion', priority = 2,
                        period = 21, profile = True, trace = False)
    
    task3 = cotask.Task (ir_sensor_task, name = 'ir_sensor', priority = 2,
                        period = 25, profile = True, trace = False)
    
    task4 = cotask.Task (perception, name = 'perception', priority = 1,
                        period = 20, profile = True, trace = False)

    cotask.task_list.append (task1)
    cotask.task_list.append (task2)
    cotask.task_list.append (task3)
    cotask.task_list.append (task4)
Пример #17
0
    heading_OK = task_share.Share('f', thread_protect=True, name="heading_OK")
    pitch_OK = task_share.Share('f', thread_protect=True, name="pitch_OK")
    trigger_ready_share = task_share.Share('f',
                                           thread_protect=True,
                                           name="trigger_ready_share")
    set_coord_share = task_share.Share('f',
                                       thread_protect=True,
                                       name="set_coord")
    calibrated_share = task_share.Share('f',
                                        thread_protect=True,
                                        name="calibrated")

    # Assigns a each of the above functions to the a task variable
    task1 = cotask.Task(heading_motor_fun,
                        name='Heading Motor',
                        priority=1,
                        period=10,
                        profile=True,
                        trace=False)
    task2 = cotask.Task(pitch_motor_fun,
                        name='Pitch_Motor',
                        priority=2,
                        period=10,
                        profile=True,
                        trace=False)
    task3 = cotask.Task(IMU_fun,
                        name='IMU',
                        priority=1,
                        period=10,
                        profile=True,
                        trace=False)
    task4 = cotask.Task(servo_fun,
Пример #18
0
                                           pyb.Pin.board.PC1,
                                           timer, channel)
    p_motor = motor_task_func.Motor_Task(p_params, p_enable,
                                           pyb.Pin.board.PB2,
                                           pyb.Pin.board.PB13,
                                           pyb.Pin.board.PA5,
                                           pyb.Pin.board.PH1,
                                           pyb.Pin.board.PC0,
                                           timer, channel)

    ####################################################################
    ############################## TASKS ###############################
    ####################################################################

    # Hub Task
    task1 = cotask.Task (hub.hub_fun, name = 'Task_1', priority = 1,
                         period = 100, profile = True, trace = False)

    # Feedback Tasks
    task2 = cotask.Task (x_feedback.fb_fun, name = 'Task_2', priority = 5,
                     period = 5, profile = True, trace = False)
    task3 = cotask.Task (z_feedback.fb_fun, name = 'Task_3', priority = 5,
                         period = 5, profile = True, trace = False)
    task4 = cotask.Task (y_feedback.fb_fun, name = 'Task_4', priority = 5,
                         period = 5, profile = True, trace = False)
    task5 = cotask.Task (p_feedback.fb_fun, name = 'Task_5', priority = 5,
                         period = 5, profile = True, trace = False)

    # Motor Tasks
    task6 = cotask.Task (x_motor.mot_fun, name = 'Task_6', priority = 3,
                         period = 20, profile = True, trace = False)
    task7 = cotask.Task (z_motor.mot_fun, name = 'Task_7', priority = 3,
Пример #19
0
        if state == OFF1:
            if IR.getCommand() == C.START:
                state = ANALYZE_US
            yield (state)


if __name__ == "__main__":

    try:
        print('\033[2JTesting scheduler in cotask.py\n')

        # intitialize motor task 1 using Task()
        t1 = cotask.Task(driveTask,
                         name='Drive Task',
                         priority=1,
                         period=10,
                         profile=True,
                         trace=False)

        t2 = cotask.Task(lineFollowerTask,
                         name='Line Follower Task',
                         priority=1,
                         period=50,
                         profile=True,
                         trace=False)
        t3 = cotask.Task(ultraSonicDistanceTask,
                         name='UltraSonic Distance Task',
                         priority=2,
                         period=50,
                         profile=True,
                         trace=False)
Пример #20
0
    # Create a share and some queues to test diagnostic printouts
    sm1 = task_share.Share('f', thread_protect=False, name="Share_1")
    sm2 = task_share.Share('f', thread_protect=False, name="Share_2")
    sm3 = task_share.Share('f', thread_protect=False, name="Share_3")
    #    md1 = task_share.Share ('B', thread_protect = False, name = "mdone1")
    #    md2 = task_share.Share ('B', thread_protect = False, name = "mdone2")
    #    md_3 = task_share.Share ('B', thread_protect = False, name = "mdone3")
    #    nv = task_share.Share ('B', thread_protect = False, name = "new value")
    # Create the tasks. If trace is enabled for any task, memory will be
    # allocated for state transition tracing, and the application will run out
    # of memory after a while and quit. Therefore, use tracing only for
    # debugging and set trace to False when it's not needed
    task1 = cotask.Task(Control1,
                        name='Control1',
                        priority=4,
                        period=10,
                        profile=True,
                        trace=False)
    task2 = cotask.Task(Control2,
                        name='Control2',
                        priority=4,
                        period=10,
                        profile=True,
                        trace=False)
    task3 = cotask.Task(Control3,
                        name='Control3',
                        priority=5,
                        period=10,
                        profile=True,
                        trace=False)
    task4 = cotask.Task(Overlord,
Пример #21
0
    file_search = True
    while file_search == True:
        file_name = io_funcs.get_input(str, 'File name? [file.txt] ')
        try:
            file = open(file_name, 'r')
            file_search = False
        except:
            print('Not a valid file name or type. Please try again')

    # Initializing motors and encoders with a task
    motor_1_task = motor_task.Motor_control_task(0)
    mname1 = 'Motor_' + str(motor_1_task.motor_number)
    cotask.task_list.append(
        cotask.Task(motor_1_task.run_motor,
                    name=mname1,
                    priority=3,
                    period=8,
                    profile=True))

    motor_2_task = motor_task.Motor_control_task(1)
    mname2 = 'Motor_' + str(motor_2_task.motor_number)
    cotask.task_list.append(
        cotask.Task(motor_2_task.run_motor,
                    name=mname2,
                    priority=3,
                    period=8,
                    profile=True))

    # Zero calibration
    print('Bring the motors to calibration point, aka x = 0 and y = L1 + L2')
    cal = True
Пример #22
0
                          thread_protect=False,
                          overwrite=False,
                          name="Queue_0")
    q1 = task_share.Queue('B',
                          8,
                          thread_protect=False,
                          overwrite=False,
                          name="Queue_1")

    # Create the tasks. If trace is enabled for any task, memory will be
    # allocated for state transition tracing, and the application will run out
    # of memory after a while and quit. Therefore, use tracing only for
    # debugging and set trace to False when it's not needed
    task1 = cotask.Task(task1_fun,
                        name='Task_1',
                        priority=1,
                        period=1000,
                        profile=True,
                        trace=False)
    task2 = cotask.Task(task2_fun,
                        name='Task_2',
                        priority=2,
                        period=100,
                        profile=True,
                        trace=False)
    cotask.task_list.append(task1)
    cotask.task_list.append(task2)

    # A task which prints characters from a queue has automatically been
    # created in print_task.py; it is accessed by print_task.put_bytes()

    # Create a bunch of silly time-wasting busy tasks to test how well the
Пример #23
0
        if x == True:
            print_task.put (data)
        x = not x

        # yield to another task and resume at this line
        yield (0)

# # ============================================================================= # #

if __name__ == "__main__":

    try:
        print ('\033[2JTesting scheduler in cotask.py\n')

        ## intitialize motor task 1 using Task()
        m1 = cotask.Task (motor_1, name = 'Motor 1', priority = 1, period = 40, profile = True, trace = False)
        ## intitialize motor task 2 using Task()
        m2 = cotask.Task (motor_2, name = 'Motor 2', priority = 1, period = 40, profile = True, trace = False)

        # add each task to the task list                     
        cotask.task_list.append (m1)
        cotask.task_list.append (m2)

        # execute the task list using the priority attribute of each task
        while True:
            cotask.task_list.pri_sched ()

        # Run the memory garbage collector to ensure memory is as defragmented as possible before the real-time scheduler is started
        gc.collect ()

    # If a keyboard interrupt is thrown, set the motor duty cycles to 0
Пример #24
0
    #                                                      pan_completion, tilt_completion)

    #    nerf_gun = nerf_task_func.Nerf_Task(WINDUP_GUN, FEED_BULLETS, pyb.Pin.board.PC6, pyb.Pin.board.PC7)

    # Create the tasks. If trace is enabled for any task, memory will be
    # allocated for state transition tracing, and the application will run out
    # of memory after a while and quit. Therefore, use tracing only for
    # debugging and set trace to False when it's not needed

    #    #Turret Hub Timing => Timing: 100 ms, Priority 1 (Lowest)
    #    task0 = cotask.Task (turret_hub.turret_hub_fun, name = 'Task_0', priority = 1,
    #                         period = 100, profile = True, trace = False)
    #Pan Encoder => Timing 2 ms, Priority 5(Highest)
    task1 = cotask.Task(pan_encoder.enc_fun,
                        name='Task_1',
                        priority=5,
                        period=2,
                        profile=True,
                        trace=False)
    #Tilt IMU => Timing 5 ms (minimum 10 ms, applied 2x SF), Priority 5(Highest)
    #    task2 = cotask.Task (tilt_IMU.IMU_fun, name = 'Task_2', priority = 5,
    #                         period = 5, profile = True, trace = False)
    #Pan Motor => Timing 20 ms, Priority 3 (Medium)
    task3 = cotask.Task(pan_motor.mot_fun,
                        name='Task_3',
                        priority=3,
                        period=20,
                        profile=True,
                        trace=False)
    #Tilt Motor => Timing 20 ms, Priority 3 (Medium)
    #    task4 = cotask.Task (tilt_motor.mot_fun, name = 'Task_4', priority = 3,
    #                         period = 20, profile = True, trace = False)
Пример #25
0
import drive
import motor_driver
import strategy

from micropython import alloc_emergency_exception_buf

alloc_emergency_exception_buf(100)

if __name__ == '__main__':
    ir.init()

    strategy.Strategy = strategy.BasicStrategy()

    drive_task = cotask.Task(drive.handler,
                             name='Drive Task',
                             priority=1,
                             period=20,
                             profile=True,
                             trace=False)
    strategy_task = cotask.Task(strategy.handler,
                                name='Strategy Task',
                                priority=1,
                                period=10,
                                profile=True,
                                trace=False)
    ir_task = cotask.Task(ir.handler,
                          name='IR Task',
                          priority=2,
                          period=50,
                          profile=True,
                          trace=False)
Пример #26
0
                          thread_protect=False,
                          overwrite=False,
                          name="Queue_0")
    q1 = task_share.Queue('B',
                          8,
                          thread_protect=False,
                          overwrite=False,
                          name="Queue_1")

    # Create the tasks. If trace is enabled for any task, memory will be
    # allocated for state transition tracing, and the application will run out
    # of memory after a while and quit. Therefore, use tracing only for
    # debugging and set trace to False when it's not needed
    task1 = cotask.Task(task1_fun,
                        name='Task_1',
                        priority=1,
                        period=100,
                        profile=True,
                        trace=False)
    task2 = cotask.Task(task2_fun,
                        name='Task_2',
                        priority=2,
                        period=100,
                        profile=True,
                        trace=False)
    task3 = cotask.Task(task3_closed_loop,
                        name='Task_3',
                        priority=3,
                        period=10,
                        profile=True,
                        trace=False)
    cotask.task_list.append(task1)
Пример #27
0
                                            pyb.Pin.board.PA0, 
                                            pyb.Pin.board.PA1, 2.2, 0.145, 200)
    
    turret_hub = turret_hub_task_func.Turret_Hub_Task(pan_position, tilt_angle, pan_coords,
                                                      tilt_coords, FEED_BULLETS, WINDUP_GUN)

    nerf_gun = nerf_task_func.Nerf_Task(WINDUP_GUN, FEED_BULLETS, pyb.Pin.board.PC7, pyb.Pin.board.PC6)


    # Create the tasks. If trace is enabled for any task, memory will be
    # allocated for state transition tracing, and the application will run out
    # of memory after a while and quit. Therefore, use tracing only for 
    # debugging and set trace to False when it's not needed
    
    #Turret Hub Timing => Timing: 100 ms, Priority 1 (Lowest)
    task0 = cotask.Task (turret_hub.turret_hub_fun, name = 'Task_0', priority = 1, 
                         period = 100, profile = True, trace = False)
    #Pan Encoder => Timing 2 ms, Priority 5(Highest)
    task1 = cotask.Task (pan_encoder.enc_fun, name = 'Task_1', priority = 5, 
                         period = 2, profile = True, trace = False)
    #Tilt IMU => Timing 5 ms (minimum 10 ms, applied 2x SF), Priority 5(Highest)
    task2 = cotask.Task (tilt_IMU.IMU_fun, name = 'Task_2', priority = 5, 
                         period = 5, profile = True, trace = False)
    #Pan Motor => Timing 20 ms, Priority 3 (Medium)
    task3 = cotask.Task (pan_motor.mot_fun, name = 'Task_3', priority = 3, 
                         period = 20, profile = True, trace = False)
    #Tilt Motor => Timing 20 ms, Priority 3 (Medium)
    task4 = cotask.Task (tilt_motor.mot_fun, name = 'Task_4', priority = 3, 
                         period = 20, profile = True, trace = False)
    #Nerf Gun => Timing 200 ms, Priority 1 (Lowest)
    task5 = cotask.Task (nerf_gun.gun_fun, name = 'Task_5', priority = 1, 
                         period = 200, profile = True, trace = False)
Пример #28
0
                                      name="Share_0_enc_1_position")
    enc_2_position = task_share.Share('i',
                                      thread_protect=False,
                                      name="Share_0_enc_2_position")

    Run = task_share.Share('i',
                           thread_protect=False,
                           name="Run_Intertask_Comm_Variable")

    # Create the tasks. If trace is enabled for any task, memory will be
    # allocated for state transition tracing, and the application will run out
    # of memory after a while and quit. Therefore, use tracing only for
    # debugging and set trace to False when it's not needed
    task1 = cotask.Task(Encoder1_fun,
                        name='Task_1',
                        priority=5,
                        period=1,
                        profile=True,
                        trace=False)
    task2 = cotask.Task(MotorCtrl1_fun,
                        name='Task_2',
                        priority=3,
                        period=10,
                        profile=True,
                        trace=False)
    #    task3 = cotask.Task (Encoder2_fun, name = 'Task_3', priority = 5,
    #                         period = 1, profile = True, trace = False)
    #    task4 = cotask.Task (MotorCtrl2_fun, name = 'Task_4', priority = 3,
    #                         period = 10, profile = True, trace = False)
    task5 = cotask.Task(UI_fun,
                        name='Task_5',
                        priority=3,
Пример #29
0
    #                                                      pan_completion, tilt_completion)

    #    nerf_gun = nerf_task_func.Nerf_Task(WINDUP_GUN, FEED_BULLETS, pyb.Pin.board.PC6, pyb.Pin.board.PC7)

    # Create the tasks. If trace is enabled for any task, memory will be
    # allocated for state transition tracing, and the application will run out
    # of memory after a while and quit. Therefore, use tracing only for
    # debugging and set trace to False when it's not needed

    #    #Turret Hub Timing => Timing: 100 ms, Priority 1 (Lowest)
    #    task0 = cotask.Task (turret_hub.turret_hub_fun, name = 'Task_0', priority = 1,
    #                         period = 100, profile = True, trace = False)
    #Pan Encoder => Timing 2 ms, Priority 5(Highest)
    task1 = cotask.Task(pan_encoder.enc_fun,
                        name='Task_1',
                        priority=5,
                        period=2,
                        profile=True,
                        trace=False)
    #Tilt IMU => Timing 5 ms (minimum 10 ms, applied 2x SF), Priority 5(Highest)
    #    task2 = cotask.Task (tilt_IMU.IMU_fun, name = 'Task_2', priority = 5,
    #                         period = 5, profile = True, trace = False)
    #    #Pan Motor => Timing 20 ms, Priority 3 (Medium)
    #    task3 = cotask.Task (pan_motor.mot_fun, name = 'Task_3', priority = 3,
    #                         period = 20, profile = True, trace = False)
    #    #Tilt Motor => Timing 20 ms, Priority 3 (Medium)
    #    task4 = cotask.Task (tilt_motor.mot_fun, name = 'Task_4', priority = 3,
    #                         period = 20, profile = True, trace = False)
    #    #Nerf Gun => Timing 200 ms, Priority 1 (Lowest)
    #    task5 = cotask.Task (nerf_gun.gun_fun, name = 'Task_5', priority = 1,
    #                         period = 200, profile = True, trace = False)
Пример #30
0
    #                     pyb.Pin.board.PC3, 8, 1, 5, 1, 'Z ')
    # y_motor = motor_task_func.Motor_Task(y_params, y_steps, y_enable, y_status, y_limit,
    #                 pyb.Pin.board.PC7, pyb.Pin.board.PC5, pyb.Pin.board.PD2,
    #                     pyb.Pin.board.PC1, 8, 2, 5, 2, 'Y ')
    # p_motor = motor_task_func.Motor_Task(p_params, p_steps, p_enable, p_status, p_limit,
    #                 pyb.Pin.board.PC9, pyb.Pin.board.PA5, pyb.Pin.board.PB9,
    #                     pyb.Pin.board.PC0, 8, 4, 5, 4, 'P ')

    ####################################################################
    ############################## TASKS ###############################
    ####################################################################

    # Hub Task
    task1 = cotask.Task(hub.hub_fun,
                        name='Task_1',
                        priority=1,
                        period=100,
                        profile=True,
                        trace=False)

    # Feedback Tasks
    task2 = cotask.Task(x_feedback.fb_fun,
                        name='Task_2',
                        priority=5,
                        period=20,
                        profile=True,
                        trace=False)
    # task3 = cotask.Task (z_feedback.fb_fun, name = 'Task_3', priority = 5,
    #                         period = 20, profile = True, trace = False)
    # task4 = cotask.Task (y_feedback.fb_fun, name = 'Task_4', priority = 5,
    #                         period = 20, profile = True, trace = False)
    # task5 = cotask.Task (p_feedback.fb_fun, name = 'Task_5', priority = 5,