








                       TRIP - The HP28s Car Trip Computer
                       ----------------------------------
                          Ver. 1.0 Copyright June, 1989
                                 Robert Peraino









     The car trip computer is a program which provides the common
statistics which most integrated car computers provide. Since the hp28
is not directly interfaced physically with your car, it cannot collect
the necessary information on-the-fly. But by simply providing the current
mileage reading, TRIP can report current time, elapsed time, elapsed miles,
average speed, estimated time of arrival (eta), and fuel consumption.
     I constantly try to improve my software, and welcome comments. I am
especially interested to know if people find TRIP helpful on long road
trips. I welcome any suggestions for added features and/or improvements.
The code listings will be presented, followed by the user guide.

-----------------------------------------------------------------------------
       Bob Peraino                   UUCP    : uunet!pyrdc!gmu90x!peraino
 George Mason University             INTERNET: peraino@gmuvax.gmu.edu
UCIS, Thompson Hall, rm 2            BITNET  : peraino@gmuvax
  4400 University Drive              PHONE   : (703)-323-2549
   Fairfax, VA  22030
-----------------------------------------------------------------------------


Listing conventions.
--------------------
     This section describes the notations used to represent the special
characters found on the hp28s.

<=    The "less than or equal to" sign.
>=    The "greater than or equal to" sign.
<>    The "not equal to" sign.


     Some code listings have a line beneath the description which contains
a colon. This notation is used for functions which require input. Items
to the left of the colon are those objects taken from the stack as input.
Items to the right of the colon are the output of the function. For Example

            string1 string : string3

means providing two strings causes the function to output a third. What
the third string is, would depend on the function.
     Each code listing is preceded by a hex number delimited by CHK[..].
This is the checksum for the code module. This number is provided to 
avoid typing mistakes. To generate a checksum after entering the module,
enter 'module name' onto the stack and run CHK:

CHK[129]
<< RCLF HEX 16 STWS SWAP RCL ->STR DUP
   #0h 1 ROT SIZE
   FOR j
    OVER j j SUB NUM R->B XOR RL
   NEXT
   ->STR 3 OVER SIZE 1 - SUB ROT STOF SWAP DROP
>>


     Be VERY careful when entering the code. CHK is, of course, case
sensitive, and so is the 28. So if you enter a variable in upper case,
and a program references it in lower case, kablooie. And, the checksum
won't match.


Module listings.
----------------

Trip - The car trip computer.




tm - Trip computer menu
     This list is used for displaying the custom menu.

CHK[F2A9]
{ FILUP AUTO UPDT TETA OFF }



TS - Target speed.
     This routine calculates average speed necessary to reach destination
     by target eta.

CHK[4C0F]
<< st TDIF HMS-> em SWAP / >>



ts - Tank size.
     This value should be replaced by the size of your tank, in
     gallons or liters.

CHK[A4]
10



mpg - Miles per gallon.
      This value should be replaced by the average miles per gallon(liter)
      for your car.

CHK[AC]
30



TETA - Target eta.
       This routine sets your estimated time of arrival value, and
       calculates average speed necessary to meet that target.
                      HH.MM : (new display)

CHK[52F2]
<< 504 525 IFUN                          ;Inverse the function on the screen.
   "TETA-" OVER NTTC + OVER 'teta' STO   ;Convert input target to char and
   SWAP TS ->STR                         ;add to output. Do same for
   "  MPH -"SWAP + + 2 DISP              ;calculated target speed.
   L13                                   ;Output lines 1 & 3.
>>



L13 - Lines 1 and 3.
      This routine displays updated lines #1 and #3.

CHK[771C]
<< "TIME-" TIME 1 5 SUB + " " +          ;Calc current time.
   ELM DUP em < "<" ">" IFTE             ;Calc behind/ahead schedule arrow.
   SWAP ->STR "MILE-" SWAP + + + 1 DISP  ;Finish elapsed miles & display L1.
   "ELAP-" ET NTTC +                     ;Calc elapsed time.
   "  FUEL-" + FC ->STR + 37 CHR + 3 DISP;Calc fuel and display L3.
>>



TDIF - Time difference.
       This routine calculates the difference between two times.

CHK[C7E4]
<< DUP2                                  ;Make a copy of the two times.
   IF < THEN                             ;If end is less than start then,
    SWAP 24 + SWAP                       ; past midnight. add 24 to end.
   END                                   ;Endif.
   HMS-                                  ;Subtract start from end.
>>



IFUN - Inverse function.
       This routine inverses the pressed function on the screen.

CHK[2C9A]
<< LCD-> -> b e s                        ;Grab beginning, end, and screen.
   << s 1 b 1 - SUB                      ;Extract screen up to function.
      s b e SUB NOT +                    ;Extract function and inverse video.
      s e 1 + 548 SUB + ->LCD            ;Extract screen remainder and display.
   >>
>>



AUTO - Automatic pilot mode.
       This routine will automatically update the display based on the
       current average speed, predicting the mileage rate.
                        (Current mileage) : (auto updated screen)

CHK[501]
<< 458 479 IFUN                          ;Inverse the function.
   UPDT AS cm -> nas ocm                 ;Update figures, save ave spd & miles.
   << DO                                 ;Calculate predicted elapsed miles and
       ET HMS-> nas * sm + UPDT          ; feed to UPDT to update screen.
      UNTIL                              ;until...
       KEY                               ; a key is pressed.
      END                                ;Enddo.
      DROP ocm 'cm' STO CLMF             ;Dump key value, replace curr. mileage.
   >>
>>



ENDT - End trip.
       This routine performs cleanup activities.

CHK[C187]
<< { STRT } tm + MENU                    ;Change menu from ENDT to STRT.
   fl STOF                               ;Reset system status.
   { st fm cm sm em fl teta } PURGE      ;Cleanup temp vars.
>>



UPDT - Update screen statistics.
               (current Mileage) : (new screen)

CHK[EE2E]
<< 481 502 IFUN                          ;Inverse function.
   'cm' STO L13                          ;Update current mileage & do L 1&3.
   "ETA -" ETA NTTC +                    ;Calc and output ETA.
   AS teta TS OVER < "<>" "><" IFTE      ;Calc ahead/behind arrows.
   "MPH -" + SWAP ->STR + + 2 DISP       ;Calc average speed and display.
>>



ETA - Estimated time of arrival.
      This routine calcs eta.

CHK[836A]
<< em ELM - AS / ->HMS CT HMS+ 24 MOD    ;Miles remaining over average speed
>>                                       ;plus current time equals eta.



FC - Fuel consumption
     This routine calculates percentage of fuel used.

CHK[A46F]
<< cm fm - mpg / ts / 100 *              ;Elapsed miles since last fillup over
>>                                       ;mpg over tank size equals usage.



AS - Average speed.

CHK[70AB]
<< ELM ET HMS-> /                        ;Elapsed miles over elapsed time.
>>



ET - Elapsed time.

CHK[808]
<< CT st TDIF                            ;Current time minus start time.
>>



CT - Current time.
     This routine takes character time "HH:MM:SS" and returns
     numeric hh.mm.ss

CHK[CD3F]
<< TIME DUP 1 2 SUB "." +                ;Grab hours.
   OVER 4 5 SUB +                        ;Grab minutes.
   SWAP 7 8 SUB + STR->                  ;Grab seconds.
>>



ELM - Elapsed miles.

CHK[B802]
<< cm sm -                               ;Current miles minus start miles.
>>



FILUP - Tank filup.
        This routine updates fm (fillup miles) for fuel consumption calc.
                     (current mileage) : (updated screen)

CHK[B6DB]
<< 435 456 IFUN                          ;Inverse function.
   DUP 'fm' STO                          ;Update fillup miles.
   UPDT                                  ;Update screen.
>>



STRT - Start trip.
       This routine sets things up for the stsrt of the trip.
 (estimated miles), (initial target eta), (current mileage) :

CHK[879D]
<< { ENDT } tm + MENU                    ;Update menu.
   DUP DUP CT 'st' STO 'fm' STO 'cm' STO ;
   'sm' STO 'teta' STO 'em' STO RCLF     ;
   'fl' STO 1 FIX                        ;
>>



NTTC - Numeric time to character.
       This routine takes the numeric time in the form hh.mmss and
       returns character form "HH:MM"

CHK[4099]
<< STD DUP IP 100 / .001 + ->STR 2 3 SUB ;Grab hours- ensure trailing zero.
   58 CHR + SWAP                         ;Add colon.
   FP .001 + ->STR 2 3 SUB + 1 FIX       ;Grab minutes.
>>



OFF - Turn the calculator off.

CHK[6E03]
<< #18E58h SYSEVAL
>>
   


Installation instructions.
--------------------------

     Enter all code modules into a new subdirectory, say, TRIP. You will
notice a call to a routine called TIME. This routine is not included here,
since variations have been posted in the past, and it is an application
in itself considering the number of modules. To work, TRIP expects your
time routine to return "HH:MM:SS". Or you can modify it to suit yourself.
If you do not have a time routine, I can supply one. Be sure to modify the
tank size and miles-per-gallon variables to suit your particular car.
     HP28c users can give it a go, but I do not know if it will fit. You
will have to remove all references to function IFUN whose only purpose is
to inverse the name of the function you press. You will also have no need
for variable tm, since the 28c has no custom menu, I believe. You will
also have to modify STRT and ENDT to remove the references to tm. If TRIP
still doesn't fit, you might want to try converting some of the low-level
functions to algebraic expressions. You will also do away with the OFF
function, whose only purpose is to move the OFF button to a more
convenient location.



User guide.
-----------

     To start a trip, you must enter the following onto the stack;

1. Number of miles (or kilometers) to destination or intermediate point.
   You should have an idea of how far you are going. If you do not know
   exactly, TRIP will still work, but the ETA will not be accurate.
   ETA is only as accurate as the stated miles.

2. Target estimated time of arrival in the format: HH.MM
   By telling TRIP when you would LIKE to get there, it can tell you the
   necessary average speed and whether you are ahead or behind schedule.

3. Current odometer reading.


     When you have entered this information, type STRT. After a pause,
the custom menu will come up and you will have a regular screen back.
The custom menu displays the following functions:

     ENDT  FILUP  AUTO  UPDT  TETA  OFF

I will describe each of these functions in logical order.

UPDT
----
     UPDT stands for Update, and is used for getting an updated screen
of information. The only parameter you need to enter is the current
odometer reading (or the last few digits, provided they won't wrap to
zero). Press UPDT, the function will highlight, and you will get a screen
that looks something like this:

                          ------------------------
                          |TIME-06:21 <MILE-21.6 |
                          |ETA -07:34<>MPH -54.8 |
                          |ELAP-00:22  FUEL-18.4%|
                          |     {functions}      |
                          ------------------------

TIME- The current time.

ETA - Estimated time of arrival. This figure is based on your average speed
      and remaining miles to go. Obviously, the farther into the trip you
      are, the more accurate the ETA will be, since the overall average
      speed will have a smaller and smaller standard deviation.

ELAP- Elapsed time into the trip.

MILE- Elapsed miles into the trip.

MPH - Average speed (miles per hour) but this would be KPH if you're using
      all metric units.

FUEL- Fuel consumed, based on your tank size and average MPG. I decided to
      make this fuel consumed rather than fuel remaining, because I didn't
      want the number to go negative. I decided 101 per cent makes more sense
      than -1 per cent.

The Arrows- The "<" next to MILE tells you that you are below your estimated
number  of miles for the trip. A ">" would mean you have exceeded your
estimate. The "<" next to ETA means you will arrive sometime before your
target ETA, at the current speed. A ">" would mean you will arrive late.
The ">" next to MPH means that you are running ahead of schedule; you are
exceeding necessary average speed to meet target eta. A "<" would mean that
you are behind schedule, and you should pick up the pace. If you see a ">"
next to MILE meaning that you have exceeded the mileage estimate, then
ignore the ETA value because it will show a time prior to the present.
     If you try to get an update less than one minute into the trip, the
numbers might be strange. In reality, you wouldn't do this anyway, but
I mention this because I know first time users will try to run it at home
just to see it, and may prematurely enter pseudo mileages.


AUTO
----

     Enter the current odometer reading and press AUTO to enter autopilot
mode. The screen will automatically update continuously until a key is
pressed. (Don't press ON/ATTN!!!)
     You might wonder how AUTO can accurately keep up the statistics if
there is no physical connection to the vehicle. When you press AUTO, it
calculates the current average speed, and makes a projection of elapsed
miles over time. For each loop, it calculates this projection and feeds
it to UPDT which does the screen upates, as if you had just typed in
the mileage. So obviously, using AUTO as soon as you start your trip
won't give you very accurate results. But if you wait until you're on
the highway for a while, it will be very accurate. And you can "tune"
it every once in a while by pressing any key to stop it, and restarting
it with the correct current mileage. This function was an afterthought. I
find it useful to use autopilot mode and fix my 28 someplace in the car
(like on the sun visor) where I can glance at it ocassionally.
     During the development of the autopilot mode, I performed an
interesting test. When writing AUTO, I realized that average speed was
a calculated value. If I were to use the calculated value on every
pass to come up with the elapsed miles, then average speed would be
calculating speed in terms of itself, since the elapsed miles would be
used in the next pass to calculate average speed! During testing, I
decided to let this happen anyway, just to see what would happen. I
expected the average speed to pitch back and forth wildly. Instead, TRIP
acted like the driver was slowly taking his foot off the gas. The average
speed slowly dropped off, heading toward zero, and the ETA got longer
and longer. Quite an interesting simulation! In the real version, average
speed is calculated only once and that one constant is used to calculate
elapsed miles. The effect of this is, the calculated average speed drops
off a few miles per hour, and then levels off. The few miles per hour are
not important, since elapsed miles are always based on a fixed speed.


FILUP
-----

     Use FILUP when you stop at a gas station and fill up your tank. It
"re-zeroes" the fuel consumption. Obviously, unless you are starting with
a full tank when you pull out of your driveway, the fuel consumption
number is not accurate until you stop to fill up. FILUP requires the
current mileage.


TETA
----

     TETA is used when you want to CHANGE your target ETA. Enter the new
target ETA in the form HH.MM. TETA will display a screen similar to
UPDT except line two displays your entered TARGET eta, and MPH shows the
TARGET average speed necessary to meet the target ETA.


OFF
---

     OFF is just the OFF key relocated to a more convenient location.
If you only get ocassional screen updates and want to shut the 28 off
afterwards, it is easier to press OFF while driving than pressing
<shift> ON.


ENDT
----

     ENDT stands for End Trip. Press this when your trip is over. ENDT
will purge the temporary variables and restore your flag settings.



Conclusion.
-----------

     It is obvious that TRIP was designed for trips with duration of
less than one day, since it doesn't take the date into account. At the
time I wrote this, I did not have date capability. Multi day trips
should consider each day's driving a separate trip. If you are a marathon
driver and intend to drive more than 24 hours straight, then you should
break up the trip into intermediate targets. I have since come up with
a date routine, and version 2.0 may take dates and many other features
into account.
     I apologize if there are any errors in this document, and would
appreciate a note from anyone who finds any so that I may correct them.
This document was written in a big hurry, to honor as closely as possible
the date I said it was going to be released.
     I welcome comments and suggestions. Happy driving!
