Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
iMSTK
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
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
Ben Boeckel
iMSTK
Commits
56e2f58e
Commit
56e2f58e
authored
7 years ago
by
Sam Horvath
Browse files
Options
Downloads
Patches
Plain Diff
ENH: Updated arduino sketch parameters
parent
969251c8
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Arduino/imstkVRPNArduino_roll_only/imstkVRPNArduino_roll_only.ino
+11
-9
11 additions, 9 deletions
...imstkVRPNArduino_roll_only/imstkVRPNArduino_roll_only.ino
with
11 additions
and
9 deletions
Arduino/imstkVRPNArduino_roll_only/imstkVRPNArduino_roll_only.ino
+
11
−
9
View file @
56e2f58e
...
...
@@ -127,6 +127,7 @@ void setup() {
// (115200 chosen because it is required for Teapot Demo output, but it's
// really up to you depending on your project)
Serial
.
begin
(
57600
);
Serial
.
println
(
"setup"
);
while
(
!
Serial
);
// wait for Leonardo enumeration, others continue immediately
// NOTE: 8MHz or slower host processors, like the Teensy @ 3.3v or Ardunio
...
...
@@ -249,11 +250,12 @@ void loop() {
accel
[
0
]
=
aa
.
x
;
accel
[
1
]
=
aa
.
y
;
accel
[
2
]
=
aa
.
z
;
ComplementaryFilter
(
accel
,
gyro
,
&
m_pitch
,
&
m_roll
);
ComplementaryFilter
(
accel
,
gyro
);
Serial
.
print
(
m_roll
);
Serial
.
print
(
","
);
Serial
.
print
(
m_pitch
);
//dummy data to fill out 6 vrpn analog channels
Serial
.
println
(
",0,0,0,0
,0
"
);
Serial
.
println
(
",0,0,0,0"
);
#endif
...
...
@@ -263,25 +265,25 @@ void loop() {
}
}
void
ComplementaryFilter
(
short
accData
[
3
],
short
gyrData
[
3
]
,
float
*
pitch
,
float
*
roll
)
void
ComplementaryFilter
(
short
accData
[
3
],
short
gyrData
[
3
])
{
float
pitchAcc
,
rollAcc
;
// Integrate the gyroscope data -> int(angularSpeed) = angle
*
pitch
+=
((
float
)
gyrData
[
0
]
/
GYROSCOPE_SENSITIVITY
)
*
dt
;
// Angle around the X-axis
*
roll
-=
((
float
)
gyrData
[
1
]
/
GYROSCOPE_SENSITIVITY
)
*
dt
;
// Angle around the Y-axis
m_
pitch
+=
((
float
)
gyrData
[
0
]
/
GYROSCOPE_SENSITIVITY
)
*
dt
;
// Angle around the X-axis
m_
roll
-=
((
float
)
gyrData
[
1
]
/
GYROSCOPE_SENSITIVITY
)
*
dt
;
// Angle around the Y-axis
// Compensate for drift with accelerometer data if !bullshit
// Sensitivity = -2 to 2 G at 16Bit -> 2G = 32768 && 0.5G = 8192
int
forceMagnitudeApprox
=
abs
(
accData
[
0
])
+
abs
(
accData
[
1
])
+
abs
(
accData
[
2
]);
if
(
forceMagnitudeApprox
>
8192
&&
forceMagnitudeApprox
<
32768
)
if
(
forceMagnitudeApprox
>
ACCELEROMETER_SENSITIVITY
&&
forceMagnitudeApprox
<
32768
)
{
// Turning around the X axis results in a vector on the Y-axis
pitchAcc
=
atan2f
((
float
)
accData
[
1
],
(
float
)
accData
[
2
])
*
180
/
M_PI
;
*
pitch
=
*
pitch
*
0.
5
+
pitchAcc
*
0.
5
;
m_
pitch
=
m_
pitch
*
0.
98
+
pitchAcc
*
0.
02
;
// Turning around the Y axis results in a vector on the X-axis
rollAcc
=
atan2f
((
float
)
accData
[
0
],
(
float
)
accData
[
2
])
*
180
/
M_PI
;
*
roll
=
*
roll
*
0.5
+
rollAcc
*
0.5
;
m_
roll
=
m_
roll
*
0.
9
5
+
rollAcc
*
0.
0
5
;
}
}
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