2 %
Copyright (c) 2012, Silvio Vallorani <silvio.vallorani@studio.unibo.it>
5 % software
for any purpose with or without fee is hereby
6 %
granted, provided that the above copyright notice and
this
7 % permission notice appear in all copies.
9 % THE SOFTWARE IS PROVIDED
"AS IS" AND THE AUTHOR DISCLAIMS
10 % ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
11 % IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
13 %
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 % WHATSOEVER RESULTING FROM LOSS OF
USE, DATA OR
PROFITS,
16 % TORTIOUS
ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
17 %
USE OR PERFORMANCE OF THIS SOFTWARE.
23 % Here 256 samples
for impactPatterns are generated accordingly to
25 % Taku Hachisu et al. (2011)
26 % Pseudo-Haptic Feedback Augmented with Visual and Tactile Vibrations
28 % Q(t) = A(v) * e^(-B*t) * sin(2*pi*f*t) (1)
30 % where Amplitude is function of velocity but quasi-linearity implies
33 % Q(t) = A * v * e^(-B*t) * sin(2*pi*f*t)
35 % Use this formula as Haptic Pattern Sample Generator needs some other
38 % PS(t) = abs(A) * v * [ 2*e^(-B*t) * (1 + sin(2*pi*f*t) ]
40 % This approch ensures non negative samples mainteining continuity.
41 % Samples are also scaled to remain in (1/3) * PMN_LEVELS range (slow).
43 % @author Silvio Vallorani
49 close all; clear all; clc;
53 PWM_LEVELS = 65000; % number of PWM levels that can be used in HapticLib
55 t = ( 0 : 0.00035 : 0.1 ); % ensure impact transitory estinguish
58 V1 = 1; V2 = 2; V3 = 3; % Three different impact velocity magnitude are
64 % Samples must be generated
using V1.
69 A_Aluminum = - 300; A_Aluminum = abs ( A_Aluminum );
73 S_Aluminum = 1 + sin( 2 * pi * F_Aluminum * t );
74 E_Aluminum = 2 * exp( - B_Aluminum * t );
76 H_Aluminum = A_Aluminum * S_Aluminum .* E_Aluminum;
77 SCALE_FACTOR = ceil( max( H_Aluminum ) );
78 H_Aluminum = floor ( H_Aluminum / SCALE_FACTOR * (PWM_LEVELS/3) );
79 H_Aluminum_V1 = V1 * H_Aluminum;
80 H_Aluminum_V2 = V2 * H_Aluminum;
81 H_Aluminum_V3 = V3 * H_Aluminum;
84 plot( t, H_Aluminum_V1 ), title(
'ALUMINUM @ SLOW' ), axis( [0 t(256) 0 PWM_LEVELS ] )
86 plot( t, H_Aluminum_V2 ), title( 'ALUMINUM @ NORMAL' ), axis( [0 t(256) 0 PWM_LEVELS ] )
88 plot( t, H_Aluminum_V3 ), title( 'ALUMINUM @ FAST' ), axis( [0 t(256) 0 PWM_LEVELS ] )
92 A_Rubber = - 240; A_Rubber = abs ( A_Rubber );
96 S_Rubber = 1 + sin( 2 * pi * F_Rubber * t );
97 E_Rubber = 2 * exp( - B_Rubber * t);
99 H_Rubber = A_Rubber * S_Rubber .* E_Rubber;
100 H_Rubber = floor ( H_Rubber / SCALE_FACTOR * (PWM_LEVELS/3) );
101 H_Rubber_V1 = V1 * H_Rubber;
102 H_Rubber_V2 = V2 * H_Rubber;
103 H_Rubber_V3 = V3 * H_Rubber;
106 plot( t, H_Rubber_V1 ), title( 'RUBBER @ SLOW' ), axis( [0 t(256) 0 PWM_LEVELS ] )
108 plot( t, H_Rubber_V2 ), title( 'RUBBER @ NORMAL' ), axis( [0 t(256) 0 PWM_LEVELS ] )
110 plot( t, H_Rubber_V3 ), title( 'RUBBER @ FAST' ), axis( [0 t(256) 0 PWM_LEVELS ] )
114 A_Wood = - 150; A_Wood = abs ( A_Wood );
118 S_Wood = 1 + sin( 2 * pi * F_Wood * t );
119 E_Wood = 2 * exp( - B_Wood * t );
121 H_Wood = A_Wood * S_Wood .* E_Wood;
122 H_Wood = floor ( H_Wood / SCALE_FACTOR * (PWM_LEVELS/3) );
123 H_Wood_V1 = V1 * H_Wood;
124 H_Wood_V2 = V2 * H_Wood;
125 H_Wood_V3 = V3 * H_Wood;
128 plot( t, H_Wood_V1 ), title( 'WOOD @ SLOW' ), axis( [0 t(256) 0 PWM_LEVELS ] )
130 plot( t, H_Wood_V2 ), title( 'WOOD @ NORMAL' ), axis( [0 t(256) 0 PWM_LEVELS ] )
132 plot( t, H_Wood_V3 ), title( 'WOOD @ FAST' ), axis( [0 t(256) 0 PWM_LEVELS ] )
134 % WRITE RESULTS ON TXT FILE
136 fileID = fopen('impact.txt', 'w', 'n');
137 formatPattern = '%5d,\t%5d,\t%5d,\t%5d,\t%5d,\t%5d,\t%5d,\t%5d,\t%5d,\t%5d,\t\t\\\n';
140 fprintf(fileID, formatPattern, H_Rubber_V1(1:255));
141 fprintf(fileID, '%5d\t\t\t\t\t\t\t\t\t\t};\n\n
',0);
143 fprintf(fileID, 'const uint8_t
woodImpactPattern[256] = {\t\t\t\t\t\t\t\t\t\t\t\\\n
');
144 fprintf(fileID, formatPattern, H_Wood_V1(1:255));
145 fprintf(fileID, '%5d\t\t\t\t\t\t\t\t\t\t};\n\n
',0);
148 fprintf(fileID, formatPattern, H_Aluminum_V1(1:255));
149 fprintf(fileID, '%5d\t\t\t\t\t\t\t\t\t\t};\n\n
',0);
152 fprintf('\nText file with Samples generated.\n
')
155 fprintf('\nBiggest Sample values exracted from FAST Patterns\n\n
')
156 fprintf('Biggest
Rubber Sample: %5d\n
',max(H_Rubber_V3))
157 fprintf('Biggest
Wood Sample: %5d\n
',max(H_Wood_V3))
158 fprintf('Biggest
Aluminum Sample: %5d\n
',max(H_Aluminum_V3))