help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Data Manipulation Problem - Vectorization


From: Thomas D. Dean
Subject: Data Manipulation Problem - Vectorization
Date: Sun, 03 Feb 2013 13:37:51 -0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 Thunderbird/17.0

Octave 3.6.2 on Ubuntu.

I have a dataset, http://www.speakeasy.org/~tomdean/20130202-run1.array
which contains 24 columns of data taken from a robot driving around a
square, first CCW, then CW.  The robot starts at Cartesian coordinates
(0,0), pointed +X.  The square coordinates are
(0,0), (0,100), (-100,100), (-100,0)

I have attached some octave code below.

I want to calculate and plot the distance from the respective side of the square to the robot. (perpendicular)

I did this from inspecting the data.  But, if I run this again, I have
to do it all again.

There should be some way to vectorize this, but, it escapes me.

What am I missing?

Tom Dean

## errors.m - process the datalog from NG02
##
## run a square, starting at (0,0), facing +x and ending back at (0,0)
## after running CCW then CW around the square
## corners are (0,0),    (0,100),    (-100,100), (-100,0), (0,0)
##             (-100,0), (-100,100), (0,100),    (0,0)
## 1  dl_count++
## 2  time_count
## 3  left_encoder_count        
## 4  right_encoder_count       
## 5  X_position        
## 6  Y_position        
## 7  odometer
## 8  theta     
## 9  target_active
## 10 X_target
## 11 Y_target  
## 12 target_bearing
## 13 target_distance
## 14 L_pwm     
## 15 R_pwm
## 16 disp_srf04_ovfl
## 17 disp_srf04_count
## 18 disp_ping_ovfl
## 19 disp_ping_count
## 20 adc[0] L  IR Sensor
## 21 adc[1] LF IR Sensor
## 22 adc[2] RF IR Sensor
## 23 adc[3] R  IR Sensor
## 24 adc[7] Battery volts
##
## use datalog to collect data
## then readdl to change into ascii for octave
A=load('20130202-run1.array');
##
select=(A(:,9)>0);  ## actually driving only when target active .gt. zero
n=size(select,1);
driving=[1:n](select); ## the index of the entries while not stopped.
position=A(select,[5,6]);
target=A(select,[10,11]);
##
at_target=A((A(:,13) > 0) & (A(:,13)<10),13);

##   target   dir  side       x       y  change
##    0,100   CCW   1         0   0:100   y-> 100
## -100,100   CCW   2    0:-100     100   x->-100
## -100,  0   CCW   3      -100   100:0   y->   0
##    0,  0   CCW   4    -100:0       0   x->   0
## -100,  0    CW   5    0:-100       0   x->-100
## -100,100    CW   6      -100   0:100   y-> 100
##    0,100    CW   7    -100:0     100   x->   0
##    0,  0    CW   8         0   100:0   y->   0
## (qty) driving - index of values while driving along each side
##                 note the driving times change...
## (40) 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 ## (40) 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 ## (40) 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 ## (40) 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 ## (45) 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 ## (48) 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 ## (48) 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 ## (48) 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 ## Sides 1,2,3,4 took 40 steps. Side 5 took 45 steps. Sides 6,7,8 took 48 steps

## side 1   [zeros(1,40);[0:100/39:100]]
## side 2   [[0:-100/39:-100];100*ones(1,40)]
## side 3   [-100*ones(1,40);[100:-100/39:0]]
## side 4   [[-100:100/39:0];zeros(1,40)]
## side 5   [[0:-100/44:-100];zeros(1,45)]
## side 6   [-100*ones(1,48);[0:100/47:100]]
## side 7   [[-100:100/47:0];100*ones(1,48)]
## side 8   [zeros(1,48);[100:-100/47:0]]
sides=[[zeros(1,40);[0:100/39:100]], [[0:-100/39:-100];100*ones(1,40)], [-100*ones(1,40);[100:-100/39:0]], [[-100:100/39:0];zeros(1,40)], [[0:-100/44:-100];zeros(1,45)], [-100*ones(1,48);[0:100/47:100]], [[-100:100/47:0];100*ones(1,48)], [zeros(1,48);[100:-100/47:0]] ]';

## error in position is
driving_error=sides - posit;
rms_error=sqrt(sum((sides - posit).^2,2))
## plot the results
## figure 1
## hold on
plot(A(:,5),A(:,6),A(:,10),A(:,11));
title("Planned vs Actual Position - distance in CM");
ylabel("CM");
legend("Actual Position","Planned Position");
grid on
## hold off
print("Planned_vs_Actual.png");
## figure 2
## hold on
subplot(2,1,1);
plot(driving_error);
title("Driving Error- Deviation From The Planned Path")
ylabel("CM")
legend("X Error","Y Error");
grid on
subplot(2,1,2);
plot(rms_error);
title("RMS Error");
ylabel("CM")
xlabel("Point");
grid on
## drawnow
print("Errors.png");
##
at_target=A(((select==0)&(A(:,13)>0)),13);
clf;
plot(at_target);
title("Target Location Error");
ylabel("CM");
xlabel("Points");
grid on;
str=strcat(sprintf("NG02 location is the center, between the wheels\n"),
           sprintf("Target Location Specification +- %.2f cm\n",30.480/4),
           sprintf("Mean At Target Error = %.2f cm",mean(at_target)) );
text(900,7,str);
print("TargetLocErr.png");





reply via email to

[Prev in Thread] Current Thread [Next in Thread]