Custom CAN message

Discussion and Support for MoTeC's M1 series ECUs

Re: Custom CAN message

Postby gtihk on Mon Aug 20, 2018 8:49 pm

I was talking about a counter at the last byte of a message which keeps changing.
I examined the logged data. It seems to repeat in this order : (3,18,33,48)
The change seems to be at a rate of 100Hz.
I am thinking of replicating this by creating a new variable called "counter".
Then,create a Schedule Function to run it at 100 Hz.

The code within the Schedule Function may be :

if(counter<48)
{
Counter=counter+15;
}
else
{
counter=3.0
}

Will this be a correct way to tackle such a problem? Any comments will be welcome.
gtihk
 
Posts: 76
Joined: Thu Jul 19, 2018 1:37 pm

Re: Custom CAN message

Postby rntechnologies on Tue Aug 21, 2018 9:01 am

Hi gtihk,
Yes, you are correct, that will work okay for a counter of +15.
You can shorten it up a little like this though:
There are some other things to note though; like when you initialise the variable, be careful with the number you initialise with as depending on how you structure things the code may still run after the initialisation and add 15 immediately instead of starting at 3.

Code: Select all
static local <unsigned integer> counter = 49;
if (counter < 48)
{
   counter += 15;
}
else
{
   counter = 3;
}
Regards,
Ryan
Powertune Australia
rntechnologies
Pro User
 
Posts: 91
Joined: Tue Aug 07, 2018 9:45 am
Location: Sydney, Australia

Re: Custom CAN message

Postby gtihk on Tue Aug 21, 2018 6:42 pm

I followed the example but there is one error.
It says," the local variable name conflicts with an existing object of the same name.
"All local variables must have a unique name."
I suppose it is referring to the channel created called "counter".
The purpose of the Scheduled Function is to update the channel "counter".
How can this error be avoided?
gtihk
 
Posts: 76
Joined: Thu Jul 19, 2018 1:37 pm

Re: Custom CAN message

Postby rntechnologies on Wed Aug 22, 2018 8:40 am

Because my code has the declaration of the counter variable in it, you have likely already declared this in your own existing code, and as such, you need to remove one of the declarations of the variable 'counter'
Regards,
Ryan
Powertune Australia
rntechnologies
Pro User
 
Posts: 91
Joined: Tue Aug 07, 2018 9:45 am
Location: Sydney, Australia

Re: Custom CAN message

Postby gtihk on Fri Aug 24, 2018 9:18 pm

Thanks!
I shall try to fix it.
gtihk
 
Posts: 76
Joined: Thu Jul 19, 2018 1:37 pm

Re: Custom CAN message

Postby gtihk on Sat Aug 25, 2018 4:34 pm

Sorted for now.
No more errors.
I added 5 counters in total.
gtihk
 
Posts: 76
Joined: Thu Jul 19, 2018 1:37 pm

Re: Custom CAN message

Postby gtihk on Mon Aug 27, 2018 8:52 pm

Next on the to do list would be custom CAN receive such as speeds from the ABS unit.
Any suggestions for this please?
gtihk
 
Posts: 76
Joined: Thu Jul 19, 2018 1:37 pm

Re: Custom CAN message

Postby David Ferguson on Tue Aug 28, 2018 3:15 am

Determine the details of the data you want to receive (ie, bus speed, byte ordering, scaling, messages IDs, etc). You may need to use a CAN bus sniffer / analyzer to figure this information out. Expect to spend many hours on this if you don't have documentation with this information available.

Consider hiring someone to create the code for M1 build for you -- they will need the info above to get started.

If you really, really want to do this yourself, then
Read the M1 Development Manaual section on CAN Communications.
Search this forum for threads on M1 CAN Comunications (there are a couple of receiving CAN data, with some important clues).
Create a scheduled function to read the data and write it into channels that you can use.

Only ask questions about a problem after you have tried to solve it yourself. Please describe what you've done/tried.

Good Luck!
David Ferguson
Veracity Racing Data
David Ferguson
Pro User
 
Posts: 1378
Joined: Fri Nov 07, 2008 2:45 am
Location: Paso Robles, California

Re: Custom CAN message

Postby gtihk on Tue Aug 28, 2018 12:25 pm

Thanks, David!
I have used CANcapture and have some information on some vehicles that I have done.
I heard that wheel speed is heavily integrated into different modules and would be a difficult one to solve.
What is your experience on this please?
gtihk
 
Posts: 76
Joined: Thu Jul 19, 2018 1:37 pm

Re: Custom CAN message

Postby rntechnologies on Tue Aug 28, 2018 3:04 pm

Is the ABS unit a bosch unit?
If so, Bosch do publish a lot of information surrounding their CAN structure, you should be able to piece together stuff around the internet to help with this.

Another note, Generally the formula to calculate wheel speed should also take into account wheel diameter. So keep that in mind when doing your calculation.
Regards,
Ryan
Powertune Australia
rntechnologies
Pro User
 
Posts: 91
Joined: Tue Aug 07, 2018 9:45 am
Location: Sydney, Australia

PreviousNext

Return to M1 ECUs

Who is online

Users browsing this forum: No registered users and 15 guests

cron