@@ -37,6 +37,7 @@ var tool_color = '#bf964b';
37
37
var utility_color = '#bead76' ;
38
38
var vision_color = '#546e7a' ;
39
39
var conveyor_color = '#00838f' ;
40
+ var sound_color = '#FFC0CB' ;
40
41
41
42
// Color object for vision
42
43
//TODO Should be in a class
@@ -1430,12 +1431,126 @@ Blockly.Blocks['niryo_one_get_connected_conveyors_id'] = {
1430
1431
this . appendDummyInput ( ) . appendField ( 'Get list of connected conveyors' ) ;
1431
1432
this . setOutput ( true , null ) ;
1432
1433
this . setColour ( conveyor_color ) ;
1434
+ this . setHelpUrl ( '' ) ;
1435
+ this . setTooltip ( 'Conveyors directions available with Niryo One.' ) ;
1436
+ }
1437
+ } ;
1438
+
1439
+ // Sound
1440
+
1441
+ Blockly . Blocks [ 'niryo_one_get_sounds' ] = {
1442
+ init : function ( ) {
1443
+ this . appendDummyInput ( ) . appendField ( 'Get sound name list' ) ;
1444
+ this . setOutput ( true , null ) ;
1445
+ this . setColour ( sound_color ) ;
1446
+ this . setHelpUrl ( '' ) ;
1447
+ this . setTooltip ( 'Get sound name list.' ) ;
1448
+ }
1449
+ } ;
1450
+
1451
+ Blockly . Blocks [ 'niryo_one_set_volume' ] = {
1452
+ init : function ( ) {
1453
+ this . appendValueInput ( 'SET_VOLUME' )
1454
+ . setCheck ( 'Number' )
1455
+ . appendField ( 'Set volume procentage of robot to' ) ;
1456
+ this . appendDummyInput ( ) . appendField ( '%' ) ;
1457
+ this . setInputsInline ( true ) ;
1433
1458
this . setPreviousStatement ( true , null ) ;
1434
1459
this . setNextStatement ( true , null ) ;
1460
+ this . setColour ( sound_color ) ;
1461
+ this . setTooltip (
1462
+ 'Set the volume percentage of the robot. Volume percentage of the sound (0: no sound, 100: max sound)'
1463
+ ) ;
1435
1464
this . setHelpUrl ( '' ) ;
1436
- this . setTooltip ( 'Conveyors directions available with Niryo One.' ) ;
1437
1465
}
1438
1466
} ;
1467
+
1468
+ Blockly . Blocks [ 'niryo_one_stop_sound' ] = {
1469
+ init : function ( ) {
1470
+ this . appendDummyInput ( ) . appendField ( 'Stop sound' ) ;
1471
+ this . setPreviousStatement ( true , null ) ;
1472
+ this . setNextStatement ( true , null ) ;
1473
+ this . setColour ( sound_color ) ;
1474
+ this . setHelpUrl ( '' ) ;
1475
+ this . setTooltip ( 'Stop a sound being played.' ) ;
1476
+ }
1477
+ } ;
1478
+
1479
+ Blockly . Blocks [ 'niryo_one_get_sound_duration' ] = {
1480
+ init : function ( ) {
1481
+ this . appendValueInput ( 'SOUND_NAME' )
1482
+ . setCheck ( 'String' )
1483
+ . appendField ( 'Get duration of sound named' ) ;
1484
+ this . setOutput ( true , null ) ;
1485
+ this . setColour ( sound_color ) ;
1486
+ this . setHelpUrl ( '' ) ;
1487
+ this . setTooltip (
1488
+ 'Returns the duration in seconds of a sound stored in the robot database raise SoundRosWrapperException if the sound doesn’t exists'
1489
+ ) ;
1490
+ }
1491
+ } ;
1492
+
1493
+ Blockly . Blocks [ 'niryo_one_play_sound' ] = {
1494
+ init : function ( ) {
1495
+ this . appendValueInput ( 'SOUND_NAME' )
1496
+ . setCheck ( 'String' )
1497
+ . appendField ( 'Play sound named' ) ;
1498
+
1499
+ // this.appendValueInput('WAIT_END')
1500
+ // .setcheck('Boolean')
1501
+ // .appendField('wait until the end');
1502
+
1503
+ this . appendDummyInput ( ) . appendField ( 'wait until the end' ) ;
1504
+ this . appendDummyInput ( ) . appendField (
1505
+ new Blockly . FieldDropdown ( [
1506
+ [ 'True' , '1' ] ,
1507
+ [ 'False' , '0' ]
1508
+ ] ) ,
1509
+ 'WAIT_END'
1510
+ ) ;
1511
+
1512
+ this . appendValueInput ( 'START_TIME' )
1513
+ . setCheck ( 'Number' )
1514
+ . appendField ( 'starting from this second' ) ;
1515
+
1516
+ this . appendValueInput ( 'END_TIME' )
1517
+ . setCheck ( 'Number' )
1518
+ . appendField ( 'ending at this second' ) ;
1519
+
1520
+ this . setPreviousStatement ( true , null ) ;
1521
+ this . setNextStatement ( true , null ) ;
1522
+ this . setColour ( sound_color ) ;
1523
+ this . setHelpUrl ( '' ) ;
1524
+ this . setTooltip (
1525
+ 'Play a sound from the robot, given its name, whether to for the end of the sound before exiting the function (True or False), the start time of the sound from the value in seconds and end time of the sound at this value in seconds.'
1526
+ ) ;
1527
+ }
1528
+ } ;
1529
+
1530
+ Blockly . Blocks [ 'niryo_one_say' ] = {
1531
+ init : function ( ) {
1532
+ this . appendValueInput ( 'SAY_TEXT' ) . setCheck ( 'String' ) . appendField ( 'Say' ) ;
1533
+ this . appendDummyInput ( ) . appendField ( 'in' ) ;
1534
+ this . appendDummyInput ( ) . appendField (
1535
+ new Blockly . FieldDropdown ( [
1536
+ [ 'English' , '0' ] ,
1537
+ [ 'French' , '1' ] ,
1538
+ [ 'Spanish' , '2' ] ,
1539
+ [ 'Mandarin' , '3' ] ,
1540
+ [ 'Portuguese' , '4' ]
1541
+ ] ) ,
1542
+ 'LANGUAGE_SELECT'
1543
+ ) ;
1544
+ this . setPreviousStatement ( true , null ) ;
1545
+ this . setNextStatement ( true , null ) ;
1546
+ this . setColour ( sound_color ) ;
1547
+ this . setHelpUrl ( '' ) ;
1548
+ this . setTooltip (
1549
+ 'Use gtts (Google Text To Speech) to interprete a string as sound.'
1550
+ ) ;
1551
+ }
1552
+ } ;
1553
+
1439
1554
/*
1440
1555
* Generators
1441
1556
*/
@@ -2338,7 +2453,76 @@ BlocklyPy['niryo_one_get_connected_conveyors_id'] = function (block) {
2338
2453
return code ;
2339
2454
} ;
2340
2455
2341
- // Creating a toolbox containing all the main (default) blocks.
2456
+ // Sound
2457
+ BlocklyPy [ 'niryo_one_get_sounds' ] = function ( block ) {
2458
+ var code = 'n.get_sounds()\n' ;
2459
+ return [ code , BlocklyPy . ORDER_NONE ] ;
2460
+ } ;
2461
+
2462
+ BlocklyPy [ 'niryo_one_set_volume' ] = function ( block ) {
2463
+ var value_set_volume =
2464
+ BlocklyPy . valueToCode ( block , 'SET_VOLUME' , BlocklyPy . ORDER_ATOMIC ) || '0' ;
2465
+ value_set_volume = value_set_volume . replace ( '(' , '' ) . replace ( ')' , '' ) ;
2466
+ var code = 'n.set_volume(' + value_set_volume + ')\n' ;
2467
+ return code ;
2468
+ } ;
2469
+
2470
+ BlocklyPy [ 'niryo_one_stop_sound' ] = function ( block ) {
2471
+ var code = 'n.stop_sound()\n' ;
2472
+ return [ code , BlocklyPy . ORDER_NONE ] ;
2473
+ } ;
2474
+
2475
+ BlocklyPy [ 'niryo_one_get_sound_duration' ] = function ( block ) {
2476
+ var value_sound_name =
2477
+ BlocklyPy . valueToCode ( block , 'SOUND_NAME' , BlocklyPy . ORDER_ATOMIC ) || '0' ;
2478
+ value_sound_name = value_sound_name . replace ( '(' , '' ) . replace ( ')' , '' ) ;
2479
+ var code = 'n.get_sound_duration(' + value_sound_name + ')\n' ;
2480
+ return [ code , BlocklyPy . ORDER_NONE ] ;
2481
+ } ;
2482
+
2483
+ BlocklyPy [ 'niryo_one_play_sound' ] = function ( block ) {
2484
+ var value_sound_name =
2485
+ BlocklyPy . valueToCode ( block , 'SOUND_NAME' , BlocklyPy . ORDER_ATOMIC ) || '0' ;
2486
+ value_sound_name = value_sound_name . replace ( '(' , '' ) . replace ( ')' , '' ) ;
2487
+
2488
+ var dropdown_wait_end = block . getFieldValue ( 'WAIT_END' ) ;
2489
+
2490
+ var value_start_time =
2491
+ BlocklyPy . valueToCode ( block , 'START_TIME' , BlocklyPy . ORDER_ATOMIC ) || '0' ;
2492
+ value_start_time = value_start_time . replace ( '(' , '' ) . replace ( ')' , '' ) ;
2493
+
2494
+ var value_end_time =
2495
+ BlocklyPy . valueToCode ( block , 'END_TIME' , BlocklyPy . ORDER_ATOMIC ) || '0' ;
2496
+ value_end_time = value_end_time . replace ( '(' , '' ) . replace ( ')' , '' ) ;
2497
+
2498
+ var code =
2499
+ 'n.play_sound(' +
2500
+ value_sound_name +
2501
+ ', ' +
2502
+ dropdown_wait_end +
2503
+ ', ' +
2504
+ value_start_time +
2505
+ ', ' +
2506
+ value_end_time +
2507
+ ')\n' ;
2508
+
2509
+ return code ;
2510
+ } ;
2511
+
2512
+ BlocklyPy [ 'niryo_one_say' ] = function ( block ) {
2513
+ var value_say_text =
2514
+ BlocklyPy . valueToCode ( block , 'SAY_TEXT' , BlocklyPy . ORDER_ATOMIC ) || '0' ;
2515
+ value_say_text = value_say_text . replace ( '(' , '' ) . replace ( ')' , '' ) ;
2516
+
2517
+ var dropdown_language_select = block . getFieldValue ( 'LANGUAGE_SELECT' ) ;
2518
+
2519
+ var code =
2520
+ 'n.say(' + value_say_text + ', ' + dropdown_language_select + ')\n' ;
2521
+ return code ;
2522
+ } ;
2523
+
2524
+ // Creating a toolbox containing all the main (default) blocks
2525
+ // and adding the niryo category.
2342
2526
const TOOLBOX = {
2343
2527
kind : 'categoryToolbox' ,
2344
2528
contents : [
@@ -2970,6 +3154,30 @@ const TOOLBOX = {
2970
3154
{
2971
3155
kind : 'BLOCK' ,
2972
3156
type : 'niryo_one_get_connected_conveyors_id'
3157
+ } ,
3158
+ {
3159
+ kind : 'BLOCK' ,
3160
+ type : 'niryo_one_get_sounds'
3161
+ } ,
3162
+ {
3163
+ kind : 'BLOCK' ,
3164
+ type : 'niryo_one_set_volume'
3165
+ } ,
3166
+ {
3167
+ kind : 'BLOCK' ,
3168
+ type : 'niryo_one_stop_sound'
3169
+ } ,
3170
+ {
3171
+ kind : 'BLOCK' ,
3172
+ type : 'niryo_one_get_sound_duration'
3173
+ } ,
3174
+ {
3175
+ kind : 'BLOCK' ,
3176
+ type : 'niryo_one_play_sound'
3177
+ } ,
3178
+ {
3179
+ kind : 'BLOCK' ,
3180
+ type : 'niryo_one_say'
2973
3181
}
2974
3182
]
2975
3183
}
0 commit comments