×

Sale ends todayGet 30% off any course (excluding packages)

Ends in --- --- ---

CAN Bus Communications Decoded: Step 5: Determine Variable Scaling

Watch This Course

$199 USD $99.50 USD

-OR-
Or 8 easy payments of only $12.44 Instant access. Easy checkout. No fees. Learn more
Course Access for Life
60 day money back guarantee

Step 5: Determine Variable Scaling

07.40

00:00 - Last step of the process is going to be determining that parameter scaling.
00:04 Now we know its location I'm going to make some known physical inputs on the steering wheel, I'm going to record those data bytes in a spreadsheet and then we're going to go through the process of determining that parameter scaling.
00:16 So the first thing I'm going to do is looking at 0D0 there.
00:21 With the steering wheel essentially dead straight, I can actually have it reading almost exactly 0.
00:31 Now you'll see as I move the steering wheel just back and forth, those 2 data bytes are flicking between 00 00 and FF FF.
00:41 That's actually telling me something about how our data is going to be coded already.
00:47 Because the default point for a steering wheel, the centre point is going to be 0°, and then we've got both clockwise and counter clockwise rotation, we've essentially got a positive and a negative number.
00:59 And seeing 0 means 0 on our data stream, and if I turn the steering wheel slightly counter clockwise, our data byte reading goes up to FF FF which is the maximum value.
01:12 I'm pretty certain when we go through the process in our spreadsheet, we're going to find that this is actually being transmitted as a signed integer data type which when we're at that spreadsheet we'll have a little bit more of a talk about what that means.
01:24 For the moment though I'm just going to pop our steering wheel in some known positions and record the corresponding data bytes onto our spreadsheet.
01:32 Now that I've got those recorded in there I can actually just remove our steering wheel to get it out of the way and we can do a little bit more work on our laptop to figure out that parameter scaling.
01:43 So immediately looking at this I can see that byte 1 is not changing a huge amount in response to our inputs whereas byte 0 is actually changing quite a lot.
01:53 So this is definitely transmitted as a 16 bit value and byte 0 is going to be our less significant bits with byte one being our most significant bits so it's transmitted little endian.
02:06 So I'm just going to make another column here and I'm going to concatenate those 2 together using our function for that.
02:16 And make sure I get the order correct so we want our high byte first and our low byte second.
02:26 Then I'm just going to propagate that down and that's going to do exactly the same for the rest of our data there.
02:34 So FC53 FC53, excellent.
02:38 So that's now our complete 16 bit value concatenated together and I can convert that into a decimal now using a hex to decimal command.
02:59 Excellent and once again, we can see that looks like we're getting some pretty good values out there.
03:06 So looking at the physical inputs that we've made.
03:11 My first one here, 45° clockwise rotation, concatenated together and then converted into decimal we've got 444.
03:21 So I think we're going to be looking at a scaling factor of 10 here.
03:25 I suspect that our steering wheel angle is being transmitted in an accuracy of 1 decimal place.
03:33 So it's basically being transmitted multiplied by 10 and then all the devices on the bus know to divide it by 10 to get back to the actual value but we get that decimal place of accuracy as well so although I was aiming for 45°, what this is telling me is I actually turned the steering wheel to 44.4°.
03:51 So what I'm going to do is make another column here which is just going to be this column divided by 10.
04:03 And I'm just going to propagate that down these 2 for the moment, that's looking excellent.
04:09 Now we need to talk about that signed integer data type which is how we're in this instance transmitting a negative value.
04:16 So this is different to how we've talked about it previously where we used an offset to increase the overall value that the receiving devices then knew they had to subtract.
04:27 In this instance, the way a signed data type works is for a 16 bit value, we can have from 0 to 65,535.
04:37 When we decide that those 16 bits are now going to represent a signed value, we shift the range and we can transmit negative - 32,768, I think, to + 32, 768, or it's very close to that, I might be one off in one of the figures there.
04:57 The way we do that is if the 15th bit of that value is set to a 1 it means the rest of the bits represent a negative value.
05:08 If that bit is set to 0, the rest of the bits represent a positive value.
05:12 How that works in actuality is the hex to decimal command has converted this as an unsigned value.
05:22 We can simply take this and subtract it from 65, 535 and that will give us what this means as a signed integer value.
05:32 So I'll go ahead and we'll do that.
05:35 I'm actually, I'm just going to do that down here, equals 65,535 minus this value here.
05:51 I'll just have to do that again.
05:53 65, 535 minus this value here.
06:05 And then in these columns here I'm just going to take those and divide them by our scaling factor.
06:16 And that's going to give us our rotation in the counter clockwise direction.
06:20 Now I was aiming for 45° counter clockwise but I've actually turned the steering wheel almost all the way to 60° counter clockwise.
06:27 It is quite a tricky thing to actually line up by eye doing that.
06:31 However our data is all agreeing really nicely there.
06:34 So I am very confident that we've worked out our parameter location and scaling.
06:40 So just to recap, what we've figured out there is that on our main OEM data bus in this vehicle that we've tapped into on the OBD2 port, it's a 500 Kb per second bus, we've found that data byte with the PID 0D0 on bytes 0 and 1 we've got our steering wheel angle parameter.
07:00 That's being transmitted as a signed integer and there is a factor of 10 involved there so we get 1 decimal place of precision as well.
07:08 We're going to be able to set up our video recording system to interface with that CAN bus now, it's going to record that data and let us put a really nice graphic on the display to show what the driver's input was at that point in the track.
07:21 'Cause the camera setup in this car you can't actually see the driver.
07:25 We're also going to plumb that into the main data logging system in the vehicle and it's going to be able to log the steering wheel position as well and we'll be able to compare those data between runs and different drivers to really help with the driver training.

We usually reply within 12hrs (often sooner)

Need Help?

Need help choosing a course?

Experiencing website difficulties?

Or need to contact us for any other reason?