Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: garbear/mecanum
base: 56aa736b4c
...
head fork: garbear/mecanum
compare: e4fcba40bf
  • 2 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
85 avr_controller/matlab/LoadData.m
View
@@ -1,7 +1,8 @@
function LoadData()
-dirname = 'R:\mecanum\avr_controller\';
-backup = 'C:\Users\Garrett\Dropbox\Documents\Projects\Robot\Encoders\Data\';
+%dirname = 'R:\mecanum\avr_controller\';
+%backup = 'C:\Users\Garrett\Dropbox\Documents\Projects\Robot\Encoders\Data\';
+dirname = 'C:\Users\Garrett\Dropbox\Documents\Projects\Robot\Encoders\Data\';
dirlist = dir([dirname '*.txt']);
% Loop in reverse to find the last qualifying file name
@@ -14,9 +15,11 @@ function LoadData()
end
% Backup the data first
+%{
if ~exist([backup filename], 'file')
copyfile([dirname filename], [backup filename]);
end
+%}
dt = .0005; % s
x = load([dirname filename]);
@@ -35,7 +38,7 @@ function LoadData()
% Strategy: every time a bit is flipped and back again, calculate the
% period and duty cycle. Check the rest of the signal midpoints against the
% expected values.
-start = x(1);
+start = x(1); % Re-evaluate at new (flipped) value
minFlip = 1; % Skip this many samples before finding the first flip
while 2 + minFlip < length(x)
@@ -72,10 +75,9 @@ function LoadData()
end
%}
- %offset1 = ceil((flip + 1) / 2);
- %offset2 = floor(period - (flip - 1) / 2);
- offset1 = (flip + 1) / 2;
- offset2 = period - (flip - 1) / 2;
+ % Round to the right
+ offset1 = ceil((flip + 1) / 2);
+ offset2 = floor(period - (flip - 1) / 2);
err = 0;
max_err = 1;
while offset2 <= length(x) && err < max_err
@@ -89,6 +91,7 @@ function LoadData()
offset2 = offset2 + period;
end
+ % Found our period
if err < max_err
break;
end
@@ -102,8 +105,72 @@ function LoadData()
minFlip = i;
end
-% Got our period and duty cycle
-period * dt
+% If the while loop was invalidated we ran out of periods to try
+if 2 + minFlip >= length(x)
+ period = length(x);
+ flip = length(x);
+ for i = 2 : length(x)
+ if x(i) ~= start
+ flip = i - 1;
+ break;
+ end
+ end
+ %flop = period - flip;
+end
+
+% Recalculate offsets
+offset1 = ceil((flip + 1) / 2);
+offset2 = floor(period - (flip - 1) / 2);
+
+% Got our period and duty cycle, look for edges
+% Start left of period, sweep right until we hit a bit == start
+leadingRisingEdges = ones(1, floor(length(x) / period));
+for i = 2 : floor(length(x) / period) % First edge is obviously at offset 0
+ for j = period * (i-2) + offset2 : period * (i-1) + offset1
+ if x(j) == start
+ leadingRisingEdges(i) = j;
+ break;
+ end
+ end
+end
+
+% Assuming a duty cycle with a leading 1:
+
+% Default rise time of 0, can't have a rise time of 1
+riseTime = zeros(1, length(leadingRisingEdges));
+for i = 1 : length(leadingRisingEdges)
+ % Sweep in reverse direction looking for maximum rise time
+ for j = offset1 : -1 : 1
+ if x(min(leadingRisingEdges(i) + j, length(x))) ~= start
+ riseTime(i) = j + 1;
+ break;
+ end
+ end
+end
+
+leadingFallingEdges = zeros(1, floor(length(x) / period));
+for i = 1 : length(leadingFallingEdges)
+ for j = period * (i-1) + offset1 : period * (i-1) + offset2
+ if x(j) ~= start
+ leadingFallingEdges(i) = j;
+ break;
+ end
+ end
+end
+
+fallTime = zeros(1, length(leadingFallingEdges));
+for i = 1 : length(fallTime)
+ % Sweep in reverse direction looking for maximum fall time
+ for j = period - offset2 : -1 : 1
+ if x(min(leadingFallingEdges(i) + j, length(x))) == start
+ fallTime(i) = j + 1;
+ break;
+ end
+ end
+end
+
+
+period
duty = flip / period
end
2  avr_controller/src/SystemShutdown.cpp
View
@@ -33,6 +33,6 @@ int main(int argc, char **argv)
{
bool ret = true;
ret &= 0 == setuid(0);
- ret &= 0 == system("poweroff");
+ ret &= 0 == system("shutdown -h now");
return ret ? 0 : 1;
}

No commit comments for this range

Something went wrong with that request. Please try again.