trying to make project work

Dependencies:   mbed airMouseWorkingLib ledControl2 USBDevice

Files at this revision

API Documentation at this revision

Comitter:
jresnik
Date:
Sat Nov 28 18:27:48 2020 +0000
Commit message:
Testing

Changed in this revision

.mbed Show annotated file Show diff for this revision Revisions of this file
MPU6050.lib Show annotated file Show diff for this revision Revisions of this file
USBDevice.lib Show annotated file Show diff for this revision Revisions of this file
ledControl.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
mbed_config.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.mbed	Sat Nov 28 18:27:48 2020 +0000
@@ -0,0 +1,2 @@
+ROOT=.
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MPU6050.lib	Sat Nov 28 18:27:48 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mposter/code/airMouseWorkingLib/#2528350ee05b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/USBDevice.lib	Sat Nov 28 18:27:48 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/USBDevice/#53949e6131f6
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ledControl.lib	Sat Nov 28 18:27:48 2020 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/BaserK/code/ledControl2/#1655ee0ec2ca
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Nov 28 18:27:48 2020 +0000
@@ -0,0 +1,169 @@
+/*   Getting Pitch and Roll Angles from MPU6050
+*
+*    @author: Baser Kandehir 
+*    @date: July 16, 2015
+*    @license: MIT license
+*     
+*   Copyright (c) 2015, Baser Kandehir, baser.kandehir@ieee.metu.edu.tr
+*
+*   Permission is hereby granted, free of charge, to any person obtaining a copy
+*   of this software and associated documentation files (the "Software"), to deal
+*   in the Software without restriction, including without limitation the rights
+*   to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+*   copies of the Software, and to permit persons to whom the Software is
+*   furnished to do so, subject to the following conditions:
+*
+*   The above copyright notice and this permission notice shall be included in
+*   all copies or substantial portions of the Software.
+*
+*   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+*   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+*   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+*   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+*   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+*   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+*   THE SOFTWARE.
+*   
+*    @description of the program: 
+*    
+*    First of all most of the credit goes to Kris Winer for his useful MPU6050 code.
+*    I rewrite the code in my way using class prototypes and my comments. This program
+*    can be a starter point for more advanced projects including quadcopters, balancing
+*    robots etc. Program takes accelerometer and gyroscope data from the MPU6050 registers
+*    and calibrates them for better results. Then uses this data is to obtain pitch and roll
+*    angles and writes these angles to the terminal which mbed is connected to. 
+*   
+*    @connections:
+*-------------------------------------------------------------- 
+*    |LPC1768|        |Peripherals|
+*    Pin 9 ---------> SDA of MPU6050
+*    Pin 10 --------> SCL of MPU6050
+*    GND -----------> GND of MPU6050
+*    VOUT (3.3 V) --> VCC of MPU6050
+*---------------------------------------------------------------
+*-------------------------------------------------------------- 
+*    |NUCLEO F411RE|  |Peripherals|
+*    D14 -----------> SDA of MPU6050
+*    D15 -----------> SCL of MPU6050
+*    GND -----------> GND of MPU6050
+*    VOUT (3.3 V) --> VCC of MPU6050
+*---------------------------------------------------------------
+
+
+*   Note: For any mistakes or comments, please contact me.
+*/
+
+#include "MPU6050.h"
+#include "ledControl.h"
+
+//! Variable debug
+#define DEBUG
+/* */
+#include "mbed.h"
+#include "USBMouse.h"
+
+//create mouse object
+USBMouse mouse;
+/* Defined in the MPU6050.cpp file  */
+// I2C i2c(p9,p10);         // setup i2c (SDA,SCL)  
+
+//! Instance pc de classe Serial
+Serial pc(USBTX,USBRX);    // default baud rate: 9600
+//! Instance mpu6050 de classe MPU6050
+MPU6050 mpu6050;           // class: MPU6050, object: mpu6050 
+//! instance toggler1 de classe Ticker
+//! instance filer de classe Ticker
+// Ticker 
+// A Ticker is used to call a function at a recurring interval.
+// You can use as many separate Ticker objects as you require.
+Ticker toggler1;
+Ticker filter;           
+
+void toggle_led1();
+void toggle_led2();
+void compFilter();
+
+float pitchAngle = 0;
+float rollAngle = 0;
+
+int main() 
+{
+    pc.baud(9600);                              // baud rate: 9600
+    mpu6050.whoAmI();                           // Communication test: WHO_AM_I register reading 
+    wait(1);
+    mpu6050.calibrate(accelBias,gyroBias);      // Calibrate MPU6050 and load biases into bias registers
+    pc.printf("Calibration is completed. \r\n");
+    wait(0.5);
+    mpu6050.init();                             // Initialize the sensor
+    wait(1);
+    pc.printf("MPU6050 is initialized for operation.. \r\n\r\n");
+    wait_ms(500);
+    
+    /*
+    gxDelta = 0
+    gyDelta = 0
+    gzDelta = 0
+    
+    axDelta = 0
+    ayDelta = 0
+    azDelta = 0
+    
+    prevgx = gx
+    prevgy = gy
+    prevgz = gz
+    
+    prevax = ax
+    prevay = ay
+    prevaz = az
+    */
+    
+    //deltaThreshold = 0.2
+    
+    while(1) 
+    {
+     
+     /* Uncomment below if you want to see accel and gyro data */
+        
+        pc.printf(" _____________________________________________________________  \r\n");
+        pc.printf("| Accelerometer(g) | ax=%.3f | ay=%.3f | az=%.3f                \r\n",ax,ay,az);
+        pc.printf("| Gyroscope(deg/s) | gx=%.3f | gy=%.3f | gz=%.3f                \r\n",gx,gy,gz);
+        pc.printf("|_____________________________________________________________  \r\n\r\n");
+//        
+        wait(0.1);
+                
+        filter.attach(&compFilter, 0.005);    // Call the complementaryFilter func. every 5 ms (200 Hz sampling period)
+        
+        #ifdef DEBUG
+        pc.printf(" [Debug On]  \r\n");
+        mpu6050.complementaryFilter(&pitchAngle, &rollAngle);
+        #endif
+        
+        
+        pc.printf(" _______________\r\n");
+        pc.printf("| Pitch: %.3f   \r\n",pitchAngle);
+        pc.printf("| Roll:  %.3f   \r\n",rollAngle);
+        pc.printf("|_______________\r\n\r\n");
+        
+        wait(1.1);
+        
+        /*
+        gxDelta = gx - prevgx;
+        gyDelta = gy - prevgy;
+        gzDelta = gz - prevgz;
+        
+        axDelta = ax - prevax;
+        ayDelta = ay - prevay;
+        azDelta = az - prevaz;
+        */
+        
+        
+    }
+}
+
+
+void toggle_led1() {ledToggle(1);}
+void toggle_led2() {ledToggle(2);}
+
+/* This function is created to avoid address error that caused from Ticker.attach func */ 
+void compFilter() {mpu6050.complementaryFilter(&pitchAngle, &rollAngle);}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sat Nov 28 18:27:48 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed_config.h	Sat Nov 28 18:27:48 2020 +0000
@@ -0,0 +1,56 @@
+/*
+ * mbed SDK
+ * Copyright (c) 2017 ARM Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Automatically generated configuration file.
+// DO NOT EDIT, content will be overwritten.
+
+#ifndef __MBED_CONFIG_DATA__
+#define __MBED_CONFIG_DATA__
+
+// Configuration parameters
+#define MBED_CONF_PLATFORM_CRASH_CAPTURE_ENABLED           0                                                                              // set by library:platform
+#define MBED_CONF_PLATFORM_CTHUNK_COUNT_MAX                8                                                                              // set by library:platform
+#define MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE        9600                                                                           // set by library:platform
+#define MBED_CONF_PLATFORM_ERROR_ALL_THREADS_INFO          0                                                                              // set by library:platform
+#define MBED_CONF_PLATFORM_ERROR_DECODE_HTTP_URL_STR       "\nFor more info, visit: https://armmbed.github.io/mbedos-error/?error=0x%08X" // set by library:platform
+#define MBED_CONF_PLATFORM_ERROR_FILENAME_CAPTURE_ENABLED  0                                                                              // set by library:platform
+#define MBED_CONF_PLATFORM_ERROR_HIST_ENABLED              0                                                                              // set by library:platform
+#define MBED_CONF_PLATFORM_ERROR_HIST_SIZE                 4                                                                              // set by library:platform
+#define MBED_CONF_PLATFORM_ERROR_REBOOT_MAX                1                                                                              // set by library:platform
+#define MBED_CONF_PLATFORM_FATAL_ERROR_AUTO_REBOOT_ENABLED 0                                                                              // set by library:platform
+#define MBED_CONF_PLATFORM_FORCE_NON_COPYABLE_ERROR        0                                                                              // set by library:platform
+#define MBED_CONF_PLATFORM_MAX_ERROR_FILENAME_LEN          16                                                                             // set by library:platform
+#define MBED_CONF_PLATFORM_POLL_USE_LOWPOWER_TIMER         0                                                                              // set by library:platform
+#define MBED_CONF_PLATFORM_STDIO_BAUD_RATE                 9600                                                                           // set by library:platform
+#define MBED_CONF_PLATFORM_STDIO_BUFFERED_SERIAL           0                                                                              // set by library:platform
+#define MBED_CONF_PLATFORM_STDIO_CONVERT_NEWLINES          0                                                                              // set by library:platform
+#define MBED_CONF_PLATFORM_STDIO_CONVERT_TTY_NEWLINES      0                                                                              // set by library:platform
+#define MBED_CONF_PLATFORM_STDIO_FLUSH_AT_EXIT             1                                                                              // set by library:platform
+#define MBED_CONF_PLATFORM_USE_MPU                         1                                                                              // set by library:platform
+#define MBED_CONF_TARGET_BOOT_STACK_SIZE                   0x1000                                                                         // set by target:Target
+#define MBED_CONF_TARGET_CONSOLE_UART                      1                                                                              // set by target:Target
+#define MBED_CONF_TARGET_DEEP_SLEEP_LATENCY                0                                                                              // set by target:Target
+#define MBED_CONF_TARGET_DEFAULT_ADC_VREF                  NAN                                                                            // set by target:Target
+#define MBED_CONF_TARGET_INIT_US_TICKER_AT_BOOT            0                                                                              // set by target:Target
+#define MBED_CONF_TARGET_MPU_ROM_END                       0x0fffffff                                                                     // set by target:Target
+#define MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE    ETHERNET                                                                       // set by target:LPC1768
+#define MBED_CONF_TARGET_TICKLESS_FROM_US_TICKER           0                                                                              // set by target:Target
+#define MBED_CONF_TARGET_US_TICKER_TIMER                   3                                                                              // set by target:LPC1768
+#define MBED_CONF_TARGET_XIP_ENABLE                        0                                                                              // set by target:Target
+
+#endif
+