I’m posting these scripts because 1) they are required for the Shift Assist dashboard that I’ve also posted here
http://www.palmerperformance.com/forum/index.php?topic=1334.0, and 2) because they provide good examples of what can done with scripts beyond simple calculations.
These scripts use a broader range of javascript capabilities than the scripts that have been shared before. Specifically, they use:
- Arrays
- The javascript Math object
- The javascript Number object
- The javascript String object
- The Obdii.PidState object
- A technique to store and retrieve an array from a PidSate
Two of the scripts run a procedure that guides a user/driver through steps to capture data for wheel circumference and final drive ratios.
F2G_GEARF2G_Gear provides the current gear number in the metric unit value and a suggested gear in the English unit value. The script requires the wheel circumference, the engine RPM, and the vehicle speed as inputs to calculate a drive ratio. This drive ratio is compared to the final drive ratios of the vehicle to determine a current gear.
One of the highlights of the script is the use of an array to store the actual final drive ratios which makes the matching of ratios more efficient that having a long string of if-else-if statements.
Another feature of the script is the ability to suggest a different gear to increase fuel efficiency or suggest a gear for times when the clutch is not engaged.
To avoid flip-flopping of the gear value which is distracting on the dashboard, the gear value can indicate its stability. Whole numbers indicate a gear that is stable while a gear number + 0.1 indicates that the gear value is rapidly changing and is unstable. To achieve this, the last 3 gear values are stored in the PID state and compared to the current gear value. When the gear value hasn’t changed for 4 passes through the script the gear value is deemed stable.
F2G_SMOOTH_VSSF2G_SMOOTH_VSS calculates the moving average of SAE.VSS using its last n values. Instead of using the previous frames to retrieve last n VSS values, which only works while recording a log, the script saves the previous VSS values in an array which is stored in and retrieved from the PidState. This means that the script works in both Monitor and Record modes.
The script was created to smooth out the VSS values and provide some decimal points to make the Shift Points gauge scroll more smoothly.
F2G_FINAL_DRIVE_RATIOThis is a simple script that calculates the current final drive ratio using a known wheel circumference, vehicle speed and engine RPM. Log it to capture final drive ratio of a particular gear.
F2G_FINAL_DRIVE_RATIO_PROCThis script drives the Final Drive Analysis dashboard. It provides instructions and status that the user can follow to obtain their vehicle’s final drive ratios.
It’s basically a timed sequence of instructions that starts when a trigger is set off (revving the engine to 3000 RPM). Each phase allows time to shift to the appropriate gear and capture 12 seconds of final drive ratio readings. At the end of each phase the average final drive ratio is calculated and appended to the previous results so a table of final drive ratios is visible on screen.
F2G_WHEEL_CIRCUMFERENCEThis script calculates a wheel circumference based on a provided final drive ratio and the engine RPM and vehicle speed readings. Use it log wheel circumference in a particular gear.
F2G_WHEEL_CIRCUMFERENCE_PROCThis script drives the wheel circumference analysis dashboard. Instructions are provided and when followed the script will calculate and display an average wheel circumference.
I've attached the scripts in two formats, one for import into PCMSCAN and the other in text format so they can be read before hand.