馬達版控制 API === [TOC] ## gCode ### gCode 檔名與格式 gCode 目前是使用文字檔格式,並不侷限副檔名。 為了一些編輯器顯示語法提示的方便, 可使用附檔名為 .js 或 .c 都以開啟編輯器的語法提示。 ### Comment %[debugLevel] 註解 Example: %0 設定軸向代碼 %1 設定速度 與 Debug Level 設定搭配可過濾希望列印的字串 // 註解 此種註解將永不被列印 ### Debug level Example: debug=1 Debug Level = 1 , 此時 debug level 小於 1 的字串將不被列印 ### 設定軸代號 Example: y=axis0 v=axis1 m=axis2 x=axis3 將第 0 軸馬達代碼設為 y 將第 1 軸馬達代碼設為 v 將第 2 軸馬達代碼設為 m 將第 3 軸馬達代碼設為 x ### 建立軸座標變數 軸代碼+數字的變數 Example: y0=5000 // 建立 y 軸座標變數,數值為 5000 y1=10000 y2=y0+y1 ### 設定軸座標 Example: y0=500 // 建立軸座標變數 y0 y1=y0+1000 // 建立軸座標變數 y1 v0=1000 // 建立軸座標變數 v0 x0=5000 // 建立軸座標變數 x0 y0 // 設定 y 軸移動到座標變數 y0 的位置,結束後才執行下一行 v0 // 設定 v 軸移動到座標變數 v0 的位置,結束後才執行下一行 x0,y1,v0 // 設定 x ,y,v 軸,同步移動到對應軸變數位置,全部移動完成才執行下一行 ### 常用變數 * 軸代號+"_POS": 此變數代表目前軸座標位置 Example: y_POS , x_POS , m_POS , v_POS Usage: y_POS=500 , origPos=y_POS * 軸代號+"_VL": 此變數代表目前軸速度 Level Example: y_VL , x_VL , m_VL , v_VL Usage: y_VL=1 , origVL=y_VL * 軸代號+"_VTL": 此變數代表目前軸移動的 Torque Level Example: y_VTL , x_VTL , m_VTL , v_VTL Usage: y_VTL=1 , origVL=y_VTL ### 一般變數宣告 只要不是上述常用變數名稱之非數字開頭字串,皆可當作變數名稱使用 Example: tmp, cc .... ### 常用函式 * INIT: 重新初始化馬達參數 * HOME: 將馬達座標移到 HOME 的位置 * SEARCH_SWITCH: 將馬達座標重新回歸到對位感測器的位置 * GET_POSITION: 從馬達版重新讀取座標,更新到常用變數的目前軸座標變數中 <b> 一般 GET_POSITION 不常被使用,因為任何移動指令都會更新軸的位置到常用變數中 </b> ### include Example: include "function2.js" 插入 function2.js 內的 gCode 到此行中 ### 副程式宣告 Example: function getTip(x) { x_pos=500+x v1 v0 x_pos=600+x } getTip(100) ### Delay Example: delay 200 // 200 ms ### For loop Example: [20] { x0,y1,v2 delay 250 x0,y1,v0 delay 250 } ## MQTT * IP: localhost * MQTT Port: 2002 * MQTT over WebSocket Port: 2001 * Host Topic: /katsura/motor/host * Client Topic: /katsura/motor/client ### Motor Init * Send payload : ``` { command: 'init' } ``` * Response: ``` { status: 'init done' } ``` ### Get Position * Send payload : ``` { motorIndex: 0, command: 'getPosition' } ``` * Response: ``` { status: 'getPosition done', value: [axis0_POS,axis1_POS,axis2_POS...] } ``` ### Move * Send payload : ``` { motorIndex: 0, axis=0, target=1000, command: 'move' } ``` * Response: ``` { status: 'move done', motorIndex: 0, axis=0, target=1000, } ``` ### Search Switch * Send payload : ``` { command: 'searchSwitch' } ``` * Response: ``` { status: 'searchSwitch done', } ``` ### Torque Off * Send payload : ``` { command: 'torqueOff' } ``` * Response: ``` { status: 'torqueOff done', } ``` ### Teaching * Send payload : ``` { command: 'teaching', motorIndex: 0, axis=0, } ``` * Response: ``` { status: 'teaching done', motorIndex: 0, axis=0, } ``` ### Save Origin 儲存 HOME 座標 * Send payload : ``` { command: 'saveOrigin', } ``` * Response: ``` { status: 'saveOrigin done',/ } ``` ### HOME * Send payload : ``` { command: 'home', } ``` * Response: ``` { status: 'home done', } ``` ### Load Script * Send payload : ``` { command: 'loadScript', file: 'script'+FILENAME, } ``` * Response: ``` { status: 'loadScript done', } ``` ### Start Script * Send payload : ``` { command: 'startScript', } ``` * Response: ``` { status: 'startScript done', } ```