343 lines
15 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Workflow: Sensor Data Mapping | HiAPI-C# 2025 </title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="title" content="Workflow: Sensor Data Mapping | HiAPI-C# 2025 ">
<link rel="icon" href="../img/HiAPI.favicon.ico">
<link rel="stylesheet" href="../public/docfx.min.css">
<link rel="stylesheet" href="../public/main.css">
<meta name="docfx:navrel" content="../toc.html">
<meta name="docfx:tocrel" content="toc.html">
<meta name="docfx:rel" content="../">
<meta name="loc:inThisArticle" content="In this article">
<meta name="loc:searchResultsCount" content="{count} results for &quot;{query}&quot;">
<meta name="loc:searchNoResults" content="No results for &quot;{query}&quot;">
<meta name="loc:tocFilter" content="Filter by title">
<meta name="loc:nextArticle" content="Next">
<meta name="loc:prevArticle" content="Previous">
<meta name="loc:themeLight" content="Light">
<meta name="loc:themeDark" content="Dark">
<meta name="loc:themeAuto" content="Auto">
<meta name="loc:changeTheme" content="Change theme">
<meta name="loc:copy" content="Copy">
<meta name="loc:downloadPdf" content="Download PDF">
<script type="module" src="./../public/docfx.min.js"></script>
<script>
const theme = localStorage.getItem('theme') || 'auto'
document.documentElement.setAttribute('data-bs-theme', theme === 'auto' ? (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light') : theme)
</script>
</head>
<body class="tex2jax_ignore" data-layout="" data-yaml-mime="">
<header class="bg-body border-bottom">
<nav id="autocollapse" class="navbar navbar-expand-md" role="navigation">
<div class="container-xxl flex-nowrap">
<a class="navbar-brand" href="../index.html">
<img id="logo" class="svg" src="../img/HiAPI.logo.png" alt="">
</a>
<button class="btn btn-lg d-md-none border-0" type="button" data-bs-toggle="collapse" data-bs-target="#navpanel" aria-controls="navpanel" aria-expanded="false" aria-label="Toggle navigation">
<i class="bi bi-three-dots"></i>
</button>
<div class="collapse navbar-collapse" id="navpanel">
<div id="navbar">
<form class="search" role="search" id="search">
<i class="bi bi-search"></i>
<input class="form-control" id="search-query" type="search" disabled placeholder="Search" autocomplete="off" aria-label="Search">
</form>
</div>
</div>
</div>
</nav>
</header>
<main class="container-xxl">
<div class="toc-offcanvas">
<div class="offcanvas-md offcanvas-start" tabindex="-1" id="tocOffcanvas" aria-labelledby="tocOffcanvasLabel">
<div class="offcanvas-header">
<h5 class="offcanvas-title" id="tocOffcanvasLabel">Table of Contents</h5>
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" data-bs-target="#tocOffcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body">
<nav class="toc" id="toc"></nav>
</div>
</div>
</div>
<div class="content">
<div class="actionbar">
<button class="btn btn-lg border-0 d-md-none" type="button" data-bs-toggle="offcanvas" data-bs-target="#tocOffcanvas" aria-controls="tocOffcanvas" aria-expanded="false" aria-label="Show table of contents">
<i class="bi bi-list"></i>
</button>
<nav id="breadcrumb"></nav>
</div>
<article data-uid="Workflow-SensorMapping">
<h1 id="workflow-sensor-data-mapping">Workflow: Sensor Data Mapping</h1>
<p>This workflow covers mapping external sensor data (dynamometer, smart tool holder, accelerometer) to simulation toolpaths so that simulation steps can index real-world measurement data.</p>
<pre><code class="lang-mermaid">flowchart TD
Prepare[&quot;Prepare sensor CSV data&quot;]
Configure[&quot;Configure time mapping&quot;]
Simulate[&quot;Run simulation&quot;]
Map[&quot;Map data to simulation steps&quot;]
View[&quot;View mapped results&quot;]
Prepare --&gt; Configure --&gt; Simulate --&gt; Map --&gt; View
</code></pre>
<h2 id="overview">Overview</h2>
<p>Data mapping associates external sensor measurements with simulated machining steps. After mapping, each step can reference real-world force, torque, and acceleration data for:</p>
<ul>
<li>Inspecting machining states</li>
<li>Training milling coefficients (see <a class="xref" href="force-training.html">Workflow: Milling Force Parameter Training</a>)</li>
<li>Calibrating milling coefficients</li>
<li>Comparing simulated vs. measured forces</li>
</ul>
<p>Depending on data volume and application, mapping is either <strong>one-to-one</strong> (each step maps to one data point) or <strong>one-to-many</strong> (each step maps to multiple data points from high-sampling-rate sensors).</p>
<hr>
<h2 id="1-prepare-sensor-csv-data">1. Prepare Sensor CSV Data</h2>
<h3 id="sensor-data-format">Sensor Data Format</h3>
<p>The CSV file must have a header row with <code>ActualTime</code> and sensor channels:</p>
<table>
<thead>
<tr>
<th>Source</th>
<th>Headers</th>
<th>Aliases</th>
</tr>
</thead>
<tbody>
<tr>
<td>Dynamometer</td>
<td><code>Fx</code>, <code>Fy</code>, <code>Fz</code></td>
<td><code>Workpiece.Fx</code>, <code>Workpiece.Fy</code>, <code>Workpiece.Fz</code></td>
</tr>
<tr>
<td>Smart tool holder</td>
<td><code>Mx</code>, <code>My</code>, <code>Mz</code></td>
<td><code>Holder.Mx</code>, <code>Holder.My</code>, <code>Holder.Mz</code></td>
</tr>
<tr>
<td>Accelerometer</td>
<td><code>Ax</code>, <code>Ay</code>, <code>Az</code></td>
<td></td>
</tr>
</tbody>
</table>
<pre><code class="lang-csv">ActualTime,Mx,My,Mz
18:23:54.703,-0.02923,0.10733,0.00409
18:23:54.704,0.04155,-0.04457,0.00448
...
</code></pre>
<p>The time format is <code>&lt;hours&gt;:&lt;minutes&gt;:&lt;seconds&gt;.&lt;fractional seconds&gt;</code>. Additional fields (e.g., <code>CH1</code>, <code>CH2</code>) may be included and will be available after mapping.</p>
<h3 id="controller-data-format-for-two-layer-mapping">Controller Data Format (for Two-Layer Mapping)</h3>
<p>The controller CSV must contain at least <code>FileNo</code>, <code>LineNo</code>, and <code>ActualTime</code>:</p>
<pre><code class="lang-csv">FileNo,LineNo,ActualTime,MC.X,MC.Y,MC.Z,...
1,6,00:00:00.030,0,0,0.37,...
</code></pre>
<hr>
<h2 id="2-configure-time-mapping">2. Configure Time Mapping</h2>
<h3 id="strategy-a-one-to-one-mapping-mapsinglebycsvfile">Strategy A: One-to-One Mapping (MapSingleByCsvFile)</h3>
<p><a class="xref" href="../api/Hi.MachiningProcs.SessionShell.html#Hi_MachiningProcs_SessionShell_MapSingleByCsvFile_">MapSingleByCsvFile</a> reads a CSV file and uses time interpolation to map each data point to one simulation step.</p>
<pre><code class="lang-csharp">PlayNcFile(&quot;NC/file1.nc&quot;);
MapSingleByCsvFile(&quot;Data/sensor.csv&quot;);
</code></pre>
<h3 id="strategy-b-one-to-one-via-playcsvfile">Strategy B: One-to-One via PlayCsvFile</h3>
<p><a class="xref" href="../api/Hi.MachiningProcs.SessionShell.html#Hi_MachiningProcs_SessionShell_PlayCsvFile_">PlayCsvFile</a> can drive the simulation directly from CSV data, where each row becomes one step. Custom fields in the CSV are automatically available on each step.</p>
<pre><code class="lang-csharp">PlayCsvFile(&quot;Data/controller.csv&quot;);
</code></pre>
<h3 id="strategy-c-one-to-many-global-mapping-mapseriesbycsvfile">Strategy C: One-to-Many Global Mapping (MapSeriesByCsvFile)</h3>
<p>For high-sampling-rate data, first establish <code>ActualTime</code> via one-to-one mapping, then map the series:</p>
<pre><code class="lang-csharp">PlayNcFile(&quot;NC/file1.nc&quot;);
MapSingleByCsvFile(&quot;Data/controller.csv&quot;); // establishes ActualTime
MapSeriesByCsvFile(&quot;Data/sensor.csv&quot;); // maps high-rate series
</code></pre>
<h3 id="strategy-d-one-to-many-local-mapping-anchor-based">Strategy D: One-to-Many Local Mapping (Anchor-Based)</h3>
<p>For mapping sensor data to specific NC path segments using anchors.</p>
<p><strong>Step 1 — Specify input data and time ranges:</strong></p>
<pre><code class="lang-csharp">ClearTimeMappingData();
AddTimeDataByFile(&quot;lineA&quot;, &quot;Mapping/sensor1.csv&quot;, &quot;18:25:51.7100&quot;, &quot;18:26:12.9910&quot;);
AddTimeDataByFile(&quot;lineB&quot;, &quot;Mapping/sensor1.csv&quot;, &quot;18:26:30.5750&quot;, &quot;18:27:12.2880&quot;);
</code></pre>
<p><strong>Step 2 — Specify NC path anchors</strong> (embedded in NC code):</p>
<pre><code>X13. F20 ;@LineSelection(&quot;lineA&quot;, FirstTouch, ShiftTime_s(2), LineEnd, ShiftDistance_mm(-1));
X25. F10 ;@LineSelection(&quot;lineB&quot;, FirstTouch, null, LastTouch, null);
</code></pre>
<p>For range mapping across multiple NC lines, use <code>BeginSelection</code> / <code>EndSelection</code>:</p>
<pre><code>;@BeginSelection(&quot;region1&quot;, LineBegin, null);
...
;@EndSelection(&quot;region1&quot;, LineEnd, null);
</code></pre>
<p><strong>Anchor Flags:</strong></p>
<table>
<thead>
<tr>
<th>Flag</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>LineBegin</code></td>
<td>Motion start point of the line</td>
</tr>
<tr>
<td><code>LineEnd</code></td>
<td>Motion end point of the line</td>
</tr>
<tr>
<td><code>FirstTouch</code></td>
<td>First contact with the workpiece</td>
</tr>
<tr>
<td><code>LastTouch</code></td>
<td>Last contact with the workpiece</td>
</tr>
</tbody>
</table>
<p><strong>Offset Options:</strong></p>
<table>
<thead>
<tr>
<th>Offset</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>null</code></td>
<td>No offset</td>
</tr>
<tr>
<td><code>ShiftTime_s(&lt;seconds&gt;)</code></td>
<td>Time-based offset (positive = forward)</td>
</tr>
<tr>
<td><code>ShiftDistance_mm(&lt;mm&gt;)</code></td>
<td>Distance-based offset (positive = forward)</td>
</tr>
</tbody>
</table>
<div class="NOTE">
<h5>Note</h5>
<p>For FANUC controllers that do not support <code>;</code> as a comment character, enclose the script command in a comment block:</p>
<pre><code>X13. F20 (;@LineSelection(&quot;lineA&quot;, FirstTouch, null, LineEnd, null);)
</code></pre>
</div>
<h3 id="map-on-selection-end">Map on Selection End</h3>
<p><a class="xref" href="../api/Hi.MachiningProcs.SessionShell.html#Hi_MachiningProcs_SessionShell_EnableMapOnSelectionEnd">EnableMapOnSelectionEnd</a> controls automatic mapping when a selection ends (default: <code>true</code>):</p>
<pre><code class="lang-csharp">EnableMapOnSelectionEnd = true; // EndSelection triggers Map automatically
</code></pre>
<h3 id="clearing-mapping-data">Clearing Mapping Data</h3>
<p>Mapping data persists across player resets. To clear:</p>
<pre><code class="lang-csharp">ClearTimeMappingData();
</code></pre>
<hr>
<h2 id="3-run-simulation">3. Run Simulation</h2>
<pre><code class="lang-csharp">PlayNcFile(&quot;NC/file1.nc&quot;);
</code></pre>
<div class="NOTE">
<h5>Note</h5>
<p><strong>Why interpret NC code instead of playing CSV directly?</strong>
The system NC interpreter produces more accurate simulation paths than direct controller CSV playback, which has limited sampling resolution that distorts tool paths.</p>
</div>
<hr>
<h2 id="4-map-data">4. Map Data</h2>
<p>After simulation, apply the mapping strategy chosen in step 2. For the two-layer chained approach:</p>
<pre><code class="lang-csharp">// Chain 1: Controller data → simulation steps (via FileNo/LineNo → ActualTime)
MapSingleByCsvFile(&quot;Data/controller.csv&quot;);
// Chain 2: Sensor data → simulation steps (via ActualTime → sensor readings)
MapSeriesByCsvFile(&quot;Data/sensor.csv&quot;);
</code></pre>
<p>The chaining works because:</p>
<ul>
<li>Simulation steps and controller data share <code>FileNo</code>/<code>LineNo</code> anchors</li>
<li>Controller data and sensor data share <code>ActualTime</code> anchors</li>
<li>After chaining, simulation steps can index sensor data</li>
</ul>
<div class="TIP">
<h5>Tip</h5>
<p>Due to machine acceleration/deceleration, simulation time and actual time diverge over longer durations. Anchor-based linear projection corrects for this drift.</p>
</div>
<hr>
<h2 id="5-view-mapped-results">5. View Mapped Results</h2>
<p>After mapping, sensor data is available on each step. Use the UI to:</p>
<ul>
<li>View color gradient maps on the workpiece geometry</li>
<li>Inspect time-series charts</li>
<li>Click-to-track specific data channels</li>
</ul>
<p>Export mapped results:</p>
<pre><code class="lang-csharp">WriteStepFiles(&quot;Output/[NcName].step.csv&quot;);
WriteShotFiles(&quot;Output/[NcName].shot.csv&quot;, 1);
</code></pre>
<hr>
<h2 id="complete-two-layer-mapping-example">Complete Two-Layer Mapping Example</h2>
<pre><code class="lang-csharp">// Configure resolution
MachiningResolution_mm = 0.125;
EnablePhysics = true;
// Clear any previous mapping data
ClearTimeMappingData();
// Run simulation using NC interpreter for accurate paths
PlayNcFile(&quot;NC/machining.nc&quot;);
// Map controller data (contains FileNo, LineNo, ActualTime)
MapSingleByCsvFile(&quot;Data/controller.csv&quot;);
// Map high-rate sensor data (contains ActualTime and force/torque)
MapSeriesByCsvFile(&quot;Data/sensor.csv&quot;);
// Export results
WriteStepFiles(&quot;Output/[NcName].step.csv&quot;);
</code></pre>
<h2 id="see-also">See Also</h2>
<ul>
<li><a class="xref" href="force-training.html">Workflow: Milling Force Parameter Training</a> — using mapped data for coefficient training</li>
<li><a class="xref" href="basic-simulation.html">Workflow: Basic Machining Simulation</a> — basic simulation setup</li>
<li><a class="xref" href="../manual/runtime/step.html">Step</a> — step data model</li>
<li><a class="xref" href="../manual/runtime/session-shell.html">Glossary: SessionShell Quick-Reference</a> — SessionShell quick-reference</li>
<li><a class="xref" href="examples/mapping-demo.html">Example Project: Mapping Controller and Sensor Data to Simulated NC Toolpaths and Updating Milling Coefficients</a> — mapping demo example project</li>
<li><a class="xref" href="examples/milling-training-dynamometer.html">Example Project: Training Milling Coefficients with a Dynamometer</a> — dynamometer training example project</li>
</ul>
</article>
<div class="contribution d-print-none">
</div>
<div class="next-article d-print-none border-top" id="nextArticle"></div>
</div>
<div class="affix">
<nav id="affix"></nav>
</div>
</main>
<div class="container-xxl search-results" id="search-results"></div>
<footer class="border-top text-secondary">
<div class="container-xxl">
<div class="flex-fill">
<span> Copyright © 2025 <a href='https://superhightech.com.tw'>Tech Coordinate</a>. All rights reserved. <a href='https://superhightech.com.tw'>超級高科技股份有限公司</a> © 2025 版權所有 </span>
</div>
</div>
</footer>
</body>
</html>