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

added comments for IMU function headers #13

Open
wants to merge 13 commits into
base: develop
Choose a base branch
from
34 changes: 28 additions & 6 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ int mspeed2, mspeed4 = MOTOR_MIN; // Motors along the y-axis
//=> Changing their speeds will affect the roll


/*
* Function to initialize the Gyro sample rate.
* Measure and Set the base offset value for the gyro for better calculations in the GetAngleMeasurements function.
*/
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please align the '' characters like seen elsewhere. Also, the spaces between the '' characters and the first letter are way to long. Please, only one space.

void InitGyro()
{
// Set the internal sample rate to 1kHz and set the sample
Expand All @@ -66,10 +70,10 @@ void InitGyro()
// Calculate an average offset for the gyro
for (int i = 0; i < OFFSET_AVG_SAMPLES; i++)
{
gyroOffsetX += gyro.getGyroX();
gyroOffsetY += gyro.getGyroY();
gyroOffsetX += gyro.getGyroX();
gyroOffsetY += gyro.getGyroY();
}

// Uses the gyroOffset calculated above while getting the samples to give a more accurate offset value on startup for the gyro
gyroOffsetX /= OFFSET_AVG_SAMPLES;
gyroOffsetY /= OFFSET_AVG_SAMPLES;

Expand All @@ -78,6 +82,12 @@ void InitGyro()
#endif
}


/*
* Initialize the accelerometer and set the sample rate frequency.
* Measure and set the base offset of the accelerometer at startup to give better
* measurements in the GetAnglemeasurements function.
*/
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, align the '*' characters please. Capitalize!

If you end a sentence, put a '.' character.

void InitAccelerometer()
{
// Put the ADXL345 into standby mode to configure the device
Expand All @@ -100,7 +110,7 @@ void InitAccelerometer()
acclOffsetY += fg.y;
acclOffsetZ += (fg.z - 1);
}

// Using the accelOffsets samples above to get the average value to give us a more accurate value startup offset value for the accel.
acclOffsetX /= OFFSET_AVG_SAMPLES;
acclOffsetY /= OFFSET_AVG_SAMPLES;
acclOffsetZ /= OFFSET_AVG_SAMPLES;
Expand All @@ -110,12 +120,24 @@ void InitAccelerometer()
#endif
}


/*
* Initializes the Gyro and the accelerometer at startup.
*/
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments above.

void InitIMU(void)
{
InitGyro();
InitAccelerometer();
InitGyro(); // Initialize the gyro
InitAccelerometer(); // Initialize the accelerometer
}


/*
* Function using a sample time to calculate the current angle over time.
* The main features of this function are the filter for the accelerometer
* the measurements gathered from the gyro to get the current angle
* and the complimentary filter we used to get our accurate measurement of our
* angle at any given point in time.
*/
void GetAngleMeasurements()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, see comments above.

{
if (((tcurr = t.read_ms()) - tprev) >= IMU_SAMPLE_TIME)
Expand Down