sameh4
Posts: 50
Joined: Wed Nov 29, 2017 6:58 pm

How to manage the CAN message rate with the SocketCAN API?

Wed May 27, 2020 3:06 pm

I would like to ensure that some of my CAN messages are being sent at a frequency/rate between 50 and 100Hz. I am also not sure how I would calculate that...

It looks like the message rate is a broadcast rate and a feature of the CAN bus protocol, based on the following quote from a stack-exchange answer.
This is usually called the broadcast rate, how often you send that message on the bus, e.g. how fast a vehicle is moving should be sent fairly often, but the coolant temperature will not change very often, so can be sent far less frequently.
I am using the SocketCAN API with this https://www.seeedstudio.com/2-Channel-C ... -4072.html SeedStudio CAN bus Shield and the RaspberryPi 3B+.

I was looking at what the Broadcast Manager does in the SocketCAN API. It seems to do what I am trying to do, except for a single (cyclic) message, where as I would like a subset of messages with different; each with new data,

I am wondering if there's a way to manage this in the SocketCAN API that I've overlooked?

Or is this something that's CPU and device specific? I.e. the clock frequency of the CPU will determine how fast messages are sent, assuming of course that messages are being sent on an independent thread in a loop.

Moreover, how do I calculate the message rate in a good deterministic way using C/C++?

deepo
Posts: 574
Joined: Sun Dec 30, 2018 8:36 pm
Location: Denmark

Re: How to manage the CAN message rate with the SocketCAN API?

Fri May 29, 2020 9:07 pm

Sorry, I don't know anything about CAN messages, but...

An unobtrusive way to measure message rate is to record a timestamp before sending an amount of messages, send the messages incrementing a counter variable for each message sent, and another timestamp recorded when you stop sending messages.

Then divide the amount of messages sent by the time spent sending the messages to get the message rate.

The longer the test the more accurate your result will be.

Example:
5250 messages sent over 75 sec gives 70 messages per second.

/Mogens

Return to “Automation, sensing and robotics”