Project

General

Profile

Statistics
| Revision:

root / trunk / code / behaviors / formation_control / push_pull / vectorSizeSpecs.m @ 1510

History | View | Annotate | Download (1.38 KB)

1
% vectorSizeSpecs - Script used to help calculate the max scalar value by
2
% 		which to multiply the BOM unit vectors (thus increasing the
3
%		precision of the scaled vectors) such that in the worst case, the
4
%		total net sum will not overflow the data type used to represent
5
%		the net vector components.
6
%
7
%	Author: John Sexton, Colony Project, CMU Robotics Club
8

    
9

    
10
% Parameters
11
maxIntensity = 255;
12
dataBits = 16;
13
scalar = 25;
14

    
15
n = 0:8;
16
angle = n * 2 * pi / 16;
17

    
18
vector_components = sin(angle);
19
max_net_component = sum(vector_components);
20

    
21
% Formula for max_net_component (mnc), obtained by summing
22
% values from the unit circle at angles of 0 : pi/8 : pi
23
% in quadrants I and II
24
mnc = 1;									%sin(pi/2)
25
mnc = mnc + (2*  (1/2)*sqrt(2+sqrt(2)));	%sin(3pi/8) and sin(5pi/8)
26
mnc = mnc + (2*  sqrt(2)/2);				%sin(pi/4) and sin(3pi/4)
27
mnc = mnc + (2*  (1/2)*sqrt(2-sqrt(2)));	%sin(pi/8) and sin(7pi/8)
28

    
29

    
30
calc_scalar = (2^(dataBits-1)-1) / (max_net_component * maxIntensity);
31
% calc_scalar = 25.560 => use 25 as scalor
32

    
33
fprintf('With %d data bits, calculated scalar value: %.3f\n\n', dataBits, calc_scalar);
34

    
35

    
36
% Check worst case
37
scaled_vector_components = scalar * vector_components;
38

    
39
worst_case = scaled_vector_components * maxIntensity;
40
worst_sum = sum(worst_case);
41
fprintf('With scalar %d, max worst case sum: %d\n', scalar, worst_sum);
42
fprintf('Max number: 2^(%d-1) - 1 = %d\n', dataBits, (2^(dataBits-1)-1));