Skip to content

Commit

Permalink
Removed Magic Number
Browse files Browse the repository at this point in the history
  • Loading branch information
jkerpe committed Oct 26, 2023
1 parent 8349e11 commit de6f03c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
22 changes: 16 additions & 6 deletions lib/SensorFusion/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,22 @@ void App::sendSensorData() const
imu.readMag();
imu.getMagnetometerValues(magnetometerValues);

/* Write the values into a Byte Array */
Util::int16ToByteArray(&payload[0 * sizeof(int16_t)], sizeof(int16_t), accelerationValues[0]);
Util::int16ToByteArray(&payload[1 * sizeof(int16_t)], sizeof(int16_t), accelerationValues[1]);
Util::int16ToByteArray(&payload[2 * sizeof(int16_t)], sizeof(int16_t), turnRates[2]);
Util::int16ToByteArray(&payload[3 * sizeof(int16_t)], sizeof(int16_t), magnetometerValues[0]);
Util::int16ToByteArray(&payload[4 * sizeof(int16_t)], sizeof(int16_t), magnetometerValues[1]);
/**
* Write the values into a Byte Array in this order:
* Acceleration in X
* Acceleration in Y
* TurnRate around Z
* Magnetometer value in X
* Magnetometer value in Y
* Angle calculated by Odometry
* Position in X calculated by Odometry
* Position in Y calculated by Odometry
*/
Util::int16ToByteArray(&payload[0 * sizeof(int16_t)], sizeof(int16_t), accelerationValues[AXIS_INDEX_X]);
Util::int16ToByteArray(&payload[1 * sizeof(int16_t)], sizeof(int16_t), accelerationValues[AXIS_INDEX_Y]);
Util::int16ToByteArray(&payload[2 * sizeof(int16_t)], sizeof(int16_t), turnRates[AXIS_INDEX_Z]);
Util::int16ToByteArray(&payload[3 * sizeof(int16_t)], sizeof(int16_t), magnetometerValues[AXIS_INDEX_X]);
Util::int16ToByteArray(&payload[4 * sizeof(int16_t)], sizeof(int16_t), magnetometerValues[AXIS_INDEX_Y]);
Util::int16ToByteArray(&payload[5 * sizeof(int16_t)], sizeof(int16_t), orientationOdometryInt16);
Util::int16ToByteArray(&payload[6 * sizeof(int16_t)], sizeof(int16_t), positionXOdometryInt16);
Util::int16ToByteArray(&payload[7 * sizeof(int16_t)], sizeof(int16_t), positionYOdometryInt16);
Expand Down
7 changes: 6 additions & 1 deletion lib/SensorFusion/App.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ class App
/** Differential drive control period in ms. */
static const uint32_t DIFFERENTIAL_DRIVE_CONTROL_PERIOD = 5U;

/** Indices of axis x, y and z. */
static const uint8_t AXIS_INDEX_X = 0U;
static const uint8_t AXIS_INDEX_Y = 1U;
static const uint8_t AXIS_INDEX_Z = 2U;

/** Sending Data period in ms. */
static const uint32_t SEND_SENSORS_DATA_PERIOD = 20;

Expand Down Expand Up @@ -128,7 +133,7 @@ class App
* Send the following Sensor data via SerialMuxProt:
* Acceleration in X
* Acceleration in Y
* turnRateZ around Z
* TurnRate around Z
* Magnetometer value in X
* Magnetometer value in Y
* Angle calculated by Odometry
Expand Down

0 comments on commit de6f03c

Please sign in to comment.