Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers replace math::Vector<3> with matrix::Vector3f #9121

Merged
merged 1 commit into from
Mar 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/drivers/device/integrator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Integrator::~Integrator()
}

bool
Integrator::put(uint64_t timestamp, math::Vector<3> &val, math::Vector<3> &integral, uint64_t &integral_dt)
Integrator::put(uint64_t timestamp, matrix::Vector3f &val, matrix::Vector3f &integral, uint64_t &integral_dt)
{
if (_last_integration_time == 0) {
/* this is the first item in the integrator */
Expand All @@ -84,7 +84,7 @@ Integrator::put(uint64_t timestamp, math::Vector<3> &val, math::Vector<3> &integ
}

// Use trapezoidal integration to calculate the delta integral
math::Vector<3> delta_alpha = (val + _last_val) * dt * 0.5f;
matrix::Vector3f delta_alpha = (val + _last_val) * dt * 0.5f;
_last_val = val;

// Calculate coning corrections if required
Expand Down Expand Up @@ -126,7 +126,7 @@ Integrator::put(uint64_t timestamp, math::Vector<3> &val, math::Vector<3> &integ
}

bool
Integrator::put_with_interval(unsigned interval_us, math::Vector<3> &val, math::Vector<3> &integral,
Integrator::put_with_interval(unsigned interval_us, matrix::Vector3f &val, matrix::Vector3f &integral,
uint64_t &integral_dt)
{
if (_last_integration_time == 0) {
Expand All @@ -145,10 +145,10 @@ Integrator::put_with_interval(unsigned interval_us, math::Vector<3> &val, math::
return put(timestamp, val, integral, integral_dt);
}

math::Vector<3>
matrix::Vector3f
Integrator::get(bool reset, uint64_t &integral_dt)
{
math::Vector<3> val = _alpha;
matrix::Vector3f val = _alpha;

if (reset) {
_reset(integral_dt);
Expand All @@ -157,11 +157,11 @@ Integrator::get(bool reset, uint64_t &integral_dt)
return val;
}

math::Vector<3>
Integrator::get_and_filtered(bool reset, uint64_t &integral_dt, math::Vector<3> &filtered_val)
matrix::Vector3f
Integrator::get_and_filtered(bool reset, uint64_t &integral_dt, matrix::Vector3f &filtered_val)
{
// Do the usual get with reset first but don't return yet.
math::Vector<3> ret_integral = get(reset, integral_dt);
matrix::Vector3f ret_integral = get(reset, integral_dt);

// Because we need both the integral and the integral_dt.
filtered_val(0) = ret_integral(0) * 1000000 / integral_dt;
Expand Down
18 changes: 9 additions & 9 deletions src/drivers/device/integrator.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Integrator
* @return true if putting the item triggered an integral reset and the integral should be
* published.
*/
bool put(uint64_t timestamp, math::Vector<3> &val, math::Vector<3> &integral, uint64_t &integral_dt);
bool put(uint64_t timestamp, matrix::Vector3f &val, matrix::Vector3f &integral, uint64_t &integral_dt);

/**
* Put an item into the integral but provide an interval instead of a timestamp.
Expand All @@ -74,7 +74,7 @@ class Integrator
* @return true if putting the item triggered an integral reset and the integral should be
* published.
*/
bool put_with_interval(unsigned interval_us, math::Vector<3> &val, math::Vector<3> &integral,
bool put_with_interval(unsigned interval_us, matrix::Vector3f &val, matrix::Vector3f &integral,
uint64_t &integral_dt);

/**
Expand All @@ -84,7 +84,7 @@ class Integrator
* @param integral_dt Get the dt in us of the current integration (only if reset).
* @return the integral since the last read-reset
*/
math::Vector<3> get(bool reset, uint64_t &integral_dt);
matrix::Vector3f get(bool reset, uint64_t &integral_dt);

/**
* Get the current integral and reset the integrator if needed. Additionally give the
Expand All @@ -95,18 +95,18 @@ class Integrator
* @param filtered_val The integral differentiated by the integration time.
* @return the integral since the last read-reset
*/
math::Vector<3> get_and_filtered(bool reset, uint64_t &integral_dt, math::Vector<3> &filtered_val);
matrix::Vector3f get_and_filtered(bool reset, uint64_t &integral_dt, matrix::Vector3f &filtered_val);

private:
uint64_t _auto_reset_interval; /**< the interval after which the content will be published
and the integrator reset, 0 if no auto-reset */
uint64_t _last_integration_time; /**< timestamp of the last integration step */
uint64_t _last_reset_time; /**< last auto-announcement of integral value */
math::Vector<3> _alpha; /**< integrated value before coning corrections are applied */
math::Vector<3> _last_alpha; /**< previous value of _alpha */
math::Vector<3> _beta; /**< accumulated coning corrections */
math::Vector<3> _last_val; /**< previous input */
math::Vector<3> _last_delta_alpha; /**< integral from previous previous sampling interval */
matrix::Vector3f _alpha; /**< integrated value before coning corrections are applied */
matrix::Vector3f _last_alpha; /**< previous value of _alpha */
matrix::Vector3f _beta; /**< accumulated coning corrections */
matrix::Vector3f _last_val; /**< previous input */
matrix::Vector3f _last_delta_alpha; /**< integral from previous previous sampling interval */
bool _coning_comp_on; /**< true to turn on coning corrections */

/* we don't want this class to be copied */
Expand Down
8 changes: 4 additions & 4 deletions src/drivers/imu/adis16448/adis16448.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1533,16 +1533,16 @@ ADIS16448::measure()
arb.temperature_raw = report.temp;
arb.temperature = (report.temp * 0.07386f) + 31.0f;

math::Vector<3> aval(x_in_new, y_in_new, z_in_new);
math::Vector<3> aval_integrated;
matrix::Vector3f aval(x_in_new, y_in_new, z_in_new);
matrix::Vector3f aval_integrated;

bool accel_notify = _accel_int.put(arb.timestamp, aval, aval_integrated, arb.integral_dt);
arb.x_integral = aval_integrated(0);
arb.y_integral = aval_integrated(1);
arb.z_integral = aval_integrated(2);

math::Vector<3> gval(x_gyro_in_new, y_gyro_in_new, z_gyro_in_new);
math::Vector<3> gval_integrated;
matrix::Vector3f gval(x_gyro_in_new, y_gyro_in_new, z_gyro_in_new);
matrix::Vector3f gval_integrated;

bool gyro_notify = _gyro_int.put(grb.timestamp, gval, gval_integrated, grb.integral_dt);
grb.x_integral = gval_integrated(0);
Expand Down
4 changes: 2 additions & 2 deletions src/drivers/imu/bmi055/bmi055_accel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -758,8 +758,8 @@ BMI055_accel::measure()
arb.y = _accel_filter_y.apply(y_in_new);
arb.z = _accel_filter_z.apply(z_in_new);

math::Vector<3> aval(x_in_new, y_in_new, z_in_new);
math::Vector<3> aval_integrated;
matrix::Vector3f aval(x_in_new, y_in_new, z_in_new);
matrix::Vector3f aval_integrated;

bool accel_notify = _accel_int.put(arb.timestamp, aval, aval_integrated, arb.integral_dt);
arb.x_integral = aval_integrated(0);
Expand Down
4 changes: 2 additions & 2 deletions src/drivers/imu/bmi055/bmi055_gyro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -730,8 +730,8 @@ BMI055_gyro::measure()
grb.y = _gyro_filter_y.apply(y_gyro_in_new);
grb.z = _gyro_filter_z.apply(z_gyro_in_new);

math::Vector<3> gval(x_gyro_in_new, y_gyro_in_new, z_gyro_in_new);
math::Vector<3> gval_integrated;
matrix::Vector3f gval(x_gyro_in_new, y_gyro_in_new, z_gyro_in_new);
matrix::Vector3f gval_integrated;

bool gyro_notify = _gyro_int.put(grb.timestamp, gval, gval_integrated, grb.integral_dt);
grb.x_integral = gval_integrated(0);
Expand Down
8 changes: 4 additions & 4 deletions src/drivers/imu/bmi160/bmi160.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1180,8 +1180,8 @@ BMI160::measure()
arb.y = _accel_filter_y.apply(y_in_new);
arb.z = _accel_filter_z.apply(z_in_new);

math::Vector<3> aval(x_in_new, y_in_new, z_in_new);
math::Vector<3> aval_integrated;
matrix::Vector3f aval(x_in_new, y_in_new, z_in_new);
matrix::Vector3f aval_integrated;

bool accel_notify = _accel_int.put(arb.timestamp, aval, aval_integrated, arb.integral_dt);
arb.x_integral = aval_integrated(0);
Expand Down Expand Up @@ -1218,8 +1218,8 @@ BMI160::measure()
grb.y = _gyro_filter_y.apply(y_gyro_in_new);
grb.z = _gyro_filter_z.apply(z_gyro_in_new);

math::Vector<3> gval(x_gyro_in_new, y_gyro_in_new, z_gyro_in_new);
math::Vector<3> gval_integrated;
matrix::Vector3f gval(x_gyro_in_new, y_gyro_in_new, z_gyro_in_new);
matrix::Vector3f gval_integrated;

bool gyro_notify = _gyro_int.put(arb.timestamp, gval, gval_integrated, grb.integral_dt);
grb.x_integral = gval_integrated(0);
Expand Down
4 changes: 2 additions & 2 deletions src/drivers/imu/fxas21002c/fxas21002c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1062,8 +1062,8 @@ FXAS21002C::measure()
gyro_report.y = _gyro_filter_y.apply(y_in_new);
gyro_report.z = _gyro_filter_z.apply(z_in_new);

math::Vector<3> gval(x_in_new, y_in_new, z_in_new);
math::Vector<3> gval_integrated;
matrix::Vector3f gval(x_in_new, y_in_new, z_in_new);
matrix::Vector3f gval_integrated;

bool gyro_notify = _gyro_int.put(gyro_report.timestamp, gval, gval_integrated, gyro_report.integral_dt);
gyro_report.x_integral = gval_integrated(0);
Expand Down
4 changes: 2 additions & 2 deletions src/drivers/imu/fxos8701cq/fxos8701cq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1460,8 +1460,8 @@ FXOS8701CQ::measure()
accel_report.y = _accel_filter_y.apply(y_in_new);
accel_report.z = _accel_filter_z.apply(z_in_new);

math::Vector<3> aval(x_in_new, y_in_new, z_in_new);
math::Vector<3> aval_integrated;
matrix::Vector3f aval(x_in_new, y_in_new, z_in_new);
matrix::Vector3f aval_integrated;

bool accel_notify = _accel_int.put(accel_report.timestamp, aval, aval_integrated, accel_report.integral_dt);
accel_report.x_integral = aval_integrated(0);
Expand Down
4 changes: 2 additions & 2 deletions src/drivers/imu/l3gd20/l3gd20.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1032,8 +1032,8 @@ L3GD20::measure()
report.y = _gyro_filter_y.apply(yin);
report.z = _gyro_filter_z.apply(zin);

math::Vector<3> gval(xin, yin, zin);
math::Vector<3> gval_integrated;
matrix::Vector3f gval(xin, yin, zin);
matrix::Vector3f gval_integrated;

bool gyro_notify = _gyro_int.put(report.timestamp, gval, gval_integrated, report.integral_dt);
report.x_integral = gval_integrated(0);
Expand Down
4 changes: 2 additions & 2 deletions src/drivers/imu/lsm303d/lsm303d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1569,8 +1569,8 @@ LSM303D::measure()
accel_report.y = _accel_filter_y.apply(y_in_new);
accel_report.z = _accel_filter_z.apply(z_in_new);

math::Vector<3> aval(x_in_new, y_in_new, z_in_new);
math::Vector<3> aval_integrated;
matrix::Vector3f aval(x_in_new, y_in_new, z_in_new);
matrix::Vector3f aval_integrated;

bool accel_notify = _accel_int.put(accel_report.timestamp, aval, aval_integrated, accel_report.integral_dt);
accel_report.x_integral = aval_integrated(0);
Expand Down
8 changes: 4 additions & 4 deletions src/drivers/imu/mpu6000/mpu6000.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2012,8 +2012,8 @@ MPU6000::measure()
arb.y = _accel_filter_y.apply(y_in_new);
arb.z = _accel_filter_z.apply(z_in_new);

math::Vector<3> aval(x_in_new, y_in_new, z_in_new);
math::Vector<3> aval_integrated;
matrix::Vector3f aval(x_in_new, y_in_new, z_in_new);
matrix::Vector3f aval_integrated;

bool accel_notify = _accel_int.put(arb.timestamp, aval, aval_integrated, arb.integral_dt);
arb.x_integral = aval_integrated(0);
Expand Down Expand Up @@ -2055,8 +2055,8 @@ MPU6000::measure()
grb.y = _gyro_filter_y.apply(y_gyro_in_new);
grb.z = _gyro_filter_z.apply(z_gyro_in_new);

math::Vector<3> gval(x_gyro_in_new, y_gyro_in_new, z_gyro_in_new);
math::Vector<3> gval_integrated;
matrix::Vector3f gval(x_gyro_in_new, y_gyro_in_new, z_gyro_in_new);
matrix::Vector3f gval_integrated;

bool gyro_notify = _gyro_int.put(arb.timestamp, gval, gval_integrated, grb.integral_dt);
grb.x_integral = gval_integrated(0);
Expand Down
8 changes: 4 additions & 4 deletions src/drivers/imu/mpu9250/mpu9250.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1423,8 +1423,8 @@ MPU9250::measure()
arb.y = _accel_filter_y.apply(y_in_new);
arb.z = _accel_filter_z.apply(z_in_new);

math::Vector<3> aval(x_in_new, y_in_new, z_in_new);
math::Vector<3> aval_integrated;
matrix::Vector3f aval(x_in_new, y_in_new, z_in_new);
matrix::Vector3f aval_integrated;

bool accel_notify = _accel_int.put(arb.timestamp, aval, aval_integrated, arb.integral_dt);
arb.x_integral = aval_integrated(0);
Expand Down Expand Up @@ -1461,8 +1461,8 @@ MPU9250::measure()
grb.y = _gyro_filter_y.apply(y_gyro_in_new);
grb.z = _gyro_filter_z.apply(z_gyro_in_new);

math::Vector<3> gval(x_gyro_in_new, y_gyro_in_new, z_gyro_in_new);
math::Vector<3> gval_integrated;
matrix::Vector3f gval(x_gyro_in_new, y_gyro_in_new, z_gyro_in_new);
matrix::Vector3f gval_integrated;

bool gyro_notify = _gyro_int.put(arb.timestamp, gval, gval_integrated, grb.integral_dt);
grb.x_integral = gval_integrated(0);
Expand Down
9 changes: 9 additions & 0 deletions src/lib/conversion/rotation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ get_rot_matrix(enum Rotation rot, math::Matrix<3, 3> *rot_matrix)
rot_matrix->from_euler(roll, pitch, yaw);
}

__EXPORT matrix::Dcmf
get_rot_matrix(enum Rotation rot)
{
return matrix::Dcmf{matrix::Eulerf{
math::radians((float)rot_lookup[rot].roll),
math::radians((float)rot_lookup[rot].pitch),
math::radians((float)rot_lookup[rot].yaw)}};
}

#define HALF_SQRT_2 0.70710678118654757f

__EXPORT void
Expand Down
4 changes: 2 additions & 2 deletions src/lib/conversion/rotation.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ const rot_lookup_t rot_lookup[] = {
/**
* Get the rotation matrix
*/
__EXPORT void
get_rot_matrix(enum Rotation rot, math::Matrix<3, 3> *rot_matrix);
__EXPORT void get_rot_matrix(enum Rotation rot, math::Matrix<3, 3> *rot_matrix);

__EXPORT matrix::Dcmf get_rot_matrix(enum Rotation rot);

/**
* rotate a 3 element float vector in-place
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class DfAK8963Wrapper : public AK8963
float z_scale;
} _mag_calibration;

math::Matrix<3, 3> _rotation_matrix;
matrix::Dcmf _rotation_matrix;

int _mag_orb_class_instance;

Expand All @@ -136,7 +136,7 @@ DfAK8963Wrapper::DfAK8963Wrapper(enum Rotation rotation) :
_mag_calibration.z_offset = 0.0f;

// Get sensor rotation matrix
get_rot_matrix(rotation, &_rotation_matrix);
_rotation_matrix = get_rot_matrix(rotation);
}

DfAK8963Wrapper::~DfAK8963Wrapper()
Expand Down Expand Up @@ -285,7 +285,7 @@ int DfAK8963Wrapper::_publish(struct mag_sensor_data &data)
mag_report.y_raw = 0;
mag_report.z_raw = 0;

math::Vector<3> mag_val(data.field_x_ga, data.field_y_ga, data.field_z_ga);
matrix::Vector3f mag_val(data.field_x_ga, data.field_y_ga, data.field_z_ga);

// apply sensor rotation on the accel measurement
mag_val = _rotation_matrix * mag_val;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class DfHmc5883Wrapper : public HMC5883
float z_scale;
} _mag_calibration;

math::Matrix<3, 3> _rotation_matrix;
matrix::Dcmf _rotation_matrix;

int _mag_orb_class_instance;

Expand All @@ -136,7 +136,7 @@ DfHmc5883Wrapper::DfHmc5883Wrapper(enum Rotation rotation, const char *path) :
_mag_calibration.z_offset = 0.0f;

// Get sensor rotation matrix
get_rot_matrix(rotation, &_rotation_matrix);
_rotation_matrix = get_rot_matrix(rotation);
}

DfHmc5883Wrapper::~DfHmc5883Wrapper()
Expand Down Expand Up @@ -283,9 +283,9 @@ int DfHmc5883Wrapper::_publish(struct mag_sensor_data &data)
mag_report.y_raw = 0;
mag_report.z_raw = 0;

math::Vector<3> mag_val(data.field_x_ga,
data.field_y_ga,
data.field_z_ga);
matrix::Vector3f mag_val(data.field_x_ga,
data.field_y_ga,
data.field_z_ga);

// apply sensor rotation on the accel measurement
mag_val = _rotation_matrix * mag_val;
Expand Down
Loading