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
46 changes: 46 additions & 0 deletions docs/docs/firmware/can-traffic.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

ManushPatell marked this conversation as resolved.
Show resolved Hide resolved
# Calculating CAN traffic
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

## 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

## Frequency (Hz)

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

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
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

$$
\text{Total Bits Per Second} = \sum_{i=1}^n \left(\text{Frequency}_i \times \text{Message Length}_i\right)
$$

$$
\text{Bus Load (%)} = \frac{\text{Total Bits per Second}}{\text{Baud Rate}} \times 100
ManushPatell marked this conversation as resolved.
Show resolved Hide resolved
$$

## Sample calculation

**Given**:

Battery Status: Frequency = 100Hz, Length = 400 bits
ManushPatell marked this conversation as resolved.
Show resolved Hide resolved

Motor Control: Frequency = 50Hz, Length = 100 bits

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

$$
\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