123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- /**
- * @license Licensed under the Apache License, Version 2.0 (the "License"):
- * http://www.apache.org/licenses/LICENSE-2.0
- */
- /**
- * @fileoverview Code generator for the test 2 blocks.
- */
- /*
- 'use strict';
- goog.provide('Blockly.Python.motion');
- goog.require('Blockly.Python');
- Blockly.Python['motion_setup'] = function() {
- var motion_include =' #include <RobotIRremote.h>\n' +
- ' #include <RobotIRremoteInt.h>\n' +
- ' #include <RobotIRremoteTools.h>\n\n' +
- ' #include <RobotIRremote.h>\n' +
- ' #include <RobotIRremoteInt.h>\n' +
- ' #include <RobotIRremoteTools.h>\n\n' +
- ' #include "I2Cdev.h"\n' +
- ' #include "MPU6050_6Axis_MotionApps20.h"\n' +
- ' #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE\n' +
- ' #include "Wire.h"\n' +
- ' #endif\n\n';
- Blockly.Python.addInclude('motion_include',motion_include);
- var motion_declaration_A =' MPU6050 mpu;\n' +
- ' #define OUTPUT_READABLE_QUATERNION\n\n' +
- ' #define OUTPUT_READABLE_WORLDACCEL\n' +
- ' #define OUTPUT_READABLE_REALACCEL\n' +
- ' '
- ' bool dmpReady = false; // set true if DMP init was successful\n' +
- ' uint8_t mpuIntStatus; // holds actual interrupt status byte from MPU\n' +
- ' uint8_t devStatus; // return status after each device operation (0 = success, !0 = error)\n' +
- ' uint16_t packetSize; // expected DMP packet size (default is 42 bytes)\n'+
- ' uint16_t fifoCount; // count of all bytes currently in FIFO\n' +
- ' uint8_t fifoBuffer[64]; // FIFO storage buffer\n\n' +
- ' Quaternion q; // [w, x, y, z] quaternion container\n' +
- ' VectorInt16 aa; // [x, y, z] accel sensor measurements\n' +
- ' VectorInt16 aaReal; // [x, y, z] gravity-free accel sensor measurements\n'+
- ' VectorInt16 aaWorld; // [x, y, z] world-frame accel sensor measurements\n'+
- ' VectorFloat gravity; // [x, y, z] gravity vector\n' +
- ' float euler[3]; // [psi, theta, phi] Euler angle container\n' +
- ' float ypr[3]; // [yaw, pitch, roll] yaw/pitch/roll container and gravity vector\n\n'+
- ' volatile bool mpuInterrupt = false; // indicates whether MPU interrupt pin has gone high\n';
- Blockly.Python.addDeclaration('motion_declaration_A', motion_declaration_A);
- //var motion_declaration_B = ' const int MPU_addr=0x68; // I2C address of the MPU-6050\n' +
- // ' int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;\n';
- //Blockly.Python.addDeclaration('motion_declaration_B', motion_declaration_B);
- var dmpDataReady = ' void dmpDataReady() {\n' +
- ' mpuInterrupt = true;\n' +
- ' }\n';
- Blockly.Python.addFunction('motion_dmpDateReady_function', dmpDataReady);
- var motion_setup =' #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE\n' +
- ' Wire.begin();\n' +
- ' TWBR = 24; // 400kHz I2C clock (200kHz if CPU is 8MHz)\n' +
- ' #elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE\n' +
- ' Fastwire::setup(400, true);\n' +
- ' #endif\n' +
- ' mpu.initialize();\n' +
- ' devStatus = mpu.dmpInitialize();\n' +
- ' mpu.setXGyroOffset(220);\n' +
- ' mpu.setYGyroOffset(76);\n' +
- ' mpu.setZGyroOffset(-85);\n' +
- ' mpu.setZAccelOffset(1788);\n' +
- ' if (devStatus == 0) {\n' +
- ' mpu.setDMPEnabled(true);\n'+
- ' attachInterrupt(0, dmpDataReady, RISING);\n' +
- ' mpuIntStatus = mpu.getIntStatus();\n' +
- ' dmpReady = true;\n' +
- ' packetSize = mpu.dmpGetFIFOPacketSize();\n' +
- ' } else {\n' +
- ' }\n';
- Blockly.Python.addSetup('motion_setup',motion_setup);
- var motion_code = 'if (!dmpReady) return;\n' +
- 'if (mpu.getFIFOCount() >= packetSize) {\n' +
- 'mpu.getFIFOBytes(fifoBuffer, packetSize);\n' +
- 'mpu.dmpGetQuaternion(&q, fifoBuffer);\n' +
- 'mpu.dmpGetEuler(euler, &q);\n' +
- '}\n' +
- 'mpuInterrupt = false;\n' +
- 'mpuIntStatus = mpu.getIntStatus();\n' +
- 'fifoCount = mpu.getFIFOCount();\n' +
- 'if ((mpuIntStatus & 0x10) || fifoCount == 1024) {\n' +
- // reset so we can continue cleanly
- ' mpu.resetFIFO();\n' +
- '} else if (mpuIntStatus & 0x02) {\n' +
- ' while (fifoCount < packetSize) fifoCount = mpu.getFIFOCount();\n' +
- ' mpu.getFIFOBytes(fifoBuffer, packetSize);\n' +
- ' fifoCount -= packetSize;\n' +
- // display quaternion values in easy matrix form: w x y z
- ' mpu.dmpGetQuaternion(&q, fifoBuffer);\n' +
- ' mpu.dmpGetAccel(&aa, fifoBuffer);\n' +
- ' mpu.dmpGetGravity(&gravity, &q);\n' +
- ' mpu.dmpGetLinearAccel(&aaReal, &aa, &gravity);\n' +
- ' mpu.dmpGetLinearAccelInWorld(&aaWorld, &aaReal, &q);\n'+
- '}\n';
- return motion_code;
-
- };
- Blockly.Python['motion_getRawData'] = function() {
- var dropdown_rawdatatype = block.getFieldValue('rawdatatype');
- var dropdown_rawdatalocate = block.getFieldValue('rawdatalocate');
- var code ='';
- if (dropdown_rawdatatype == 'motion_rawdata_accelerate') {
- code = 'aa';
- } else if (dropdown_rawdatatype == 'motion_rawdata_gyroscope') {
- code = '';
- }
- if (dropdown_rawdatalocate == 'motion_rawdata_x') {
- code +='.x\n';
- } else if (dropdown_rawdatalocate == 'motion_rawdata_y') {
- code +='.y\n';
- } else if (dropdown_rawdatalocate == 'motion_rawdata_z') {
- code +='.z\n';
- }
- return [code,Blockly.Python.ORDER_ATOMIC];
- };
- */
|