Jump to content
The mkiv Supra Owners Club

Maths function question


Chris Wilson

Recommended Posts

combine('GPS LAT HW', 'GPS LAT LW') / 10000000

 

is the function I have had suggested, but as soon as I write it in my data logging maths section as a function to combine two 16 bit channels into one 32 bit and divide the result by 10000000 it barfs with:

 

 

 

(0): Invalid number of arguments for function: 'combine'. 3 expected.

 

What else does it want, anyone know? Thanks.

Link to comment
Share on other sites

  • Replies 90
  • Created
  • Last Reply

Top Posters In This Topic

Does the GEMS pro software offer an "IF" function? If it is available, you can check to see if the low word is negative before combining it with the high word. If it is negative, you need to add 65536 (0xFFFF), otherwise just use as-is.

 

I tried the standard GEMS software but couldn't find any way to define maths channels. There doesn't appear to be any detailed documentation on the maths functions online.

Link to comment
Share on other sites

It does have an IF function, plus a whole caboodle more stuff. There's an issue though. The logger is seeing raw data off the CAN BUS, and none of the data GEMS sees is negative. Looking at the Motec stuff, before the maths in i2 does its stuff, some of the figures ARE negative. The ecu outputs what it outputs on the CAN, so I can't see how it's an ecu thing, somehow i2 is seeing negative figures and GDA is not, I'll attach tow screenshots, if I may, showing this. Both are from the same location within a few inches, albeit at different times, and at one point I move the GPS receiver around for a few feet in a pretty random way. If you can help at all I would be very grateful, I have now become obsessional about getting this working, but determination is being overcome by my pitiful grasp of the maths :( Cheers! If you like I can post screen shots of the maths function pages from the pro software, without the dongle (pay for to use the Pro version of GDA) you can't see it at all.

Link to comment
Share on other sites

If GEMS always sees positive numbers, that's not a problem. The high word can be negative or positive, the low word needs to be interpreted as positive.

 

You need to create a maths function that if the high word is greater than 32767, subtract 65536. Then you can combine it with the positive low word.

Link to comment
Share on other sites

I'll try that now, thanks guys! Here's the syntax page from the help file:

 

The maths language has the following common syntactical elements:

Comments

Comments can be added to scripts as a memo of the authors intent or as an aid to other people understanding how the script works. A comment starts with a '#' character and the comment continues up to the next new-line character.

Though it is not an error, it is good practice to start comments with capital letters and end them with a full stop.

e.g.

# Calculate Front Wheel speed.

# avg_nonzero accounts for the fail-off

# state of the wheel speed sensors.

avg_nonzero('LF Wheel Spd', 'RF Wheel Spd')

Numbers

Floating point, integer and boolean numbers are supported.

Integers can be specified as decimal (base 10) numbers by entering them naturally.

e.g.

10

42

153

Integers may also be written in hexadecimal (base 16) notation by prefixing the number with '0x'.

e.g.

0x1FFF

0xFFFFFFFF

Floating point numbers are specified by including a decimal point.

e.g.

0.1

5.6

5.0

Boolean numbers can be specified as 'true' or false' and are really handled as integers that are either zero (false) or non-zero (true).

Numbers may also be explicitly cast to another type using one of the cast functions:

int(5)

real(0xFFFF)

bool(false)

Channel References

Channels can be referred to in maths scripts by enclosing them in single quotes.

e.g.

'Engine Speed'

Unit References

Units may be referenced within maths scripts by enclosing them in square brackets.

e.g.

[m/s]

Additionally the quantity that a unit belongs to can be specified if the unit would otherwise be ambiguous:

e.g.

[speed:m/s]

Units can be specified as conversions in scripts as a post-fix term to any expression.

e.g.

10[m/s]

'Road Speed'[m/s]

(5 * 8)[m/s]

Operators

The following operators are provided:

Unary Prefix

- Negates following number. e.g. -10 or -'Speed'

+ Has no effect, antonym of unary '-'.

! Logical NOT (boolean). e.g. true == !false

Arithmetic

+ Addition

- Subtraction

/ Division

* Multiplication

** Exponentiation (i.e. x ** y === xy)

% Modulo (remainder of integer division)

Bitwise

>> Right shift

& Bitwise AND

^ Bitwise XOR

| Bitwise OR

Relational

> More than

>= More than or equal to

== Equal to

!= Not equal to

Logical

&& Logical AND (boolean)

|| Logical OR (boolean)

Grouping

Sub-expressions may be grouped by using parenthesis.

An opening bracket '(' should be later followed by a closing bracket ')'.

Bracketed expressions may be nested.

e.g.

5 * (2 + (3 - 4))

Grouped expressions can be used to ensure that the order of evaluation is correct.

e.g.

(1 + 2) * (3 + 4)

Is not the same as:

1 + 2 * 3 + 4

This is because multiply takes precedence over plus. As with normal algebra.

Constants

Constants are immutable named values.

To use a constant in your script, refer to it by name.

e.g.

PI

Functions

Functions are referred to by name and are followed by an argument list, enclosed in brackets.

Individual arguments should be separated by commas.

e.g.

cos(0.1)

sin('Steering Angle')

atan2('longitudinal G', 'Lateral G')

Link to comment
Share on other sites

Right! Now the figures have a correct sign, but the coordinates put the receiver about 60 miles south of where it really was, see the comparison with the Motec figures. Google Earth export shows the Motec figures to be spot on to a few yards, the GDA ones are way out (but in the same county, rather than in Russia's wheat belt, as they were before :) You patience is fabulous, so is my appreciation. Thanks again.

Link to comment
Share on other sites

That's the decimal thing I was talking about Chris. To go from decimal to mins and seconds you need to multiply the fraction by 0.6, to go the opposite way you divide by 0.6.

 

That is the reason they are different, the answer you get from the function above gives you it in mins/secs whereas the other one is in decimal.

 

In order to work it out you need to take everything after the decimal point and divide by 0.6 to get them both the same.

 

Not sure exactly how you will do that in this program. What is the command list? In Excel I used "Fix" or "Rounddown",IIRC, to get it to shorten the 52.52665 (made up) to 52. I then subtracted 52 from the number giving 0.52665. I then divided by 0.6 and added to the 52 to get the decimal figure.

Link to comment
Share on other sites

Do you have a function along the lines of 'div()'?

 

I think you'll need something like this to get the whole number of degrees. You'll need this to apply Scott's formula from the other thread.

 

Failing that, is there a list of all the functions available?

 

What am I on about!? Scott's right, you need a function along the lines of RoundDown() or Floor().

Link to comment
Share on other sites

OK, it looks like you have a floor() function. Try this:

 

(((combine16(if('GPS LAT HW'>32767,('GPS LAT HW'-65536),'GPS LAT HW'),'GPS LAT LW')/10000000)-(floor(combine16(if('GPS LAT HW'>32767,('GPS LAT HW'-65536),'GPS LAT HW'),'GPS LAT LW')/10000000)))/0.6)+(floor(combine16(if('GPS LAT HW'>32767,('GPS LAT HW'-65536),'GPS LAT HW'),'GPS LAT LW')/10000000))

Link to comment
Share on other sites

On a side note, that GEMS software looks great. I wish my ECU had a CAN output so I could use one of their loggers! I have to do it by hand with .csv files.

 

Did you get the Autronics? GDA Pro will import CSV files. Motec i2 pro will only import files from 3 other ecus / loggers, unless you buy a 10K licence to do what you will with it :(

 

If you send me a smallish csv file I'll try importing it and see how it manages. GDA is very similar to i2. To be honest i2 is better, GDA will crash if you do funny things, i2 is solid as a rock.

Link to comment
Share on other sites

I think you missed the main one mate lol.

 

(((combine16(if('GPS LAT HW'>32767,('GPS LAT HW'-65536),'GPS LAT HW'),'GPS LAT LW')/10000000)-(floor(combine16(if('GPS LAT HW'>32767,('GPS LAT HW'-65536),'GPS LAT HW'),'GPS LAT LW')/10000000)))/0.6)+(floor(combine16(if('GPS LAT HW'>32767,('GPS LAT HW'-65536),'GPS LAT HW'),'GPS LAT LW')/10000000))

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. You might also be interested in our Guidelines, Privacy Policy and Terms of Use.