Skip to content

Commit 250279a

Browse files
authored
Merge pull request #3046 from RoborisenDev/develop-hw
(PINGPONG) 실과수업용 확장 추가
2 parents 2e90888 + 9cab2fb commit 250279a

File tree

1 file changed

+209
-19
lines changed

1 file changed

+209
-19
lines changed

src/playground/blocks/hardware/block_pingpong.js

Lines changed: 209 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ Entry.PingpongG1 = new (class PingpongG1 {
189189
type: 'pingpong_g1_when_button_pressed',
190190
},
191191
class: 'PingpongG1',
192-
isNotFor: ['PingpongG1'],
192+
isNotFor: ['PingpongG1','PingpongPracticalArts'],
193193
event: 'pp_when_button_pressed',
194194
func(sprite, script) {
195195
const buttonData = Entry.hw.portData.BUTTON;
@@ -230,7 +230,7 @@ Entry.PingpongG1 = new (class PingpongG1 {
230230
TILT_DIR: 1,
231231
},
232232
class: 'PingpongG1',
233-
isNotFor: ['PingpongG1'],
233+
isNotFor: ['PingpongG1','PingpongPracticalArts'],
234234
event: 'pp_when_tilted',
235235
func(sprite, script) {
236236
const tiltDir = script.getStringField('TILT_DIR');
@@ -273,7 +273,7 @@ Entry.PingpongG1 = new (class PingpongG1 {
273273
},
274274
//paramsKeyMap: { },
275275
class: 'PingpongG1',
276-
isNotFor: ['PingpongG1'],
276+
isNotFor: ['PingpongG1','PingpongPracticalArts'],
277277
func(sprite, script) {
278278
const pd = Entry.hw.portData;
279279
//return Entry.PingpongG1.sensor_data.BUTTON == 1;
@@ -301,7 +301,7 @@ Entry.PingpongG1 = new (class PingpongG1 {
301301
TILT_DIR: 0,
302302
},
303303
class: 'PingpongG1',
304-
isNotFor: ['PingpongG1'],
304+
isNotFor: ['PingpongG1','PingpongPracticalArts'],
305305
func(sprite, script) {
306306
const tiltDir = script.getStringField('TILT_DIR', script);
307307
const pd = Entry.hw.portData;
@@ -367,7 +367,7 @@ Entry.PingpongG1 = new (class PingpongG1 {
367367
},
368368
paramsKeyMap: { DIR: 0 },
369369
class: 'PingpongG1',
370-
isNotFor: ['PingpongG1'],
370+
isNotFor: ['PingpongG1','PingpongPracticalArts'],
371371
func(sprite, script) {
372372
const dir = script.getStringField('DIR', script);
373373
const pd = Entry.hw.portData;
@@ -411,7 +411,7 @@ Entry.PingpongG1 = new (class PingpongG1 {
411411
def: { params: [], type: 'pingpong_g1_get_sensor_value' },
412412
paramsKeyMap: { SENSOR: 0 },
413413
class: 'PingpongG1',
414-
isNotFor: ['PingpongG1'],
414+
isNotFor: ['PingpongG1','PingpongPracticalArts'],
415415
func(sprite, script) {
416416
const sensorType = script.getStringField('SENSOR', script);
417417
const pd = Entry.hw.portData;
@@ -450,7 +450,7 @@ Entry.PingpongG1 = new (class PingpongG1 {
450450
TILT_DIR: 0,
451451
},
452452
class: 'PingpongG1',
453-
isNotFor: ['PingpongG1'],
453+
isNotFor: ['PingpongG1','PingpongPracticalArts'],
454454
func(sprite, script) {
455455
const tiltDir = script.getStringField('TILT_DIR', script);
456456
const pd = Entry.hw.portData;
@@ -500,7 +500,7 @@ Entry.PingpongG1 = new (class PingpongG1 {
500500
},
501501
paramsKeyMap: { DIR: 0, DEGREE: 1 },
502502
class: 'PingpongG1_motor',
503-
isNotFor: ['PingpongG1'],
503+
isNotFor: ['PingpongG1','PingpongPracticalArts'],
504504
func(sprite, script) {
505505
return Entry.PingpongG1.postCallReturn(script, () => {
506506
const dir = script.getStringField('DIR');
@@ -557,7 +557,7 @@ Entry.PingpongG1 = new (class PingpongG1 {
557557
},
558558
paramsKeyMap: { SPEED: 0 },
559559
class: 'PingpongG1_motor',
560-
isNotFor: ['PingpongG1'],
560+
isNotFor: ['PingpongG1','PingpongPracticalArts'],
561561
func(sprite, script) {
562562
return Entry.PingpongG1.postCallReturn(script, () => {
563563
let speed = script.getNumberValue('SPEED');
@@ -604,7 +604,7 @@ Entry.PingpongG1 = new (class PingpongG1 {
604604
},
605605
paramsKeyMap: {},
606606
class: 'PingpongG1_motor',
607-
isNotFor: ['PingpongG1'],
607+
isNotFor: ['PingpongG1','PingpongPracticalArts'],
608608
func(sprite, script) {
609609
return Entry.PingpongG1.postCallReturn(script, () => {
610610
const opt = [2, 0, 0, 1, 0, 0];
@@ -635,7 +635,7 @@ Entry.PingpongG1 = new (class PingpongG1 {
635635
def: { params: [{ type: 'angle' }], type: 'pingpong_g1_rotate_servo_mortor' },
636636
paramsKeyMap: { DEGREE: 0 },
637637
class: 'PingpongG1_motor',
638-
isNotFor: ['PingpongG1'],
638+
isNotFor: ['PingpongG1','PingpongPracticalArts'],
639639
func(sprite, script) {
640640
return Entry.PingpongG1.postCallReturn(script, () => {
641641
let angle = script.getNumberValue('DEGREE', script);
@@ -680,7 +680,7 @@ Entry.PingpongG1 = new (class PingpongG1 {
680680
},
681681
paramsKeyMap: { X: 0, Y: 1, onoff: 2 },
682682
class: 'PingpongG1_peripheral_LED',
683-
isNotFor: ['PingpongG1'],
683+
isNotFor: ['PingpongG1','PingpongPracticalArts'],
684684
func(sprite, script) {
685685
return Entry.PingpongG1.postCallReturn(script, () => {
686686
let dotX = script.getNumberValue('X', script);
@@ -718,7 +718,7 @@ Entry.PingpongG1 = new (class PingpongG1 {
718718
def: { params: [null, null], type: 'pingpong_g1_set_dot_string' },
719719
paramsKeyMap: { STR: 0, DURATION: 1 },
720720
class: 'PingpongG1_peripheral_LED',
721-
isNotFor: ['PingpongG1'],
721+
isNotFor: ['PingpongG1','PingpongPracticalArts'],
722722
func(sprite, script) {
723723
return Entry.PingpongG1.postCallReturn(script, () => {
724724
const str = script.getStringValue('STR', script);
@@ -754,7 +754,7 @@ Entry.PingpongG1 = new (class PingpongG1 {
754754
def: { params: [], type: 'pingpong_g1_set_dot_clear' },
755755
paramsKeyMap: {},
756756
class: 'PingpongG1_peripheral_LED',
757-
isNotFor: ['PingpongG1'],
757+
isNotFor: ['PingpongG1','PingpongPracticalArts'],
758758
func(sprite, script) {
759759
return Entry.PingpongG1.postCallReturn(script, () => {
760760
const packet = Entry.PingpongG1.makePacket(0xa2, 0xe3, [0x70, 1, 0, ' ']);
@@ -788,7 +788,7 @@ Entry.PingpongG1 = new (class PingpongG1 {
788788
def: { params: [], type: 'pingpong_g1_playNoteForBeats' },
789789
paramsKeyMap: { NOTE: 0, BEATS: 1 },
790790
class: 'PingpongG1_Music',
791-
isNotFor: ['PingpongG1'],
791+
isNotFor: ['PingpongG1','PingpongPracticalArts'],
792792
func(sprite, script) {
793793
return Entry.PingpongG1.postCallReturn(script, () => {
794794
const NOTE = script.getNumberField('NOTE', script);
@@ -822,7 +822,7 @@ Entry.PingpongG1 = new (class PingpongG1 {
822822
def: { params: [], type: 'pingpong_g1_restForBeats' },
823823
paramsKeyMap: { BEATS: 0 },
824824
class: 'PingpongG1_Music',
825-
isNotFor: ['PingpongG1'],
825+
isNotFor: ['PingpongG1','PingpongPracticalArts'],
826826
func(sprite, script) {
827827
return Entry.PingpongG1.postCallReturn(script, () => {
828828
const BEATS = script.getNumberValue('BEATS', script);
@@ -852,7 +852,7 @@ Entry.PingpongG1 = new (class PingpongG1 {
852852
def: { params: [], type: 'pingpong_g1_setTempo' },
853853
paramsKeyMap: { TEMPO: 0 },
854854
class: 'PingpongG1_Music',
855-
isNotFor: ['PingpongG1'],
855+
isNotFor: ['PingpongG1','PingpongPracticalArts'],
856856
func(sprite, script) {
857857
let tempo = script.getNumberValue('TEMPO', script);
858858
Entry.PingpongG1.tempo = Entry.PingpongG1._clampTempo(tempo);
@@ -869,11 +869,94 @@ Entry.PingpongG1 = new (class PingpongG1 {
869869
def: { params: [], type: 'pingpong_g1_getTempo' },
870870
paramsKeyMap: {},
871871
class: 'PingpongG1_Music',
872-
isNotFor: ['PingpongG1'],
872+
isNotFor: ['PingpongG1','PingpongPracticalArts'],
873873
func(sprite, script) {
874874
return Entry.PingpongG1.tempo;
875875
},
876876
},
877+
878+
set_steering_direction: {
879+
color: EntryStatic.colorSet.block.default.HARDWARE,
880+
outerLine: EntryStatic.colorSet.block.darken.HARDWARE,
881+
skeleton: 'basic',
882+
statements: [],
883+
params: [
884+
{
885+
type: 'Dropdown',
886+
options: Lang.Blocks.pingpong_opts_mono,
887+
value: 90,
888+
bgColor: EntryStatic.colorSet.block.darken.HARDWARE,
889+
arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE,
890+
},
891+
{ type: 'Indicator', img: 'block_icon/hardware_icon.svg', size: 12, },
892+
],
893+
events: {},
894+
def: { params: [], type: 'set_steering_direction' },
895+
paramsKeyMap: { DEGREE: 0,},
896+
class: 'PingpongG1_motor',
897+
isNotFor: ['PingpongPracticalArts'],
898+
func(sprite, script) {
899+
return Entry.PingpongG1.postCallReturn(script, () => {
900+
let angle = script.getNumberValue('DEGREE', script);
901+
902+
angle = Math.min(Math.max(angle, 0), 180);
903+
904+
const packet = Entry.PingpongG1.makePacket(0xe1, 0x00, [2, 0, angle, 1]);
905+
return [packet, 400];
906+
});
907+
},
908+
},
909+
910+
move_by_distance: {
911+
color: EntryStatic.colorSet.block.default.HARDWARE,
912+
outerLine: EntryStatic.colorSet.block.darken.HARDWARE,
913+
skeleton: 'basic',
914+
statements: [],
915+
params: [
916+
{
917+
type: 'Dropdown',
918+
options: Lang.Blocks.pingpong_direction,
919+
value: Lang.Blocks.pingpong_direction[0][1],
920+
bgColor: EntryStatic.colorSet.block.darken.HARDWARE,
921+
arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE,
922+
},
923+
{ type: 'Block', accept: 'string', defaultType: 'number', value: 10 },
924+
{ type: 'Indicator', img: 'block_icon/hardware_icon.svg', size: 12, },
925+
],
926+
events: {},
927+
def: { params: [], type: 'move_by_distance' },
928+
paramsKeyMap: { DIR: 0, CM: 1 },
929+
class: 'PingpongG1_motor',
930+
isNotFor: ['PingpongPracticalArts'],
931+
func(sprite, script) {
932+
return Entry.PingpongG1.postCallReturn(script, () => {
933+
const direction = script.getStringField('DIR');
934+
let degree = script.getNumberValue('CM');
935+
degree = degree*9; // convert cm to degree
936+
937+
let speed = 800;
938+
if (direction == 'back') {
939+
speed *= -1;
940+
}
941+
942+
degree = Math.min(Math.max(degree, 0), 5000);
943+
944+
let step = Math.round(degree * 5.5);
945+
if (step > 32768) {
946+
step = 32768;
947+
}
948+
949+
const opt = [2, 1, 0, 2, 0, 0, 0, 0, 0, 0];
950+
const packet = Entry.PingpongG1.makePacket(0xc1, 0x0004, opt); // SETP_MOTOR
951+
952+
packet.writeInt16BE(speed, 13);
953+
packet.writeUInt16BE(step, 17);
954+
955+
const waitTime = Math.round(((1100 - Math.abs(speed)) / 99) * step) + 400;
956+
return [packet, waitTime];
957+
});
958+
},
959+
},
877960
};
878961
}
879962

@@ -899,11 +982,18 @@ Entry.PingpongG1 = new (class PingpongG1 {
899982
pingpong_g1_restForBeats: '%1 박자 쉬기 %2',
900983
pingpong_g1_setTempo: '악보 빠르기를 %1 으로 정하기 %2',
901984
pingpong_g1_getTempo: '악보 빠르기',
985+
set_steering_direction: '조향 바퀴를 %1 방향으로 설정',
986+
move_by_distance: '%1으로%2cm 이동하기',
902987
},
903988
Blocks: {
904989
pingpong_right: '오른쪽',
905990
pingpong_left: '왼쪽',
906991

992+
pingpong_direction :[
993+
['앞쪽','front'],
994+
['뒤쪽','back']
995+
],
996+
907997
pingpong_rotate_cw: '시계',
908998
pingpong_rotate_ccw: '반시계',
909999

@@ -958,6 +1048,28 @@ Entry.PingpongG1 = new (class PingpongG1 {
9581048
['시 (B5)', 71],
9591049
['도 (C6)', 72],
9601050
],
1051+
1052+
pingpong_opts_mono :[
1053+
['왼쪽 45°' ,45],
1054+
['왼쪽 40°' ,50],
1055+
['왼쪽 35°' ,55],
1056+
['왼쪽 30°' ,60],
1057+
['왼쪽 25°' ,65],
1058+
['왼쪽 20°' ,70],
1059+
['왼쪽 15°' ,75],
1060+
['왼쪽 10°' ,80],
1061+
['왼쪽 5°' ,85],
1062+
['정면' ,90],
1063+
['오른쪽 5°' ,95],
1064+
['오른쪽 10°' ,100],
1065+
['오른쪽 15°' ,105],
1066+
['오른쪽 20°' ,110],
1067+
['오른쪽 25°' ,115],
1068+
['오른쪽 30°' ,120],
1069+
['오른쪽 35°' ,125],
1070+
['오른쪽 40°' ,130],
1071+
['오른쪽 45°' ,135],
1072+
]
9611073
},
9621074
},
9631075
en: {
@@ -980,11 +1092,18 @@ Entry.PingpongG1 = new (class PingpongG1 {
9801092
pingpong_g1_restForBeats: 'rest for %1 beats %2',
9811093
pingpong_g1_setTempo: 'set tempo to %1 %2',
9821094
pingpong_g1_getTempo: 'tempo',
1095+
set_steering_direction: 'Set the steering wheel to %1 direction',
1096+
move_by_distance: 'Move %1 by %2 cm',
9831097
},
9841098
Blocks: {
9851099
pingpong_right: 'right',
9861100
pingpong_left: 'left',
9871101

1102+
pingpong_direction :[
1103+
['Front','front'],
1104+
['Back','back']
1105+
],
1106+
9881107
pingpong_rotate_cw: 'clockwise',
9891108
pingpong_rotate_ccw: 'counter clockwise',
9901109

@@ -1038,6 +1157,28 @@ Entry.PingpongG1 = new (class PingpongG1 {
10381157
['Ti (B5)', 71],
10391158
['Do (C6)', 72],
10401159
],
1160+
1161+
pingpong_opts_mono: [
1162+
['Left 45°', 45],
1163+
['Left 40°', 50],
1164+
['Left 35°', 55],
1165+
['Left 30°', 60],
1166+
['Left 25°', 65],
1167+
['Left 20°', 70],
1168+
['Left 15°', 75],
1169+
['Left 10°', 80],
1170+
['Left 5°', 85],
1171+
['Center', 90],
1172+
['Right 5°', 95],
1173+
['Right 10°', 100],
1174+
['Right 15°', 105],
1175+
['Right 20°', 110],
1176+
['Right 25°', 115],
1177+
['Right 30°', 120],
1178+
['Right 35°', 125],
1179+
['Right 40°', 130],
1180+
['Right 45°', 135],
1181+
]
10411182
},
10421183
},
10431184
};
@@ -1099,4 +1240,53 @@ Entry.PingpongG1 = new (class PingpongG1 {
10991240
};
11001241
})();
11011242

1102-
module.exports = Entry.PingpongG1;
1243+
Entry.PingpongPracticalArts = new (class PingpongPracticalArts {
1244+
constructor() {
1245+
this.id = '35.5';
1246+
this.name = 'PingpongPracticalArts';
1247+
this.url = 'https://www.roborisen.com';
1248+
this.imageName = 'pingpong_g1.png';
1249+
this.delayTime = 50;
1250+
this.title = {
1251+
ko: '핑퐁(실과수업용)',
1252+
en: 'Pingpong (for Practical Arts class)',
1253+
};
1254+
this.communicationType = 'manual';
1255+
1256+
this.blockMenuBlocks = [
1257+
'pingpong_g1_when_button_pressed',
1258+
'pingpong_g1_is_button_pressed',
1259+
'pingpong_g1_when_tilted',
1260+
'pingpong_g1_is_tilted',
1261+
'pingpong_g1_get_tilt_value',
1262+
'pingpong_g1_is_top_shape',
1263+
'pingpong_g1_get_sensor_value',
1264+
'pingpong_g1_motor_rotate',
1265+
'pingpong_g1_start_motor_rotate',
1266+
'pingpong_g1_stop_motor_rotate',
1267+
'pingpong_g1_rotate_servo_mortor',
1268+
'set_steering_direction',
1269+
'move_by_distance',
1270+
'pingpong_g1_set_dot_pixel',
1271+
'pingpong_g1_set_dot_string',
1272+
'pingpong_g1_set_dot_clear',
1273+
'pingpong_g1_playNoteForBeats',
1274+
'pingpong_g1_restForBeats',
1275+
'pingpong_g1_setTempo',
1276+
'pingpong_g1_getTempo',
1277+
];
1278+
}
1279+
1280+
setZero() {return Entry.PingpongG1.setZero();}
1281+
sendCommand(packet) {return Entry.PingpongG1.sendCommand(packet);}
1282+
afterReceive(pd) {return Entry.PingpongG1.afterReceive(pd);}
1283+
postCallReturn(script, myfunc) {return Entry.PingpongG1.postCallReturn(script, myfunc);}
1284+
_clampBeats(beats) {return Entry.PingpongG1._clampBeats(beats);}
1285+
_clampTempo(tempo) {return Entry.PingpongG1._clampTempo(tempo);}
1286+
_beatsToDuration(beats) {return Entry.PingpongG1._beatsToDuration(beats);}
1287+
makePacket(opcode, taskid, opt) {return Entry.PingpongG1.makePacket(opcode, taskid, opt);}
1288+
getBlocks() {return Entry.PingpongG1.getBlocks()}
1289+
setLanguage() {return Entry.PingpongG1.setLanguage();}
1290+
1291+
})();
1292+
module.exports = [Entry.PingpongG1, Entry.PingpongPracticalArts];

0 commit comments

Comments
 (0)