Robobot and MATLAB

From Rsewiki

Back to Robobot

Logfiles

Many of the Robobot parts can generate log files.

Logfiles are important to

  • debug code and design
  • analyze situations (possibly also for debugging).

Teensy logfiles

The Teensy code can comment log data in RAM. This is the fastest possible log file, but it has a limited length; 250kbytes are reserved for this.

An example is shown below with a sample time of 2ms. The column explanation is at the top.

%% finished demo 1
%  1    time 0.0000 sec, from Bode (122)
%  2  3 Motor voltage (V) left, right: 0.00 0.00
%  4  5 Wheel velocity (m/s) left, right: -0.0000 0.0000
%  6    Turnrate (rad/s): 0.0000
%  7  8  9 10 Pose x,y,h,tilt (m,m,rad,rad): 0.0000 0.0000 0.0000 3.1256
% 11 .. 29 Edge sensor: left pos, right pos, line valid, crossing, values d d d d d d d d,  white, used, LED high, average white, line detect count, crossing detect count
% 30    Battery voltage (12.02 V)
0.0000 0.00 0.00 -0.0000 0.0000 0.0000 0.0000 0.0000 0.00000 3.12557 0.00 0.00 0 0 0 0 0 0 0 0 0 0  1 1 1 0.00 0 0 12.02 
0.0020 0.00 0.00 -0.0000 0.0000 0.0000 0.0000 0.0000 0.00000 3.12554 0.00 0.00 1 0 720 624 613 672 768 830 870 941  1 1 1 0.76 0 1 12.01 
0.0040 0.00 0.00 -0.0000 0.0000 0.0000 0.0000 0.0000 0.00000 3.12551 2.76 2.76 1 0 640 600 583 609 748 871 881 830  1 1 1 0.72 0 2 12.02 
...
0.1060 8.12 -4.12 -0.0000 0.0000 0.0000 0.0000 0.0000 0.00000 3.12551 2.31 2.31 1 0 613 586 572 573 778 982 916 728  1 1 1 0.72 0 20 11.95 
0.1080 7.95 -3.95 -0.0000 0.0000 0.0000 0.0002 -0.0000 -0.00159 3.12552 2.27 2.27 1 0 618 583 579 563 786 987 917 721  1 1 1 0.72 0 20 11.70 
0.1100 7.98 -3.98 -0.0000 0.0000 0.0000 0.0004 -0.0000 -0.00319 3.12543 2.30 2.30 1 0 623 574 579 571 788 980 914 734  1 1 1 0.72 0 20 11.53 
0.1120 8.01 -4.01 -0.0000 0.0000 0.0000 0.0006 -0.0000 -0.00797 3.12500 2.34 2.34 1 0 626 579 575 587 785 967 924 738  1 1 1 0.72 0 20 11.47 
0.1140 7.90 -3.90 0.3420 0.0000 -1.4553 0.0011 -0.0000 -0.01275 3.12490 2.32 2.32 1 0 618 588 581 603 786 983 910 741  1 1 1 0.73 0 20 11.45 
0.1160 7.93 -3.93 0.5213 0.0000 -2.2184 0.0013 -0.0000 -0.02071 3.12555 2.36 2.36 1 0 618 583 581 588 793 984 907 760  1 1 1 0.73 0 20 11.50 
0.1180 7.77 -3.77 0.6019 -0.1235 -3.0867 0.0015 -0.0000 -0.02868 3.12641 2.32 2.32 1 0 621 596 584 587 796 998 920 747  1 1 1 0.73 0 20 11.53 
0.1200 7.78 -3.78 0.6689 -0.3611 -4.3826 0.0019 -0.0000 -0.03824 3.12722 2.35 2.35 1 0 632 599 590 592 782 975 921 741  1 1 1 0.73 0 20 11.56 
0.1220 7.64 -3.64 0.7130 -0.4086 -4.7726 0.0022 -0.0000 -0.04780 3.12773 2.32 2.32 1 0 629 585 575 591 773 980 912 728  1 1 1 0.72 0 20 11.59 
0.1240 7.53 -3.53 0.7425 -0.4177 -4.9369 0.0026 -0.0001 -0.05736 3.12796 2.30 2.30 1 0 611 586 571 597 773 975 903 725  1 1 1 0.72 0 20 11.62 
0.1260 7.82 -3.82 0.7666 -0.4193 -5.0463 0.0030 -0.0001 -0.06693 3.12845 2.43 2.43 1 0 613 585 572 585 757 965 912 749  1 1 1 0.72 0 20 11.64 
0.1280 7.56 -3.56 0.8042 -0.4161 -5.1927 0.0034 -0.0001 -0.07649 3.12959 2.35 2.35 1 0 610 573 570 589 773 978 907 741  1 1 1 0.72 0 20 11.65 
0.1300 7.38 -3.38 0.8556 -0.4010 -5.3472 0.0039 -0.0002 -0.08764 3.13112 2.31 2.31 1 0 618 579 560 583 786 975 899 740  1 1 1 0.72 0 20 11.66 
0.1320 7.52 -3.52 0.9004 -0.3869 -5.4777 0.0045 -0.0002 -0.09879 3.13295 2.38 2.38 1 0 615 586 565 575 775 957 918 743  1 1 1 0.72 0 20 11.69 
0.1340 7.35 -3.35 0.9178 -0.3764 -5.5073 0.0050 -0.0003 -0.10995 3.13508 2.34 2.34 1 0 613 584 575 591 792 967 900 753  1 1 1 0.72 0 20 11.70

This Matlab script uses the data for 2 plots, one for line following for the full buffer and the other a specific set of line sensor values.

%% Line follow plot
close all
clear
%% load
%  1    time 0.0000 sec, from Bode (122)
%  2  3 Motor voltage (V) left, right: 0.00 0.00
%  4  5 Wheel velocity (m/s) left, right: -0.0000 0.0000
%  6    Turnrate (rad/s): 0.0000
%  7  8  9 10 Pose x,y,h,tilt (m,m,rad,rad): 0.0000 0.0000 0.0000 3.1256
% 11 .. 29 Edge sensor: left pos, right pos, line valid, crossing, values d d d d d d d d,  white, used, LED high, average white,  line detect count, crossing detect count
% 30    Battery voltage (12.02 V)
dd_15 = load('aaa_bode_15.txt'); % Kp = 0.8 % with lead 1.0 - 0.15 - step
dd_16 = load('aaa_bode_16.txt'); % Kp = 0.5 % with lead 0.8 - 0.15 - step
%%
dd = dd_16;
fig = 100000 + 100 * 16;
%% control
h = figure(fig);
hold off
plot(dd(:,1), dd(:,2))
hold on
plot(dd(:,1), dd(:,3))
% line
plot(dd(:,1), dd(:,13))
plot(dd(:,1), dd(:,11))
plot(dd(:,1), dd(:,6))
legend('left V', 'right V', 'line valid','line pos','turnrate')
xlabel('sec');
grid on
saveas(h,"bode_set_16_line_follow.png")
%% detection
n = 720;
h = figure(fig + 1);
hold off
nn = 1:8
plot(nn, dd(n,15:22),'r')
hold on
for (j = n:n+10)
    plot(nn, dd(j,15:22),'r')
    x = dd(j, 11) + 4;
    plot([x,x], [700, 1000],'r')
end
n = 124
for (j = n:n+10)
    plot(nn, dd(j,15:22),'b')
    x = dd(j, 11) + 4;
    plot([x,x], [700, 1000],'b')
end
grid on
xlabel('sensor number')
ylabel('Normalized sensor value')
title('Two positions (124,720), notice varying floor level.')
saveas(h,"bode_set_a6_720_124.png")

The first part is to load the data. The second part is a way to determine figure numbers. Then the two analysis plots.

The first plot shows the effect of line control (hand-tuned). It shows the detected line position (purple) and the two motor voltages that are a consequence of the line-follow controller. In addition, the turn rate is included (green).

The second plot shows the sensor values for a 4cm wide white tape line at different points on the path.

The vertical lines are the estimated line position.

Teensy interface

Matlab