From fe511ab63d31c731bad6c34592587ec16097ad72 Mon Sep 17 00:00:00 2001 From: sayoung388 Date: Wed, 27 Apr 2016 12:15:27 -0600 Subject: [PATCH 01/13] added comments for IMU function headers --- src/main.cpp | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 90432d7..70b05a9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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 and give it the base offset value to give +* better calculations in the GetAngleMeasurements function +*/ void InitGyro() { // Set the internal sample rate to 1kHz and set the sample @@ -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(); } - + //use the average calculated while getting the samples to give a more accurate offset value gyroOffsetX /= OFFSET_AVG_SAMPLES; gyroOffsetY /= OFFSET_AVG_SAMPLES; @@ -78,6 +82,12 @@ void InitGyro() #endif } + +/* +* initialize the accelerometer and set the sample rate frequency +* Also get the base offset of the accelerometer at startup to give better +* measurements in the GetAnglemeasurements function +*/ void InitAccelerometer() { // Put the ADXL345 into standby mode to configure the device @@ -100,7 +110,7 @@ void InitAccelerometer() acclOffsetY += fg.y; acclOffsetZ += (fg.z - 1); } - + //Using the offsets sames get the average value to give us a more accurate value acclOffsetX /= OFFSET_AVG_SAMPLES; acclOffsetY /= OFFSET_AVG_SAMPLES; acclOffsetZ /= OFFSET_AVG_SAMPLES; @@ -110,12 +120,24 @@ void InitAccelerometer() #endif } + +/* +* Initializes the Gyro and the accelerometer at startup +*/ void InitIMU(void) { - InitGyro(); - InitAccelerometer(); + InitGyro(); //initualize 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() { if (((tcurr = t.read_ms()) - tprev) >= IMU_SAMPLE_TIME) @@ -148,10 +170,6 @@ void GetAngleMeasurements() } } -/* - * Updates the PID inputs and outputs. This function is called every iteration - * of the main control loop, but PID is only updated at a 100Hz rate. - */ void ControlUpdate() { // Update the PID control values, and issue a PID computation @@ -205,7 +223,7 @@ void SetMotor(uint8_t motor, uint16_t value) { pc.printf("set motor %d to %d\r\n", motor, value); #endif - // Change each individual motor/ESC, or update throttle + // Change each individual motor/ESC in manual mode or set to automatic, or update throttle switch(motor) { case ESC_1: motormode = MANUAL; From cf0eb79999b37031edaf64fd0f3bed2e372d891c Mon Sep 17 00:00:00 2001 From: sayoung388 Date: Wed, 27 Apr 2016 12:23:32 -0600 Subject: [PATCH 02/13] Adjusted spacing --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 70b05a9..20feb4b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -56,8 +56,8 @@ int mspeed2, mspeed4 = MOTOR_MIN; // Motors along the y-axis /* -* Function to initialize the Gyro sample rate and give it the base offset value to give -* better calculations in the GetAngleMeasurements function +* Function to initialize the Gyro sample rate and give it the base offset value to give +* better calculations in the GetAngleMeasurements function */ void InitGyro() { From feb714d107f805bb20a3398f361b0f2d0a292aaa Mon Sep 17 00:00:00 2001 From: sayoung388 Date: Wed, 27 Apr 2016 12:25:04 -0600 Subject: [PATCH 03/13] Adjusted spacing on offset --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 20feb4b..9c80b63 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -70,8 +70,8 @@ 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(); } //use the average calculated while getting the samples to give a more accurate offset value gyroOffsetX /= OFFSET_AVG_SAMPLES; From cb8ae0186f93410b2e9daab613ec7cb2d2122fc6 Mon Sep 17 00:00:00 2001 From: sayoung388 Date: Wed, 27 Apr 2016 12:26:30 -0600 Subject: [PATCH 04/13] added periods to show new sentences in comments --- src/main.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 9c80b63..9ad7854 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -57,7 +57,7 @@ int mspeed2, mspeed4 = MOTOR_MIN; // Motors along the y-axis /* * Function to initialize the Gyro sample rate and give it the base offset value to give -* better calculations in the GetAngleMeasurements function +* better calculations in the GetAngleMeasurements function. */ void InitGyro() { @@ -84,9 +84,9 @@ void InitGyro() /* -* initialize the accelerometer and set the sample rate frequency +* initialize the accelerometer and set the sample rate frequency. * Also get the base offset of the accelerometer at startup to give better -* measurements in the GetAnglemeasurements function +* measurements in the GetAnglemeasurements function. */ void InitAccelerometer() { @@ -122,7 +122,7 @@ void InitAccelerometer() /* -* Initializes the Gyro and the accelerometer at startup +* Initializes the Gyro and the accelerometer at startup. */ void InitIMU(void) { @@ -132,11 +132,11 @@ void InitIMU(void) /* -* function using a sample time to calculate the current angle over time +* 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 +* angle at any given point in time. */ void GetAngleMeasurements() { From cb234b1f0b3a0c47a22f773c7060be51b4def8fe Mon Sep 17 00:00:00 2001 From: sayoung388 Date: Wed, 27 Apr 2016 12:27:50 -0600 Subject: [PATCH 05/13] undid comment change --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 9ad7854..8a8f6e9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -223,7 +223,7 @@ void SetMotor(uint8_t motor, uint16_t value) { pc.printf("set motor %d to %d\r\n", motor, value); #endif - // Change each individual motor/ESC in manual mode or set to automatic, or update throttle + // Change each individual motor/ESC, or update throttle switch(motor) { case ESC_1: motormode = MANUAL; From 7bcafa63d454e6e65bb125b6571dca43dec50de1 Mon Sep 17 00:00:00 2001 From: sayoung388 Date: Wed, 27 Apr 2016 12:28:43 -0600 Subject: [PATCH 06/13] fixed typo --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 8a8f6e9..2565925 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -126,7 +126,7 @@ void InitAccelerometer() */ void InitIMU(void) { - InitGyro(); //initualize the gyro + InitGyro(); //initialize the gyro InitAccelerometer(); //initialize the accelerometer } From 782207a072a1d406e36de9e02387b9943c7937be Mon Sep 17 00:00:00 2001 From: sayoung388 Date: Wed, 27 Apr 2016 12:31:07 -0600 Subject: [PATCH 07/13] Fixed comment spacing and capitalized first letters --- src/main.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 2565925..0a28fba 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -73,7 +73,7 @@ void InitGyro() gyroOffsetX += gyro.getGyroX(); gyroOffsetY += gyro.getGyroY(); } - //use the average calculated while getting the samples to give a more accurate offset value + // Use the average calculated while getting the samples to give a more accurate offset value gyroOffsetX /= OFFSET_AVG_SAMPLES; gyroOffsetY /= OFFSET_AVG_SAMPLES; @@ -84,7 +84,7 @@ void InitGyro() /* -* initialize the accelerometer and set the sample rate frequency. +* Initialize the accelerometer and set the sample rate frequency. * Also get the base offset of the accelerometer at startup to give better * measurements in the GetAnglemeasurements function. */ @@ -110,7 +110,7 @@ void InitAccelerometer() acclOffsetY += fg.y; acclOffsetZ += (fg.z - 1); } - //Using the offsets sames get the average value to give us a more accurate value + // Using the offsets sames get the average value to give us a more accurate value acclOffsetX /= OFFSET_AVG_SAMPLES; acclOffsetY /= OFFSET_AVG_SAMPLES; acclOffsetZ /= OFFSET_AVG_SAMPLES; @@ -122,7 +122,7 @@ void InitAccelerometer() /* -* Initializes the Gyro and the accelerometer at startup. +* Initializes the Gyro and the accelerometer at startup. */ void InitIMU(void) { @@ -132,8 +132,8 @@ void InitIMU(void) /* -* function using a sample time to calculate the current angle over time. -* the main features of this function are the filter for 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. From 3d80e8f87bac8433fce1e6b9a63566472543ee30 Mon Sep 17 00:00:00 2001 From: sayoung388 Date: Wed, 27 Apr 2016 12:32:15 -0600 Subject: [PATCH 08/13] Fixed comment spacing and capitalized first letters 2.0 --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 0a28fba..8128c63 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -126,8 +126,8 @@ void InitAccelerometer() */ void InitIMU(void) { - InitGyro(); //initialize the gyro - InitAccelerometer(); //initialize the accelerometer + InitGyro(); // Initialize the gyro + InitAccelerometer(); // Initialize the accelerometer } From e30ce2619394f99e534544817f3154359ce4f6f9 Mon Sep 17 00:00:00 2001 From: sayoung388 Date: Wed, 27 Apr 2016 12:35:16 -0600 Subject: [PATCH 09/13] added comments that were deleted back in --- src/main.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 8128c63..4e4304e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -170,6 +170,10 @@ void GetAngleMeasurements() } } +/* + * Updates the PID inputs and outputs. This function is called every iteration + * of the main control loop, but PID is only updated at a 100Hz rate. + */ void ControlUpdate() { // Update the PID control values, and issue a PID computation From e5cf53889d8993b6c22ce3c607b3d028f9ab7329 Mon Sep 17 00:00:00 2001 From: sayoung388 Date: Wed, 27 Apr 2016 12:37:34 -0600 Subject: [PATCH 10/13] fixed comment for gyro offset --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 4e4304e..85a94fa 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -73,7 +73,7 @@ void InitGyro() gyroOffsetX += gyro.getGyroX(); gyroOffsetY += gyro.getGyroY(); } - // Use the average calculated while getting the samples to give a more accurate offset value + // 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; From 28cc8cbf078d98c9a064436a12bed0ad6ff2fd84 Mon Sep 17 00:00:00 2001 From: sayoung388 Date: Wed, 27 Apr 2016 12:38:45 -0600 Subject: [PATCH 11/13] changed comment for accel offset --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 85a94fa..53ccfc7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -110,7 +110,7 @@ void InitAccelerometer() acclOffsetY += fg.y; acclOffsetZ += (fg.z - 1); } - // Using the offsets sames get the average value to give us a more accurate value + // 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; From e976cfa3b17b56cc2c0eaa72dfb2c4fb585f5011 Mon Sep 17 00:00:00 2001 From: sayoung388 Date: Wed, 27 Apr 2016 12:40:57 -0600 Subject: [PATCH 12/13] updated initGyro function header --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 53ccfc7..cdb3a95 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -56,8 +56,8 @@ int mspeed2, mspeed4 = MOTOR_MIN; // Motors along the y-axis /* -* Function to initialize the Gyro sample rate and give it the base offset value to give -* better calculations in the GetAngleMeasurements function. +* Function to initialize the Gyro sample rate. +* Measure and Set the base offset value for the gyro for better calculations in the GetAngleMeasurements function. */ void InitGyro() { From eed78e73413953f8268ffe3387a0989ac507cea4 Mon Sep 17 00:00:00 2001 From: sayoung388 Date: Wed, 27 Apr 2016 12:42:39 -0600 Subject: [PATCH 13/13] changed accel init function header comments --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index cdb3a95..9a741c3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -85,7 +85,7 @@ void InitGyro() /* * Initialize the accelerometer and set the sample rate frequency. -* Also get the base offset of the accelerometer at startup to give better +* Measure and set the base offset of the accelerometer at startup to give better * measurements in the GetAnglemeasurements function. */ void InitAccelerometer()