Jump to content

soak

Members
  • Posts

    3
  • Joined

  • Last visited

soak's Achievements

Newbie

Newbie (1/4)

0

Reputation

  1. Additionally, looking into Javascript timing there seem to be two methods. Method 1 uses Date().getTime() which offers millisecond resolution (not very good). Method 2 uses performance.now() and offers sub-microsecond resolution. Method 2 would be preferable but I can't seem to run it natively in a waveforms script. Is there a required import to make the performance package work? I have tried `const { performance } = require('perf_hooks');` to import as would be required in node.js but that didn't seem to work. Thanks again!
  2. Hi @attila, Thanks for the help, however, it seems that the Analog Discovery 2 that I have does not support the Scope.Time.taken command. I have reached this conclusion by printing the result of Scope.Time.taken and getting an undefined result: print(Scope.Time.taken) --> undefined Is there an alternate approach to do timing using the Analog Discovery 2 hardware, or would you suggest that I keep track of timing in javascript, at the cost of reduced precision? Thanks, Dylan
  3. Hello, I am trying to use my Analog Discovery 2 to stand in as an element of a feedback control system. Specifically what I mean by that is that I've designed a PID circuit and I would like to feed the output of the PID into my AD2 scope, do some calculations, then use the AWG to output a voltage back into my PID circuit. I have written a waveform script that *mostly* does what I want, but am having some trouble with getting the voltage and time data I want from the scope. One more piece of context is that the dynamics of this system are quite long (order minutes) which might effect the best way to do this. With that context, here are my questions: 1) How can I grab the most recent datapoint acquired by the scope? 2) How can I get the amount of time between the last datapoint that I grabbed, and the most recent one? Here is a section of the code that I have written so far, with comments of the part that I don't know how to do. // Setup Instruments Scope.Time.Mode.text("Shift") Scope.Trigger.Trigger.text = "Repeated"; Wavegen.Channel1.Mode.text = "Simple"; Wavegen.Channel1.Simple.Offset.value = 0; Scope.run(); Wavegen.run(); // Do the thing var heading = start_heading; while( true ){ if(!Scope.wait()) throw "Stopped"; // Don't know how to fill this part out var this_sample_idx = ????; var last_sample_idx = ????; // Figure out timing for integration var t_last_sample = Scope.Channel1.TimeOfIndex(last_sample_idx); var t_this_sample = Scope.Channel1.TimeOfIndex(this_sample_idx); var dt = t_this_sample - t_last_sample; // Grab voltage data from scope var voltage = Scope.Channel1.Sample(this_sample_idx); // Simulated vehicle var current_rudder_angle = voltage_to_rudder_angle(voltage); var current_rate_of_turn = rudder_angle_to_rate_of_turn(current_rudder_angle); heading = rate_of_turn_to_heading(current_rate_of_turn, heading, dt); // Calculate difference var err = set_heading - heading; // Output error using AWG Wavegen.Channel1.Simple.Offset.value = err; } Thanks so much for the help! -Dylan
×
×
  • Create New...