-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.xml
186 lines (139 loc) · 6.62 KB
/
index.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>Prabhpreet Singh Dua on Prabhpreet Singh Dua</title>
<link>http://prabhpreet.github.io/</link>
<description>Recent content in Prabhpreet Singh Dua on Prabhpreet Singh Dua</description>
<generator>Hugo -- gohugo.io</generator>
<language>en-us</language>
<copyright>&copy; 2018 Prabhpreet Singh Dua</copyright>
<lastBuildDate>Wed, 20 Apr 2016 00:00:00 +0000</lastBuildDate>
<atom:link href="/" rel="self" type="application/rss+xml" />
<item>
<title>Suppressed BPSK Demodulator using Costas Loop on a Microsemi FPGA</title>
<link>http://prabhpreet.github.io/project/isro/</link>
<pubDate>Wed, 27 Apr 2016 00:00:00 +0000</pubDate>
<guid>http://prabhpreet.github.io/project/isro/</guid>
<description></description>
</item>
<item>
<title>Cooperative Spectrum Sharing in Cognitive Radio Networks</title>
<link>http://prabhpreet.github.io/project/cooperativespectrumsharing/</link>
<pubDate>Wed, 27 May 2015 00:00:00 +0000</pubDate>
<guid>http://prabhpreet.github.io/project/cooperativespectrumsharing/</guid>
<description></description>
</item>
<item>
<title>Scheduler</title>
<link>http://prabhpreet.github.io/project/scheduler/</link>
<pubDate>Mon, 27 Apr 2015 00:00:00 +0000</pubDate>
<guid>http://prabhpreet.github.io/project/scheduler/</guid>
<description></description>
</item>
<item>
<title>Sampling sensors</title>
<link>http://prabhpreet.github.io/post/sampling-sensors/</link>
<pubDate>Sun, 07 Dec 2014 12:00:00 +0000</pubDate>
<guid>http://prabhpreet.github.io/post/sampling-sensors/</guid>
<description>
<p>I am currently working on a robotics project and it required a bit of quick testing. The quickest way to get a reading, other than the LCD was UART + a Matlab script. I wrote my own MATLAB script, but it required some obscure functions to get it working.</p>
<p>So I thought I&rsquo;ll share the important tidbits.</p>
<h3 id="the-serial-object">The serial object</h3>
<p>It&rsquo;s kind of like the file pointer data structure in C. It will store the port info, but you&rsquo;ll have to use <code>fopen</code>, <code>fgets</code> and <code>fclose</code> like manipulating files in C. Actually, the port data has been abstracted to the file. However, <code>fclose</code> is a big deal if you want other programs (such as a code uploader) to access your port.</p>
<pre><code class="language-matlab">s = serial('COM3') % COM3 is a port. Put whatever port your connected to!
set(s,'BaudRate', 115200); %Set your baud rate!
s.InputBufferSize = 5000; %Set the input buffer size (how much data can be stored)
fopen(s);
... %Other code omitted
while(1) %Infinite loop!
if s.BytesAvailable &gt; 0 % To avoid timeout and other weird things
str = fgets(s);
...
end
end
fclose(s); %Now you can access the object
</code></pre>
<h3 id="exception-error-handling">Exception/Error handling</h3>
<p>You&rsquo;ll need this part because you want to close your port and let other programs access it in case something bad happens.</p>
<pre><code class="language-matlab">try
... %Your code here
catch err %Catch the damn problem
fclose(s);
end;
</code></pre>
<h3 id="plotting">Plotting</h3>
<p>Here you can plot as usual as except you&rsquo;ll have to use <code>drawnow</code> to plot your data immediately and <code>hold on</code> if you&rsquo;re going to add data to the existing plot.</p>
<pre><code class="language-matlab">figure(1);
hold on;
...
while(1)
...
plot(A);
drawnow;
end
</code></pre>
<h3 id="string-manipulation">String manipulation</h3>
<p>Here I&rsquo;ve used <code>sscanf</code> to manipulate the string. I think there is also a direct function to get both getting a line and scanning done at the same time. You can look up the usage easily. The code basically returns a column vector according to the format specified using C&rsquo;s format specifiers (but look it up, to make sure!).</p>
<p>My data was of a white line sensor and I was getting it&rsquo;s left, middle and right values hence the <code>L:%d M:%d R:%d</code>.</p>
<pre><code class="language-matlab">A = sscanf(str, 'L:%d M:%d R:%d');
</code></pre>
<h3 id="all-the-code">All the code</h3>
<p>Here it is, in all it&rsquo;s glory:</p>
<pre><code class="language-matlab">clear all;
close all;
figure(1);
delay = 0.5;
s = serial('COM3');
set(s,'BaudRate', 115200);
s.InputBufferSize = 5000;
fopen(s);
input('Ready?');
try
A = [0;0;0];
while(1)
if s.BytesAvailable &gt; 0
str = fgets(s);
A = sscanf(str, 'L:%d M:%d R:%d');
bar(A)
axis([0 4 0 255]);
drawnow
A = [0;0;0];
end
end;
fclose(s);
catch err
fclose(s);
end;
</code></pre>
</description>
</item>
<item>
<title>Automatic Room Temperature Control</title>
<link>http://prabhpreet.github.io/project/automaticroom/</link>
<pubDate>Sun, 27 Apr 2014 00:00:00 +0000</pubDate>
<guid>http://prabhpreet.github.io/project/automaticroom/</guid>
<description></description>
</item>
<item>
<title>Badnaam</title>
<link>http://prabhpreet.github.io/project/badnaam/</link>
<pubDate>Wed, 27 Nov 2013 00:00:00 +0000</pubDate>
<guid>http://prabhpreet.github.io/project/badnaam/</guid>
<description></description>
</item>
<item>
<title>Avenues</title>
<link>http://prabhpreet.github.io/project/avenues/</link>
<pubDate>Tue, 27 Aug 2013 00:00:00 +0000</pubDate>
<guid>http://prabhpreet.github.io/project/avenues/</guid>
<description></description>
</item>
<item>
<title>Yet another static blog generator</title>
<link>http://prabhpreet.github.io/project/yasbg/</link>
<pubDate>Tue, 27 Apr 2010 00:00:00 +0000</pubDate>
<guid>http://prabhpreet.github.io/project/yasbg/</guid>
<description></description>
</item>
</channel>
</rss>