Plot Something - ME 405 Term Project
|
Implements multitasking with scheduling and some performance logging. More...
Public Member Functions | |
def | __init__ (self, run_fun, name="NoName", priority=0, period=None, profile=False, trace=False) |
Initialize a task object so it may be run by the scheduler. More... | |
bool | schedule (self) |
This method is called by the scheduler; it attempts to run this task. More... | |
bool | ready (self) |
This method checks if the task is ready to run. More... | |
def | reset_profile (self) |
This method resets the variables used for execution time profiling. More... | |
def | get_trace (self) |
This method returns a string containing the task's transition trace. More... | |
def | go (self) |
Method to set a flag so that this task indicates that it's ready to run. More... | |
def | __repr__ (self) |
This method converts the task to a string for diagnostic use. More... | |
Public Attributes | |
name | |
The name of the task, hopefully a short and descriptive string. | |
priority | |
The task's priority, an integer with higher numbers meaning higher priority. | |
period | |
The period, in milliseconds, between runs of the task's run() method. More... | |
go_flag | |
Flag which is set true when the task is ready to be run by the scheduler. | |
Implements multitasking with scheduling and some performance logging.
This class implements behavior common to tasks in a cooperative multitasking system which runs in MicroPython. The ability to be scheduled on the basis of time or an external software trigger or interrupt is implemented, state transitions can be recorded, and run times can be profiled. The user's task code must be implemented in a generator which yields the state (and the CPU) after it has run for a short and bounded period of time.
Example:
def cotask.Task.__init__ | ( | self, | |
run_fun, | |||
name = "NoName" , |
|||
priority = 0 , |
|||
period = None , |
|||
profile = False , |
|||
trace = False |
|||
) |
Initialize a task object so it may be run by the scheduler.
This method initializes a task object, saving copies of constructor parameters and preparing an empty dictionary for states.
run_fun | The function which implements the task's code. It must be a generator which yields the current state. |
name | The name of the task, by default NoName . This should be overridden with a more descriptive name by the programmer. |
priority | The priority of the task, a positive integer with higher numbers meaning higher priority (default 0) |
period | The time in milliseconds between runs of the task if it's run by a timer or None if the task is not run by a timer. The time can be given in a float or int ; it will be converted to microseconds for internal use by the scheduler. |
profile | Set to True to enable run-time profiling |
trace | Set to True to generate a list of transitions between states. Note: This slows things down and allocates memory. |
def cotask.Task.__repr__ | ( | self | ) |
This method converts the task to a string for diagnostic use.
It shows information about the task, including execution time profiling results if profiling has been done.
def cotask.Task.get_trace | ( | self | ) |
This method returns a string containing the task's transition trace.
The trace is a set of tuples, each of which contains a time and the states from and to which the system transitioned.
def cotask.Task.go | ( | self | ) |
Method to set a flag so that this task indicates that it's ready to run.
This method may be called from an interrupt service routine or from another task which has data that this task needs to process soon.
bool cotask.Task.ready | ( | self | ) |
This method checks if the task is ready to run.
If the task runs on a timer, this method checks what time it is; if not, this method checks the flag which indicates that the task is ready to go. This method may be overridden in descendent classes to implement some other behavior.
def cotask.Task.reset_profile | ( | self | ) |
This method resets the variables used for execution time profiling.
This method is also used by init
() to create the variables.
bool cotask.Task.schedule | ( | self | ) |
This method is called by the scheduler; it attempts to run this task.
If the task is not yet ready to run, this method returns False
immediately; if this task is ready to run, it runs the task's generator up to the next yield()
and then returns True
.
True
if the task ran or False
if it did not cotask.Task.period |
The period, in milliseconds, between runs of the task's run()
method.
If the period is None
, the run()
method won't be run on a time basis but will instead be run by the scheduler as soon as feasible after code such as an interrupt handler calls the go()
method.