Smart Home Device, with Motion in Space (ATMega4808)
Budget: €8 – €30 EUR
1 Description
The purpose of this laboratory exercise is to simulate the operation of a smart home device that moves in the space of an empty room. It starts from a corner of the room and its purpose is to draw its outline. As it moves in space it will receive values from a sensor that measures the distance of the device from an obstacle in front of it (here the sensor values will be measured by the Analog to Digital Converter - ADC). If the value is below the allowed (you set any value between 1-254) the device should stop and move left. The device will choose to move right if the right sensor shows that there is no wall to the right of the device (it will also be simulated with the ADC), i.e. the value is above the allowable. When it reaches the corner from which it started, the device must stop. Also, if a switch is pressed, the device must perform a 180 degree turn and return to its position following the path it has taken so far.
Some assumptions that will be used are the following:
• Movement will be simulated by an LED (when moving straight LED1 is on otherwise off).
• There is only one ADC available on the board, so to use it in two different modes (checking if it is approaching a wall and checking if there is a wall to the right in the normal course or to the left in the case of the reverse course) it should accept values from each sensor alternately per regular intervals. Specifically, initially it will receive continuous values from the side sensor (Free-Running Mode) and as soon as T=3s pass, it will receive a single value from the front sensor (Single Conversion). Once T2= 2s have passed, the ADC will return to its first mode, that is to accept values from the side sensor (Free-Running Mode). These procedures should be continuously performed until the contour of the room is completed.
• Right and left turns will be simulated with two different LEDs (LED0 and LED2 respectively) which are lit until a timer/counter (TCA0 timer/counter) reaches a certain value (we encourage you to put values that are convenient for you and explain how you found the values).
• When a switch is pressed (Switch 5) the reverse course will be activated.
As for the reverse course, the device must stop and turn 180 degrees at any point in the room when the switch (Switch 5) is pressed. This will be simulated with the three LEDs (LED 0, 1, 2) simultaneously activated for a period of time (using a timer). It will then perform the exact same process in reverse.
Specifically, as it advances and the ADC receives a value less than the threshold, the device will turn right (LED0). The ADC continues to receive values from the front sensor in Single Conversion mode. When it realizes that there is no wall to the left, i.e. the ADC accepts a value greater than the threshold set by the left sensor, the device moves to the left (LED2). The left sensor works the same way as the right sensor. Therefore, for the left turn this time the ADC will be in Free-Running Mode. Finally, when it realizes that it has returned to its original position, it terminates.
Lab Questions 2
1. Implement the motion code of the home device when the room is square (so the right sensor and the second function of the ADC are not needed). However, functions with timings will be needed to simulate turns.
2. Implement the motion code for a random room that also contains two obtuse angles, this is where the second function of the ADC is introduced. Figure 2.2 below shows an example of such a room for a proper understanding of the problem. However, the device should be able to respond correctly even in an unfamiliar room.
3. Implement reverse operation.
1 Develop code and verify that all functions perform as intended.
2 A detailed report is delivered with the operation of your code, along with a flowchart. Explain how your code performs all the processes of the application discussed above, as well as the possible elements (interrupts, timers, ADC, etc.) you chose and used.
The purpose of this laboratory exercise is to simulate the operation of a smart home device that moves in the space of an empty room. It starts from a corner of the room and its purpose is to draw its outline. As it moves in space it will receive values from a sensor that measures the distance of the device from an obstacle in front of it (here the sensor values will be measured by the Analog to Digital Converter - ADC). If the value is below the allowed (you set any value between 1-254) the device should stop and move left. The device will choose to move right if the right sensor shows that there is no wall to the right of the device (it will also be simulated with the ADC), i.e. the value is above the allowable. When it reaches the corner from which it started, the device must stop. Also, if a switch is pressed, the device must perform a 180 degree turn and return to its position following the path it has taken so far.
Some assumptions that will be used are the following:
• Movement will be simulated by an LED (when moving straight LED1 is on otherwise off).
• There is only one ADC available on the board, so to use it in two different modes (checking if it is approaching a wall and checking if there is a wall to the right in the normal course or to the left in the case of the reverse course) it should accept values from each sensor alternately per regular intervals. Specifically, initially it will receive continuous values from the side sensor (Free-Running Mode) and as soon as T=3s pass, it will receive a single value from the front sensor (Single Conversion). Once T2= 2s have passed, the ADC will return to its first mode, that is to accept values from the side sensor (Free-Running Mode). These procedures should be continuously performed until the contour of the room is completed.
• Right and left turns will be simulated with two different LEDs (LED0 and LED2 respectively) which are lit until a timer/counter (TCA0 timer/counter) reaches a certain value (we encourage you to put values that are convenient for you and explain how you found the values).
• When a switch is pressed (Switch 5) the reverse course will be activated.
As for the reverse course, the device must stop and turn 180 degrees at any point in the room when the switch (Switch 5) is pressed. This will be simulated with the three LEDs (LED 0, 1, 2) simultaneously activated for a period of time (using a timer). It will then perform the exact same process in reverse.
Specifically, as it advances and the ADC receives a value less than the threshold, the device will turn right (LED0). The ADC continues to receive values from the front sensor in Single Conversion mode. When it realizes that there is no wall to the left, i.e. the ADC accepts a value greater than the threshold set by the left sensor, the device moves to the left (LED2). The left sensor works the same way as the right sensor. Therefore, for the left turn this time the ADC will be in Free-Running Mode. Finally, when it realizes that it has returned to its original position, it terminates.
Lab Questions 2
1. Implement the motion code of the home device when the room is square (so the right sensor and the second function of the ADC are not needed). However, functions with timings will be needed to simulate turns.
2. Implement the motion code for a random room that also contains two obtuse angles, this is where the second function of the ADC is introduced. Figure 2.2 below shows an example of such a room for a proper understanding of the problem. However, the device should be able to respond correctly even in an unfamiliar room.
3. Implement reverse operation.
1 Develop code and verify that all functions perform as intended.
2 A detailed report is delivered with the operation of your code, along with a flowchart. Explain how your code performs all the processes of the application discussed above, as well as the possible elements (interrupts, timers, ADC, etc.) you chose and used.