Software for Grin Cycle Analyst and Phaserunner log data

rberger

10 W
Joined
Mar 9, 2015
Messages
76
Location
Saratoga, CA
I've been working on getting some software running on a Raspberry Pi to collect the log data from the Grin Cycle Analyst and Phaserunner so I can analyze my temperature and performance issues on my Pedalec ICE Trike with those gadget and a Crystalyte M3540R motor.

There are three packages that build on each other. They are all written in Ruby. I chose Ruby since I know it well and there was a very nice Modbus library for it

There are now ruby gems for my packages available for download and easy installation (assuming you have ruby installed).

They are:
* Cycle Analyst Logger https://rubygems.org/gems/cycle_analyst_logger
* Phaserunner Logger https://rubygems.org/gems/phaserunner
* ASI Object and Grin BOD file viewers https://rubygems.org/gems/asi_bod

These are described in more detail below

Unless you want to hack on it, just use the ruby gems to install things. Source is on github in the links below.

1. Cycle Analyst Logger
This is the main one to use if you want to capture logs from the Cycle Analyst and optionally the Phaserunner.

It connects via a serial port (USB usually) to the CA and another serial port to the Phaserunner. You can ignore the other two gems if you just want to use this to get logs from the Cycle Analyst and Phaserunner.

It just listens to the CA spewing its log output and for every CA log line, it polls for some data from the Phaserunner.

It can output the data to stdout and also to a file that is created on each run with a timestamp in its name.
The output is a true Comma Separated Vale (CSV) which can be read directly by Excel. It has a header line with the names of the values and the units.

Running the help command of the gem executable is the best way to get the latest command line documentation. Assuming you have Ruby 2.x (tested with Ruby 2.4) installed:

Code:
gem install cycle_analyst_logger
cycle_analyst_logger help
cycle_analyst_logger help log
cycle_analyst_logger log

By default it will log forever to stdout (the terminal) and to a file with a name in the format:
Code:
cycle_analyst.YYYY-MM-DD-H-S.csv

It logs the following attributes:
* Timestamp
* Cycle Analyst Amp Hours (Ah)
* Cycle Analyst Volts (V)
* Cycle Analyst Current (A)
* Cycle Analyst Speed (Kph)
* Cycle Analyst Distance (Km)
* Cycle Analyst Motor Temp (DegC)
* Cycle Analyst Human Cadence (RPM)
* Cycle Analyst Human Power (W)
* Cycle Analyst Human Torque (Nm)
* Cycle Analyst Throttle In (V)
* Cycle Analyst Throttle Out (V)
* Cycle Analyst AuxA ()
* Cycle Analyst AuxD ()
* Cycle Analyst Limit Flags (bit flags)
* Cycle Analyst Faults
* Phaserunner Faults ()
* Phaserunner Controller Temperature (deg Celsius)
* Phaserunner Vehicle Speed (Km/hour)
* Phaserunner Motor Temperature (deg Celsius)
* Phaserunner Motor Current (Amps)
* Phaserunner Motor RPM (RPM)
* Phaserunner Motor Speed (% of rated rpm)
* Phaserunner Battery Voltage (Volts)
* Phaserunner Battery Current (Amps)
* Phaserunner Battery State of Charge (%)
* Phaserunner Battery Power (Watts)
* Phaserunner Last Fault ()
* Phaserunner Warnings ()
* Phaserunner Motor Input Power (W)

Some Phaserunner values that are logged are always empty, but due to how the Modbus works, it seems more efficient to get a range of registers than individual registers (an untested assumption at this time but makes sense as its one request over a serial port instead of a dozen).

Note: I am not yet scaling the Phaserunner values. They are the raw values right now. I could use some help on how to apply the scale to the values. Its not clear. Do I divide the value with the raw scale? Or something else? It doesn't seem that dividing or multiplying the scale value works right.

I will add a post processor that can output standard CA data logger files eventually so they could be imported to other tools that expect that format.

2. Phaserunner
This is the Phaserunner only log tool. It is used by cycle_analyst_logger to get the Phaserunner values. The Phaserunner tool can be used by itself to get just Phaserunner stuff. It logs the Phaserunner values described in the previous gem.

The Phaserunner tool also lets you read individual or ranges of registers from the Phaserunner.
This code base could be extended for also writing to Phaserunner registers. No plans for now.

If you installed the cycle_analyst_logger gem, the Phaserunner gem is installed also. But to do an install and run its help and the operation:

Code:
gem install phaserunner
phaserunner help
phaserunner help log
phaserunner log

3. asi_bod

This tool contains and can read in the ASIObjectDictionary.xml file from the ASI BacDoor Software which was the basis for the Phaserunner and the BOD.json file that comes with the Phaserunner Software. I mainly used it to merge the descriptions from ASIObjectDictionary.xml into BOD.json. asi_bod and the other tools use that modified file (BODm.json) to be able to present Descriptions of the registers.

The asi_bod gem will automatically be installed if you installed any of the others.

asi_bod also allows you to view and search the files which helps when you are trying to find things. You can search by register address (the Integer value) or by a sub-string against any of the keys. The most useful feature is:

Code:
asi_bod find -b by_key_substring name <a word in a register name you are looking for>
For example to find all the registers with the word 'Torque' in them:
Code:
asi_bod find -b by_key_substring name Torque

Caveats, Warnings, How you can help

* This is still a work in progress and no warranty or guarantee of support for the code, but it is open source under the MIT License.
* Its still underdevelopment and can change at any time.
* Its been tested on Ubuntu 16.04.3 macOS High Sierra. Should run everywhere Ruby can run but no guarantees.
* If you hack on it and want me to consider adding it in, please send a pull request on github.
https://github.com/rberger/cycle_analyst_logger/pulls
* Unfortunately I have not written any tests. So tests would be welcome!
* If you find bugs, you can file an issue in the 'Issues" section of the github repository.
https://github.com/rberger/cycle_analyst_logger/issues
 
Thank you for posting this up.

I can think of at least a couple of people's projects that could use / were looking for logging CA data (without using the Cycle Analogger or a laptop).
 
One thing I could use help on is:

How does the 'scale' parameter work in Phaserunner registers. The dictionary that comes with the Phaserunner (BOD.json) has a scale field for each register. Most of them are 1 which seems clearly that you can just use the value of the register along with the 'units' field.

But many of them have '4096' as the 'scale' value. In these cases, multiplying or dividing the register value by 4096 doesn't seem to get a final value that is correct.

So would love to hear from someone who knows!

Thanks,
Rob
 
Does dividing by 4096 and then multiplying by 100 give you a sensible % value?

Just guessing here, from what I’ve read in other threads.
 
Back
Top