Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Random strange number appearing in columns #1059

Closed
stevedanomodolor opened this issue May 23, 2020 · 0 comments
Closed

Random strange number appearing in columns #1059

stevedanomodolor opened this issue May 23, 2020 · 0 comments

Comments

@stevedanomodolor
Copy link

Support Question

...ask your question here.
I am currently working on a project that uses perspective for visualization. After sending the data I notice that random numbers appear on the first row that does not have anything to do with the number in the other rows, I am not sure whether this is a bug ?. Weirdly enough, this does not seem to affect the visualization part so I am assuming it is a bug but I am not sure. In theory it is supposed to be 300, the total number of rows.
Another thing. I notice is that when I try to use the requestanimation frame technique to update the table, i get strange spike in the result(this was not so when I used the settimeout function to update the table). The image of this phenomenon can be seen is as follows.
strange_spike

Also, when I try to calculate the frame rates,(this can be seen in the code below) and visualize it, I get a random number like the photo shown below in the column at the right end. Is there a reason why this is happening?
avg_fps

It is going to be difficult to reproduce the code because there are lot of codes from c that does the computation function but you can change that function to any numbers to try it out.

// variables for perspective update

// How many rows per update?
// const UPDATE_SIZE = 1;

// Update every N milliseconds
const TICK_RATE = 50;


// Size limit of the table
const TABLE_SIZE = 300;
// requestAnimationFrame
var requestAnimationFrame = window.requestAnimationFrame
                            || window.mozRequestAnimationFrame
                            || window.webkitRequestAnimationFrame
                            || window.msRequestAnimationFrame

var cancelAnimationFrame = window.cancelAnimationFrame
                            || window.mozCancelAnimationFrame




// initializing simulation variables
var controler = 0;
var dt = 0.0001; // 0.1 ms
var lastLoop = 0;
//var freq = 0.0;
var state = "run";
var pos_output = 0;
var avg_freq = 0;
var worker = perspective.worker();
var schema = {
      lastUpdate: "datetime",
      comp_time: "float", // time of simulation in seconds
      va: "float",
      vc: "float",
      vb: "float",
      rpm: "float",
      position: "float", // curent position
      iq: "float",
      id: "float",
      // frequency: "integer",
      avg_frequency: "integer"

};

const table = worker.table(schema, {
      limit: TABLE_SIZE
});

// function update_data_visualized(){
//       requestAnimationFrame(update_data_visualized)
//
//       if (state == "run") {
//
//           }
//
//
// }
function restart() {
      console.log("You restarted")
      _restart();
      controler = 0;
      state = "run";
      avg_freq = 0.0;
      //freq = 0.0;
      lastLoop = 0;

}
// initialize computattion function
const init_comp = () => {

      console.log("Computation initialized");
      _restart(); // from c
      requestAnimationFrame(update_motor)


}


// main update function


      function update_motor() {
            requestAnimationFrame(update_motor)




            var thisLoop = new Date;
            if (lastLoop == 0) {
                  lastLoop = thisLoop;
                  return;
            }
            var freq = 1000 / (thisLoop - lastLoop);
            lastLoop = thisLoop;

            avg_freq = (avg_freq * 0.9)+(freq * 0.1);

            var Vbus = document.getElementById('vbus').value * 1.0;
            var rpm = document.getElementById('rpm').value * 1.0;
            var slidersetpos = document.getElementById('pos').value * 1.0;
            var loadt = document.getElementById('loadt').value * 1e-2;
            var loadj = document.getElementById('loadj').value * 1e-3;

            if (state == "run") {
                  var steps = 1 / freq / dt;
                  let array_result = new Float32Array(Module.HEAPF64.buffer, _computational_data(Vbus, loadt, loadj, slidersetpos, rpm, controler, steps), 8);


                  if (controler == 2) {
                        pos_output = array_result[5];
                  } else {
                        pos_output = 0;
                  }

                  var rows = [];
                  rows.push({
                        lastUpdate: new Date,
                        comp_time: array_result[0], // time of simulation in seconds
                        va: array_result[1],
                        vc: array_result[2],
                        vb: array_result[3],
                        rpm: array_result[4],
                        position: pos_output, // For visualitzation purpose
                        iq: array_result[6],
                        id: array_result[7],
                        avg_frequency: avg_freq

                  });

                  // return(rows);
                  table.update(rows);


            }




      }





window.addEventListener("WebComponentsReady", function() {
      var elem = document.getElementsByTagName("perspective-viewer")[0];


      elem.load(table);
      // elem.toggleConfig();

      init_comp();






      //Loop and update the `table` oocasionally.
      // (function postRow() {
      //       if (state == "run") {
      //             table.update(update_motor());
      //
      //       }
      //       setTimeout(postRow, TICK_RATE);
      // })();




},{passive: true, capture: true});

...be sure to search existing issues since someone might have already asked something similar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant