Files
ESP-Nodes/ESP-IDF_Robot/tutorial/docs/build/html/data.html
2025-07-19 01:34:55 -04:00

174 lines
9.7 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="en" data-content_root="./">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
<title>3. DATA STRUCTS &#8212; Byte Rider 06-2025 documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css?v=5ecbeea2" />
<link rel="stylesheet" type="text/css" href="_static/basic.css?v=b08954a9" />
<link rel="stylesheet" type="text/css" href="_static/alabaster.css?v=27fed22d" />
<script src="_static/documentation_options.js?v=e6ef2064"></script>
<script src="_static/doctools.js?v=9bcbadda"></script>
<script src="_static/sphinx_highlight.js?v=dc90522c"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="4. TRANSMITTER" href="transmitter.html" />
<link rel="prev" title="2. HOW DOES IT WORK?" href="overview.html" />
<link rel="stylesheet" href="_static/custom.css" type="text/css" />
</head><body>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<section id="data-structs">
<h1><span class="section-number">3. </span>DATA STRUCTS<a class="headerlink" href="#data-structs" title="Link to this heading"></a></h1>
<p>The struct serves as the data payload for sending control signals from the transmitting device to the receiver using ESP-NOW.
In addition, it may contain additional data such as telemetry, battery status, etc. The <em>sensors_data_t</em> struct encapsulates all control commands and sensor states
relevant to the vehicles operation. Its intended to be sent from a transmitting device (like a remote control) to a receiver
(such as a microcontroller on board of the vehicle).</p>
<div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="k">typedef</span><span class="w"> </span><span class="k">struct</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">x_axis</span><span class="p">;</span><span class="w"> </span><span class="c1">// Joystick x-position</span>
<span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">y_axis</span><span class="p">;</span><span class="w"> </span><span class="c1">// Joystick y-position</span>
<span class="w"> </span><span class="kt">bool</span><span class="w"> </span><span class="n">nav_bttn</span><span class="p">;</span><span class="w"> </span><span class="c1">// Joystick push button</span>
<span class="w"> </span><span class="kt">bool</span><span class="w"> </span><span class="n">led</span><span class="p">;</span><span class="w"> </span><span class="c1">// LED ON/OFF state</span>
<span class="w"> </span><span class="kt">uint8_t</span><span class="w"> </span><span class="n">motor1_rpm_pwm</span><span class="p">;</span><span class="w"> </span><span class="c1">// PWMs for 4 DC motors</span>
<span class="w"> </span><span class="kt">uint8_t</span><span class="w"> </span><span class="n">motor2_rpm_pwm</span><span class="p">;</span>
<span class="w"> </span><span class="kt">uint8_t</span><span class="w"> </span><span class="n">motor3_rpm_pwm</span><span class="p">;</span>
<span class="w"> </span><span class="kt">uint8_t</span><span class="w"> </span><span class="n">motor4_rpm_pwm</span><span class="p">;</span>
<span class="p">}</span><span class="w"> </span><span class="n">__attribute__</span><span class="p">((</span><span class="n">packed</span><span class="p">))</span><span class="w"> </span><span class="n">sensors_data_t</span><span class="p">;</span>
</pre></div>
</div>
<div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="k">struct</span><span class="w"> </span><span class="nc">motors_rpm</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">motor1_rpm_pwm</span><span class="p">;</span>
<span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">motor2_rpm_pwm</span><span class="p">;</span>
<span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">motor3_rpm_pwm</span><span class="p">;</span>
<span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">motor4_rpm_pwm</span><span class="p">;</span>
<span class="p">};</span>
</pre></div>
</div>
<p>When used with communication protocols like ESP-NOW, this struct is <strong>encoded</strong> into a byte stream, then
<strong>transmitted</strong> at regular intervals or in response to user input, and finally
<strong>decoded</strong> on the receiving end to control hardware.</p>
<div class="admonition-what-is-struct admonition">
<p class="admonition-title">What is struct?</p>
<p>In C programming, a struct (short for structure) is a user-defined data type that lets you group multiple variables of different types together under a
single name. Its like a container that holds related information — perfect for organizing data that logically belongs together. Structs are especially
powerful in systems programming, embedded projects, and when dealing with raw binary data — like parsing sensor input or transmitting control packets over
ESP-NOW.</p>
</div>
<section id="data-payload">
<h2><span class="section-number">3.1. </span>Data Payload<a class="headerlink" href="#data-payload" title="Link to this heading"></a></h2>
<p><em>x_axis</em> and <em>y_axis</em> fields capture analog input from a joystick, determining direction and speed.
<em>nav_bttn</em> represents a joystick push-button.</p>
<p><em>led</em> allows the transmitter to toggle an onboard LED and is used for status indication (e.g. pairing, battery warning, etc).</p>
<p><em>motor1_rpm_pwm</em> to <em>motor4_rpm_pwm</em> provide individual PWM signals to four DC motors.
This enables fine-grained speed control, supports differential drive configurations, and even allows for maneuvering in multi-directional platforms like omni-wheel robots.</p>
<section id="why-use-attribute-packed">
<h3><span class="section-number">3.1.1. </span>Why use __attribute((packed))?<a class="headerlink" href="#why-use-attribute-packed" title="Link to this heading"></a></h3>
<p>ESP-NOW uses fixed-size data packets (up to 250 bytes). The <em>__attribute__((packed))</em> removes compiler-added padding for precise byte alignment.</p>
<p>As <em>packed</em> attribute tells the compiler not to add any padding between fields in memory, this makes the struct:</p>
<blockquote>
<div><ul class="simple">
<li><p>Compact</p></li>
<li><p>Predictable for serialization over protocols like UART or ESP-NOW</p></li>
<li><p>Ideal for low-latency transmission in embedded systems</p></li>
</ul>
</div></blockquote>
<p>This ensures the receiver interprets the exact byte layout you expect, minimizing bandwidth and maximizing compatibility across platforms.</p>
</section>
</section>
</section>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="Main">
<div class="sphinxsidebarwrapper">
<h1 class="logo"><a href="index.html">Byte Rider</a></h1>
<search id="searchbox" style="display: none" role="search">
<div class="searchformwrapper">
<form class="search" action="search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" placeholder="Search"/>
<input type="submit" value="Go" />
</form>
</div>
</search>
<script>document.getElementById('searchbox').style.display = "block"</script><h3>Navigation</h3>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="intro.html">1. OVERVIEW</a></li>
<li class="toctree-l1"><a class="reference internal" href="overview.html">2. HOW DOES IT WORK?</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">3. DATA STRUCTS</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#data-payload">3.1. Data Payload</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#why-use-attribute-packed">3.1.1. Why use __attribute((packed))?</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="transmitter.html">4. TRANSMITTER</a></li>
<li class="toctree-l1"><a class="reference internal" href="receiver.html">5. RECEIVER</a></li>
<li class="toctree-l1"><a class="reference internal" href="progress.html">6. WORK-IN-PROGRESS WALK THROUGH</a></li>
<li class="toctree-l1"><a class="reference internal" href="references.html">7. REFERENCES</a></li>
</ul>
<div class="relations">
<h3>Related Topics</h3>
<ul>
<li><a href="index.html">Documentation overview</a><ul>
<li>Previous: <a href="overview.html" title="previous chapter"><span class="section-number">2. </span>HOW DOES IT WORK?</a></li>
<li>Next: <a href="transmitter.html" title="next chapter"><span class="section-number">4. </span>TRANSMITTER</a></li>
</ul></li>
</ul>
</div>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="footer">
&#169;2025, Alexander B.
|
Powered by <a href="https://www.sphinx-doc.org/">Sphinx 8.2.3</a>
&amp; <a href="https://alabaster.readthedocs.io">Alabaster 1.0.0</a>
|
<a href="_sources/data.rst.txt"
rel="nofollow">Page source</a>
</div>
</body>
</html>