# Thunder CAN - Expressing negative numbers in binary

## Recommended Posts

Hi

I'm trying to get Longitudinal acceleration from CAN, wondering if negative numbers are expressed with a trailing bit or something? The values I'm getting have an extra 30 on them, does this have anything to do with expressing negative?

##### Share on other sites

Usually there is good info in the "test calculator" to show how the parameter is scaled/stored but it looks like the detail for those parameters is missing.  Usually we use unsigned integers with an offset to allow for negative values, so this is probably what you are seeing.  I suspect it will be something like a 3G offset, so the accel can read from -3G to +3G.  I will see if I can get some more detail for you tomorrow.

##### Share on other sites

Thanks Adam, To be honest I had not checked Test calculator but now that I look at it, I see why I needed * 0.001 - 30. Over CAN I'm only getting a positive number out and I can't tell whether it's forward or backward. On the ECU, Forward acceleration shows as negative and braking force shows as positive I'm not sure if this is correct but I've done a leveling calibration before and no change to that.

Stored in ECU with:
ECU Resolution      = 0.001 G
ECU Width (bits)    = 16
Display Offset    = 30 G
Minimum           = -10 G
Maximum           = 10 G

##### Share on other sites

Just thought on it a bit further, the reason it's -30 is so if it wanted to display -30 it would send 0, Now I just need to know which direction is which

##### Share on other sites
13 minutes ago, mikegt4dude said:

n the ECU, Forward acceleration shows as negative and braking force shows as positive I'm not sure if this is correct but I've done a leveling calibration before and no change to that.﻿

That is opposite to how most would want it.  You should be able to correct that with the "orientation correction" setting.

I just relised why my test calculator didnt work - I wasnt using a thunder...

The test calculator is actually very handy to see the effects of scaling/offsets etc.  Have a play with that calculator bit at the bottom.

2 minutes ago, mikegt4dude said:

Just thought on it a bit further, the reason it's -30 is so if it wanted to display -30 it would send 0, Now I just need to know which direction is which

Correct, -30G would be sent over CAN as "0".  +30G would be "60000".

##### Share on other sites

Riiiiiiight, Orientation correction is what I'm missing all along, the CAN value should be fine once I sort this. So it says if the pin header is facing the front of the car it should be zero, I have it above the tunnel mounted flat just behind the ABS sensor (fluked a good choice) but the pin header is 90 deg CCW of the front of the car, Not sure what value that should equate to but it takes 180 max

Okay, I just realised it takes -180 as well, so ECU pin header facing passenger side, the front of the car should be 90deg CW in relation to the ECU so I'm guessing that's what I should put

##### Share on other sites

Im not sure either, I would have thought 90 or -90 but I would just unclip the ecu and tip it up to simulate braking or accel and you will soon work it out.

##### Share on other sites

Hmmm this has turned from crap to crap ... Gonna try -90 now

Here is Mister Thunder's flat centre mounted passenger side facing

##### Share on other sites

This is what I'm trying to do with the accelerometer to get back an estimated non driven speed on a 4wd, thoughts?

##### Share on other sites

It almost looks like you might need 180 or -180 for your orientation correction from that log above.

##### Share on other sites

I think we're getting somewhere, hey thanks for your help as always Adam this is freakin awesome!

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.