Java Reference
In-Depth Information
programming problems usually benefit from a flowchart. The logic
flowchartedin Figure1-2 isbasedonrechargingthebatteriesifitisafter
5:00 PM “and” if the battery meter reads less than 80%. In this case both
conditions have to be true for the action of recharging the battery to take
place. An alternative set of rules could state that the robot must recharge
itself if it is after 5:00 PM “or” if the battery is less than 80% full. In this
case, either condition determines that the robot recharges. The flowchart
torepresentthislogicmustbemodified,asshownin Figure1-3 .
START
Read internalclock
YES
Is it past 5:00 PM
?
Continue working
NO
Recharge battery
Read battery meter
YES
Are batteries
< 80% full
?
END
NO
Figure 1-3 Alternative Logic for Recharging a Robot Battery
Now suppose that there are critical functions that you do not want the
domestic robot to interrupt, even if it is after 5:00 PM or if the battery is
less than 80% charged. For example, if the robot is walking the dog you
may not want it to let go of the leash and go plug itself into the wall outlet.
In this case, you would have to modify the flowchart and insert an addi-
tional test so that recharging does not take place if the robot is currently
performing a critical activity. Furthermore, you may decide that a very
low battery could damage the machine; therefore, if the meter shows less
than 20% full charge, the robot should plug itself into the outlet no matter
what. Here again, the program logic and the flowchart would have to be
 
 
Search WWH ::




Custom Search