Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
Firmware
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Alberto Ruiz Garcia
Firmware
Commits
d5a7aaa0
Commit
d5a7aaa0
authored
8 years ago
by
Julian Oes
Committed by
Lorenz Meier
8 years ago
Browse files
Options
Downloads
Patches
Plain Diff
df_hmc5883_wrapper: rotation on driver level
parent
969940e9
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/platforms/posix/drivers/df_hmc5883_wrapper/df_hmc5883_wrapper.cpp
+33
-21
33 additions, 21 deletions
...s/posix/drivers/df_hmc5883_wrapper/df_hmc5883_wrapper.cpp
with
33 additions
and
21 deletions
src/platforms/posix/drivers/df_hmc5883_wrapper/df_hmc5883_wrapper.cpp
+
33
−
21
View file @
d5a7aaa0
...
...
@@ -59,8 +59,8 @@
#include
<uORB/topics/parameter_update.h>
#include
<board_config.h>
//#include <mathlib/math/filter/LowPassFilter2p.hpp>
//
#include <lib/conversion/rotation.h>
#include
<lib/conversion/rotation.h>
#include
<hmc5883/HMC5883.hpp>
#include
<DevMgr.hpp>
...
...
@@ -74,7 +74,7 @@ using namespace DriverFramework;
class
DfHmc9250Wrapper
:
public
HMC5883
{
public:
DfHmc9250Wrapper
(
/*
enum Rotation rotation
*/
);
DfHmc9250Wrapper
(
enum
Rotation
rotation
);
~
DfHmc9250Wrapper
();
...
...
@@ -97,8 +97,6 @@ private:
void
_update_mag_calibration
();
//enum Rotation _rotation;
orb_advert_t
_mag_topic
;
int
_param_update_sub
;
...
...
@@ -112,20 +110,21 @@ private:
float
z_scale
;
}
_mag_calibration
;
math
::
Matrix
<
3
,
3
>
_rotation_matrix
;
int
_mag_orb_class_instance
;
perf_counter_t
_mag_sample_perf
;
};
DfHmc9250Wrapper
::
DfHmc9250Wrapper
(
/*
enum Rotation rotation
*/
)
:
DfHmc9250Wrapper
::
DfHmc9250Wrapper
(
enum
Rotation
rotation
)
:
HMC5883
(
MAG_DEVICE_PATH
),
_mag_topic
(
nullptr
),
_param_update_sub
(
-
1
),
_mag_calibration
{},
_mag_orb_class_instance
(
-
1
),
_mag_sample_perf
(
perf_alloc
(
PC_ELAPSED
,
"df_mag_read"
))
/*_rotation(rotation)*/
{
// Set sane default calibration values
_mag_calibration
.
x_scale
=
1.0
f
;
...
...
@@ -134,6 +133,9 @@ DfHmc9250Wrapper::DfHmc9250Wrapper(/*enum Rotation rotation*/) :
_mag_calibration
.
x_offset
=
0.0
f
;
_mag_calibration
.
y_offset
=
0.0
f
;
_mag_calibration
.
z_offset
=
0.0
f
;
// Get sensor rotation matrix
get_rot_matrix
(
rotation
,
&
_rotation_matrix
);
}
DfHmc9250Wrapper
::~
DfHmc9250Wrapper
()
...
...
@@ -278,9 +280,19 @@ int DfHmc9250Wrapper::_publish(struct mag_sensor_data &data)
mag_report
.
x_raw
=
NAN
;
mag_report
.
y_raw
=
NAN
;
mag_report
.
z_raw
=
NAN
;
mag_report
.
x
=
(
data
.
field_x_ga
-
_mag_calibration
.
x_offset
)
*
_mag_calibration
.
x_scale
;
mag_report
.
y
=
(
data
.
field_y_ga
-
_mag_calibration
.
y_offset
)
*
_mag_calibration
.
y_scale
;
mag_report
.
z
=
(
data
.
field_z_ga
-
_mag_calibration
.
z_offset
)
*
_mag_calibration
.
z_scale
;
math
::
Vector
<
3
>
mag_val
((
data
.
mag_ga_x
-
_mag_calibration
.
x_offset
)
*
_mag_calibration
.
x_scale
,
(
data
.
mag_ga_y
-
_mag_calibration
.
y_offset
)
*
_mag_calibration
.
y_scale
,
(
data
.
mag_ga_z
-
_mag_calibration
.
z_offset
)
*
_mag_calibration
.
z_scale
);
// apply sensor rotation on the accel measurement
mag_val
=
_rotation_matrix
*
mag_val
;
mag_report
.
x
=
mag_val
(
0
);
mag_report
.
y
=
mag_val
(
1
);
mag_report
.
z
=
mag_val
(
2
);
// TODO: get these right
//mag_report.scaling = -1.0f;
...
...
@@ -315,14 +327,14 @@ namespace df_hmc5883_wrapper
DfHmc9250Wrapper
*
g_dev
=
nullptr
;
int
start
(
/*
enum Rotation rotation
*/
);
int
start
(
enum
Rotation
rotation
);
int
stop
();
int
info
();
void
usage
();
int
start
(
/*
enum Rotation rotation
*/
)
int
start
(
enum
Rotation
rotation
)
{
g_dev
=
new
DfHmc9250Wrapper
(
/*
rotation
*/
);
g_dev
=
new
DfHmc9250Wrapper
(
rotation
);
if
(
g_dev
==
nullptr
)
{
PX4_ERR
(
"failed instantiating DfHmc9250Wrapper object"
);
...
...
@@ -389,9 +401,9 @@ info()
void
usage
()
{
PX4_
WARN
(
"Usage: df_hmc5883_wrapper 'start', 'info', 'stop'"
);
PX4_
WARN
(
"options:"
);
//
PX4_
WARN
(" -R rotation");
PX4_
INFO
(
"Usage: df_hmc5883_wrapper 'start', 'info', 'stop'"
);
PX4_
INFO
(
"options:"
);
PX4_
INFO
(
" -R rotation"
);
}
}
// namespace df_hmc5883_wrapper
...
...
@@ -401,7 +413,7 @@ int
df_hmc5883_wrapper_main
(
int
argc
,
char
*
argv
[])
{
int
ch
;
//
enum Rotation rotation = ROTATION_NONE;
enum
Rotation
rotation
=
ROTATION_NONE
;
int
ret
=
0
;
int
myoptind
=
1
;
const
char
*
myoptarg
=
NULL
;
...
...
@@ -409,9 +421,9 @@ df_hmc5883_wrapper_main(int argc, char *argv[])
/* jump over start/off/etc and look at options first */
while
((
ch
=
px4_getopt
(
argc
,
argv
,
"R:"
,
&
myoptind
,
&
myoptarg
))
!=
EOF
)
{
switch
(
ch
)
{
//
case 'R':
//
rotation = (enum Rotation)atoi(myoptarg);
//
break;
case
'R'
:
rotation
=
(
enum
Rotation
)
atoi
(
myoptarg
);
break
;
default:
df_hmc5883_wrapper
::
usage
();
...
...
@@ -428,7 +440,7 @@ df_hmc5883_wrapper_main(int argc, char *argv[])
if
(
!
strcmp
(
verb
,
"start"
))
{
ret
=
df_hmc5883_wrapper
::
start
(
/*
rotation
*/
);
ret
=
df_hmc5883_wrapper
::
start
(
rotation
);
}
else
if
(
!
strcmp
(
verb
,
"stop"
))
{
...
...
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