From 2817bd081d6d6515563415412388c03569d9dcb6 Mon Sep 17 00:00:00 2001 From: Jason Kim Date: Wed, 13 Mar 2024 17:57:21 +0900 Subject: [PATCH 01/18] =?UTF-8?q?auto=20report=20=ED=8C=A8=ED=82=B7=20pars?= =?UTF-8?q?ing=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../robotis_RB100_Practical_AssemblyBT.json | 2 +- app/modules/robotis_RB100_practice.js | 1048 +++++++++++++++++ 2 files changed, 1049 insertions(+), 1 deletion(-) create mode 100644 app/modules/robotis_RB100_practice.js diff --git a/app/modules/robotis_RB100_Practical_AssemblyBT.json b/app/modules/robotis_RB100_Practical_AssemblyBT.json index 7ff42b9f7..346ac260f 100644 --- a/app/modules/robotis_RB100_Practical_AssemblyBT.json +++ b/app/modules/robotis_RB100_Practical_AssemblyBT.json @@ -7,7 +7,7 @@ "category": "module", "platform": ["win32"], "icon" : "robotis_RB100im_Practical_Assembly.png", - "module": "robotis_RB100_Practice_Course.js", + "module": "robotis_RB100_practice.js", "url": "http://www.steamcup.org/ko/", "email": "jason@robotis.com", "reconnect" : true, diff --git a/app/modules/robotis_RB100_practice.js b/app/modules/robotis_RB100_practice.js new file mode 100644 index 000000000..218183858 --- /dev/null +++ b/app/modules/robotis_RB100_practice.js @@ -0,0 +1,1048 @@ +function Module() { + this.isReadDataArrived = true; + this.isConnected = true; + this.addressToRead = []; + this.varTimeout = null; + + this.prevInstruction = 0; + this.prevAddress = []; + this.prevLength = []; + this.prevValue = []; + + this.servoPrevAddres = []; // add by kjs 20170627 + this.servoPrevLength = []; // add by kjs 20170627 + this.servoPrevValue = []; // add by kjs 20170627 + this.servoPrevAddres2 = []; // add by kjs 20170627 + this.servoPrevLength2 = []; // add by kjs 20170627 + this.servoPrevValue2 = []; // add by kjs 20170627 + this.servoPrevAddres3 = []; // add by kjs 20170627 + this.servoPrevLength3 = []; // add by kjs 20170627 + this.servoPrevValue3 = []; // add by kjs 20170627 + this.servoPrevAddres4 = []; // add by kjs 20170627 + this.servoPrevLength4 = []; // add by kjs 20170627 + this.servoPrevValue4 = []; // add by kjs 20170627 + + this.receiveBuffer = []; // buffer to receive from H/W + this.dataBuffer = []; // saved sensor value buffer + this.robotisBuffer = []; // buffer to save 'ROBOTIS_DATA' + this.receiveAddress = -1; // to check read packet + this.receiveLength = -1; // to check read packet + this.defaultLength = -1; // to check read packet + + this.packetReceiveState = 0; + this.headerCount = 0; + + this.isFront = 32; // add by kjs 170511 + this.prevRightValue = 0; + this.prevLeftValue = 0; + this.isRight = false; + + //this.touchSensor = 0; + this.humidity = []; + this.temperature = []; + this.colorSensor = []; + this.touchSensor = []; + this.irSensor = []; + this.lightSensor = []; + this.detectedSound = 0; + this.detectringSound = 0; + this.userButtonState = 0; + this.isUpdate = []; // add by kjs 170623 + this.prevState = []; // add by kjs 170623 +} + +Module.prototype.init = function(handler, config) { + //console.log("######### init"); + +}; + +Module.prototype.lostController = function(self, callback) { + self.timer = setInterval(() => { + if (self.connected) { + if (self.received == false) { + if (this.isConnected == false) { + self.connected = false; + if (callback) { + callback('lost'); + } + } + this.isConnected = false; + } + self.received = false; + } + }, 1000); +}; + +Module.prototype.requestInitialData = function() { + //console.log("######### requestInitialData"); + this.isReadDataArrived = true; + this.isConnected = true; + this.addressToRead = []; + this.varTimeout = null; + + this.prevInstruction = 0; + this.prevAddress = []; + this.prevLength = []; + this.prevValue = []; + + this.servoPrevAddres = []; + this.servoPrevLength = []; + this.servoPrevValue = []; + + this.receiveBuffer = []; + this.dataBuffer = []; + this.robotisBuffer = []; + this.receiveAddress = -1; + this.receiveLength = -1; + this.defaultLength = -1; + + //this.touchSensor = 0; + this.colorSensor = []; + this.temperature = []; + this.humidity = []; + this.touchSensor = []; + this.irSensor = []; + this.lightSensor = []; + this.detectedSound = 0; + this.detectringSound = 0; + this.userButtonState = 0; + + this.servoPrevAddres = []; // add by kjs 20170627 + this.servoPrevLength = []; // add by kjs 20170627 + this.servoPrevValue = []; // add by kjs 20170627 + this.servoPrevAddres2 = []; // add by kjs 20170627 + this.servoPrevLength2 = []; // add by kjs 20170627 + this.servoPrevValue2 = []; // add by kjs 20170627 + this.servoPrevAddres3 = []; // add by kjs 20170627 + this.servoPrevLength3 = []; // add by kjs 20170627 + this.servoPrevValue3 = []; // add by kjs 20170627 + this.servoPrevAddres4 = []; // add by kjs 20170627 + this.servoPrevLength4 = []; // add by kjs 20170627 + this.servoPrevValue4 = []; // add by kjs 20170627 + + this.robotisBuffer.push([INST_WRITE, 21, 2, 20]); + this.robotisBuffer.push([INST_WRITE, 19, 1, 1]); // bypass 모드 켜기 + this.robotisBuffer.push([INST_WRITE, 20, 1, 0]); // bypass port를 BLE로 설정 + this.robotisBuffer.push([INST_WRITE, 23, 1, 1]); // auto report 기능 켜기 + + return this.readPacket(200, 0, 2); +}; + +Module.prototype.checkInitialData = function(data, config) { + console.log('######### checkInitialData'); + + return true; +}; + +Module.prototype.validateLocalData = function(data) { + return true; +}; + +Module.prototype.requestRemoteData = function(handler) { + for (let indexA = 0; indexA < this.dataBuffer.length; indexA++) { // 일반형 + if (this.dataBuffer[indexA] != undefined) { + // console.log("indexA: " + indexA + " value: " + this.dataBuffer[indexA]); + if (indexA == 55) { + console.log(`requestRemoteData: ${this.dataBuffer[indexA]}`); + } + handler.write(indexA, this.dataBuffer[indexA]); + } + } + //실과형 + //console.log("###### value : " + this.detectedSound); + for (let i = 0; i < 4; i++) { + handler.write(`TOUCH${i}`, this.touchSensor[i]); // 접촉 센서 + handler.write(`IR${i}`, this.irSensor[i]); // 적외선 센서 + handler.write(`LIGHT${i}`, this.lightSensor[i]); // 조도 센서 + handler.write(`COLOR${i}`, this.colorSensor[i]); // 칼라 센서 + handler.write(`HUMIDTY${i}`, this.humidity[i]); // 습도 센서 + handler.write(`TEMPERATURE${i}`, this.temperature[i]); // 온도 센서 + } + handler.write('DETECTEDSOUNDE', this.detectedSound); // 최종 소리 감지 횟수 + handler.write('DETECTINGSOUNDE1', this.detectringSound); // 실시간 소리 감지 횟수 + handler.write('USERBUTTONSTATE', this.userButtonState); +}; + +Module.prototype.handleRemoteData = function(handler) { + const data = handler.read('ROBOTIS_DATA'); + + const setZero = handler.read('setZero'); + if (setZero[0] == 1) { + this.robotisBuffer = []; + + this.servoPrevAddres = []; // add by kjs 20170627 + this.servoPrevLength = []; // add by kjs 20170627 + this.servoPrevValue = []; // add by kjs 20170627 + this.servoPrevAddres2 = []; // add by kjs 20170627 + this.servoPrevLength2 = []; // add by kjs 20170627 + this.servoPrevValue2 = []; // add by kjs 20170627 + this.servoPrevAddres3 = []; // add by kjs 20170627 + this.servoPrevLength3 = []; // add by kjs 20170627 + this.servoPrevValue3 = []; // add by kjs 20170627 + this.servoPrevAddres4 = []; // add by kjs 20170627 + this.servoPrevLength4 = []; // add by kjs 20170627 + this.servoPrevValue4 = []; // add by kjs 20170627 + } + for (let index = 0; index < data.length; index++) { + const instruction = data[index][0]; + const address = data[index][1]; + const length = data[index][2]; + const value = data[index][3]; + let doSend = false; + //console.log("###2 : " + address + " and : " + value + " inst : " + instruction + " length : " + length); + if (instruction == INST_NONE) { + doSend = false; + } else if (instruction == INST_READ) { + if (this.isReadDataArrived == false && + this.prevInstruction == INST_READ && + this.prevAddress == address && + this.prevLength == length && + this.prevValue == value) { + doSend = false; + } else { + doSend = true; + } + } else if (instruction == INST_BYPASS_READ) { + if (this.isReadDataArrived == false && + this.prevInstruction == INST_BYPASS_READ && + this.prevAddress == address && + this.prevLength == length && + this.prevValue == value) { + doSend = false; + } else { + doSend = true; + } + } + //console.log("dosend : " + doSend); + if (doSend) { + for (let indexA = 0; indexA < this.robotisBuffer.length; indexA++) { + if (data[index][0] == this.robotisBuffer[indexA][0] && + data[index][1] == this.robotisBuffer[indexA][1] && + data[index][2] == this.robotisBuffer[indexA][2] && + data[index][3] == this.robotisBuffer[indexA][3]) { + doSend = false; + break; + } + } + } + if (instruction == INST_WRITE || + instruction == 4 || + instruction == 5 || + instruction == 6 || + instruction == INST_BYPASS_WRITE) { + doSend = true; + } + if (!doSend) { + continue; + } + + if (setZero[0] == 1) { + this.prevInstruction = 0; + this.prevAddress = []; + this.prevLength = []; + this.prevValue = []; + + this.servoPrevAddres = []; // add by kjs 20170627 + this.servoPrevLength = []; // add by kjs 20170627 + this.servoPrevValue = []; // add by kjs 20170627 + this.servoPrevAddres2 = []; // add by kjs 20170627 + this.servoPrevLength2 = []; // add by kjs 20170627 + this.servoPrevValue2 = []; // add by kjs 20170627 + this.servoPrevAddres3 = []; // add by kjs 20170627 + this.servoPrevLength3 = []; // add by kjs 20170627 + this.servoPrevValue3 = []; // add by kjs 20170627 + this.servoPrevAddres4 = []; // add by kjs 20170627 + this.servoPrevLength4 = []; // add by kjs 20170627 + this.servoPrevValue4 = []; // add by kjs 20170627 + } else { + this.prevInstruction = instruction; + this.prevAddress = address; + this.prevLength = length; + this.prevValue = value; + this.prevServoSet(address, value, length); + } + + if (instruction == INST_WRITE || + instruction == INST_DXL_SYNCWRITE || + instruction == INST_DXL_REGWRITE || + instruction == INST_DXL_ACTION || + instruction == INST_BYPASS_WRITE) { + this.robotisBuffer.push(data[index]); + if (instruction == INST_WRITE) { + // 만약 bypass mode를 enable 한다고 하면 + if (address == 19 && value == 1) { + // bypass port를 BLE로 설정 + this.robotisBuffer.push([INST_WRITE, 20, 1, 0]); + } + } + } else if (instruction == INST_READ || instruction == INST_BYPASS_READ) { + if (this.addressToRead[address] == undefined || this.addressToRead[address] == 0) { + this.addressToRead[address] = 1; + this.robotisBuffer.push(data[index]); + } else { + // 10번 이상 읽지 못한다면 에러이므로 강제로 읽을 수 있도록 처리 + this.addressToRead[address] += 1; + if (this.addressToRead[address] >= 10) { + this.addressToRead[address] = 0; + } + } + } + } +}; + +Module.prototype.requestLocalData = function() { + let sendBuffer = null; + let dataLength = 0; + if (this.isReadDataArrived == false) { + //console.log("######## 1"); + return sendBuffer; + } + ///////////////// + this.isConnected = true; + if (!this.isConnected) { + this.receiveAddress = -1; + return this.readPacket(200, 0, 2); + } + + { + const data = this.robotisBuffer.shift(); + if (data == null) { + return sendBuffer; + } + const instruction = data[0]; + const address = data[1]; + const length = data[2]; + let value = data[3]; + const value2 = data[4]; + //console.log('send address : ' + address + ', ' + value + ", " + length); // add by kjs 170426 + if (instruction == INST_WRITE) { + if (length == 1) { + sendBuffer = this.writeBytePacket(200, address, value); + } else if (length == 2) { + sendBuffer = this.writeWordPacket(200, address, value); + } else if (length == 4) { + sendBuffer = this.writeDWordPacket(200, address, value); + } else { + console.log(value); + sendBuffer = this.writeCustomLengthPacket(200, address, value, length); + } + } else if (instruction == INST_READ) { + this.addressToRead[address] = 0; + sendBuffer = this.readPacket(200, address, length); + } else if (instruction == INST_DXL_SYNCWRITE) { //function(ids, address, rLength, values) + //this.isReadDataArrived = true; + const ids = data[4]; + value = data[5]; + const tmpSendBuffer = this.dxlSyncWritePacket(ids, address, length, value); + const tmp = []; + for (let j = 0; j < tmpSendBuffer / 20; j++) { + for (let i = j * 20; i < j * 20 + 20; i++) { + tmp.push(tmpSendBuffer[i]); + } + sendBuffer.push(tmp); + } + + sendBuffer = this.dxlSyncWritePacket(ids, address, length, value); + } else if (instruction == INST_DXL_REGWRITE) { + const ids = data[4]; + + sendBuffer = this.dxlRegWritePacket(ids[0], address, length, value); + } else if (instruction == INST_DXL_ACTION) { + sendBuffer = this.dxlActionWrite(); + } else if (instruction == INST_BYPASS_READ) { + const id = value; + this.addressToRead[address] = 0; + sendBuffer = this.readPacket(id, address, length); + } else if (instruction == INST_BYPASS_WRITE) { + const id = value; + this.addressToRead[address] = 0; + if (length == 1) { + sendBuffer = this.writeBytePacket(id, address, value2); + } else if (length == 2) { + sendBuffer = this.writeWordPacket(id, address, value2); + } else { + sendBuffer = this.writeDWordPacket(id, address, value2); + } + } + + console.log(`send buffer : ${sendBuffer}`); + if (sendBuffer[0] == 0xFF && + sendBuffer[1] == 0xFF && + sendBuffer[2] == 0xFD && + sendBuffer[3] == 0x00 && + sendBuffer[4] == 0xC8 || + (sendBuffer[4] >= 100 && sendBuffer[4] <= 119) || + (sendBuffer[4] >= 1 && sendBuffer[4] <= 63)) { + dataLength = this.makeWord(sendBuffer[5], sendBuffer[6]); + + if (sendBuffer[7] == INST_READ) { + this.receiveAddress = address; + this.receiveLength = length; + this.defaultLength = data[2]; + this.isReadDataArrived = false; + if (this.varTimeout != null) { + clearTimeout(this.varTimeout); + } + + this.varTimeout = setTimeout(() => { + this.isReadDataArrived = true; + }, 100); + } + } + } + return sendBuffer; +}; +Module.prototype.packetChecker = function(data) { + if (data[0] == 0xFF && data[1] == 0xFF && data[2] == 0xFD) { + return true; + } else { + return false; + } +}; + +Module.prototype.handleLocalData = function(data) { // data: Native Buffer + let stuffLength = 0; + console.log(`length: ${data.length}`); + for (let i = 0; i < data.length; i++) { + //this.receiveBuffer.push(data[i]); + const dataIn = data[i]; + + switch (this.packetReceiveState) { + case PACKET_STATE_IDLE: + if (this.headerCount >= 2) { + rxPacket.header[2] = dataIn; + + if (rxPacket.header[0] == 0xFF && + rxPacket.header[1] == 0xFF && + rxPacket.header[2] == 0xFD) { + this.headerCount = 0; + this.packetReceiveState = PACKET_STATE_RESERVED; + } else { + rxPacket.header[0] = rxPacket.header[1]; + rxPacket.header[1] = rxPacket.header[2]; + rxPacket.header[2] = 0; + } + } else { + rxPacket.header[this.headerCount] = dataIn; + this.headerCount++; + } + break; + + case PACKET_STATE_RESERVED: + if (dataIn == 0xFD) { + this.packetReceiveState = PACKET_STATE_IDLE; + } else { + rxPacket.reserved = dataIn; + this.packetReceiveState = PACKET_STATE_ID; + } + break; + + case PACKET_STATE_ID: + rxPacket.id = dataIn; + this.packetReceiveState = PACKET_STATE_LENGTH_L; + break; + + case PACKET_STATE_LENGTH_L: + rxPacket.packetLength = dataIn; + this.packetReceiveState = PACKET_STATE_LENGTH_H; + break; + + case PACKET_STATE_LENGTH_H: + rxPacket.packetLength |= (dataIn << 8); + this.packetReceiveState = PACKET_STATE_DATA; + rxPacket.index = 0; + break; + + case PACKET_STATE_DATA: + rxPacket.data[rxPacket.index] = dataIn; + rxPacket.index++; + + if (rxPacket.index >= rxPacket.packetLength - 2) { + this.packetReceiveState = PACKET_STATE_CRC_L; + } + break; + + case PACKET_STATE_CRC_L: + rxPacket.crcReceived = dataIn; + this.packetReceiveState = PACKET_STATE_CRC_H; + break; + + case PACKET_STATE_CRC_H: + rxPacket.crcReceived |= (dataIn << 8); + + stuffLength = this.removeStuffing(rxPacket.data, rxPacket.packetLength); + rxPacket.packetLength -= stuffLength; + + rxPacket.cmd = rxPacket.data[0]; + rxPacket.error = rxPacket.data[1]; + + if (rxPacket.cmd == DXL_INST_STATUS) { + console.log(`rx length: ${rxPacket.packetLength}`); + console.log(`LINE CAT: ${rxPacket.data[45]}`); + this.dataBuffer[55] = rxPacket.data[45]; + } + + this.packetReceiveState = PACKET_STATE_IDLE; + break; + + + default: + // code block + } + } + + /* + if (this.receiveBuffer.length >= 11 + this.receiveLength) { + this.isConnected = true; + // console.log('<< 1 : ' + this.receiveLength + ' : ' + this.receiveBuffer); + + // while (this.receiveBuffer.length > 0) { + while (this.receiveBuffer.length >= 11) { + if (this.receiveBuffer.shift() == 0xFF) { + if (this.receiveBuffer.shift() == 0xFF) { + if (this.receiveBuffer.shift() == 0xFD) { + if (this.receiveBuffer.shift() == 0x00) { + const id = this.receiveBuffer.shift(); + if (id == 0xC8 || + (id >= 100 && id <= 119) || + (id >= 1 && id <= 63)) { + const packetLength = this.makeWord(this.receiveBuffer.shift(), + this.receiveBuffer.shift()); + // if (packetLength > 4) { + // console.log("?? : " + this.receiveLength + ' / ' + (packetLength - 4)); + if (this.receiveLength == (packetLength - 4)) { + this.receiveBuffer.shift(); // take 0x55 - status check byte + this.receiveBuffer.shift(); // take 0x00 - error check byte + + const valueLength = packetLength - 4; + const returnValue = []; + let tmpValue = 0; + for (let index = 0; index < valueLength / this.defaultLength; index++) { + if (this.defaultLength == 1) { + tmpValue = this.receiveBuffer.shift(); + returnValue.push(tmpValue); + // returnValue.push(this.receiveBuffer.shift()); + } else if (this.defaultLength == 2) { + tmpValue = this.receiveBuffer.shift() | (this.receiveBuffer.shift() << 8); + if (tmpValue > 60000) { + tmpValue = tmpValue - 65536; + } + returnValue.push(tmpValue); + } else if (this.defaultLength == 4) { + tmpValue = this.receiveBuffer.shift() | + (this.receiveBuffer.shift() << 8) | + (this.receiveBuffer.shift() << 16) | + (this.receiveBuffer.shift() << 24); + + returnValue.push(tmpValue); + } + } + + if (this.receiveAddress != -1) { + if (this.varTimeout != null) { + clearTimeout(this.varTimeout); + } + + for (let index = 0; index < returnValue.length; index++) { + this.dataBuffer[this.receiveAddress + index * this.defaultLength] = + returnValue[index]; + } + + this.isReadDataArrived = true; + //console.log('<- ' + + //new Date().getHours() + ':' + + //new Date().getMinutes() + ':' + + //new Date().getMilliseconds() + '\n' + + //this.receiveAddress + ' : ' + returnValue); + } else { + //console.log('<- ' + + //new Date().getHours() + ':' + + //new Date().getMinutes() + ':' + + //new Date().getMilliseconds() + '\n' + '-1'); + } + + this.receiveBuffer.shift(); // take crc check byte + this.receiveBuffer.shift(); // take crc check byte + + // break because this packet has no error. + break; + } else { + for (let i = 0; i < packetLength; i++) { + this.receiveBuffer.shift(); // take bytes of write status + } + } + } + } + } + } + } + } + } + */ +}; + +Module.prototype.reset = function() { + this.addressToRead = []; + this.varTimeout = null; + + this.prevInstruction = 0; + this.prevAddress = []; + this.prevLength = []; + this.prevValue = []; + + this.receiveBuffer = []; + this.dataBuffer = []; + this.robotisBuffer = []; + this.receiveAddress = -1; + this.receiveLength = -1; + this.defaultLength = -1; + + this.servoPrevAddres = []; // add by kjs 20170731 + this.servoPrevLength = []; // add by kjs 20170627 + this.servoPrevValue = []; // add by kjs 20170627 + this.servoPrevAddres2 = []; // add by kjs 20170627 + this.servoPrevLength2 = []; // add by kjs 20170627 + this.servoPrevValue2 = []; // add by kjs 20170627 + this.servoPrevAddres3 = []; // add by kjs 20170627 + this.servoPrevLength3 = []; // add by kjs 20170627 + this.servoPrevValue3 = []; // add by kjs 20170627 + this.servoPrevAddres4 = []; // add by kjs 20170627 + this.servoPrevLength4 = []; // add by kjs 20170627 + this.servoPrevValue4 = []; // add by kjs 20170731 +}; + +module.exports = new Module(); + +const DXL_INST_STATUS = 0x55; + +const INST_NONE = 0; +const INST_READ = 2; +const INST_WRITE = 3; +const INST_DXL_SYNCWRITE = 4; +const INST_DXL_REGWRITE = 5; +const INST_DXL_ACTION = 6; +const INST_BYPASS_READ = 0xA2; +const INST_BYPASS_WRITE = 0xA3; + +const PACKET_STATE_IDLE = 0; +const PACKET_STATE_RESERVED = 1; +const PACKET_STATE_ID = 2; +const PACKET_STATE_LENGTH_L = 3; +const PACKET_STATE_LENGTH_H = 4; +const PACKET_STATE_DATA = 5; +const PACKET_STATE_CRC_L = 6; +const PACKET_STATE_CRC_H = 7; + +const rxPacket = { + header: [0, 0, 0], + reserved: 0, + id: 0, + cmd: 0, + error: 0, + type: 0, + index: 0, + packetLength: 0, + paramLength: 0, + crc: 0, + crcReceived: 0, + checksum: 0, + checksumReceived: 0, + data: [], +}; + +//const rxPacket = Object.assign({}, packet); + +Module.prototype.writeBytePacket = function(id, address, value) { + console.log('######### writeBytepacket'); + const packet = []; + packet.push(0xff); + packet.push(0xff); + packet.push(0xfd); + packet.push(0x00); + packet.push(id); + packet.push(0x06); + packet.push(0x00); + packet.push(INST_WRITE); + packet.push(this.getLowByte(address)); + packet.push(this.getHighByte(address)); + packet.push(value); + const crc = this.updateCRC(0, packet, packet.length); + packet.push(this.getLowByte(crc)); + packet.push(this.getHighByte(crc)); + return packet; +}; + +Module.prototype.writeWordPacket = function(id, address, value) { + console.log('######### writeWordPacket'); + const packet = []; + packet.push(0xff); + packet.push(0xff); + packet.push(0xfd); + packet.push(0x00); + packet.push(id); + packet.push(0x07); + packet.push(0x00); + packet.push(INST_WRITE); + packet.push(this.getLowByte(address)); + packet.push(this.getHighByte(address)); + packet.push(this.getLowByte(value)); + packet.push(this.getHighByte(value)); + const crc = this.updateCRC(0, packet, packet.length); + packet.push(this.getLowByte(crc)); + packet.push(this.getHighByte(crc)); + return packet; +}; + +Module.prototype.writeDWordPacket = function(id, address, value) { + console.log('######### writeDWordPacket'); + const packet = []; + packet.push(0xff); + packet.push(0xff); + packet.push(0xfd); + packet.push(0x00); + packet.push(id); + packet.push(0x09); + packet.push(0x00); + packet.push(INST_WRITE); + packet.push(this.getLowByte(address)); + packet.push(this.getHighByte(address)); + packet.push(this.getLowByte(this.getLowWord(value))); + packet.push(this.getHighByte(this.getLowWord(value))); + packet.push(this.getLowByte(this.getHighWord(value))); + packet.push(this.getHighByte(this.getHighWord(value))); + console.log(`packet : ${packet}`); + const crc = this.updateCRC(0, packet, packet.length); + packet.push(this.getLowByte(crc)); + packet.push(this.getHighByte(crc)); + return packet; +}; + +Module.prototype.writeCustomLengthPacket = function(id, address, buf, length) { + //console.log("######### writeCustomLengthPacket"); + const packet = []; + let i = 0; + packet.push(0xff); + packet.push(0xff); + packet.push(0xfd); + packet.push(0x00); + packet.push(id); + packet.push(length + 5); + packet.push(0x00); + packet.push(INST_WRITE); + packet.push(this.getLowByte(address)); + packet.push(this.getHighByte(address)); + console.log(buf); + for (i = 0; i < length; i++) { + console.log(buf[i]); + if (typeof(buf[i]) == 'number') { + packet.push(buf[i]); + } else if (typeof(buf[i]) == 'string') { + packet.push(buf[i].charCodeAt(0)); + } + } + //console.log("packet : " + packet); + const crc = this.updateCRC(0, packet, packet.length); + packet.push(this.getLowByte(crc)); + packet.push(this.getHighByte(crc)); + return packet; +}; + +Module.prototype.dxlRegWritePacket = function(id, address, length, value) { + const packet = []; + const paramLength = length + 5; + let tmp1 = 0; + let tmp2 = 0; + + packet.push(0xff); + packet.push(0xff); + packet.push(0xfd); + packet.push(0x00); + + packet.push(this.getLowByte(id)); + packet.push(this.getLowByte(paramLength)); + packet.push(this.getHighByte(paramLength)); + + packet.push(0x04); + + packet.push(this.getLowByte(address)); + packet.push(this.getHighByte(address)); + + switch (length) { + case 1: + packet.push(this.getLowByte(value)); + break; + case 2: + break; + case 4: + packet.push(this.getLowByte(this.getLowWord(value))); + packet.push(this.getHighByte(this.getLowWord(value))); + packet.push(this.getLowByte(this.getHighWord(value))); + packet.push(this.getHighByte(this.getHighWord(value))); + break; + case 8: + tmp1 = value / 4294967296; + tmp2 = value % 4294967296; + + packet.push(this.getLowByte(this.getLowWord(tmp1))); + packet.push(this.getHighByte(this.getLowWord(tmp1))); + packet.push(this.getLowByte(this.getHighWord(tmp1))); + packet.push(this.getHighByte(this.getHighWord(tmp1))); + + packet.push(this.getLowByte(this.getLowWord(tmp2))); + packet.push(this.getHighByte(this.getLowWord(tmp2))); + packet.push(this.getLowByte(this.getHighWord(tmp2))); + packet.push(this.getHighByte(this.getHighWord(tmp2))); + break; + } + + const crc = this.updateCRC(0, packet, packet.length); + packet.push(this.getLowByte(crc)); + packet.push(this.getHighByte(crc)); + return packet; +}; + +Module.prototype.dxlActionWrite = function() { + const packet = []; + packet.push(0xff); + packet.push(0xff); + packet.push(0xfd); + packet.push(0x00); + + packet.push(0xfe); + + packet.push(0x03); + packet.push(0x00); + + packet.push(0x05); + + const crc = this.updateCRC(0, packet, packet.length); + packet.push(this.getLowByte(crc)); + packet.push(this.getHighByte(crc)); + return packet; +}; + +Module.prototype.dxlSyncWritePacket = function(ids, address, rLength, values) { + const packet = []; + const paramLength = 7 + ids.length * (rLength + 1); + + packet.push(0xff); + packet.push(0xff); + packet.push(0xfd); + packet.push(0x00); + packet.push(0xfe); + + packet.push(this.getLowByte(paramLength)); + packet.push(this.getHighByte(paramLength)); + + packet.push(0x83); + + packet.push(this.getLowByte(address)); + packet.push(this.getHighByte(address)); + + packet.push(this.getLowByte(rLength)); + packet.push(this.getHighByte(rLength)); + + for (let i = 0; i < ids.length; i++) { + packet.push(this.getLowByte(ids[i])); + switch (rLength) { + case 1: + packet.push(this.getLowByte(values[i])); + break; + case 2: + break; + case 4: + packet.push(this.getLowByte(this.getLowWord(values[i]))); + packet.push(this.getHighByte(this.getLowWord(values[i]))); + packet.push(this.getLowByte(this.getHighWord(values[i]))); + packet.push(this.getHighByte(this.getHighWord(values[i]))); + break; + } + } + + const crc = this.updateCRC(0, packet, packet.length); + packet.push(this.getLowByte(crc)); + packet.push(this.getHighByte(crc)); + return packet; +}; + +Module.prototype.prevServoCompare = function(address, value, length) { + if ((address >= 108 && address <= 111) && value == 7) { //Module + if (this.prevInstruction == INST_WRITE && + this.servoPrevAddres == address && + this.servoPrevLength == length && + this.servoPrevValue == value) { + //doSend = false; + return true; + } + } + + if (address >= 128 && address <= 131) { //Mode + if (this.prevInstruction == INST_WRITE && + this.servoPrevAddres2 == address && + this.servoPrevLength2 == length && + this.servoPrevValue2 == value) { + //doSend = false; + return true; + } + } + + if (address >= 140 && address <= 146) { //Speed + if (this.prevInstruction == INST_WRITE && + this.servoPrevAddres3 == address && + this.servoPrevLength3 == length && + this.servoPrevValue3 == value) { + //doSend = false; + return true; + } + } + + if (address >= 156 && address <= 162) { //Position + if (this.prevInstruction4 == INST_WRITE && + this.servoPrevAddres4 == address && + this.servoPrevLength4 == length && + this.servoPrevValue4 == value) { + //doSend = false; + return true; + } + } +}; + +Module.prototype.prevServoSet = function(address, value, length) { + if ((address >= 108 && address <= 111) && value == 7) { //Module + this.servoPrevAddres = address; + this.servoPrevLength = length; + this.servoPrevValue = value; + } + + if (address >= 128 && address <= 131) { //Mode + this.servoPrevAddres2 = address; + this.servoPrevLength2 = length; + this.servoPrevValue2 = value; + } + + if (address >= 140 && address <= 146) { //Speed + this.servoPrevAddres3 = address; + this.servoPrevLength3 = length; + this.servoPrevValue3 = value; + } + + if (address >= 156 && address <= 162) { //Position + this.servoPrevAddres4 = address; + this.servoPrevLength4 = length; + this.servoPrevValue4 = value; + } +}; + +Module.prototype.readPacket = function(id, address, lengthToRead) { + //console.log("######### readPacket"); + const packet = []; + packet.push(0xff); + packet.push(0xff); + packet.push(0xfd); + packet.push(0x00); + packet.push(id); + packet.push(0x07); + packet.push(0x00); + packet.push(INST_READ); + packet.push(this.getLowByte(address)); + packet.push(this.getHighByte(address)); + packet.push(this.getLowByte(lengthToRead)); + packet.push(this.getHighByte(lengthToRead)); + const crc = this.updateCRC(0, packet, packet.length); + packet.push(this.getLowByte(crc)); + packet.push(this.getHighByte(crc)); + return packet; +}; + +const crcTable = [0x0000, + 0x8005, 0x800F, 0x000A, 0x801B, 0x001E, 0x0014, 0x8011, + 0x8033, 0x0036, 0x003C, 0x8039, 0x0028, 0x802D, 0x8027, + 0x0022, 0x8063, 0x0066, 0x006C, 0x8069, 0x0078, 0x807D, + 0x8077, 0x0072, 0x0050, 0x8055, 0x805F, 0x005A, 0x804B, + 0x004E, 0x0044, 0x8041, 0x80C3, 0x00C6, 0x00CC, 0x80C9, + 0x00D8, 0x80DD, 0x80D7, 0x00D2, 0x00F0, 0x80F5, 0x80FF, + 0x00FA, 0x80EB, 0x00EE, 0x00E4, 0x80E1, 0x00A0, 0x80A5, + 0x80AF, 0x00AA, 0x80BB, 0x00BE, 0x00B4, 0x80B1, 0x8093, + 0x0096, 0x009C, 0x8099, 0x0088, 0x808D, 0x8087, 0x0082, + 0x8183, 0x0186, 0x018C, 0x8189, 0x0198, 0x819D, 0x8197, + 0x0192, 0x01B0, 0x81B5, 0x81BF, 0x01BA, 0x81AB, 0x01AE, + 0x01A4, 0x81A1, 0x01E0, 0x81E5, 0x81EF, 0x01EA, 0x81FB, + 0x01FE, 0x01F4, 0x81F1, 0x81D3, 0x01D6, 0x01DC, 0x81D9, + 0x01C8, 0x81CD, 0x81C7, 0x01C2, 0x0140, 0x8145, 0x814F, + 0x014A, 0x815B, 0x015E, 0x0154, 0x8151, 0x8173, 0x0176, + 0x017C, 0x8179, 0x0168, 0x816D, 0x8167, 0x0162, 0x8123, + 0x0126, 0x012C, 0x8129, 0x0138, 0x813D, 0x8137, 0x0132, + 0x0110, 0x8115, 0x811F, 0x011A, 0x810B, 0x010E, 0x0104, + 0x8101, 0x8303, 0x0306, 0x030C, 0x8309, 0x0318, 0x831D, + 0x8317, 0x0312, 0x0330, 0x8335, 0x833F, 0x033A, 0x832B, + 0x032E, 0x0324, 0x8321, 0x0360, 0x8365, 0x836F, 0x036A, + 0x837B, 0x037E, 0x0374, 0x8371, 0x8353, 0x0356, 0x035C, + 0x8359, 0x0348, 0x834D, 0x8347, 0x0342, 0x03C0, 0x83C5, + 0x83CF, 0x03CA, 0x83DB, 0x03DE, 0x03D4, 0x83D1, 0x83F3, + 0x03F6, 0x03FC, 0x83F9, 0x03E8, 0x83ED, 0x83E7, 0x03E2, + 0x83A3, 0x03A6, 0x03AC, 0x83A9, 0x03B8, 0x83BD, 0x83B7, + 0x03B2, 0x0390, 0x8395, 0x839F, 0x039A, 0x838B, 0x038E, + 0x0384, 0x8381, 0x0280, 0x8285, 0x828F, 0x028A, 0x829B, + 0x029E, 0x0294, 0x8291, 0x82B3, 0x02B6, 0x02BC, 0x82B9, + 0x02A8, 0x82AD, 0x82A7, 0x02A2, 0x82E3, 0x02E6, 0x02EC, + 0x82E9, 0x02F8, 0x82FD, 0x82F7, 0x02F2, 0x02D0, 0x82D5, + 0x82DF, 0x02DA, 0x82CB, 0x02CE, 0x02C4, 0x82C1, 0x8243, + 0x0246, 0x024C, 0x8249, 0x0258, 0x825D, 0x8257, 0x0252, + 0x0270, 0x8275, 0x827F, 0x027A, 0x826B, 0x026E, 0x0264, + 0x8261, 0x0220, 0x8225, 0x822F, 0x022A, 0x823B, 0x023E, + 0x0234, 0x8231, 0x8213, 0x0216, 0x021C, 0x8219, 0x0208, + 0x820D, 0x8207, 0x0202, +]; + +Module.prototype.makeWord = function(a, b) { + return ((a & 0xff) | ((b & 0xff) << 8)); +}; + +Module.prototype.getLowByte = function(a) { + return (a & 0xff); +}; + +Module.prototype.getHighByte = function(a) { + return ((a >> 8) & 0xff); +}; + +Module.prototype.getLowWord = function(a) { + return (a & 0xffff); +}; + +Module.prototype.getHighWord = function(a) { + return ((a >> 16) & 0xffff); +}; + +Module.prototype.updateCRC = function(crcAccum, dataBlkPtr, dataBlkSize) { + let i = 0; + let j = 0; + let crc = crcAccum; + + for (j = 0; j < dataBlkSize; j++) { + i = ((crc >> 8) ^ dataBlkPtr[j]) & 0xff; + crc = (crc << 8) ^ crcTable[i]; + } + + return crc; +}; + +Module.prototype.removeStuffing = function(buffer, length) { + let i = 0; + let stuffLength = 0; + let index = 0; + + for (i = 0; i < length; i++) { + if (i >= 2) { + if (buffer[i - 2] == 0xFF && + buffer[i - 1] == 0xFF && + buffer[i] == 0xFD) { + i++; + stuffLength++; + } + } + buffer[index++] = buffer[i]; + } + + return stuffLength; +}; From 64023242a1ab9b4697b2fb9f78c902626c2f8b10 Mon Sep 17 00:00:00 2001 From: Jason Kim Date: Thu, 14 Mar 2024 14:04:00 +0900 Subject: [PATCH 02/18] =?UTF-8?q?=EB=B6=88=ED=95=84=EC=9A=94=20=EB=A1=9C?= =?UTF-8?q?=EA=B7=B8=20=EC=82=AD=EC=A0=9C=20/=20RB-100=20=EA=B8=B0?= =?UTF-8?q?=EC=A1=B4=EB=B0=A9=EC=8B=9D=20auto=20report=20=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=84=B0=20=EC=A0=80=EC=9E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/modules/robotis_RB100_practice.js | 100 ++++++++++++++++++++++++-- 1 file changed, 93 insertions(+), 7 deletions(-) diff --git a/app/modules/robotis_RB100_practice.js b/app/modules/robotis_RB100_practice.js index 218183858..16e22c8c1 100644 --- a/app/modules/robotis_RB100_practice.js +++ b/app/modules/robotis_RB100_practice.js @@ -124,7 +124,9 @@ Module.prototype.requestInitialData = function() { this.robotisBuffer.push([INST_WRITE, 19, 1, 1]); // bypass 모드 켜기 this.robotisBuffer.push([INST_WRITE, 20, 1, 0]); // bypass port를 BLE로 설정 this.robotisBuffer.push([INST_WRITE, 23, 1, 1]); // auto report 기능 켜기 - + this.robotisBuffer.push([INST_WRITE, 4250, 1, 1]); // huskylens 텍스트 지우기 + this.robotisBuffer.push([INST_WRITE, 722, 1, 0]); // dxl 토크 끄기 + return this.readPacket(200, 0, 2); }; @@ -142,14 +144,12 @@ Module.prototype.requestRemoteData = function(handler) { for (let indexA = 0; indexA < this.dataBuffer.length; indexA++) { // 일반형 if (this.dataBuffer[indexA] != undefined) { // console.log("indexA: " + indexA + " value: " + this.dataBuffer[indexA]); - if (indexA == 55) { - console.log(`requestRemoteData: ${this.dataBuffer[indexA]}`); - } handler.write(indexA, this.dataBuffer[indexA]); } } //실과형 //console.log("###### value : " + this.detectedSound); + /* for (let i = 0; i < 4; i++) { handler.write(`TOUCH${i}`, this.touchSensor[i]); // 접촉 센서 handler.write(`IR${i}`, this.irSensor[i]); // 적외선 센서 @@ -161,6 +161,7 @@ Module.prototype.requestRemoteData = function(handler) { handler.write('DETECTEDSOUNDE', this.detectedSound); // 최종 소리 감지 횟수 handler.write('DETECTINGSOUNDE1', this.detectringSound); // 실시간 소리 감지 횟수 handler.write('USERBUTTONSTATE', this.userButtonState); + */ }; Module.prototype.handleRemoteData = function(handler) { @@ -323,7 +324,6 @@ Module.prototype.requestLocalData = function() { } else if (length == 4) { sendBuffer = this.writeDWordPacket(200, address, value); } else { - console.log(value); sendBuffer = this.writeCustomLengthPacket(200, address, value, length); } } else if (instruction == INST_READ) { @@ -478,8 +478,34 @@ Module.prototype.handleLocalData = function(data) { // data: Native Buffer if (rxPacket.cmd == DXL_INST_STATUS) { console.log(`rx length: ${rxPacket.packetLength}`); - console.log(`LINE CAT: ${rxPacket.data[45]}`); - this.dataBuffer[55] = rxPacket.data[45]; + if (rxPacket.packetLength >= 147) { + let tempValue = 0; + for (let i = 0; i < 56; i++) { + switch (addrMap[i][1]) { + case 1: + this.dataBuffer[addrMap[i][2]] = rxPacket.data[2 + addrMap[i][0]]; + break; + + case 2: + tempValue = rxPacket.data[2 + addrMap[i][0]] + + (rxPacket.data[2 + addrMap[i][0] + 1] << 8); + if (tempValue >= 32768) { + tempValue = tempValue - 65536; + } + console.log(`tempValue: ${tempValue}`); + this.dataBuffer[addrMap[i][2]] = tempValue; + break; + + + case 4: + this.dataBuffer[addrMap[i][2]] = rxPacket.data[2 + addrMap[i][0]] + + (rxPacket.data[2 + addrMap[i][0] + 1] << 8) + + (rxPacket.data[2 + addrMap[i][0] + 2] << 16) + + (rxPacket.data[2 + addrMap[i][0] + 3] << 24); + break; + } + } + } } this.packetReceiveState = PACKET_STATE_IDLE; @@ -650,6 +676,66 @@ const rxPacket = { data: [], }; +const addrMap = [ + [0,4,302], + [4,1,42], + [5,1,44], + [6,1,45], + [7,1,47], + [8,1,50], + [9,1,51], + [10,1,52], + [11,1,68], + [12,2,70], + [14,2,72], + [16,2,74], + [18,2,76], + [20,2,78], + [22,2,80], + [24,2,82], + [26,2,84], + [28,1,86], + [29,1,87], + [30,2,88], + [32,2,90], + [34,1,112], + [35,1,118], + [36,1,119], + [37,1,122], + [38,1,123], + [39,1,124], + [40,1,125], + [41,1,160], + [42,1,220], + [43,2,360], + [45,2,362], + [47,2,364], + [49,2,366], + [51,2,368], + [53,2,370], + [55,1,372], + [56,1,373], + [57,1,374], + [58,1,375], + [59,1,376], + [60,1,377], + [61,1,378], + [62,1,379], + [63,1,380], + [64,1,381], + [65,1,382], + [66,1,383], + [67,1,500], + [68,1,501], + [69,8,502], + [77,1,700], + [78,1,810], + [79,1,5015], + [80,1,5030], + [81,1,5031], + [82,1,5040], +]; + //const rxPacket = Object.assign({}, packet); Module.prototype.writeBytePacket = function(id, address, value) { From d822200733cca54e5ae1868e0963e7b609438af6 Mon Sep 17 00:00:00 2001 From: Jason Kim Date: Fri, 15 Mar 2024 08:50:33 +0900 Subject: [PATCH 03/18] =?UTF-8?q?=EC=A0=9C=EC=96=B4=EA=B8=B0=20=EA=B0=92?= =?UTF-8?q?=20+=20line=EC=9C=A0=ED=98=95=20+=20huskylens=EA=B0=92=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC=20=EC=A7=80=EC=9B=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/modules/robotis_RB100_practice.js | 60 ++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 2 deletions(-) diff --git a/app/modules/robotis_RB100_practice.js b/app/modules/robotis_RB100_practice.js index 16e22c8c1..500ba27cd 100644 --- a/app/modules/robotis_RB100_practice.js +++ b/app/modules/robotis_RB100_practice.js @@ -480,7 +480,7 @@ Module.prototype.handleLocalData = function(data) { // data: Native Buffer console.log(`rx length: ${rxPacket.packetLength}`); if (rxPacket.packetLength >= 147) { let tempValue = 0; - for (let i = 0; i < 56; i++) { + for (let i = 0; i < addrMap.length; i++) { switch (addrMap[i][1]) { case 1: this.dataBuffer[addrMap[i][2]] = rxPacket.data[2 + addrMap[i][0]]; @@ -492,7 +492,6 @@ Module.prototype.handleLocalData = function(data) { // data: Native Buffer if (tempValue >= 32768) { tempValue = tempValue - 65536; } - console.log(`tempValue: ${tempValue}`); this.dataBuffer[addrMap[i][2]] = tempValue; break; @@ -505,6 +504,34 @@ Module.prototype.handleLocalData = function(data) { // data: Native Buffer break; } } + + // line category + this.dataBuffer[5201] = rxPacket.data[2 + 143]; + + for (let i = 0; i < addrMap2.length; i++) { + switch (addrMap2[i][1]) { + case 1: + this.dataBuffer[addrMap2[i][2]] = rxPacket.data[2 + addrMap2[i][0]]; + break; + + case 2: + tempValue = rxPacket.data[2 + addrMap2[i][0]] + + (rxPacket.data[2 + addrMap2[i][0] + 1] << 8); + if (tempValue >= 32768) { + tempValue = tempValue - 65536; + } + this.dataBuffer[addrMap2[i][2]] = tempValue; + break; + + + case 4: + this.dataBuffer[addrMap2[i][2]] = rxPacket.data[2 + addrMap2[i][0]] + + (rxPacket.data[2 + addrMap2[i][0] + 1] << 8) + + (rxPacket.data[2 + addrMap2[i][0] + 2] << 16) + + (rxPacket.data[2 + addrMap2[i][0] + 3] << 24); + break; + } + } } } @@ -736,6 +763,35 @@ const addrMap = [ [82,1,5040], ]; + +const addrMap2 = [ + [152,1,4000], + [153,2,4003], + [155,1,4005], + [156,1,4006], + [157,2,4009], + [159,2,4011], + [161,2,4013], + [163,2,4015], + [165,2,4017], + [167,2,4019], + [169,2,4021], + [171,2,4023], + [173,2,4025], + [175,2,4027], + [177,1,4031], + [178,1,4032], + [179,1,4033], + [180,2,4036], + [182,2,4038], + [184,2,4040], + [186,2,4042], + [188,2,4044], + [190,2,4046], + [192,2,4048], + [194,2,4050], +]; + //const rxPacket = Object.assign({}, packet); Module.prototype.writeBytePacket = function(id, address, value) { From 1b95ce3a999c1938b64efa449b85c81218c7dbac Mon Sep 17 00:00:00 2001 From: Jason Kim Date: Fri, 15 Mar 2024 11:10:29 +0900 Subject: [PATCH 04/18] =?UTF-8?q?=EC=97=B0=EA=B2=B0=EC=8B=9C=20=ED=8C=A8?= =?UTF-8?q?=ED=82=B7=20=ED=8C=8C=EB=9D=BC=EB=AF=B8=ED=84=B0=20=EC=B4=88?= =?UTF-8?q?=EA=B8=B0=ED=99=94=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/modules/robotis_RB100_practice.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/app/modules/robotis_RB100_practice.js b/app/modules/robotis_RB100_practice.js index 500ba27cd..6e62474e6 100644 --- a/app/modules/robotis_RB100_practice.js +++ b/app/modules/robotis_RB100_practice.js @@ -126,6 +126,21 @@ Module.prototype.requestInitialData = function() { this.robotisBuffer.push([INST_WRITE, 23, 1, 1]); // auto report 기능 켜기 this.robotisBuffer.push([INST_WRITE, 4250, 1, 1]); // huskylens 텍스트 지우기 this.robotisBuffer.push([INST_WRITE, 722, 1, 0]); // dxl 토크 끄기 + + rxPacket.header = [0, 0, 0]; + rxPacket.reserved = 0; + rxPacket.id = 0; + rxPacket.cmd = 0; + rxPacket.error = 0; + rxPacket.type = 0; + rxPacket.index = 0; + rxPacket.packetLength = 0; + rxPacket.paramLength = 0; + rxPacket.crc = 0; + rxPacket.crcReceived = 0; + rxPacket.checksum = 0; + rxPacket.checksumReceived = 0; + rxPacket.data = []; return this.readPacket(200, 0, 2); }; From f06c9753d9f8681606a27e4a206527f7cf839b00 Mon Sep 17 00:00:00 2001 From: Jason Kim Date: Wed, 20 Mar 2024 17:45:45 +0900 Subject: [PATCH 05/18] =?UTF-8?q?=ED=8C=A8=ED=82=B7=EA=B8=B8=EC=9D=B4=20?= =?UTF-8?q?=EB=B9=84=EC=A0=95=EC=83=81=EC=8B=9C=20=ED=8F=90=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/modules/robotis_RB100_practice.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/modules/robotis_RB100_practice.js b/app/modules/robotis_RB100_practice.js index 6e62474e6..512e76fdb 100644 --- a/app/modules/robotis_RB100_practice.js +++ b/app/modules/robotis_RB100_practice.js @@ -464,7 +464,11 @@ Module.prototype.handleLocalData = function(data) { // data: Native Buffer case PACKET_STATE_LENGTH_H: rxPacket.packetLength |= (dataIn << 8); - this.packetReceiveState = PACKET_STATE_DATA; + if (rxPacket.packetLength < 1000) { + this.packetReceiveState = PACKET_STATE_DATA; + } else { + this.packetReceiveState = PACKET_STATE_IDLE; + } rxPacket.index = 0; break; From 6e7baa775bed2ff06a86a14e324decb699cc0ef3 Mon Sep 17 00:00:00 2001 From: Jason Kim Date: Wed, 20 Mar 2024 17:46:02 +0900 Subject: [PATCH 06/18] =?UTF-8?q?2=EC=A2=85=EC=84=BC=EC=84=9C=EA=B0=92=20?= =?UTF-8?q?=EC=A0=80=EC=9E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/modules/robotis_RB100_practice.js | 39 +++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/app/modules/robotis_RB100_practice.js b/app/modules/robotis_RB100_practice.js index 512e76fdb..f2a44d16a 100644 --- a/app/modules/robotis_RB100_practice.js +++ b/app/modules/robotis_RB100_practice.js @@ -29,6 +29,14 @@ function Module() { this.receiveLength = -1; // to check read packet this.defaultLength = -1; // to check read packet + this.pirPir = []; + this.pirTemperature = []; + this.pirHumidity = []; + this.pirBrightness = []; + this.distanceDistance = []; + this.distanceButton = []; + this.distanceBrightness = []; + this.packetReceiveState = 0; this.headerCount = 0; @@ -95,6 +103,14 @@ Module.prototype.requestInitialData = function() { this.receiveAddress = -1; this.receiveLength = -1; this.defaultLength = -1; + + this.pirPir = []; + this.pirTemperature = []; + this.pirHumidity = []; + this.pirBrightness = []; + this.distanceDistance = []; + this.distanceButton = []; + this.distanceBrightness = []; //this.touchSensor = 0; this.colorSensor = []; @@ -162,6 +178,17 @@ Module.prototype.requestRemoteData = function(handler) { handler.write(indexA, this.dataBuffer[indexA]); } } + + // ID 100인 온습도+조도+동작감지센서 + handler.write('PIR_100_PIR', this.pirPir[0]); + handler.write('PIR_100_TEMPERATURE', this.pirTemperature[0]); + handler.write('PIR_100_HUMIDITY', this.pirHumidity[0]); + handler.write('PIR_100_BRIGHTNESS', this.pirBrightness[0]); + + // ID 110인 거리+버튼+조도센서 + handler.write('DIST_110_DISTANCE', this.dataBuffer[148] + (this.dataBuffer[149] << 8)); + handler.write('DIST_110_BUTTON', this.dataBuffer[150]); + handler.write('DIST_110_BRIGHTNESS', this.dataBuffer[151]); //실과형 //console.log("###### value : " + this.detectedSound); /* @@ -526,6 +553,18 @@ Module.prototype.handleLocalData = function(data) { // data: Native Buffer // line category this.dataBuffer[5201] = rxPacket.data[2 + 143]; + + + // 온습도+조도+동작감지센서값 + this.pirPir[0] = rxPacket.data[2 + 144]; + this.pirTemperature[0] = rxPacket.data[2 + 145]; + this.pirHumidity[0] = rxPacket.data[2 + 146]; + this.pirBrightness[0] = rxPacket.data[2 + 147]; + + // 거리+버튼+조도센서값 + this.distanceDistance[0] = rxPacket.data[2 + 148]; + this.distanceButton[0] = rxPacket.data[2 + 150] + (rxPacket.data[2 + 150] << 8); + this.distanceBrightness[0] = rxPacket.data[2 + 151]; for (let i = 0; i < addrMap2.length; i++) { switch (addrMap2[i][1]) { From 5b6d100253aa10836a4052a02e580865f5ff707e Mon Sep 17 00:00:00 2001 From: dalgona-edu Date: Thu, 21 Mar 2024 11:17:55 +0900 Subject: [PATCH 07/18] =?UTF-8?q?dc=EB=AA=A8=ED=84=B0=20=EB=B8=94=EB=A1=9D?= =?UTF-8?q?=20=ED=99=9C=EC=84=B1=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/modules/dalgona_basic.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/modules/dalgona_basic.js b/app/modules/dalgona_basic.js index 958b96250..c1507c54d 100644 --- a/app/modules/dalgona_basic.js +++ b/app/modules/dalgona_basic.js @@ -554,7 +554,7 @@ Module.prototype.makeOutputBuffer = function (device, port, data) { } case this.sensorTypes.PWM: { value.writeInt16LE(data); - buNffer = new Buffer([255, 85, 6, sensorIdx, this.actionTypes.SET, device, port]); + buffer = new Buffer([255, 85, 6, sensorIdx, this.actionTypes.SET, device, port]); buffer = Buffer.concat([buffer, value, dummy]); break; } From 8a0e066a769adb19a80dfb2396374eecb3487ecd Mon Sep 17 00:00:00 2001 From: Jason Kim Date: Fri, 22 Mar 2024 19:00:11 +0900 Subject: [PATCH 08/18] =?UTF-8?q?dxl=20=EC=9C=84=EC=B9=98=EA=B0=92?= =?UTF-8?q?=EC=9D=84=20auto=20report=ED=8C=A8=ED=82=B7=EC=97=90=EC=84=9C?= =?UTF-8?q?=20=EB=B0=9B=EC=95=84=EC=84=9C=20=EC=A0=80=EC=9E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/modules/robotis_RB100_practice.js | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/app/modules/robotis_RB100_practice.js b/app/modules/robotis_RB100_practice.js index f2a44d16a..cc060a885 100644 --- a/app/modules/robotis_RB100_practice.js +++ b/app/modules/robotis_RB100_practice.js @@ -29,6 +29,8 @@ function Module() { this.receiveLength = -1; // to check read packet this.defaultLength = -1; // to check read packet + this.dxlPositions = []; + this.pirPir = []; this.pirTemperature = []; this.pirHumidity = []; @@ -104,6 +106,8 @@ Module.prototype.requestInitialData = function() { this.receiveLength = -1; this.defaultLength = -1; + this.dxlPositions = []; + this.pirPir = []; this.pirTemperature = []; this.pirHumidity = []; @@ -179,6 +183,13 @@ Module.prototype.requestRemoteData = function(handler) { } } + for (let i = 0; i < 64; i++) { + if (this.dxlPositions[i] != undefined && + this.dxlPositions[i] != 0xFFFF) { + handler.write(`DXL_POS_${i}`, this.dxlPositions[i]); // 다이나믹셀 위치값 + } + } + // ID 100인 온습도+조도+동작감지센서 handler.write('PIR_100_PIR', this.pirPir[0]); handler.write('PIR_100_TEMPERATURE', this.pirTemperature[0]); @@ -444,7 +455,7 @@ Module.prototype.packetChecker = function(data) { Module.prototype.handleLocalData = function(data) { // data: Native Buffer let stuffLength = 0; - console.log(`length: ${data.length}`); + //console.log(`length: ${data.length}`); for (let i = 0; i < data.length; i++) { //this.receiveBuffer.push(data[i]); const dataIn = data[i]; @@ -551,9 +562,18 @@ Module.prototype.handleLocalData = function(data) { // data: Native Buffer } } + // DXL Position + for (let i = 0; i < 20; i++) { + const currentId = rxPacket.data[2 + 83 + (3 * i)]; + const currentPos = rxPacket.data[2 + 83 + (3 * i) + 1] + + (rxPacket.data[2 + 83 + (3 * i) + 2] << 8); + if (currentId != 0xFF && currentPos != 0xFFFF) { + this.dxlPositions[currentId] = currentPos; + } + } + // line category this.dataBuffer[5201] = rxPacket.data[2 + 143]; - // 온습도+조도+동작감지센서값 this.pirPir[0] = rxPacket.data[2 + 144]; From 9cf7e060f78753e7c653538a1bb27dc3aacc2fe7 Mon Sep 17 00:00:00 2001 From: Jason Kim Date: Tue, 26 Mar 2024 17:26:04 +0900 Subject: [PATCH 09/18] =?UTF-8?q?bypass=20=ED=8C=A8=ED=82=B7=20=EA=B0=80?= =?UTF-8?q?=EB=B3=80=EA=B8=B8=EC=9D=B4=20=ED=8C=A8=ED=82=B7=20=EC=A7=80?= =?UTF-8?q?=EC=9B=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/modules/robotis_RB100_practice.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/modules/robotis_RB100_practice.js b/app/modules/robotis_RB100_practice.js index cc060a885..d9ef7b0a7 100644 --- a/app/modules/robotis_RB100_practice.js +++ b/app/modules/robotis_RB100_practice.js @@ -413,8 +413,10 @@ Module.prototype.requestLocalData = function() { sendBuffer = this.writeBytePacket(id, address, value2); } else if (length == 2) { sendBuffer = this.writeWordPacket(id, address, value2); - } else { + } else if (length == 4) { sendBuffer = this.writeDWordPacket(id, address, value2); + } else { + sendBuffer = this.writeCustomLengthPacket(id, address, value2, length); } } From 1cca73b2bd8cb5d150aa41da46286adcf5977493 Mon Sep 17 00:00:00 2001 From: Jason Kim Date: Mon, 1 Apr 2024 20:14:29 +0900 Subject: [PATCH 10/18] =?UTF-8?q?=EB=A1=9C=EA=B7=B8=20=EC=A3=BC=EC=84=9D?= =?UTF-8?q?=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/modules/robotis_RB100_practice.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/modules/robotis_RB100_practice.js b/app/modules/robotis_RB100_practice.js index d9ef7b0a7..e1db0296b 100644 --- a/app/modules/robotis_RB100_practice.js +++ b/app/modules/robotis_RB100_practice.js @@ -932,7 +932,7 @@ Module.prototype.writeDWordPacket = function(id, address, value) { packet.push(this.getHighByte(this.getLowWord(value))); packet.push(this.getLowByte(this.getHighWord(value))); packet.push(this.getHighByte(this.getHighWord(value))); - console.log(`packet : ${packet}`); + //console.log(`packet : ${packet}`); const crc = this.updateCRC(0, packet, packet.length); packet.push(this.getLowByte(crc)); packet.push(this.getHighByte(crc)); @@ -953,9 +953,9 @@ Module.prototype.writeCustomLengthPacket = function(id, address, buf, length) { packet.push(INST_WRITE); packet.push(this.getLowByte(address)); packet.push(this.getHighByte(address)); - console.log(buf); + //console.log(buf); for (i = 0; i < length; i++) { - console.log(buf[i]); + //console.log(buf[i]); if (typeof(buf[i]) == 'number') { packet.push(buf[i]); } else if (typeof(buf[i]) == 'string') { From 0f1101b2292a25b72b1d9ade44c983dd65caceb7 Mon Sep 17 00:00:00 2001 From: Jason Kim Date: Mon, 1 Apr 2024 20:14:53 +0900 Subject: [PATCH 11/18] =?UTF-8?q?setZero=EC=9D=B8=20=EA=B2=BD=EC=9A=B0=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC=20=EC=97=86=EC=9D=B4=20=EB=A6=AC=ED=84=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/modules/robotis_RB100_practice.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/modules/robotis_RB100_practice.js b/app/modules/robotis_RB100_practice.js index e1db0296b..b9f22ac85 100644 --- a/app/modules/robotis_RB100_practice.js +++ b/app/modules/robotis_RB100_practice.js @@ -236,6 +236,8 @@ Module.prototype.handleRemoteData = function(handler) { this.servoPrevAddres4 = []; // add by kjs 20170627 this.servoPrevLength4 = []; // add by kjs 20170627 this.servoPrevValue4 = []; // add by kjs 20170627 + + return; } for (let index = 0; index < data.length; index++) { const instruction = data[index][0]; From c74c5946294c8ac64878510639e365a5ebee1155 Mon Sep 17 00:00:00 2001 From: Jason Kim Date: Mon, 8 Apr 2024 17:46:53 +0900 Subject: [PATCH 12/18] =?UTF-8?q?=EB=93=9C=EB=9D=BC=EC=9D=B4=EB=B2=84=20?= =?UTF-8?q?=EC=84=A4=EC=B9=98=20=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/drivers/ROBOTIS/RobotisDriverInstaller.exe | Bin 0 -> 6656 bytes app/drivers/ROBOTIS/RobotisDriverInstaller.pdb | Bin 0 -> 13824 bytes .../robotis_RB100_Practical_AssemblyBT.json | 2 +- 3 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 app/drivers/ROBOTIS/RobotisDriverInstaller.exe create mode 100644 app/drivers/ROBOTIS/RobotisDriverInstaller.pdb diff --git a/app/drivers/ROBOTIS/RobotisDriverInstaller.exe b/app/drivers/ROBOTIS/RobotisDriverInstaller.exe new file mode 100644 index 0000000000000000000000000000000000000000..28b754655f49896d6231bcc3362dfd7b881b271d GIT binary patch literal 6656 zcmeHLeQX@X6@Pno{)Cv=4vDFOY|c11#6EulA&rUcv*TQA$FA>er^G1PyBpg}_I8ii zJ;#QE0)+zVhd>||T0m4#wUKC*(yD}_sv?!DQWdGFAhi-gRIStx(Nd&JrIiZ(z1h9< zId%&CQSlFZo;UN}n|bfeo0&InJbuId6egkw%6sn-ok7jtfP()UoCLdW`;Y4A2Q@G4 zIHQfdv?H}>x_VwZ3)0Bx8N;?6PfrV77Hr+L_2G%6o^!GywrNxC6@lo<5u!0IOs_oM zIA7HE28FZ>vXYdVPnI)7mrxSMFR`dh67)bB!L zkUPQc0it^=17dk~jOaq(5496rT26nzwoX)C)~6cy!7@DNiDeJ?Q=0(5Q*#aM2Btop z=vYj;G6PK6Hh=~T#gxjw0azcC!gA1&ZKY!>D5&DnnKCB>NQ~+ZLh<`qB=l zfa`frplsw3?tb2{xhq23G$Q=fZ>zn%5es-hgVqML@%$8M}yoYsHDN6#b8i6fZ+x|k0(~A1_-Hp}qtK6^J*$G^p zV&m9QH9~%eQI@>5_I0Xmuc~T;|0{P^c2u=p3F^+P^gqFyZEa{@MVeZ_+i3D7+6^PM z%R_Cum@$<6)R4xW!^i8m)EDcD^>+1kU&oXRvH-gvrsZ~`M^QhGL)(({q-ig>+~Xkj z#w(~>rjvAOjlWG=MyC_QptS>k4We6yEGNyK@xerG^y<(Su!#QM+Dljq)~=&~r_NLb zY8Y4Ap3LXM{9+B;Rhzd_NQAk^BhBdJb16l>$f;w`txUN_T^>Nr!%N^hv@hLf% zHXd+M?HhNp1xs8{Q%>6POm|qCOF|}W*E1|j$e36bH0j@b=jlQ@H{(dlOjB~j^+b*) z(l?2WN3+g}Yx;&w*GOAJwGX&cB5O+UOvm=wQv%Ao4Y=cmX;UoYIWmwMn=06znG>;u z?Fs4RlR_?;8R62nA>Bp88gvIegp72-6Etn-4BJ=`+0;s2P~MYdNQ4sKypo_9Azc`P zC_^dmg?9kAyEx&<Gg(Sf^DL zqXjd&iWP?jK3mT?U|M1wGw|N9X)M@|>zNsshDExtu)telRfbQ)I$$eeL5n^Q)*Hs< zAzYRg+$Sg>P6^9cR;{wt4>k&S11oJ>rdQ_EVarP7@{TNX*>NFlVfFUJvX({IUX$1` zH(-zPzQ+zLS(KQdVYPi7xk97Dix;F6wzo?2?<~SHXAF-<>?Kn=b`D)=WEm@)Eu+jB z(qu2VMI}kkkY2)`cgPjq(P>vC7lmbwEQ<{9Xr>hp4|>{JLuMxmUcTUM$QqFn2Zsm6 zr7%2k$eA_mtaCz!D?aTrUdqjBpidI=O{=aqYJoPjhVLKDY}j&XjYn@P?Yk4 zzIvvN*x8ABUjfY;rgy-RBg-cHBO}xyQ3}W5WE|Jx%BL1#P*$Bw)uN;&L>{qf*BnhD zs~ti~QG$|ml;VhQan!@$%pm3_=nx%1iWeoCZAFh2L{*Oj<-m9F^AJhr*3f&Y2b2Wa zG!H2P(4Ycx5>L^1v;oY5Y=Iaoh%Oo-iJybAmoLHkwfL>jej8Ei2qdy*i9S#L>T}QO zbm22^KC9E+KmX;K!>{gn;h~?!5W&xE`RVCD{PiEB-~PpH{?gz4^XpXo>@9OMm-M}H zA8zN+=B5Z>6Pns(bzz;f3SHCcH)){=>N*A?MM-e8I#k(&?5VDTLUna@l@tc7!}z+o z3O%HtrZwas1*56qW;B=!F#y#URn>-?LJc?an1WrH&R#p@R-n4 zuBaOPb|Jc)v#C^Q>#Q{Lha9`K#j%~86Ry&QJT`a_hA`k!l+$>BoyL1`Dmk1y`}f0- z-~F{m;!l3JqV1j+->u^z!+YnFvvZ?~RL9uh(A;GFD6ow^_94km`lh+%J=e?yE<4ZY zSU#I3FL+DA9Qq2kb#ATyPL}l}IvVG*F4RS?G6W%1faP)TwUR!tUcmp25>ih~9j|D9 zI_~jb(`DNHJb3av^u-P6Josdp1i$Go^8G-b7$ABFr?L1wj5O>o!5(1RJ7H`T(6~s1&#cVw4NMfkaj;|}R66}F=pcCak}p0L$?S1tcA`b)PH>^MjbkUIwb3rZrdL>@OG&v1bj zp^cPJ*V1&nrgZ#zU}F#Q?%bpNx+=%tFeh`3_~VOEQ?zs@Fc8T$q8m^8Q&X@7&cpckO)N48jAh@<$poT!HuA zZ`@nY|773(<(#E2`LB=uC~lOfF6@lM8Bc$7I(499PgHkRl4m)#=#Q=lH@g4&O||=s z;O(J9fbI523)0@}W)_j=yB#?*BOTY7_c}68Zm;3yVoTjo9q%A>UbtTI@>bd)O4m!m z5?S2fNRiiA#CKd&w{eB{N5@wN^LfieN{dHL%*f}XoxTK57F?CGen5MAqG}v;yU1#h zIj#gaC{o;9fSn>ciT5Wmiv{6+K&ib&sXD$@Iez90i^uT9v~-JMf7Eaj_L75yKdKkZ z!3<~j{n2^Daz!vHC8To$Yl^0KuCaYzXUPfZu&=YYLO^(Def)i79?+4mLHQH?ADIOo JEB**Q@Lz4-z%~E? literal 0 HcmV?d00001 diff --git a/app/drivers/ROBOTIS/RobotisDriverInstaller.pdb b/app/drivers/ROBOTIS/RobotisDriverInstaller.pdb new file mode 100644 index 0000000000000000000000000000000000000000..49b01ab3fef3af01ea3d718af28103ae5428980c GIT binary patch literal 13824 zcmeHNTWl0n7(Tm{OD|hkumua&v4Ubtcek{*KnS;8imPo}C3PT0=Wnc?hL$p=XgFF`B{jD-N)4e%Bv4QmYZDN^^1u-IJ-zzzQLza`UHr+Y8Ut_%H^9n3GjNF@{7Q@cQ*>czQCK8Ms;h&-VI%GI#l? zw!Imu@m>6IUdo5mZ!d3u=jCHZqbEL|zVwx|!^Msv^Qdn5b#rZQk~`ZAPY?!fHvjoi zbg%!6vpKmqL7M2fc?$--{=Wq|Qy}YV=jOF%W?l&Pw~2w46aIHkZ+zzHAHV+?>|blg z3y&XqE||IyJXI;g)miaVJKs~+o$q?F>9fllE*{WN9_6-?^3>-al|`?$#8=OmckT7# z2lDMy?>SKzn4kTcJ2+AN_Wb;R3=9tq53%ddv6|Sb_O@;9o8numo7Qh=Z;f^!wngjI zOvQ-l${tydtA?3Kr)7PN$*sE9ttWazNkfRPRqe*!_HMGn&ytd}S^ zUNW}izLA%3_ad`J5VkG__0FXM?&1+0L+>hOtbp7IiaWsmx^gYmU|WU zjxF;G#NyzyZTk&V?iJ-D;ZRh=l94nOO*KNBWL4Icq?qfbSY{#-ccqb ztNmz$g?z6r8@to+pcHv*n>(-1)Wve7XUF}GGK#TH+go4PXl#+Y6y0udOfeFjX}ODa zvM#Pdqw1;=;xVL?Pj`B9x30^o8MErq^!+Sf4!h|&c8Z#6RMK*5!t4>1$Y*D{>p^}@ zP9@Nm?AmQvk}oO9O`6+w^_uRE4n$5)(a`0l=mM#~0d1u#NI`henpWpfTh5PfKYHOGF8Bb zfop&g@M&NLn*RcD8R7?lgG0j^@)1V-2rvRX21IveP6EMK<_lmo@H-%Q%zO`IxgUV_ zh?AEUz)QfDz`ud3fd2q#cNGX9GXDbC0sUx86gVBY5m*Rp1Qr3~z)~Q5%>;xb0vJ^R zu>-mox(V70eG>W-bT$S$S`H~e%_Z=%1fG<@i=b$LqP38Kcm&}MP^L@Sv=G8|*}TOF zFF?3P3AL#52I0Wj|R|fJx~dX^N#3)I>NIO&QOrS0SoZ3e;suHKIr5S3&d%R9m?An zJRCnO-uKyu4}@=iy%@?~7>e4uhT8Qj>l;M%m!T`p*mKTztkV%cPJ#i;z<1+!O4@PU zQrJ!hc}8?b^1Zn7bnaNQ?$Hff=#(w_mV}iWZ6bl5+&>1mo_pdk;4$Da;4$Da;4v_@82AsJL_LZC literal 0 HcmV?d00001 diff --git a/app/modules/robotis_RB100_Practical_AssemblyBT.json b/app/modules/robotis_RB100_Practical_AssemblyBT.json index 346ac260f..a38030e77 100644 --- a/app/modules/robotis_RB100_Practical_AssemblyBT.json +++ b/app/modules/robotis_RB100_Practical_AssemblyBT.json @@ -13,7 +13,7 @@ "reconnect" : true, "driver": { "win32-ia32": "ROBOTIS/ROBOTIS CDC Driver.bat", - "win32-x64": "ROBOTIS/ROBOTIS CDC Driver.bat" + "win32-x64": "ROBOTIS/RobotisDriverInstaller.exe" }, "selectPort" : false, "hardware": { From 2dcffc1072d74c0a90cd86b29dd136b3f6b894d4 Mon Sep 17 00:00:00 2001 From: Jason Kim Date: Thu, 11 Apr 2024 09:46:30 +0900 Subject: [PATCH 13/18] =?UTF-8?q?=EA=B6=8C=ED=95=9C=EC=83=81=EC=8A=B9=20?= =?UTF-8?q?=ED=95=84=EC=9A=94=ED=95=9C=20=EA=B2=BD=EC=9A=B0=20=EB=A9=94?= =?UTF-8?q?=EC=8B=9C=EC=A7=80=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ROBOTIS/RobotisDriverInstaller.exe | Bin 6656 -> 7168 bytes .../ROBOTIS/RobotisDriverInstaller.pdb | Bin 13824 -> 13824 bytes 2 files changed, 0 insertions(+), 0 deletions(-) diff --git a/app/drivers/ROBOTIS/RobotisDriverInstaller.exe b/app/drivers/ROBOTIS/RobotisDriverInstaller.exe index 28b754655f49896d6231bcc3362dfd7b881b271d..7d18a85574a74c1bf7170a44dab9f98c751edde4 100644 GIT binary patch delta 987 zcmXw2ZEQw=Y8(I?|XAj=Yq~feck2z zsweNp`1Ju2GcqG!AtC?2Xr2?kzRCQ^4XoFMdZ1e$wicVV118F4Dohtv$tAWhTmHmC zk~oD$oMcWmLEL9HHdVZ5<@_5NwQD7XgdC)-KrOvNM>&OF+$o$Znk1QR6h7%SYZVS% zX{abysiaN<5uih{5u06{l|E)A*W?){yIphDFm%|1zKkStW2^yA$oMSCH3T~I11dP^_@)Is|MQqdxDz3 zD;F4Ir1`w?&=1pIQnA9f%0uf$%0G)QI$IGDP*B%I4uY99arRogl@SGdF-VeLLM$*8r&#GKjAd|BCJ3ObHj;7!ujwLF3#u; z*iL*+M%jvk#CPH-VG!2{58)o+aXcnGg(TBq77P?!kahLqt-dMhF!aif2F0)LX!8d_ zB&f8vG$`##0Kpb@TcZ+a*%MIq`*&qDao1=SuZ_1t3;Pq1=gn!3aPsL>Pm*KGNKblm zdS*<0$k7|oD#JtZ5tS;Qbbq2Pof;e)WWFs>u%GsfA1!q6BGy4`0DI9!9R~>&s&S~a zW^22NYYt6q&GWhsx;geEa_s@fiPZDh=o^ky{C48%NOO!HO8*?>$U3xE zZzt4OkvNCuL*!<>FR3+Lo7CK6G=@se|4uC$?oYVE90hbXmQzz|rcsWouMWq#5T;3% ziYH5>?W+ftb^ndKZqy{#ikL|?aweJeV63R~Skzgtm$|Y>PTLa~DL5SsPFrV#*W(>f zs)q+Imp5FfKJOeYo3~Jmn!6{Ajh`Lz;*Z98*jgfebBhCo=fprsU({^*Wsod&(V{6| IS$MADA2`4EmjD0& delta 592 zcmXw0O=uHg5Ph@RWYaWVH;q)WQFjxXY`U8eum@3!VhgFLw3x;pyeNVq6fH>(f+ztM zgFnSEf`2gxDyT#W21Mvhy(oCH2MUY{Z@!PIuCESVuEpnC z(L-1|AD~b-bpyH>p?_vGQ-8Qi-<|=+J!3Oa3)HP>cs~%9{E7?2*iu~HOR3P^9&8pnsoiTv|KQ3B8P)7MA7X;XfnqT_t;hfYYP5}*x zEmd@(QaW<##3j%Wz6U72zU4VB-B46A(D$$kvJ*U-F#FR`XLz?C7K$;JzpL|XA z5|8`ybf$CFzl@IkKvvxZqI+r?UATpQWD!M8xF27I69`cj4mJp{Ltc2}qCbL3(c2cC zeV7t`5GCO<8p0>=K=?GC2w%V~`7i)YaGWh|vQyS(RCdB9?+CYOfERj_#+*G-P;l}mzp_`|WeD{^&ep m)OssROOsm6c-pL6eM&XM3&ypM-uqiqZVz`NtG-b^r~L&RFm^ekux;iEW@S4Ch+J_uH)W@2^AqF zn-4qp=^x(cxPg%~1f(7aLN*HueP`w{=bo9pvila}WI-W=$qr%)EF7i}iZ-W+ZD3>! znJg-y%^0%TQ9_=HF=cY1RJ!B_sAfh6Mh2KcNlfC~d>Q&>#+^ZGp5R zkhTNT>Ok57NE-raM<8tsq~E>&*I){yU4eWHAngvM?SZrxkahynK0w+7Nc#e5Paqut zq=SKU;N*+ap@QKIqCgWx86tq#kwK8bcC)(7O2$oc@+^$fn-!EkF;Dd4nk2`uSw+o* zN#q1j8xS$P$nF&eQeZGyQABL=Gz~eRF9n5!C!f#|0s8c=hB_mjFx3)ZVw|yASLZS( E06`pD0ssI2 delta 343 zcmZq3X~@~Y!Xgw9)xlLdtgCOe2JuuN0Bp13(hYy%^s z_+(KDZAS6UjuP@rjOvpUrP3uEpqd#O7#Uy&$pH;3nfy>{m0QCXAk&J0q2U{le)s-g z!w(>B2ju?-(hfkH38>u}NV5WIS0K#|q}_lt50Lf*(qcf`Yw}0wP)5tm;W8^3Ck7a7 zl9Oj)l-aDH^of}>4QLDlLo$Q;W@)uRCXpFH)j-5xv5HX!ECVDaD~gCso~9uObiAOD d@Z=L3B0vw^)lg@|6I5CPOpF From 484ef1f8bdcad3d8c4da4566fa07b91967860509 Mon Sep 17 00:00:00 2001 From: Jason Kim Date: Thu, 11 Apr 2024 13:35:14 +0900 Subject: [PATCH 14/18] =?UTF-8?q?=EB=AC=B8=EA=B5=AC=20=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ROBOTIS/RobotisDriverInstaller.exe | Bin 7168 -> 7680 bytes .../ROBOTIS/RobotisDriverInstaller.pdb | Bin 13824 -> 13824 bytes 2 files changed, 0 insertions(+), 0 deletions(-) diff --git a/app/drivers/ROBOTIS/RobotisDriverInstaller.exe b/app/drivers/ROBOTIS/RobotisDriverInstaller.exe index 7d18a85574a74c1bf7170a44dab9f98c751edde4..a6b8a94055fddda9bb07a9ae90468229d0c5a9b9 100644 GIT binary patch delta 1451 zcmZ`(TWl0n82-+5_P(9$Zb=KYw7acsx83cs-Xe(?Y5;MSVr4B>fxrOMWo5h5?#@cV zNJ|Q#0f{!Fk%;o5FB&x_O*BSKB&iQ3@L~-3piK)VYBU-z5163wJHu}5iIq~))3qS1X=&Q z7HF|!O45Exbo1$6++9nyTaa5Q6ZF&ioud4b19YZ zm(JJnM*jl5NslM4@cg>meV%xdjIQ434?NI#A9F54gt!BoL3R=6ctoOAiKp!Oy7>LW zBy}7G<{8(ym}jk0zL+aZ`b{tJHB~!?viOSMgVgBQJe1kU_#NvTc8}T}=5g^=0xFFH zNZGo2IUZ5}u5)8p?WCV@{0r&;+_>cUpB&%gTIsR}T@NYVcKfVrVR8wrs*WYxt&ZSh zY*U}1H`F42!!(h<@UmJaa-PVK_`vCYrZz)}E9`!OYw83!H`M2u2VKXRPpj(@7HQWh z`0xgrkwOFBq;G~#q|kv*`UHmP@5Ek_dI0x2jSVmfJt`sWz)AXjI745?NA%BOo_-pa z=}+T|s6!__v=`@Mp2yYf;j(3nrZyMMy?P;kM7Q#05gRH6t5PyD#Ss%Z!`huGmMy(d zF!m2+sx1e8;*hz;uq>mL$v(D4FXk$G&e*Dt8unP=lYlw4d((J@n$}^vH`s0u1h3gA z>UY{}>$gu%U40NEuwbCX-_F1U@~rYGBFEao0b)^%vCH}Cb&MiOq(n}RT?>8OVu95@ z9Q@xAQ5U$r#r=EAwAZfBy=8#Pks_j|I$eqd)xHW~8HYma8Lh|_4Prq-? zT)6q}MPnGN>=sS$=hqq;uZu#XDQXmvipnoZQ=>xB+|0sLCtOezO_Q*`1G9S7;`3 wsd@p*h5aJ)=xnS}SxnEyR?Ph#Y7ut72+e7cKRiA*<<*MY=fbOh6|-s2zkdH2NdN!< delta 937 zcmYL|e@IhN6vw~!?YjAN&b`gH(5Y`*bIYxzizvy^N-VR;nhL3b5|#bHmorERb&}91 zg5+iql?eTl{rGEC2oXww_J`D8(O*&+VGwB4KL!0bZ*Fwqe9t+bbMEE7d*6*$$G2Wf zczPqw<4BJWkXSCu1*`;eR-t9%=z~_v^DuBg2em-LIO?{WI{`E0oC+@CmO|n%^XC-g z6H>{n;xY>|n|R9ntWYd4kGevQ`q)DzAq#VEpqf@NP)=qPioHTKNt`u{7O7)MR%C}( zNV`yEr&g5quCy;sd98$;td)|M1tYSiQlQbQId+p`3V2dQ?|&A%1e~RUgHXDfnz4@Z z(2T74$S-u;vtu`@uT9C;$_T_JDG4|;Q!?~1QO!?ugFS;5GbrRNH3tIv+$u(M^?ekt z=3}W`yfv)xttVPmt}fA+2g)ffXZn$208R7grY~Y8QXnYIJg~i%TD*h6Bl7P##nE%I zlRYQ;^!AZ#V44wYiK33~OJBpgyQQIyd^6=sqL=#>Iubf@x+=0PvY?pc^Bx2D8I16z zbPL}PBhIJvMoQ=SGcLxn>ZNJ7_?)#cG=<-WE=ShW8L@Ao3CIT(6$y zMfizfs=mfm-bX$6ct2^F*Fa`(_z+~=MG?ZV<2q>(evx|NU||GNPr3Li4A^iy&agQR`9PkI4QNH5|A=@rZ}1AH)%jU#@GkYg?CjL%^9#+ln6F>61Dh(gkB7oDFKIi<-IsbFc|NN)M)%c{z z;(FQVJf#RBeA6>Oj`Y^-y%Xs8oxG6nY932%p>-hr%zN|J!Q{h>FNR+wMyIAClZrX5 z_vcD$w$cS-@s78{jc=}gRHUu6UWOfh(}cQwOgrhgub8dITu*6t1q(hH7$YODY3E8? zSLevtq2B(w*7)G@XgrpP4#frsq*A`n^5TE;cyypo?^8wF zGPzhDv`;X{I+F2h&&(*ZY;srI-_dfL^n0#FpT{E4xZ6`^5`!odzc55E{Zjbk_gPEb zlgrD6Q1zl4_0?3M6)Vw!UZgC1xCZ^W4FlMQ)k0i8kF=?y$h}kQH460vV>mazr0R=b zPyHS?;se}(k8vZu#s++koADFsiQO&aS^wom1nsfofyUdMlgtT^Qk4ZhC&NL zGw#F|+=U(3ik-Lzqu7q8QJ=6M_fa3l12~e)&tVt!BzEH^Jd9WHC|<{7cmsQQjOtwq zQTekXSX9D_OT;GW^sH@Y6?WEZ7l-&p*ozPjhG(aj_D09g1kgN1*r5@!EU5MEw`8?!N(%R=x UQ2EdQWVO{`=qb?ZYG=%U0sXzHxBvhE delta 655 zcmaLV&ui0Q9LMn|S+=F~(rinX#jNe3nBwZTR_i7>Z5-myLB)Xn0mI8CqImEki!g>F ziuD0;3bKQs-m1BH5jM6#K}7H<2__4Bzur9Z=gr&} zBBGG!#pIlWX>`%TK4gdt4qz6KU=B|swdQVOf%z=1t#8jnNwY%)5{K~#7V!o0FwtAw zhpTu1-y;X34|tGy@<^lj6AuY-D^0V9nfKrr_9IP1K31@Z0q)1O^^xtU%*}CvQ9OZ1 zk#3`7cot9M1fIewp2u^t=K6Bc9W*Wold`6`$OwcX#$>kdTdmr7lgVnz&N%1&YN=JV zhZ#NIy{DqOE6MxgYEXoq_%U^_>rcR+?C-YZqrBbzHwgI-x@05Yt%UKHys!M{3)`Dk M)yG;qSooCs4cVuH@c;k- From 304c94907fcbe15960a69bbfde853b0f46c8238d Mon Sep 17 00:00:00 2001 From: HagwonSong Date: Mon, 15 Apr 2024 14:56:05 +0900 Subject: [PATCH 15/18] =?UTF-8?q?ToyBot=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/modules/jinirobot_toybot.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/modules/jinirobot_toybot.js b/app/modules/jinirobot_toybot.js index a260ffa1a..afbdcb071 100644 --- a/app/modules/jinirobot_toybot.js +++ b/app/modules/jinirobot_toybot.js @@ -12,7 +12,7 @@ function Module() { offset: [0, 0, 0, 0, 0] }; this.repeatRead = [ - {index: 0x13, repeat: 0x02}, // Servo Control Each + {index: 0x16, repeat: 0x02}, // Servo Current Each {index: 0x1E, repeat: 0x02}, // Servo Calibration {index: 0x43, repeat: 0x02}, // Analog Value {index: 0x53, repeat: 0x02}, // Button Control @@ -182,13 +182,13 @@ Module.prototype.parsing = function(data) { const index = data[6 + count]; const size = data[7 + count] | (data[8 + count] << 8); switch (index) { - case 0x03: { + case 0x03: { // Name this.deviceInfo.name = ''; for (let i = 10; i < 21; i++) { this.deviceInfo.name += String.fromCharCode(data[i + count]); } } break; - case 0x13: { // Control Each + case 0x16: { // Current Each const repeat = data[9 + count] * 4; for (let i = 0; i < repeat; i += 4) { const id = data[10 + i + count]; From e03e98bf80aeafdc5a31bd3ce7022976920b4855 Mon Sep 17 00:00:00 2001 From: YejinChoi <715jin@naver.com> Date: Wed, 17 Apr 2024 13:06:00 +0900 Subject: [PATCH 16/18] 240417-Change Protocol --- app/modules/iCOBOT.js | 920 +++++++++++++++--------------------------- 1 file changed, 336 insertions(+), 584 deletions(-) diff --git a/app/modules/iCOBOT.js b/app/modules/iCOBOT.js index 0fcbd504b..c56a78441 100644 --- a/app/modules/iCOBOT.js +++ b/app/modules/iCOBOT.js @@ -1,627 +1,379 @@ function Module() { - this.sp = null; - this.sensorTypes = - { - ALIVE: 0, - SENSOR: 1, - MOTOR: 2, - BUZZER: 3, - RGBLED: 4, - TONE: 5, - } - - this.actionTypes = - { - GET: 1, - SET: 2, - RESET: 3, - MODULE:4, - }; - - this.sensorValueSize = - { - FLOAT: 2, - SHORT: 3, - STRING : 4 - } - - this.digitalPortTimeList = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; - - this.sensorData = - { - SENSOR: - { - Brightness: 0, - BLeft_IR: 0, - Front_IR: 0, - BRight_IR: 0, - Sound: 0, - Right_IR: 0, - BMid_IR: 0, - Left_IR: 0, - Real_T: 0, - Real_H: 0, - Motor_F: 0, - }, + this.tx_d = new Array(22); + this.rx_d = new Array(16); + this.sensordata = { Brightness: 0, - BLeft_IR: 0, - Front_IR: 0, BRight_IR: 0, - Sound: 0, - Right_IR: 0, BMid_IR: 0, + BLeft_IR: 0, + Right_IR: 0, Left_IR: 0, + Front_IR: 0, Real_T: 0, Real_H: 0, + Sound: 0, + Motor_F: 0 + }; + this.outdata = { + left_up_red: 0, + left_up_green: 0, + left_up_blue: 0, + right_up_red: 0, + right_up_green: 0, + right_up_blue: 0, + left_down_red: 0, + left_down_green: 0, + left_down_blue: 0, + right_down_red: 0, + right_down_green: 0, + right_down_blue: 0, + tone: 0, + leftmotor_speed: 0, + leftmotor_dir: 0, + rightmotor_speed: 0, + rightmotor_dir: 0, + motor_mode: 0, + motor_value: 0, + motor_dir: 0 + }; + for(var i = 0; i < 16 ; ++i) { + this.rx_d[i] = 0; } +} - this.defaultOutput = {}; +var iCOBOT = { + LURED: 'left_up_red', + LUGREEN: 'left_up_green', + LUBLUE: 'left_up_blue', + RURED: 'right_up_red', + RUGREEN: 'right_up_green', + RUBLUE: 'right_up_blue', + LDRED: 'left_down_red', + LDGREEN: 'left_down_green', + LDBLUE: 'left_down_blue', + RDRED: 'right_down_red', + RDGREEN: 'right_down_green', + RDBLUE: 'right_down_blue', + TONE: 'tone', + LMOTORSPEED: 'leftmotor_speed', + LMOTORDIR: 'leftmotor_dir', + RMOTORSPEED: 'rightmotor_speed', + RMOTORDIR: 'rightmotor_dir', + MOTORMODE: 'motor_mode', + MOTORVALUE: 'motor_value', + MOTORDIR: 'motor_dir' +}; - this.recentCheckData = {}; +Module.prototype.init = function(handler, config){ + //console.log(this.motoring.lcdTxt); +}; - this.sendBuffers = []; +Module.prototype.lostController = function(){} - this.lastTime = 0; - this.lastSendTime = 0; - this.isDraing = false; - +Module.prototype.eventController = function(state){ + if(state === 'connected'){ + clearInterval(this.sensing); + } } -var sensorIdx = 0; - -// Handler Data -Module.prototype.init = function(handler, config) /// 초기설정, 엔트리 브라우저와 연결되었을 때 호출됨 -{ - -}; - -// Serial Port -Module.prototype.setSerialPort = function (sp) /// 시리얼포트 정보를 가지고오기, 최초 연결시도 성공 후에 호출 -{ - var self = this; +Module.prototype.setSerialPort = function(sp){ this.sp = sp; }; -// Hardware -Module.prototype.requestInitialData = function() /// 초기 송신 데이터(최초 연결시 디바이스에 보낼 데이터) -{ - return null; - //return this.makeSensorReadBuffer(this.sensorTypes.ANALOG, 0); -}; - -// Hardware Vaildation -Module.prototype.checkInitialData = function(data, config) /// 초기 수신데이터 체크 -{ - // 최초 연결시도에서 디바이스의 데이터를 받아, 원하는 데이터가 맞는지 판단하는 로직 - // requestInitialData 가 선언되어있다면 필수 - return true; -}; - -Module.prototype.afterConnect = function(that, cb) -{ - ///cb 은 화면의 이벤트를 보내는 로직입니다. 여기서는 connected - //라는 신호를 보내 강제로 연결됨 화면으로 넘어갑니다. - that.connected = true; - if (cb) { - cb('connected'); - }; +Module.prototype.requestInitialData = function(sp){ + var tx_d =this.tx_d; + tx_d[0] = 0x02; + tx_d[1] = 0x05; + tx_d[2] = 0; + tx_d[3] = 0; + tx_d[4] = 0; + tx_d[5] = 0; + tx_d[6] = 0; + tx_d[7] = 0; + tx_d[8] = 0; + tx_d[9] = 0; + tx_d[10] = 0; + tx_d[11] = 0; + tx_d[12] = 0; + tx_d[13] = 0; + tx_d[14] = 0; + tx_d[15] = 0; + tx_d[16] = 0; + tx_d[17] = 0; + tx_d[18] = 0; + tx_d[19] = 0; + tx_d[20] = 0; + tx_d[21] = 0x03; + return tx_d; }; -// 1. Hardware Vaildation -Module.prototype.validateLocalData = function(data) -{ +Module.prototype.checkInitialData = function(data,config){ return true; }; -// 2. getDataByBuffer -Module.prototype.getDataByBuffer = function(buffer) // 해당 코드 내에서만 쓰는 함수입니다. -{ - var datas = []; - var lastIndex = 0; - - buffer.forEach(function (value, idx) - { - //console.log(value, " : ", idx); - if(value == 13 && buffer[idx + 1] == 10) - { - datas.push(buffer.subarray(lastIndex, idx)); - lastIndex = idx + 2; +// 하드웨어 데이터 처리 +Module.prototype.handleLocalData = function(data){ // data: Native Buffer + var buf = this.rx_d; + var rx_check_sum = 0; + var sensordata = this.sensordata; + for(var i = 0; i> 2 ) + ((buf[4] & 0x0f) << 6)); + sensordata.BMid_IR = ((buf[4] >> 4 ) + ((buf [5] & 0x3f) << 4)); + sensordata.BLeft_IR = ((buf[5] >> 6 ) + ((buf[6]) << 2)); + sensordata.Right_IR = ((buf[7]) + ((buf[8] & 0x03 ) << 8)); + sensordata.Left_IR = ((buf[8] >> 2 ) + ((buf[9] & 0x0f) << 6)); + sensordata.Front_IR = ((buf[9] >> 4 ) + ((buf[10] & 0x3f) << 4)); + sensordata.Real_T = ((buf[10] >> 6 ) + ((buf[11]) << 2)); + sensordata.Real_H = ((buf[12]) + ((buf[13] & 0x03 ) << 8)); + sensordata.Sound = ((buf[13] >> 2 ) + ((buf[14] & 0x0f ) << 6)); + sensordata.Motor_F = ((buf[14] & 0x30) >> 4); + //console.log(sensordata.Brightness, " : ", sensordata.BRight_IR, " : ", sensordata.BMid_IR, " : ", sensordata.BLeft_IR, " : ", sensordata.Right_IR, " : ", sensordata.Left_IR, " : ", sensordata.Front_IR, " : ", sensordata.Real_T, " : ", sensordata.Real_H, " : ", sensordata.Sound, " : ", sensordata.Motor_F); } - }); - - return datas; + } }; -/* -ff 55 idx size data a -*/ -// 3. Hardware -var show_turn = 0; -Module.prototype.handleLocalData = function(data) -{ - // 하드웨어에서 보내준 정보를 가공합니다. 여기선 하드웨어에서 정보를 읽어서 처리하지 않습니다. - var self = this; - var datas = this.getDataByBuffer(data); - - value_show_new_time = new Date().getTime(); - - datas.forEach(function (data) - { - // console.log(data); - if(data.length <= 4 || data[0] !== 255 || data[1] !== 85) { - return; - } - var readData = data.subarray(2, data.length); - - var type = readData[readData.length - 1]; - var value; - var pre = 0; - - for (var i = 0; i < 11; i++) { - value = new Buffer(readData.subarray(pre,(pre+4))).readFloatLE(); - value = Math.round(value * 100) / 100; - pre = pre+4; - - switch(type) { - case self.sensorTypes.SENSOR: { - self.sensorData.SENSOR[i] = value; - switch(i){ - case 0: { - self.sensorData.Brightness = value; - break; - } - case 1: { - self.sensorData.BLeft_IR = value; - break; - } - case 2: { - self.sensorData.Front_IR = value; - break; - } - case 3: { - self.sensorData.BRight_IR = value; - break; - } - case 4: { - self.sensorData.Sound = value; - break; - } - case 5: { - self.sensorData.Right_IR = value; - break; - } - case 6: { - self.sensorData.BMid_IR = value; - break; - } - case 7: { - self.sensorData.Left_IR = value; - break; - } - case 8: { - self.sensorData.Real_T = value; - break; - } - case 9: { - self.sensorData.Real_H = value; - break; - } - default: { - break; - } - } - } - default: { - break; - } - } - - } - }); +// Web Socket(엔트리)에 전달할 데이터 +Module.prototype.requestRemoteData = function(handler){ + var sensordata = this.sensordata; + for(var key in sensordata){ + handler.write(key,sensordata[key]); + } }; -// Module.prototype.handleLocalData = function(data) -// { -// // 하드웨어에서 보내준 정보를 가공합니다. 여기선 하드웨어에서 정보를 읽어서 처리하지 않습니다. -// var self = this; -// var datas = this.getDataByBuffer(data); - -// datas.forEach(function (data) -// { -// if(data.length <= 4 || data[0] !== 255 || data[1] !== 85) { -// return; -// } -// var readData = data.subarray(2, data.length); - -// var type = readData[readData.length - 1]; -// var port = readData[readData.length - 2]; - -// var value; - -// switch(readData[0]) { -// case self.sensorValueSize.FLOAT: //2 -// { -// value = new Buffer(readData.subarray(1, 5)).readFloatLE(); -// value = Math.round(value * 100) / 100; -// //console.log(value, " : ", port); -// break; -// } -// case self.sensorValueSize.SHORT: { //3 -// value = new Buffer(readData.subarray(1, 3)).readInt16LE(); -// break; -// } -// case self.sensorValueSize.STRING: { //4 -// value = new Buffer(readData[1] + 3); -// value = readData.slice(2, readData[1] + 3); -// value = value.toString('ascii', 0, value.length); -// break; -// } -// default: { -// value = 0; -// break; -// } -// } - -// switch(type) { -// case self.sensorTypes.SENSOR: { -// self.sensorData.SENSOR[port] = value; - -// switch(port){ -// case 0: { -// self.sensorData.Brightness = value; -// break; -// } -// case 1: { -// self.sensorData.BLeft_IR = value; -// break; -// } -// case 2: { -// self.sensorData.Front_IR = value; -// break; -// } -// case 3: { -// self.sensorData.BRight_IR = value; -// break; -// } -// case 4: { -// self.sensorData.Sound = value; -// break; -// } -// case 5: { -// self.sensorData.Right_IR = value; -// break; -// } -// case 6: { -// self.sensorData.BMid_IR = value; -// break; -// } -// case 7: { -// self.sensorData.Left_IR = value; -// break; -// } -// case 8: { -// self.sensorData.Real_T = value; -// break; -// } -// case 9: { -// self.sensorData.Real_H = value; -// break; -// } -// default: { -// break; -// } -// } -// break; -// } -// default: { -// break; -// } -// } -// }); -// }; - -// 4. -Module.prototype.requestRemoteData = function(handler) -{ - // 디바이스에서 데이터를 받아온 후, 브라우저로 데이터를 보내기 위해 호출되는 로직. handler 를 세팅하는 것으로 값을 보낼 수 있다. - // handler.write(key, value) 로 세팅한 값은 Entry.hw.portData 에서 받아볼 수 있다. - /// 엔트리에 전달할 데이터. 이 코드에서는 하드웨어에서 어떤 정보도 전달하지 않습니다. - var self = this; - if(!self.sensorData) return; - - Object.keys(this.sensorData).forEach(function (key) - { - if(self.sensorData[key] != undefined) - { - handler.write(key, self.sensorData[key]); +// Web Socket 데이터 처리 +Module.prototype.handleRemoteData = function(handler){ + var outdata = this.outdata; + var newValue; + // Left Up LED + if(handler.e(iCOBOT.LURED)){ + newValue = handler.read(iCOBOT.LURED); + if(newValue < 0) newValue = 0; + else if(newValue >255 ) newValue = 255; + if(outdata.left_up_red != newValue){ + outdata.left_up_red = newValue; } - }) -}; - -// 5. -Module.prototype.handleRemoteData = function(handler) -{ - // 엔트리 브라우저에서 온 데이터를 처리한다. handler.read 로 브라우저의 데이터를 읽어올 수 있다. - // handler 의 값은 Entry.hw.sendQueue 에 세팅한 값과 같다. - /// 엔트리에서 전달된 데이터 처리(Entry.hw.sendQueue로 보낸 데이터) - var self = this; - var getDatas = handler.read('GET'); - var setDatas = handler.read('SET') || this.defaultOutput; - var time = handler.read('TIME'); - var buffer = new Buffer([]); - - if(getDatas) - { - var keys = Object.keys(getDatas); - - keys.forEach(function(key) /// key에 해당하는 데이터를 분석하여 처리 - { - var isSend = false; - var dataObj = getDatas[key]; - - if(typeof dataObj.port === 'string' || typeof dataObj.port === 'number') - { - var time = self.digitalPortTimeList[dataObj.port]; - if(dataObj.time > time) - { - isSend = true; - self.digitalPortTimeList[dataObj.port] = dataObj.time; - } - - } - else if(Array.isArray(dataObj.port)) - { - isSend = dataObj.port.every(function(port) - { - var time = self.digitalPortTimeList[port]; - return dataObj.time > time; - }); - - if(isSend) - { - dataObj.port.forEach(function(port) - { - self.digitalPortTimeList[port] = dataObj.time; - }); - } - } - - if(isSend) - { - if(!self.isRecentData(dataObj.port, key, dataObj.data)) // 여기서의 비교로 같은 명령어의 반복실행을 방지 - { - self.recentCheckData[dataObj.port] = - { - type: key, - data: dataObj.data - } - buffer = Buffer.concat([buffer, self.makeSensorReadBuffer(key, dataObj.port, dataObj.data)]); - } - } - }); } - - if(setDatas) // 출력 - { - var setKeys = Object.keys(setDatas); - setKeys.forEach(function (port) /// port에 해당하는 데이터를 분석하여 처리 - { - var data = setDatas[port]; - if(data) - { - if(self.digitalPortTimeList[port] < data.time) // 데이터 생성시간과 현 시간보다 이전 이면 - { - self.digitalPortTimeList[port] = data.time; - - if(!self.isRecentData(port, data.type, data.data)) - { - self.recentCheckData[port] = - { - type: data.type, - data: data.data - } - //console.log("data.type: ", data.type); - //console.log("data.data: ", data.data); - buffer = Buffer.concat([buffer, self.makeOutputBuffer(data.type, port, data.data)]); - - } /// 전송 패킷 생성하여 버퍼에 저장 - } - } - }); + if(handler.e(iCOBOT.LUGREEN)){ + newValue = handler.read(iCOBOT.LUGREEN); + if(newValue < 0) newValue = 0; + else if(newValue >255 ) newValue = 255; + if(outdata.left_up_green != newValue){ + outdata.left_up_green = newValue; + } } - - if(buffer.length) { - this.sendBuffers.push(buffer); + if(handler.e(iCOBOT.LUBLUE)){ + newValue = handler.read(iCOBOT.LUBLUE); + if(newValue < 0) newValue = 0; + else if(newValue >255 ) newValue = 255; + if(outdata.left_up_blue != newValue){ + outdata.left_up_blue = newValue; + } } -}; - -// 6. Hardware -Module.prototype.requestLocalData = function() // 하드웨어에 명령을 전송합니다. -{ - // 디바이스로 데이터를 보내는 로직. control: slave 인 경우 duration 주기에 맞춰 디바이스에 데이터를 보낸다. - // return 값으로 버퍼를 반환하면 디바이스로 데이터를 보내나, 아두이노의 경우 레거시 코드를 따르고 있다. - var self = this; - - if(!this.isDraing && this.sendBuffers.length > 0) - { - this.isDraing = true; - - this.sp.write(this.sendBuffers.shift(), function () - { - if(self.sp) - { - self.sp.drain(function () - { - self.isDraing = false; - }); - } - }); + // Right Up LED + if(handler.e(iCOBOT.RURED)){ + newValue = handler.read(iCOBOT.RURED); + if(newValue < 0) newValue = 0; + else if(newValue >255 ) newValue = 255; + if(outdata.right_up_red != newValue){ + outdata.right_up_red = newValue; + } } - - return null; -}; -var prePort = 0; -Module.prototype.isRecentData = function(port, type, data) -{ - var isRecent = false; - - if(port in this.recentCheckData) - { - - switch(type) - { - case 2: // 모터제어 - if(port >=1 && port <= 3) - { - if(port === prePort && this.recentCheckData[port].data.mode === data.mode && this.recentCheckData[port].data.value === data.value && (data.mode != 4 && data.mode != 5)) - { - isRecent = true; - } - else{ - // console.log("isRecent : ", isRecent,"port : ", port,"port : ", prePort,"data : ", this.recentCheckData[port].data,"data : ", data); - } - - prePort = port; - } - break; - case 3: // Buzzer제어 - if(this.recentCheckData[port].data === data) - { - isRecent = true; - } - else{ - // console.log("isRecent : ", isRecent,"type : ", type,"type : ", this.recentCheckData[port].type,"data : ", this.recentCheckData[port].data,"data : ", data); - } - break; - case 4: // RGB제어 - if(this.recentCheckData[port].data.n === data.n && this.recentCheckData[port].data.r === data.r && this.recentCheckData[port].data.g === data.g && this.recentCheckData[port].data.b === data.b) - { - isRecent = true; - } - else{ - // console.log("isRecent : ", isRecent,"type : ", type,"type : ", this.recentCheckData[port].type,"data : ", this.recentCheckData[port].data,"data : ", data); - } - break; - case 5: // Tone 제어 - //console.log("Tone: ", data.data.value, data.data.duration); - if(this.recentCheckData[port].data.value === data.value && this.recentCheckData[port].data.duration === 7) - { - isRecent = true; - } - else{ - // console.log("isRecent : ", isRecent,"type : ", type,"type : ", this.recentCheckData[port].type,"data : ", this.recentCheckData[port].data,"data : ", data); - } - break; - default: - break; + if(handler.e(iCOBOT.RUGREEN)){ + newValue = handler.read(iCOBOT.RUGREEN); + if(newValue < 0) newValue = 0; + else if(newValue >255 ) newValue = 255; + if(outdata.right_up_green != newValue){ + outdata.right_up_green = newValue; } } - // isRecent = true; 참 들어가면 통신 데이터 무조건 안 보냄. - return isRecent; -} - - -/* -ff 55 len idx action device port slot data a -0 1 2 3 4 5 6 7 8 -*/ - -Module.prototype.makeSensorReadBuffer = function(device, port, data) // 센서값 리드하는 패킷 -{ - var buffer; - var dummy = new Buffer([10]); - - if(!data) - { - buffer = new Buffer([255, 85, 5, sensorIdx, this.actionTypes.GET, device, port, 10]); - //console.log("GET: %s %s %s %s", sensorIdx, this.actionTypes.GET, device, port); - } - else - { - value = new Buffer(2); - value.writeInt16LE(data); - buffer = new Buffer([255, 85, 7, sensorIdx, this.actionTypes.GET, device, port]); - buffer = Buffer.concat([buffer, value, dummy]); + if(handler.e(iCOBOT.RUBLUE)){ + newValue = handler.read(iCOBOT.RUBLUE); + if(newValue < 0) newValue = 0; + else if(newValue >255 ) newValue = 255; + if(outdata.right_up_blue != newValue){ + outdata.right_up_blue = newValue; + } } - - sensorIdx++; - if(sensorIdx > 254) { - sensorIdx = 0; + // Left Down LED + if(handler.e(iCOBOT.LDRED)){ + newValue = handler.read(iCOBOT.LDRED); + if(newValue < 0) newValue = 0; + else if(newValue >255 ) newValue = 255; + if (outdata.left_down_red != newValue){ + outdata.left_down_red = newValue; + } } - - return buffer; -}; - -//0xff 0x55 0x6 0x0 0x1 0xa 0x9 0x0 0x0 0xa -Module.prototype.makeOutputBuffer = function(device, port, data) /// 출력 설정 -{ - var buffer; - var value = new Buffer(2); - var dummy = new Buffer([10]); - - switch(device) - { - case this.sensorTypes.MOTOR: // 모터제어 - var mode = new Buffer(2); - mode.writeInt16LE(data.mode); - value.writeInt16LE(data.value); - buffer = new Buffer([255, 85, 9, sensorIdx, this.actionTypes.SET, device, port]); - buffer = Buffer.concat([buffer, mode, value, dummy]); - // console.log("MOTOR: ", buffer); - break; - - case this.sensorTypes.BUZZER: // 스피커 제어 - // value.writeInt16LE(data); //writeFloatLE//!@#$ - buffer = new Buffer([255, 85, 6, sensorIdx, this.actionTypes.SET, device, port, data]); - buffer = Buffer.concat([buffer, dummy]); - // console.log("Buzzer : ", buffer); - break; - - case this.sensorTypes.RGBLED: - buffer = new Buffer([255, 85, 9, sensorIdx, this.actionTypes.SET, device, port, data.n, data.r, data.g, data.b]); - buffer = Buffer.concat([buffer, dummy]); - // console.log("RGBLED: ", buffer); - break; - - case this.sensorTypes.TONE: // 스피커 제어 - var time = new Buffer(2); - if($.isPlainObject(data)) - { - value.writeInt16LE(data.value); - time.writeInt16LE(data.duration); - } - else - { - value.writeInt16LE(0); - time.writeInt16LE(0); - } - buffer = new Buffer([255, 85, 9, sensorIdx, this.actionTypes.SET, device, port]); - buffer = Buffer.concat([buffer, value, time, dummy]); - // console.log("Tone : ", buffer); - break; + if(handler.e(iCOBOT.LDGREEN)){ + newValue = handler.read(iCOBOT.LDGREEN); + if(newValue < 0) newValue = 0; + else if(newValue >255 ) newValue = 255; + if(outdata.left_down_green != newValue){ + outdata.left_down_green = newValue; + } } - return buffer; -}; - -Module.prototype.disconnect = function(connect) -{ - // 커넥터가 연결해제될 때 호출되는 로직, 스캔 정지 혹은 디바이스 연결 해제시 호출된다. - var self = this; - - connect.close(); - if(self.sp) { - delete self.sp; + if(handler.e(iCOBOT.LDBLUE)){ + newValue =handler.read(iCOBOT.LDBLUE); + if(newValue < 0) newValue = 0; + else if(newValue >255 ) newValue = 255; + if(outdata.left_down_blue != newValue){ + outdata.left_down_blue = newValue; + } + } + // Right Down LED + if(handler.e(iCOBOT.RDRED)){ + newValue = handler.read(iCOBOT.RDRED); + if(newValue < 0 ) newValue = 0; + else if(newValue > 255 ) newValue = 255; + if(outdata.right_down_red != newValue) { + outdata.right_down_red = newValue; + } + } + if(handler.e(iCOBOT.RDGREEN)){ + newValue = handler.read(iCOBOT.RDGREEN); + if(newValue < 0) newValue = 0; + else if(newValue > 255) newValue = 255; + if(outdata.right_down_green != newValue){ + outdata.right_down_green = newValue; + } + } + if(handler.e(iCOBOT.RDBLUE)){ + newValue = handler.read(iCOBOT.RDBLUE); + if(newValue < 0 ) newValue = 0; + else if(newValue > 255 ) newValue = 255; + if(outdata.right_down_blue != newValue){ + outdata.right_down_blue = newValue; + } + } + // Tone + if(handler.e(iCOBOT.TONE)){ + newValue =handler.read(iCOBOT.TONE); + if(newValue < 0) newValue = 0; + else if(newValue > 65535) newValue = 65535; + if(outdata.tone != newValue){ + outdata.tone = newValue; + } + } + // Left Motor + if(handler.e (iCOBOT.LMOTORSPEED)){ + newValue = handler.read(iCOBOT.LMOTORSPEED); + if(newValue < 0) newValue = 0; + else if(newValue > 1000) newValue = 1000; + if(outdata.leftmotor_speed != newValue){ + outdata.leftmotor_speed = newValue; + } + } + if(handler.e(iCOBOT.LMOTORDIR)){ + newValue = handler.read(iCOBOT.LMOTORDIR); + if(newValue < 0) newValue = 0; + else if(newValue > 1) newValue = 1; + if(outdata.leftmotor_dir != newValue){ + outdata.leftmotor_dir = newValue; + } + } + // Left Motor + if(handler.e(iCOBOT.RMOTORSPEED)){ + newValue = handler.read(iCOBOT.RMOTORSPEED); + if(newValue < 0) newValue = 0; + else if(newValue > 1000) newValue = 1000; + if(outdata.rightmotor_speed != newValue) { + outdata.rightmotor_speed = newValue; + } + } + if(handler.e(iCOBOT.RMOTORDIR)){ + newValue = handler.read(iCOBOT.RMOTORDIR); + if(newValue < 0) newValue = 0; + else if(newValue > 1) newValue = 1; + if(outdata.rightmotor_dir != newValue){ + outdata.rightmotor_dir = newValue; + } + } + // Motor + if(handler.e(iCOBOT.MOTORMODE)){ + newValue = handler.read(iCOBOT.MOTORMODE); + if(newValue < 0) newValue = 0; + else if(newValue > 3) newValue = 3; + if(outdata.motor_mode != newValue){ + outdata.motor_mode = newValue; + } + } + if(handler.e(iCOBOT.MOTORVALUE)){ + newValue = handler.read(iCOBOT.MOTORVALUE); + if(newValue < 0 ) newValue = 0; + else if(newValue > 1023 ) newValue = 1023; + if(outdata.motor_value != newValue){ + outdata.motor_value = newValue; + } + } + if(handler.e(iCOBOT.MOTORDIR)){ + newValue = handler.read(iCOBOT.MOTORDIR); + if(newValue < 0) newValue = 0; + else if(newValue > 1) newValue = 1; + if(outdata.motor_dir != newValue){ + outdata.motor_dir = newValue; + } } }; - -// Connect -Module.prototype.reset = function() -{ - // 엔트리 브라우저와의 소켓 연결이 끊어졌을 때 발생하는 로직. - this.lastTime = 0; - this.lastSendTime = 0; +// 하드웨어에 전달할 데이터 +Module.prototype.requestLocalData = function(){ + var outdata =this.outdata; + var tx_d =this .tx_d; + var u8_tx_cnt; + var u8_cnt = 21; + + tx_d[0] = 0x02; + tx_d[1] = 0x02; + tx_d[2] = outdata.left_up_red; + tx_d[3] = outdata.left_up_green; + tx_d[4] = outdata.left_up_blue; + tx_d[5] = outdata.right_up_red; + tx_d[6] = outdata.right_up_green; + tx_d[7] = outdata.right_up_blue; + tx_d[8] = outdata.left_down_red; + tx_d[9] = outdata.left_down_green; + tx_d[10] = outdata.left_down_blue; + tx_d[11] = outdata.right_down_red; + tx_d[12] = outdata.right_down_green; + tx_d[13] = outdata.right_down_blue; + tx_d[14] = (outdata.tone & 0xFF); + tx_d[15] = (outdata.tone & 0xFF00) >> 8; + tx_d[16] = (outdata.leftmotor_speed & 0xFF); + tx_d[17] = ((outdata.leftmotor_speed >> 8) |(outdata.leftmotor_dir << 2) | ((outdata.rightmotor_speed & 0x1f) << 3)); + tx_d[18] = ((outdata.rightmotor_speed >> 5) | (outdata.rightmotor_dir << 5) | (outdata.motor_mode << 6)); + tx_d[19] = (outdata.motor_value & 0xFF); + tx_d[20] = ((outdata.motor_value >> 8) | (outdata.motor_dir << 2)); + tx_d[21] = 0x03 ; + + for(u8_tx_cnt = 2; u8_tx_cnt <= u8_cnt; u8_tx_cnt++){ + tx_d[1] = tx_d[1] + tx_d[u8_tx_cnt]; + } + tx_d[1] = tx_d[1] % 256; + // console.log("tx_d", tx_d); + return tx_d; }; +Module.prototype.reset = function(){}; -module.exports = new Module(); +module.exports = new Module(); \ No newline at end of file From 3b1fcd3e84b0082d284887ebd8498996069bd593 Mon Sep 17 00:00:00 2001 From: dalgona-edu Date: Thu, 18 Apr 2024 10:40:25 +0900 Subject: [PATCH 17/18] =?UTF-8?q?=EC=98=A4=ED=83=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/modules/dalgona_basic.js | 1 + 1 file changed, 1 insertion(+) diff --git a/app/modules/dalgona_basic.js b/app/modules/dalgona_basic.js index c1507c54d..1ab3a1585 100644 --- a/app/modules/dalgona_basic.js +++ b/app/modules/dalgona_basic.js @@ -1,3 +1,4 @@ +// dalgona_basic function Module() { this.sp = null; this.sensorTypes = { From 79c253f8b756eb604ed3a659b2a687e972a0faae Mon Sep 17 00:00:00 2001 From: Tnks2U Date: Mon, 22 Apr 2024 16:43:07 +0900 Subject: [PATCH 18/18] version up 1.9.53 --- build/entry-hw.nsi | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build/entry-hw.nsi b/build/entry-hw.nsi index 35fe147c0..ca4b5ff0e 100644 --- a/build/entry-hw.nsi +++ b/build/entry-hw.nsi @@ -14,7 +14,7 @@ !define PRODUCT_NAME "Entry_HW" !define PROTOCOL_NAME "entryhw" !define APP_NAME "Entry_HW.exe" -!define PRODUCT_VERSION "1.9.52" +!define PRODUCT_VERSION "1.9.53" !define PRODUCT_PUBLISHER "EntryLabs" !define PRODUCT_WEB_SITE "https://www.playentry.org/" diff --git a/package.json b/package.json index c0623732a..b01e923d5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "entry-hw", - "version": "1.9.52", + "version": "1.9.53", "description": "엔트리 하드웨어 연결 프로그램", "author": "EntryLabs", "main": "./app/src/index.bundle.js",