Blog 3 | RTOS | Jake

 RTOS:     Run, Record, Review

The code that Jason supplied us is a mock template of what could be potentially be used in the sweeper bots that we will be designing and implementing in the coming weeks. The code uses a state machine with RTOS (real time operating system) tasks. 

The program operates as follows: 
On boot up we are greeted with a "starting...rtos" message on the screen telling us that the board is running. After which we can see two inputs, two outputs, the state machines and what the program is currently doing using messages. All which can be seen on the board as shown here:


For the code to run the following needs to be done. 5 tasks need to be #defined. Input1, Input2, Output1, Output2 and the state machine. Each tasked needs to have its own unique code and be able to send messages to other tasks in this case the outputs telling it what to do based on what operation the input has done. 

For Input 1, when the button is pressed it sends a message to Output 1. When pressed it gives a prompt on the LCD saying that it was pressed "in1 >>1". This will then send 1 across to out1 "sending 1 to out 1". This text tells us which state we are in which is State 1. By pressing the button again this state is incremented as follows:

  • Press 1 : sending 1 to out1.
  • Press 2:  sending 2 to out1
  • Press 3:  sending 3 to out2
  • Press 4:  sending 4 to out2
For Input 2 if the ADC pot is greater than 100 it will send a message. From which the state machine reads how many messages are being sent to it. In this case 2 are being sent as seen on Putty. This reads continously until the pot value is set to be less than 100:

There are 5 states in the state machine:
  1. Startup state: Print out "starting sm"
  2. State 1: print "sending 1 to out1" => when button pressed once
  3. State 2: print "sending 2 to out1" => when button pressed twice
  4. State 3: print "sending 3 to out2" => when button pressed three times
  5. State 4: print "sending 4 to out2" => when button pressed four times
Then return to state 1.

Also contained in the state machine program is a prompt to show the user that the state machine is being ran through the states for debug info.

Comparison to what i had:
My own implementation of the RTOS state machine was wrong. I didn't have it working correctly. My vision for it was similar to the code above but didn't turn out that way. 
What I wanted to do was have it so that when I pressed a button for input 1 it would toggle an LED  on output 1. And input 2 would read the adc and output 2 would display it. I also wanted to keep ther Kernal command in aswell so we could manually enter into a different state but I didn't get to that.
I know now where I went wrong. Input 2 / Ouput 2 was the wrong idea i should've implemented it like the template above. My state machine was wrong aswell and i see now where i can improve it. I'm not happy that I was a good bit off from where I should be but seeing the template now I can see where I went wrong and can improve from.



















Comments

Popular posts from this blog

Blog 1 - Igor Kapusniak