Processing 的 GaussSense SDK 在範例中示範了基本的函式使用方法,可以視覺化 Mini GaussSense 所感測到的磁場,與運算後所得到的磁場重心、旋轉角度與傾斜狀態。
準備好 Processing 開發環境並下載 Processing 的 GaussSense SDK 後,點選 File > Examples… 中的 Contributed Libraries > GaussSense SDK for Processing,如下方左圖所示,可看到 GaussSense SDK 中 Basics 中有 9 個基本範例,此篇將介紹前五個範例內容:
We are going through the first 5 examples here.
打開第一個 e1_HelloGaussSense
可以看見原始磁場資料視覺化的結果,使用 drawRawData2D 函式會在此 Processing 視窗大小中畫出感測到的磁場資訊,可以改變裡面的寬跟高來產生自己想要的圖形大小:
gs.drawRawData2D(this.width, this.height);
第二個範例 e2_UpsampledData2d
可以將原始磁場資料透過演算法提昇磁場的精細度,產生較細緻的磁場資訊,使用 drawUpsampledData2D 函式時需要填入一個 upsampleFactor 正整數,此整數可以為 1 ~ 10 之間,越大代表細緻程度越高:
int upsampleFactor = 5; // Set between 1 ~ 10 gs.drawUpsampledData2D(this.width, this.height, upsampleFactor);
GData
在繼續之前,我們先看看 GData 資料型態。
GData 儲存了一個磁極輪廓的基本資訊,包含它的 2 維位置、磁場強度、旋轉角度與傾斜程度等等。
Get Methods | 回傳值 | 意義 |
---|---|---|
getX() | float | 顯示視窗裡的 X 座標。 |
getY() | float | 顯示視窗裡的 Y 座標。 |
getIntensity() | int | 磁場強度 單位: Gauss |
getAngle() | float | 旋轉角度 單位: Radian |
getPitch() | float | 傾斜程度 |
getPolarity() | int | 磁場極性 (0: 北極, 1: 南極) |
第三個範例 e3_Basic_BipolarPoints
將展示如何取出兩極磁場個別的重心位置,對應到視窗的座標系中,使用 drawBasicBipolarPoints 可以直接在視窗中畫出兩極磁場個別的重心,使用 getNorthPoint/getSouthPoint 則是取出以 GData 包裝的磁場的資料
float thld = 15; // Unit: Gauss float PointRadius = 15; // 畫出兩極磁場個別的重心位置 gs.drawBasicBipolarPoints(thld, PointRadius); // 畫出單極磁場的重心位置 gs.drawBasicNorthPoint(thld, PointRadius); gs.drawBasicSouthPoint(thld, PointRadius); // 取出 N/S 極磁場資訊 GData pNorth = gs.getNorthPoint(thld); GData pSouth = gs.getSouthPoint(thld);
磁場的分布狀況讓我們可以解析出目前磁鐵的傾斜程度,第四個範例 e4_TiltableBipolarPoints
可以取出 N/S 極磁場個別的傾斜程度,drawTiltableNorthPoint/drawTiltableSouthPoint 可以直接以直線的方向與長度畫出傾斜的方向和程度:
float lowThld = 15; float highThld = 30; // Select high and low thresholds to draw the tilt of N/S polar point gs.drawTiltableNorthPoint(lowThld, highThld); gs.drawTiltableSouthPoint(lowThld, highThld); // Get information (position, intensity, angle, pitch) of N/S polar point GData pTiltableNorth = gs.getTiltableNorthPoint(lowThld, highThld); GData pTiltableSouth = gs.getTiltableSouthPoint(lowThld, highThld);
當把磁鐵直立時,N/S 極可以同時被 GaussSense 感測,當兩極同時存在時,我們也可以使用兩極磁場中心解析出旋轉角度與傾斜程度,第五個範例 e5_RollAndTiltUsingBipolarMidPoint
可直接取出兩極中點和其旋轉、傾斜資訊:
float thld = 15; float RectSize = 60; // Draw midpoint with intensity threshold and size specified gs.drawBasicBipolarMidpoint(thld, RectSize); // Get information (position, intensity, angle, pitch) of midpoint GData pBipolarMidpoint = gs.getBipolarMidpoint(thld);
接下來將介紹如何連結四顆 Mini GaussSense 擴大感測範圍!或是開始學習使用為 Mini GaussSense 設計的 NFC 擴充套件。
回到教學文件目錄