Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,970 changes: 1,970 additions & 0 deletions app/firmwares/roborobo_cube.hex

Large diffs are not rendered by default.

3,565 changes: 1,785 additions & 1,780 deletions app/firmwares/roborobo_roe.hex

Large diffs are not rendered by default.

98 changes: 48 additions & 50 deletions app/modules/roborobo_base.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
const BaseModule = require('./baseModule');

const THREAD_STEP_INTERVAL = 1000 / 60;
const THREAD_STEP_INTERVAL_COMPATIBILITY = 1000 / 30;

const FirmataCMD = {
ENABLE_DIGITAL: 0xD0,
DIGITAL_CH0: 0x90,
Expand All @@ -14,7 +17,7 @@ const FirmataCMD = {
SET_PIN_MODE: 0xF4,
GET_VERSION: 0xF9,
RESET: 0xFF,
}
};

const PinMode = {
INPUT: 0x00,
Expand All @@ -34,7 +37,7 @@ const PinMode = {
RGBLED: 0x0E,
ROTARYPOSITION: 0x0F,
IGNORE: 0x7F
}
};

const SysexCMD = {
START: 0xF0,
Expand All @@ -48,7 +51,7 @@ const SysexCMD = {
I2C_REPLY: 0x77,
I2C_CONFIG: 0x78,
END: 0xF7
}
};

const Instruction = {
DIGITAL: 0x00,
Expand All @@ -71,7 +74,7 @@ const Instruction = {
GET_VERSION_FIRMWARE: 0x7D,
GET_VERSION_HARDWARE: 0x7E,
GET_VERSION: 0x7F,
}
};

const Frequency = {
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,
Expand All @@ -84,6 +87,16 @@ const Frequency = {
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,
96: 8372.018
};

const DrawMode = {
BIT: 0x00,
POINT: 0x01,
SIGN: 0x02,
STRING: 0x03,
SCROLLDRAW: 0x04,
CLEAR: 0x07
};

const RATIO_CONVERT_ANALOG_TO_ANGLE = 0.3515625;

class ArduinoBase extends BaseModule {
Expand Down Expand Up @@ -113,8 +126,6 @@ class ArduinoBase extends BaseModule {

this._receiveBuffer = [];
this._sendBuffer = [];
this._sendBuffer.push(this._getResetDeviceCommand());
this._sendBuffer.push(this._getDigitalPinEnableCommand());
}

/**
Expand Down Expand Up @@ -167,7 +178,7 @@ class ArduinoBase extends BaseModule {
if (time >= 3000) {
this._serialPort.close();
} else if (time >= 1000) {
buffer.push(...this._getRequestBatteryVoltageCommand());
buffer.push(...this.requestInitialData());
}
return buffer;
}
Expand Down Expand Up @@ -635,7 +646,7 @@ class ArduinoBase extends BaseModule {
* @param {number} pin [2, 15]
*/
_enableDigitalInput (pin) {
if (this._isDigitalPin(pin)) this.setPinMode(pin, PinMode.INPUT)
if (this._isDigitalPin(pin)) this.setPinMode(pin, PinMode.INPUT);
}

/**
Expand Down Expand Up @@ -967,21 +978,6 @@ class ArduinoBase extends BaseModule {
}

switch (data[2]) {
case Instruction.GET_SENSOR: {
// ���̷� ���� ���� ���� ��
if (data[4] == 0x09) {
const obj = this.state.rx.gyro;
obj.angle.x = (data[5] + ((data[6] & 0x01) << 7)) * ((data[6] >> 4 & 0x01) == 1 ? -1 : 1);
obj.angle.y = (data[7] + ((data[8] & 0x01) << 7)) * ((data[8] >> 4 & 0x01) == 1 ? -1 : 1);
obj.angle.z = (data[9] + ((data[10] & 0x01) << 7)) * ((data[10] >> 4 & 0x01) == 1 ? -1 : 1);

obj.gyro.x = (data[11] + ((data[12] & 0x01) << 7)) * ((data[12] >> 4 & 0x01) == 1 ? -1 : 1);
obj.gyro.y = (data[13] + ((data[14] & 0x01) << 7)) * ((data[14] >> 4 & 0x01) == 1 ? -1 : 1);
obj.gyro.z = (data[15] + ((data[16] & 0x01) << 7)) * ((data[16] >> 4 & 0x01) == 1 ? -1 : 1);

obj.shake = data[20] & 0x01;
}
} break;
// ���� üũ ��������
case Instruction.GET_VOLTAGE: {
this.voltage = data[4];
Expand All @@ -992,7 +988,7 @@ class ArduinoBase extends BaseModule {
model: data[4],
hardware: data[5],
firmware: data[6]
}
};
} break;
}
data.splice(0, length);
Expand Down Expand Up @@ -1053,7 +1049,7 @@ class ArduinoStateBase {
* }
*/
piezo: [],
}
};

/**
* ������ ���� �����Ͽ� ����
Expand Down Expand Up @@ -1093,24 +1089,7 @@ class ArduinoStateBase {
*/
rotaryPosition: [],

/**
* I2C pin ��� [18, 19] ��ȣ ����
*/
gyro: {
enable: false,
angle: {
x: 0,
y: 0,
z: 0
},
gyro: {
x: 0,
y: 0,
z: 0
},
shake: 0,
}
}
};
}

/**
Expand All @@ -1121,7 +1100,7 @@ class ArduinoStateBase {
if (!this.pin[pin]) {
this.pin[pin] = {
mode: null
}
};
}
return this.pin[pin];
}
Expand All @@ -1136,7 +1115,7 @@ class ArduinoStateBase {
motor: null,
speed: null,
state: null
}
};
}
return this.tx.motor[index];
}
Expand All @@ -1150,7 +1129,7 @@ class ArduinoStateBase {
this.tx.piezo[pin] = {
note: null,
duration: null
}
};
}
return this.tx.piezo[pin];
}
Expand All @@ -1166,7 +1145,7 @@ class ArduinoStateBase {
g: null,
b: null,
a: null
}
};
}
return this.tx.rgbLed[pin];
}
Expand All @@ -1181,7 +1160,7 @@ class ArduinoStateBase {
value: 0,
values: [],
enable: false
}
};
}
return this.rx.temperature[analogPin];
}
Expand All @@ -1204,10 +1183,29 @@ class ArduinoStateBase {
isIntegerPosition: true,
isIntegerRotation: true,
isIntegerAngle: true,
}
};
}
return this.rx.rotaryPosition[analogPin];
}
}

module.exports = {ArduinoBase, ArduinoStateBase, FirmataCMD, PinMode, SysexCMD, Instruction};
const Sleep = function (ms) {
return new Promise(resolve => setTimeout(() => resolve(), ms));
};

module.exports = {
ArduinoBase,
ArduinoStateBase,

FirmataCMD,
PinMode,
SysexCMD,
Instruction,
Frequency,
DrawMode,

THREAD_STEP_INTERVAL,
THREAD_STEP_INTERVAL_COMPATIBILITY,

Sleep
};
Loading