Skip to content

Commit

Permalink
Merge pull request #801 from entrylabs/develop-hw
Browse files Browse the repository at this point in the history
1.9.61 PR
  • Loading branch information
Tnks2U authored Dec 20, 2024
2 parents 10a0a80 + be45d4d commit 48f368b
Show file tree
Hide file tree
Showing 10 changed files with 288 additions and 20 deletions.
75 changes: 71 additions & 4 deletions app/modules/avatarbot.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,15 @@ function Module() {
Osci: 27000000,
Freq: 50
}

this.Board_Servo = {
Pulse_Min: 150,
Pulse_Max: 600,
us_Min: 400,
us_Max: 2100
us_Max: 2100,
angle: 90
}

this.Board_LED_Strip = {
En:0,
sample: 0,
Expand Down Expand Up @@ -133,7 +136,9 @@ Module.prototype.init = function(handler, config) {
this.remoteDataSet[index+6] = (this.Board_Servo.us_Min>>8)&0xff;

this.remoteDataSet[index+7] = (this.Board_Servo.us_Max)&0xff;
this.remoteDataSet[index+8] = (this.Board_Servo.us_Max>>8)&0xff;
this.remoteDataSet[index+8] = (this.Board_Servo.us_Max>>8)&0xff;

this.remoteDataSet[index+9] = (this.Board_Servo.angle)&0xff;
}

// led
Expand Down Expand Up @@ -203,10 +208,14 @@ slave 모드인 경우 duration 속성 간격으로 지속적으로 기기에
Module.prototype.requestLocalData = function() {
var queryString = [];
var data = this.remoteDataSet; // Module 객체의 dataset table read. max length 200
var checksum = 0;
for (var index = 0; index < this.avatarBotDataSet; index++) {
var query = (data[index])&0xff;
queryString.push(query); // 1byte
checksum += query;
}
checksum = (checksum)&0xff;
queryString.push(checksum); // 1byte
/*
for(var i=0; i<(data.length/10); i++)
{
Expand All @@ -222,13 +231,20 @@ Module.prototype.requestLocalData = function() {
};

// 하드웨어에서 온 데이터 처리
/*
Module.prototype.handleLocalData = function(data) {
var self = this;
for (var i = 0; i < data.length; i++) {
self.dataSet[self.dataSet_index+i] = data[i];
}


console.log('data length ', data.length);
for(var j=0; j<21; j++)
{
let i = j*10;
console.log('data ',i, ': ', self.dataSet[i], self.dataSet[i+1], self.dataSet[i+2], self.dataSet[i+3], self.dataSet[i+4], self.dataSet[i+5],
self.dataSet[i+6], self.dataSet[i+7], self.dataSet[i+8], self.dataSet[i+9]);
}
if(self.dataSet[0] === 0x99 && self.dataSet[1] === 0x01 && self.dataSet[2] === 0x01 && self.dataSet[3] === self.avatarBotDataSet)
{
self.dataSet_index = self.dataSet_index + data.length;
Expand All @@ -250,6 +266,57 @@ Module.prototype.handleLocalData = function(data) {
};
*/
Module.prototype.handleLocalData = function(data) {
var self = this;
// data.length => 211
var checksum = 0;
var getChecksum = 0;
for (var i = 0; i < data.length; i++) {
if(self.dataSet.length > i)
{
self.dataSet[self.dataSet_index+i] = data[i];
checksum += data[i];
}else{
// last buffer
getChecksum = data[i];
}
}

checksum = (checksum)&0xff;

/*
console.log('data length ', data.length, ', checksum = ', checksum, ', getChecksum = ', getChecksum);
for(var j=0; j<21; j++)
{
let i = j*10;
console.log('data ',i, ': ', self.dataSet[i], self.dataSet[i+1], self.dataSet[i+2], self.dataSet[i+3], self.dataSet[i+4], self.dataSet[i+5],
self.dataSet[i+6], self.dataSet[i+7], self.dataSet[i+8], self.dataSet[i+9]);
}
*/

if(self.dataSet[0] === 0x99 && self.dataSet[1] === 0x01 && self.dataSet[2] === 0x01 && self.dataSet[3] === self.avatarBotDataSet && getChecksum == checksum)
{
self.dataSet_index = self.dataSet_index + (data.length-1);
}else{
self.dataSet_index = 0;
return;
}

if(self.dataSet_index == self.avatarBotDataSet){
self.originParsing(self.dataSet);
self.dataSet_index = 0;
self.dataSet[0] = 0; // clear
self.dataSet[1] = 0; // clear
self.dataSet[2] = 0; // clear
self.dataSet[3] = 0; // clear
//
// console.log('[jhkim] handleLocalData - dataSet_index[11] = ', self.dataSet[11]);
}


};


/* Original Parsing FF 55 ~ */
Module.prototype.originParsing = function(data) {
Expand Down
10 changes: 5 additions & 5 deletions app/modules/avatarbot.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"en": "AvatarBot",
"ko": "AvatarBot"
},
"category": "board",
"platform": ["win32", "darwin"],
"icon" : "avatarbot.png",
"module": "avatarbot.js",
Expand All @@ -13,18 +14,17 @@
"translate": "Arduino compatible driver"
},
"reconnect" : true,
"firmware": "http://avatarmecha.ddns.net:5050/sharing/iCuhzvxcu",
"select_com_port":true,
"entry": {
"protocol": "json"
},
"hardware": {
"type": "serial",
"type": "bluetooth",
"control": "slave",
"duration": 500,
"duration": 300,
"vendor": ["Arduino", "wch.cn", "FTDI"],
"baudRate": 460800,
"lostTimer": 1000,
"baudRate": 1000000,
"lostTimer": 2000,
"firmwarecheck": false
}
}
Binary file modified app/modules/avatarbot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions app/modules/jcboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ Module.prototype.handleLocalData = function(data) {
};

Module.prototype.requestRemoteData = function(handler) {
handler.write('A0', !!(this.sensorData[6] & 0x01));
handler.write('A1', !!(this.sensorData[6] & 0x02));
handler.write('A0', (this.sensorData[6] & 0x01)==0x01? 1 : 0);
handler.write('A1', (this.sensorData[6] & 0x02)==0x02? 1 : 0);
handler.write('A2', this.sensorData[7]);
handler.write('A3', this.sensorData[8]);
handler.write('A4', this.sensorData[9]);
Expand Down
4 changes: 2 additions & 2 deletions app/modules/jdcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,12 @@ Module.prototype.handleLocalData = function(data) {
});
if(dongleData[1] == (sum&0xFF)){
deviceType = 2;
sensorData[6] = true;
sensorData[6] = 1;
sensorData[15] = dongleData[5];
sensorData[7] = dongleData[9];
sensorData[8] = dongleData[7];
sensorData[9] = dongleData[8];
sensorData[10] = (dongleData[3]&0x03)? false : true;
sensorData[10] = (dongleData[3]&0x03)? 0 : 1;
sensorData[16] = dongleData[10];
sensorData[17] = dongleData[11];
sensorData[18] = dongleData[12];
Expand Down
175 changes: 175 additions & 0 deletions app/modules/robodog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
function Module() {
this.cmdData = [0x26, 0xA8, 0x14, 0x81, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00];
this.sensorData = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00];
this.dongleData = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00];
this.robodog_head = [0x26, 0xA8, 0x14, 0x8A];
this.rk_cnt = 0;
this.pktCnt = -1;
this.pktLength = 6;
this.ledPacket = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
this.txCnt = 0;
}

Module.prototype.init = function(handler, config) {
};

Module.prototype.requestInitialData = function() {
return null;
};

Module.prototype.checkInitialData = function(data, config) {
return true;
};

Module.prototype.validateLocalData = function(data) {
return true;
};



function checksum(cmd){
let sum = 0;

cmd.forEach(function (value, idx) {
if(idx > 5)
sum += value;
});
return sum&0xFF;
}


/////////////// 엔트리에서 받은 데이터에 대한 처리 /////////////////////
Module.prototype.handleRemoteData = function(handler) {
let cmd = handler.read('CMD');

if(typeof cmd !== 'object')
return;

this.cmdData = cmd.slice();
if(this.cmdData[14] > 0){
if(this.cmdData[14] == 2){
this.ledPacket[0] = (this.cmdData[14]&0xC0) | 0x82;
this.ledPacket[1] = this.ledPacket[1] | 0x80;
for(let n=0; n<16; n++)
this.ledPacket[2+n] = this.cmdData[24+n];
}
if(this.cmdData[14] == 3){
this.ledPacket[0] = (this.cmdData[14]&0xC0) | 0x83;
this.ledPacket[1] = this.ledPacket[1] | 0x80;
for(let n=0; n<16; n++)
this.ledPacket[2+n] = this.cmdData[24+n];
}
if(this.cmdData[14] == 4){
this.ledPacket[1] = (this.cmdData[14]&0xC0) | 0x44;
this.ledPacket[0] = this.ledPacket[0] | 0x40;
for(let n=0; n<16; n++)
this.ledPacket[18+n] = this.cmdData[24+n];
}
}
else{
this.ledPacket[0] = 0;
this.ledPacket[1] = 0;
}
};


//////////////// 하드웨어로 보낼 데이터 로직 /////////////
Module.prototype.requestLocalData = function() {
if(((this.ledPacket[0]&0xC0) == 0xC0) || ((this.ledPacket[1]&0xC0) == 0xC0)){
if((this.txCnt%2) == 0){
this.cmdData[14] = this.ledPacket[0];
for(let n=0; n<16; n++)
this.cmdData[24+n] = this.ledPacket[2+n];
}
else{
this.cmdData[14] = this.ledPacket[1];
for(let n=0; n<16; n++)
this.cmdData[24+n] = this.ledPacket[18+n];
}
this.cmdData[5] = checksum(this.cmdData);
this.txCnt += 1;
}
return this.cmdData;
};

///////////// 하드웨어에서 온 데이터 처리 ///////////////////
Module.prototype.handleLocalData = function(data) {
let sensorData = this.sensorData;
let dongleData = this.dongleData;
let pktLength = this.pktLength;

let robodog_head = this.robodog_head;
data.forEach(function (value) {
this.rk_cnt = (value==robodog_head[this.rk_cnt])? this.rk_cnt+1 : 0;
if(this.rk_cnt == 4){
this.rk_cnt = 0;
this.pktCnt = 0;
}
else if(this.pktCnt >= 0){
if(this.pktCnt == 0)
pktLength = ((value>0) && (value<19))? value-4 : 16;
dongleData[4+this.pktCnt++] = value;
}

if(this.pktCnt == pktLength){
this.pktCnt = -1;
var sum = 0;
dongleData.forEach(function (value, idx) {
if(idx > 5)
sum += value;
});
if(dongleData[5] == (sum&0xFF)){
dongleData.forEach(function (value, idx) {
sensorData[idx] = value;
});
}
}
});
this.pktLength = pktLength;
};

function unsingToSign8(data)
{
return data>127? data-256 : data;
}
function unsingToSign16(data)
{
return data>32767? data-65536 : data;
}

///////////// 엔트리로 전달할 데이터 ///////////////////////////
Module.prototype.requestRemoteData = function(handler) {
handler.write("SENSORDATA", this.sensorData);
handler.write('BATTERY', this.sensorData[6]);
handler.write('TOF', this.sensorData[7]);
handler.write('ROLL', unsingToSign8(this.sensorData[8]));
handler.write('PITCH', unsingToSign8(this.sensorData[9]));
handler.write('YAW', unsingToSign16(this.sensorData[10] + this.sensorData[11]*256));
handler.write('RB0', this.sensorData[12]>127? this.sensorData[12]-256 : this.sensorData[12]);
handler.write('RB1', this.sensorData[13]>127? this.sensorData[13]-256 : this.sensorData[13]);
handler.write('RB2', this.sensorData[14]>127? this.sensorData[14]-256 : this.sensorData[14]);
handler.write('RB3', this.sensorData[15]>127? this.sensorData[15]-256 : this.sensorData[15]);
handler.write('BUTTON', this.sensorData[16]);
handler.write('RB_WATCHDOG', this.sensorData[17]);
handler.write('RB4', this.sensorData[18]>127? this.sensorData[18]-256 : this.sensorData[18]);
handler.write('RB5', this.sensorData[19]>127? this.sensorData[19]-256 : this.sensorData[19]);
};

Module.prototype.reset = function() {
this.cmdData = [0x26, 0xA8, 0x14, 0x81, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64];
this.sensorData = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00];
this.ledPacket = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
console.log("reset");
};

module.exports = new Module();
26 changes: 26 additions & 0 deletions app/modules/robodog.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"id": "1D0501",
"name": {
"en": "RoboDog",
"ko": "로보독"
},
"category": "robot",
"platform": ["win32", "darwin"],
"icon": "robodog.png",
"module": "robodog.js",
"url": "http://www.junilab.co.kr",
"driver": {
"win32-ia32": "JuniLab/dongleSetup.bat",
"win32-x64": "JuniLab/dongleSetup.bat"
},
"reconnect": true,
"hardware": {
"type": "serial",
"control": "slave",
"duration": 32,
"vendor": "Junilab_Inc",
"pnpId": "0226",
"baudRate": 19200,
"firmwarecheck": false
}
}
Binary file added app/modules/robodog.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 48f368b

Please sign in to comment.