Common use of Real-World Example Clause in Contracts

Real-World Example. Line-Following Robot‌ In this section we demonstrate how to apply our analysis to an existing real-world example, written in C. The program is simple enough that there is no potential for energy consumption optimization, but nonetheless our analysis gives insight into the program’s energy behaviour. We chose a random “simple line follower” project from the Arduino project database [1]. This robot has two motors and two sensors, and uses them to follow a black line on the floor. It works as follows. The sensors are positioned to the left and right of the line. If only the left sensor sees the line, the robot turns left. Symmetrically for the right sensor. If neither sensor sees the line, the robot moves forward. If both sensors see the line, the robot stops. The code has potential for refactoring, as it contains unnecessary repetition. However our goal was not to find the most elegant line follower robot, but to apply our method to a real-world example. The original source code, written in C, is almost valid SECA. We made two changes to the code for our parser to accept it. First, we defined the constants LOW and HIGH, and the function delay, which for our purpose is empty. Second, we replaced the statements that write to output pins and read from input pins with component calls. Figure 13 shows an excerpt of the code after these adjustments. We then created the component models for motors and sensors in the source code of our analysis engine. The simulated motors have three states, forward, backward, and stop, and corresponding component calls. In the forward and backward states, motors have a power draw of 750 mW. The sensors have no power draw, and their read component call returns a symbolic value in {0, 1}. Analysis Results. Figure 14 shows skyline diagrams for the functions loop (top) and MoveForward (bottom). The diagram for MoveForward illustrates that the function has two behaviours. One where the power draw increases in two steps from 0 to 1500 mW, and one where the power draw stays constant at 1500 mW. The functions TurnLeft and TurnRight, not shown here, look similar. The func- tion Stop, also not shown, has the opposite behaviour: the power draw decreases 1 int main() { 2 while( true ) { 3 loop(); 4 } 5 return 0; 6 } 8 if((▇▇▇▇▇▇▇▇▇▇.▇▇▇▇()==LOW) && 9 (▇▇▇▇▇▇▇▇▇▇▇.▇▇▇▇()==LOW)) { 10 MoveForward(); 11 } 13 (▇▇▇▇▇▇▇▇▇▇▇.▇▇▇▇()==HIGH)) { 14 Stop();

Appears in 2 contracts

Sources: End User Agreement, End User Agreement

Real-World Example. Line-Following Robot‌ In this section we demonstrate how to apply our analysis to an existing real-world example, written in C. The program is simple enough that there is no potential for energy consumption optimization, but nonetheless our analysis gives insight into the program’s energy behaviour. We chose a random “simple line follower” project from the Arduino project database [1]. This robot has two motors and two sensors, and uses them to follow a black line on the floorfloor. It works as follows. The sensors are positioned to the left and right of the line. If only the left sensor sees the line, the robot turns left. Symmetrically for the right sensor. If neither sensor sees the line, the robot moves forward. If both sensors see the line, the robot stops. The code has potential for refactoring, as it contains unnecessary repetition. However our goal was not to find find the most elegant line follower robot, but to apply our method to a real-world example. The original source code, written in C, is almost valid SECA. We made two changes to the code for our parser to accept it. First, we defined defined the constants LOW and HIGH, and the function delay, which for our purpose is empty. Second, we replaced the statements that write to output pins and read from input pins with component calls. Figure 13 shows an excerpt of the code after these adjustments. We then created the component models for motors and sensors in the source code of our analysis engine. The simulated motors have three states, forward, backward, and stop, and corresponding component calls. In the forward and backward states, motors have a power draw of 750 mW. The sensors have no power draw, and their read component call returns a symbolic value in {0, 1}. Analysis Results. Figure 14 shows skyline diagrams for the functions loop (top) and MoveForward (bottom). The diagram for MoveForward illustrates that the function has two behaviours. One where the power draw increases in two steps from 0 to 1500 mW, and one where the power draw stays constant at 1500 mW. The functions TurnLeft and TurnRight, not shown here, look similar. The func- tion Stop, also not shown, has the opposite behaviour: the power draw decreases 1 int main() { 2 while( true ) { 3 loop(); 4 } 5 return 0; 6 } 8 if((▇▇▇▇▇▇▇▇▇▇.▇▇▇▇()==LOW) && 9 (▇▇▇▇▇▇▇▇▇▇▇.▇▇▇▇()==LOW)) { 10 MoveForward(); 11 } 13 (▇▇▇▇▇▇▇▇▇▇▇.▇▇▇▇()==HIGH)) { 14 Stop();

Appears in 1 contract

Sources: End User Agreement