• 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?

  • Hi! You could try what we implement for the delay block: https://github.com/espruino/EspruinoWebI­DE/blob/gh-pages/blockly/blockly_espruin­o.js#L442

    There's some hacky stuff going on but basically it's able to take the code that should have gone right after, and then put it inside a function() {...} block to delay it

  • Thanks for reply, Gordon!
    Shamefully, I don't understand..
    If you can, can you explain it by code?

    Everything will be fine if there is a method that can verify if there is a nextBlock...

  • Just try it and see - there's some code further down that hooks into Blockly (which runs for all blocks) that detects that NEXTBLOCK text and re-arranges everything.

  • Thank you Gordon!

    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+","+angl­e+","+time+","+"setTimeout("+MAGIC_CALLB­ACK_CODE+", 1000*"+time+")\n;"
    }
    

    I wrote my code like this, and I know that NEXT_BLOCK works well.
    But it has an error.
    error said :
    You have more open brackets than close brackets. Please see the hints in the Editor window

    But I changed front-end for my project, so I can't use editor window.
    So I want to see codes when I push upload button at my terminal.

    /upload.html

      function sendUploadedCode() {
        Espruino.Core.MenuPortSelector.ensureCon­nected(function() {
          Espruino.callProcessor("sending");
          Espruino.callProcessor("transformForEspr­uino", uploadCode, function(code) {
            Espruino.Core.CodeWriter.writeToEspruino­(code, function() {
              Espruino.Core.Terminal.typeCharacters(co­de);
              Espruino.Core.Terminal.addNotification("­Uploaded!");
            });
          });
        });
      }
    

    I know upload button use this function, so I add one line,

    Espruino.Core.Terminal.typeCharacters(co­de);
    

    But it doesn't work. Is it possible to see uploaded codes at web ide's terminal??

  • Wed 2020.03.25

    'Is it possible to see uploaded codes at web ide's terminal?'

    Is dump() what you are after?    uploaded code source in text view

    http://www.espruino.com/Reference#l__glo­bal_dump

  • But I changed front-end for my project, so I can't use editor window.

    Maybe you could just try with a project where you haven't remove the editor window?

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Is synchronizing espurino IDE possible? Board is MDBT42Q.

Posted by Avatar for user110706 @user110706

Actions