• Hello.
    My board is MDBT42Q, and it has some motors, IR sensor by i2c.
    Everything is fine. Motors move well, IR sensors too.
    But, my robot should move synchronous.

    For example,

    Blockly.Blocks.robot_move_angle = {
        category: 'CoduBot',
        init: function () {
            this.appendDummyInput()
                .appendField('로봇 각도로 움직이기');
            this.appendValueInput('dir')
                .setCheck(['Number'])
                .appendField('방향');
            this.appendValueInput('vel')
                .setCheck(['Number'])
                .appendField('속도');
            this.appendValueInput('angle')
                .setCheck(['Number'])
                .appendField('각도');
            this.appendValueInput('time')
                .setCheck(['Number'])
                .appendField('시간');
            this.setColour(150);
            this.setPreviousStatement(true);
            this.setNextStatement(true);
        }
    }
    
    Blockly.JavaScript.robot_move_angle = function () {
        var dir = Blockly.JavaScript.valueToCode(this, 'dir', Blockly.JavaScript.ORDER_ASSIGNMENT) || '""';
        var vel = Blockly.JavaScript.valueToCode(this, 'vel', Blockly.JavaScript.ORDER_ASSIGNMENT) || '""';
        var angle = Blockly.JavaScript.valueToCode(this, 'angle', Blockly.JavaScript.ORDER_ASSIGNMENT) || '""';
        var time = Blockly.JavaScript.valueToCode(this, 'time', Blockly.JavaScript.ORDER_ASSIGNMENT) || '""';
        return `robot_move_angle(${dir}, ${vel}, ${angle}, ${time})`;
    }
    

    It is my code.
    There's a block for initialize, and it's compressed by memory problem.
    So just init once, and return function execution code.
    (I don't know this is the best.)

    Anyway, If there are two 'robot_move_angle' blocks, and time is 2 sec and 4sec,
    user will think that it will move 2 sec, and after 2 sec, it will move 4 sec.

    But unfortunately, there's a crack, because of javascript's asynchronous.
    Is there a solution?

About

Avatar for user110706 @user110706 started