Google Answers Logo
View Question
 
Q: computer ( Answered,   0 Comments )
Question  
Subject: computer
Category: Computers > Algorithms
Asked by: mohd_fm-ga
List Price: $2.00
Posted: 26 Feb 2003 19:32 PST
Expires: 28 Mar 2003 19:32 PST
Question ID: 167666
State machine exercise: 
The odometer is a simple instrument on a bicycle’s handlebar that
measures the current speed and the distance traveled. There are two
buttons, A and B.
Initially, the odometer is in the state Distance. Each time the button
A is pressed, the state successively changes to Speed to Mileage to
Time and back to Distance.
In Distance, the distance from the start of the current trip is
displayed every 200 ms with a precision of one tenth of a mile. Button
B resets the distance to zero.
In Speed, the current speed is displayed every 100 ms. 
In Mileage, the total distance traveled is displayed every 500 ms with
the precision of one mile. The mileage is never reset. (In practice,
it becomes reset to zero when the bat-teries are changed.)
In the Time state, the current, relative time is displayed every
second. Button B resets the time to zero.
a. Make a state transition diagram of the odometer object that shows:
The states and state transitions. 
The events A and B and events of type “s seconds” indicating that s
seconds have passed since the last event.
The actions taken in response to events. 
b. Adapt the state transition diagram to show the events "Battery out"
and "New battery", and the state No Battery. Hint: Use a superstate.
You can combine a and b in one diagram.
Answer  
Subject: Re: computer
Answered By: maniac-ga on 27 Feb 2003 05:16 PST
 
Hello Mohd_fm,

More ascii art - you will need to revise this to match the method you
are using to represent a state transition diagram. For example, in
ESML, the notation is
  event
------
 action
is used next to the arc between states. The states should be in
rectangles / circles as appropriate as well. The "+-+" notation is
used here to show a line w/ arrow that goes out of the state and back
into the same state. The numbers refer to the event / action pair
listed at the end.

Also note that I explicitly indicated the initial state. This makes
the explanation of the second part of the question much easier.

a. Odometer state transition diagram

               2,3           5
         1     +-+     4    +-+
Initial ---> Distance ---> Speed
               ^             |
               | 11   8      v  6
             Time   <---- Mileage
              +-+           +-+
              9,10           7
1 - power on; reset TDM [time, distance, mileage], display distance
2 - 200 ms; accumulate TDM, display distance
3 - B press; reset distance, display distance
4 - A press; display speed
5 - 100 ms; accumulate TDM, display speed
6 - A press; display mileage
7 - 500 ms; accumulate TDM, display mileage
8 - A press; display time
9 - B press; reset time, display time
10 - 1 sec; accumulate TDM, display time
11 - A press; display distance

Just a side comment - perhaps for "extra credit". As a user, I would
argue that the specification has a "bug" in it. Pressing the B (reset
accumulated values) should reset both time and distance. At least that
is how the similar option in my car works.

If you implemented what I describe strictly, you could "lose" a little
distance / time each time the A or B button is pressed. To "fix" this,
you would need to accumulate TDM as part of each of those transitions
as well. You might want to make that note as well.

b. Battery state transition

            1
  Odometer --> Off
      ^         | 2
      +---------+

1 - Battery out; turn off display and odometer
2 - New battery; turn on odometer and display, start at initial state
(the initial state already takes care of TDM reset, setting the
initial display, etc.)

Note that the "battery out" can occur at any state in the Odometer
(other than the initial state).

If this is unclear, please use a clarification request for further
information.
  --Maniac
Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy