Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
MechaRaptor - Data Processing
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Aerospace and Mechanical Engineering
tlambert
MechaRaptor - Data Processing
Commits
41b37736
Verified
Commit
41b37736
authored
2 years ago
by
Thomas Lambert
Browse files
Options
Downloads
Patches
Plain Diff
fix(ardu): fix major angle issues
parent
8145b2aa
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
utils/loadardu.m
+36
-8
36 additions, 8 deletions
utils/loadardu.m
with
36 additions
and
8 deletions
utils/loadardu.m
+
36
−
8
View file @
41b37736
function
arduData
=
loadardu
(
arduFile
)
function
[
arduShort
,
arduData
]
=
loadardu
(
arduFile
)
% LOADARDU Load the Arduino data and clean it.
% This function loads the Arduino data. Then it:
% - removes the unneeded columns
...
...
@@ -38,7 +38,6 @@ function arduData = loadardu(arduFile)
arduTable
=
loadcsv
([
'arduinoFiles/'
,
arduFile
,
'.csv'
]);
end
% Time conversion
arduTable
.
time
=
timetosec
(
arduTable
.
time
);
% Remove data with duplicate timecode
...
...
@@ -47,16 +46,22 @@ function arduData = loadardu(arduFile)
arduTable
=
arduTable
(
idx
,
:);
% Convert into table
arduData
=
table2array
(
arduTable
);
arduRaw
=
table2array
(
arduTable
);
time
=
arduRaw
(:,
1
);
% Calculate power, remove tension and current
power
=
arduData
(:,
[
6
,
8
])
.*
arduData
(:,
[
7
,
9
]);
arduData
(:,
6
:
end
)
=
[];
arduData
=
[
arduData
,
power
];
power
=
arduRaw
(:,
[
6
,
8
])
.*
arduRaw
(:,
[
7
,
9
]);
% Recalculate angles properly from wing positions recoreded
arduData
(:,
2
:
5
)
=
fixangles
(
ardu
Data
(:,
2
:
5
));
goodAngles
=
fixangles
(
ardu
Raw
(:,
2
:
5
));
% Take mean angles for each set of wings (diff is almost negligible)
meanAnglesFront
=
mean
(
goodAngles
(:,
1
:
2
),
2
);
meanAnglesAft
=
mean
(
goodAngles
(:,
3
:
4
),
2
);
% Output a cleaned up tables
arduData
=
[
time
,
goodAngles
,
power
];
% time, FL, FR, AL, AR, PowF, PowA
arduShort
=
[
time
,
meanAnglesFront
,
meanAnglesAft
,
power
];
end
function
rawTable
=
loadcsv
(
file
)
...
...
@@ -96,11 +101,15 @@ end
function
angles
=
fixangles
(
wingPos
)
% FIXANGLES Fix the angle values to avoid issues with the 12 bit overflow
% Note: 3rd sensor had an encoding issue. This issue is fixed here automatically
% Note: Aft sensors enocde in the wrong direction (Angles should be opposite)
% Note: Sometimes error with front left wing stuck at 0 or 4095 when not flapping. If stuck,
% just copy right wing
% Defaults and constants
ENC_PRECISION
=
12
;
% 12-bits encoders
MAX_WING_ANGLE
=
38.07
;
% Determined by geometry of the setup
CALIB_OFFSET
=
[
100.8984
115.7520
199.5996
131.7480
];
% Maximum angle recored BEFORE offset
CALIB_OFFSET
=
[
100.8984
115.7520
211.4648
278.6133
];
% Maximum angle recored BEFORE offset
N_VAL_STATIC
=
10
;
% Number of different positions under which it wing is supposed static
% Abbreviations
nBits
=
2
^
ENC_PRECISION
;
...
...
@@ -110,9 +119,28 @@ function angles = fixangles(wingPos)
% [FIXME] Once this is fixed in the controller, add a switch to correct or not the data
wingPos
(:,
3
)
=
mod
(
wingPos
(:,
3
)
+
nBits
/
2
,
nBits16
);
% Aft sensors are in the wrong direction
% [FIXME] Once this is fixed in the controller, add a switch to correct or not the data
wingPos
(:,
3
:
4
)
=
nBits
-
wingPos
(:,
3
:
4
);
% Convert position data into actual degree
angles
=
wingPos
*
360
/
nBits
;
% maxangles = max(angles)
% Calibrate values so max angle recored matches MAX_WING_ANGLE
angles
=
angles
-
CALIB_OFFSET
+
MAX_WING_ANGLE
;
% Fix for front wing stuck in 0 or 4095
% For some reason the first wing get sometimes stuck in strange values when there is no motion.
% It then returns a position oscillating between 0 and 4095 (or a bit more than that). This can
% be detected by simply looking if some diff in position are greater than nBist/2. If it is the
% case, either we have an abrupt change of +180° (impossible), or there is an overflow issue.
if
(
any
(
diff
(
wingPos
(:,
1
))
>
nBits
/
2
)
||
...
all
(
wingPos
(:,
1
)
==
nBits
-
1
)
||
...
all
(
wingPos
(:,
1
)
==
0
))
&&
...
~
any
(
diff
(
wingPos
(:,
2
))
>
nBits
/
2
)
angles
(:,
1
)
=
angles
(:,
2
);
end
end
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment