Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Equation for Can Traffic #241

Merged
merged 11 commits into from
Nov 7, 2024
42 changes: 25 additions & 17 deletions docs/docs/firmware/can-traffic.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,46 @@
---
title: Calculating CAN traffic on a bus
---

# Calculating CAN traffic
ManushPatell marked this conversation as resolved.
Show resolved Hide resolved

ManushPatell marked this conversation as resolved.
Show resolved Hide resolved
In order to calculate the CAN load, we must declare a few variables and their importance within the CAN protocol.

ManushPatell marked this conversation as resolved.
Show resolved Hide resolved
In order to calculate the CAN load, we must declare a few variables and their importance within the CANbus protocol.

1. Baud: (kbaud)
## Baud (kbaud)

ManushPatell marked this conversation as resolved.
Show resolved Hide resolved
The baud rate is the rate at which data is transfered in a communication channel (like CAN). For example, 9600 Baud rate is 9600 bits per second

2. Frequency (Hz)
## Frequency (Hz)

Frequency in the CANbus refers to how many CAN frames (or messages) are transmitted per second. So the greater the frequency, the more bits transferred, increasing the bus load.
Frequency is the number of messages transmitted per second for each message type. Different messages can have different frequencies.

ManushPatell marked this conversation as resolved.
Show resolved Hide resolved
3. Total Data Per Cycle
This variation affects the total bits transferred and, in turn, the bus load. To calculate bits per second, consider each message’s frequency and whether their lengths differ.

Total data per cycle includes all the bits transmitted in one CAN message. This includes not only the payload but overhead bits like start of frame, CRC, acknowledgement, control field etc.
## Total Data Per Cycle

ManushPatell marked this conversation as resolved.
Show resolved Hide resolved
Total data per cycle includes all the bits transmitted in one CAN message. This includes the payload and overhead bits like the start of frame, CRC, acknowledgment, control field, etc.

## The bus load is determined by

## The bus load is determined by:
$$
\text{Total Bits Per Second} = \sum_{i=1}^n \left(\text{Frequency}_i \times \text{Message Length}_i\right)
$$

![Bus Load Formula](https://latex.codecogs.com/png.latex?\text{Bus%20Load%20(\%)}%20=%20\frac{\text{Number%20of%20Bits%20per%20Frame}%20\times%20\text{Number%20of%20Frames%20per%20Second}}{\text{CAN%20Speed}}%20\times%20100)
$$
\text{Bus Load (%)} = \frac{\text{Total Bits per Second}}{\text{Baud Rate}} \times 100
$$
ManushPatell marked this conversation as resolved.
Show resolved Hide resolved

![Bus Load Formula](https://latex.codecogs.com/png.latex?\text{Bus%20Load%20(\%)}%20=%20\frac{\text{Total%20Bits%20per%20Second}}{\text{CAN%20Speed}}%20\times%20100)
## Sample calculation

## Sample calculation:
**Given**:

Total data/cycle: 1524 (bits per cycle)
Battery Status: Frequency = 100Hz, Length = 400 bits

ManushPatell marked this conversation as resolved.
Show resolved Hide resolved
Frequency: 200 (cycles per second)
Motor Control: Frequency = 50Hz, Length = 100 bits

Baud Rate: 500 kbaud (500,000 bits transferred per second)

![Solved Bus Load Formula](https://latex.codecogs.com/png.latex?\text{Bus%20Load%20(\%)}%20=%20\frac{1,524%20\times%20200}{500,000}%20\times%20100%20=%2060.96\%)
$$
\text{Total Bits Per Second} = (100 \times 400) + (50 \times 100) = 40,000 + 5,000 = 45,000 \text{ bits per second}
$$

$$
\text{Bus Load} = \left(\frac{45,000}{500,000}\right) \times 100 = 9\%
$$
12 changes: 12 additions & 0 deletions docs/docs/firmware/javascripts/katex.js
ManushPatell marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
document$.subscribe(({ body }) => {

ManushPatell marked this conversation as resolved.
Show resolved Hide resolved

renderMathInElement(body, {
delimiters: [
{ left: "$$", right: "$$", display: true },
{ left: "$", right: "$", display: false },
{ left: "\\(", right: "\\)", display: false },
{ left: "\\[", right: "\\]", display: true }
],
})
})
9 changes: 8 additions & 1 deletion docs/mkdocs.yml
ManushPatell marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ theme:
extra_css:
- stylesheets/extra.css

extra_javascript:
- javascripts/mathjax.js
- https://unpkg.com/mathjax@3/es5/tex-mml-chtml.js

copyright: Copyright © McMaster Formula Electric

plugins:
Expand Down Expand Up @@ -73,7 +77,7 @@ plugins:

markdown_extensions:
- admonition
- abbr
# - abbr
- attr_list
- md_in_html
- pymdownx.details
Expand All @@ -91,6 +95,8 @@ markdown_extensions:
base_path:
- !relative
- !relative $docs_dir/../
- pymdownx.arithmatex:
generic: true

repo_url: https://github.com/macformula/racecar
repo_name: macformula/racecar
Expand Down Expand Up @@ -123,6 +129,7 @@ nav:
- firmware/architecture.md
- firmware/project-structure/index.md
- firmware/compile-project.md
- firmware/can-traffic.md
- Glossary: glossary.md

watch:
Expand Down
Loading