2.74 MATLAB code for Interface to Nucleo

Revision:
7:3816d5dae909
Parent:
4:41f9e216a12d
Child:
8:58d93d7564ed
--- a/Experiment_Example_MATLAB.m	Fri Aug 21 22:29:47 2020 +0000
+++ b/Experiment_Example_MATLAB.m	Wed Aug 26 19:35:49 2020 +0000
@@ -1,27 +1,35 @@
 function output_data = Experiment_Example_MATLAB()
     figure(1);  clf;       % Create an empty figure to update later
-    subplot(211)
+    subplot(311)
     h1 = plot([0],[0]);
     h1.XData = []; h1.YData = [];
     ylabel('Position (counts)');
     
-    subplot(212)
+    subplot(312)
     h2 = plot([0],[0]);
     h2.XData = []; h2.YData = [];
     ylabel('Velocity (counts/s)');
     
+    subplot(313)
+    h3 = plot([0],[0]);
+    h3.XData = []; h3.YData = [];
+    ylabel('Current (volts)');
+    
     % This function will get called any time there is new data from
     % the FRDM board. Data comes in blocks, rather than one at a time.
     function my_callback(new_data)
         t = new_data(:,1);   % time
         pos = new_data(:,2); % position
         vel = new_data(:,3); % velocity
+        curr = new_data(:,4); %current
         N = length(pos);
         
         h1.XData(end+1:end+N) = t;   % Update subplot 1
         h1.YData(end+1:end+N) = pos;
         h2.XData(end+1:end+N) = t;   % Update subplot 2
         h2.YData(end+1:end+N) = vel;
+        h3.XData(end+1:end+N) = t;   % Update subplot 2
+        h3.YData(end+1:end+N) = curr;
     end
     
     frdm_ip  = '192.168.1.100';     % FRDM board ip
@@ -30,10 +38,10 @@
     params.timeout  = 2;            % end of experiment timeout
     
     % The example program provided takes two arguments
-    v1 = 1.0;           % pwm applied for first second 
-    v2 = 0.0;           % pwm applied for second second
+    v1 = 0.5;           % pwm applied for first second 
+    v2 = 0;           % pwm applied for second second
     input = [v1 v2];    % input sent to FRDM board
-    output_size = 3;    % number of outputs expected
+    output_size = 4;    % number of outputs expected
    
     output_data = RunExperiment(frdm_ip,frdm_port,input,output_size,params);
     
@@ -41,3 +49,4 @@
 
 
 
+