Skip to content

Commit 86c3c47

Browse files
authored
Merge pull request #640 from RoboroboLab/develop-hw
RoE 관련 코드 전면 수정
2 parents f2e5f76 + c53d9b5 commit 86c3c47

12 files changed

+4981
-2213
lines changed

app/firmwares/roborobo_cube.hex

Lines changed: 1970 additions & 0 deletions
Large diffs are not rendered by default.

app/firmwares/roborobo_roe.hex

Lines changed: 1785 additions & 1780 deletions
Large diffs are not rendered by default.

app/modules/roborobo_base.js

Lines changed: 48 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
const BaseModule = require('./baseModule');
22

3+
const THREAD_STEP_INTERVAL = 1000 / 60;
4+
const THREAD_STEP_INTERVAL_COMPATIBILITY = 1000 / 30;
5+
36
const FirmataCMD = {
47
ENABLE_DIGITAL: 0xD0,
58
DIGITAL_CH0: 0x90,
@@ -14,7 +17,7 @@ const FirmataCMD = {
1417
SET_PIN_MODE: 0xF4,
1518
GET_VERSION: 0xF9,
1619
RESET: 0xFF,
17-
}
20+
};
1821

1922
const PinMode = {
2023
INPUT: 0x00,
@@ -34,7 +37,7 @@ const PinMode = {
3437
RGBLED: 0x0E,
3538
ROTARYPOSITION: 0x0F,
3639
IGNORE: 0x7F
37-
}
40+
};
3841

3942
const SysexCMD = {
4043
START: 0xF0,
@@ -48,7 +51,7 @@ const SysexCMD = {
4851
I2C_REPLY: 0x77,
4952
I2C_CONFIG: 0x78,
5053
END: 0xF7
51-
}
54+
};
5255

5356
const Instruction = {
5457
DIGITAL: 0x00,
@@ -71,7 +74,7 @@ const Instruction = {
7174
GET_VERSION_FIRMWARE: 0x7D,
7275
GET_VERSION_HARDWARE: 0x7E,
7376
GET_VERSION: 0x7F,
74-
}
77+
};
7578

7679
const Frequency = {
7780
0: 32.7032, 1: 34.6478, 2: 36.7081, 3: 38.8909, 4: 41.2034, 5: 43.6535, 6: 46.2493, 7: 48.9994, 8: 51.9130, 9: 55.0000, 10: 58.2705, 11: 61.7354,
@@ -84,6 +87,16 @@ const Frequency = {
8487
84: 4186.009, 85: 4434.922, 86: 4698.636, 87: 4978.036, 88: 5274.041, 89: 5587.652, 90: 5919.911, 91: 6271.927, 92: 6644.875, 93: 7040.000, 94: 7458.620, 95: 7902.133,
8588
96: 8372.018
8689
};
90+
91+
const DrawMode = {
92+
BIT: 0x00,
93+
POINT: 0x01,
94+
SIGN: 0x02,
95+
STRING: 0x03,
96+
SCROLLDRAW: 0x04,
97+
CLEAR: 0x07
98+
};
99+
87100
const RATIO_CONVERT_ANALOG_TO_ANGLE = 0.3515625;
88101

89102
class ArduinoBase extends BaseModule {
@@ -113,8 +126,6 @@ class ArduinoBase extends BaseModule {
113126

114127
this._receiveBuffer = [];
115128
this._sendBuffer = [];
116-
this._sendBuffer.push(this._getResetDeviceCommand());
117-
this._sendBuffer.push(this._getDigitalPinEnableCommand());
118129
}
119130

120131
/**
@@ -167,7 +178,7 @@ class ArduinoBase extends BaseModule {
167178
if (time >= 3000) {
168179
this._serialPort.close();
169180
} else if (time >= 1000) {
170-
buffer.push(...this._getRequestBatteryVoltageCommand());
181+
buffer.push(...this.requestInitialData());
171182
}
172183
return buffer;
173184
}
@@ -635,7 +646,7 @@ class ArduinoBase extends BaseModule {
635646
* @param {number} pin [2, 15]
636647
*/
637648
_enableDigitalInput (pin) {
638-
if (this._isDigitalPin(pin)) this.setPinMode(pin, PinMode.INPUT)
649+
if (this._isDigitalPin(pin)) this.setPinMode(pin, PinMode.INPUT);
639650
}
640651

641652
/**
@@ -967,21 +978,6 @@ class ArduinoBase extends BaseModule {
967978
}
968979

969980
switch (data[2]) {
970-
case Instruction.GET_SENSOR: {
971-
// 자이로 센서 상태 변경 값
972-
if (data[4] == 0x09) {
973-
const obj = this.state.rx.gyro;
974-
obj.angle.x = (data[5] + ((data[6] & 0x01) << 7)) * ((data[6] >> 4 & 0x01) == 1 ? -1 : 1);
975-
obj.angle.y = (data[7] + ((data[8] & 0x01) << 7)) * ((data[8] >> 4 & 0x01) == 1 ? -1 : 1);
976-
obj.angle.z = (data[9] + ((data[10] & 0x01) << 7)) * ((data[10] >> 4 & 0x01) == 1 ? -1 : 1);
977-
978-
obj.gyro.x = (data[11] + ((data[12] & 0x01) << 7)) * ((data[12] >> 4 & 0x01) == 1 ? -1 : 1);
979-
obj.gyro.y = (data[13] + ((data[14] & 0x01) << 7)) * ((data[14] >> 4 & 0x01) == 1 ? -1 : 1);
980-
obj.gyro.z = (data[15] + ((data[16] & 0x01) << 7)) * ((data[16] >> 4 & 0x01) == 1 ? -1 : 1);
981-
982-
obj.shake = data[20] & 0x01;
983-
}
984-
} break;
985981
// 전압 체크 프로토콜
986982
case Instruction.GET_VOLTAGE: {
987983
this.voltage = data[4];
@@ -992,7 +988,7 @@ class ArduinoBase extends BaseModule {
992988
model: data[4],
993989
hardware: data[5],
994990
firmware: data[6]
995-
}
991+
};
996992
} break;
997993
}
998994
data.splice(0, length);
@@ -1053,7 +1049,7 @@ class ArduinoStateBase {
10531049
* }
10541050
*/
10551051
piezo: [],
1056-
}
1052+
};
10571053

10581054
/**
10591055
* 센서의 값을 수신하여 저장
@@ -1093,24 +1089,7 @@ class ArduinoStateBase {
10931089
*/
10941090
rotaryPosition: [],
10951091

1096-
/**
1097-
* I2C pin 사용 [18, 19] 번호 고정
1098-
*/
1099-
gyro: {
1100-
enable: false,
1101-
angle: {
1102-
x: 0,
1103-
y: 0,
1104-
z: 0
1105-
},
1106-
gyro: {
1107-
x: 0,
1108-
y: 0,
1109-
z: 0
1110-
},
1111-
shake: 0,
1112-
}
1113-
}
1092+
};
11141093
}
11151094

11161095
/**
@@ -1121,7 +1100,7 @@ class ArduinoStateBase {
11211100
if (!this.pin[pin]) {
11221101
this.pin[pin] = {
11231102
mode: null
1124-
}
1103+
};
11251104
}
11261105
return this.pin[pin];
11271106
}
@@ -1136,7 +1115,7 @@ class ArduinoStateBase {
11361115
motor: null,
11371116
speed: null,
11381117
state: null
1139-
}
1118+
};
11401119
}
11411120
return this.tx.motor[index];
11421121
}
@@ -1150,7 +1129,7 @@ class ArduinoStateBase {
11501129
this.tx.piezo[pin] = {
11511130
note: null,
11521131
duration: null
1153-
}
1132+
};
11541133
}
11551134
return this.tx.piezo[pin];
11561135
}
@@ -1166,7 +1145,7 @@ class ArduinoStateBase {
11661145
g: null,
11671146
b: null,
11681147
a: null
1169-
}
1148+
};
11701149
}
11711150
return this.tx.rgbLed[pin];
11721151
}
@@ -1181,7 +1160,7 @@ class ArduinoStateBase {
11811160
value: 0,
11821161
values: [],
11831162
enable: false
1184-
}
1163+
};
11851164
}
11861165
return this.rx.temperature[analogPin];
11871166
}
@@ -1204,10 +1183,29 @@ class ArduinoStateBase {
12041183
isIntegerPosition: true,
12051184
isIntegerRotation: true,
12061185
isIntegerAngle: true,
1207-
}
1186+
};
12081187
}
12091188
return this.rx.rotaryPosition[analogPin];
12101189
}
12111190
}
12121191

1213-
module.exports = {ArduinoBase, ArduinoStateBase, FirmataCMD, PinMode, SysexCMD, Instruction};
1192+
const Sleep = function (ms) {
1193+
return new Promise(resolve => setTimeout(() => resolve(), ms));
1194+
};
1195+
1196+
module.exports = {
1197+
ArduinoBase,
1198+
ArduinoStateBase,
1199+
1200+
FirmataCMD,
1201+
PinMode,
1202+
SysexCMD,
1203+
Instruction,
1204+
Frequency,
1205+
DrawMode,
1206+
1207+
THREAD_STEP_INTERVAL,
1208+
THREAD_STEP_INTERVAL_COMPATIBILITY,
1209+
1210+
Sleep
1211+
};

0 commit comments

Comments
 (0)