Blog 3 Qimeng Liu

 In this bolg, I and my partner Yoma finished a little RTOS project with state machine. I will introduce our project and compare with the Jason's version.

Jason's version

In this project, there are 5 different task:
    input1_rtos_task: 
This task monitors the digital input switch on PIN_4. When the switch is pressed, it sends the message INPUT_1_ON to the state_machine_rtos_task. It is used to detect user button input and trigger state changes.

    input2_rtos_task:
This task reads the analogue input using the ADC on channel AN0. When the ADC value is greater than 100, it sends the message INPUT_2_ADC_GREATER_THAN_100 to the state_machine_rtos_task. It is used to monitor the analogue sensor/input level.

    output1_rtos_task:
This task receives messages from the state machine and processes output actions for output channel 1. In the current program, it reads the received message and prints it through the serial port for debugging. It represents the first controlled output task.

    output2_rtos_task:
This task receives messages from the state machine and processes output actions for output channel 2. Similar to output1_rtos_task, it reads the message and prints it through the serial port. It represents the second controlled output task.

    state_machine_rtos_task: 
This is the master task of the project. It receives input messages from input1_rtos_task and input2_rtos_task, checks the current state, decides the next state, and sends the correct command to output1_rtos_task or output2_rtos_task. Therefore, it acts as the main controller of the whole system.



The task define diagram is showing below



The state machine is showing below:




Our Project

There are 6 different task in our project.
The_break_en task:
This task is used to enable the brake. It displays the brake status on the LCD, shows that the brake is on, and increases the temperature-related variable T. It represents the brake-on operation of the system.

The_break_dis task:
This task is used to disable the brake. It updates the LCD display and decreases the variable T. It represents the brake-off operation of the system.

The_motor_en task:
This task is used to enable the motor. It shows the motor-on message on the LCD and increases the speed-related variable S. It represents the motor-on operation of the system.

The_motor_dis task:
This task is used to disable the motor. It updates the LCD to show that the motor is off and decreases the variable S. It represents the motor-off operation of the system.

The_kernal task:
This is the command input task. It receives user commands from the serial port, checks whether the command is valid, and sends the corresponding message to the State Machine task. In this way, it acts as the interface between the user and the control system.

State_Machine task:
This is the Master Control in the project. It receives messages from The Kernal task, stores the required brake and motor states, checks the values of T and S, and then decides whether to enable or disable the brake and motor tasks. It controls the whole system according to both user commands and safety threshold conditions.
 
The task define diagram is shown below:


The state machine is showing below:



Compare the two project

Both programs use a master task / state machine idea. In the first code, state_machine_rtos_task receives input messages and decides which output task should get a message next. In the second code, state_machine receives command messages from The_Kernal and decides which motor or brake task should be enabled or disabled. So in both cases, one central task controls the behaviour of the other tasks.

Both codes also use RTOS message passing. In the first program, input tasks send messages to the state machine, and the state machine sends messages to output tasks. In the second program, The_kernal sends command messages to State_Machine. This means both designs are built around task communication through queues.


Jason's code is a generic RTOS state-machine demo. It is mainly used to show how multiple RTOS tasks can communicate: two input tasks, two output tasks, and one state machine task. It reacts to a push button and ADC input and cycles through several states.

Our code is a motor and brake control application. It is not just a demo. It is designed to control brake and motor operations using serial commands and internal variables T and S, which act like monitored values with upper and lower thresholds.


However, the first program is mainly a demonstration of a finite-state machine using button and ADC inputs, while the second program is a practical motor and brake control system using serial commands. The first code cycles through predefined states and sends messages to output tasks, whereas the second code uses a supervisory state machine that checks temperature and speed thresholds and then enables or disables brake and motor tasks accordingly. Therefore, the second program is more application-oriented and has a more advanced control structure than the first one.








Comments

Popular posts from this blog

Blog 1 - Igor Kapusniak

Blog 5 - Bin Bot Project - Davin Barron