Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of 1TEST_Flight_Protocol by
main.cpp@1:e8a99f19604e, 2017-05-22 (annotated)
- Committer:
- skyyoungsik
- Date:
- Mon May 22 06:10:35 2017 +0000
- Revision:
- 1:e8a99f19604e
- Parent:
- 0:c466d770ffa7
cui_test;
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| skyyoungsik | 0:c466d770ffa7 | 1 | #include "mbed.h" |
| skyyoungsik | 0:c466d770ffa7 | 2 | #include "ROBOFRIEN_GUI.h" |
| skyyoungsik | 1:e8a99f19604e | 3 | #include "ROBOFRIEN_LED.h" |
| skyyoungsik | 0:c466d770ffa7 | 4 | #include <math.h> |
| skyyoungsik | 0:c466d770ffa7 | 5 | |
| skyyoungsik | 0:c466d770ffa7 | 6 | #define PI 3.14159265359 // This value will be used when calculating angles |
| skyyoungsik | 0:c466d770ffa7 | 7 | |
| skyyoungsik | 0:c466d770ffa7 | 8 | Timer MainTimer; |
| skyyoungsik | 0:c466d770ffa7 | 9 | DigitalOut myled2(LED2); |
| skyyoungsik | 0:c466d770ffa7 | 10 | DigitalOut myled3(LED3); |
| skyyoungsik | 0:c466d770ffa7 | 11 | ROBOFRIEN_GUI GUI; |
| skyyoungsik | 1:e8a99f19604e | 12 | ROBOFRIEN_LED LED; |
| skyyoungsik | 0:c466d770ffa7 | 13 | int cnt; |
| skyyoungsik | 0:c466d770ffa7 | 14 | int main() { |
| skyyoungsik | 1:e8a99f19604e | 15 | GUI.Init(); |
| skyyoungsik | 1:e8a99f19604e | 16 | LED.Init(); |
| skyyoungsik | 1:e8a99f19604e | 17 | |
| skyyoungsik | 1:e8a99f19604e | 18 | LED.HeadlightPeriod = GUI.headlight_period; |
| skyyoungsik | 1:e8a99f19604e | 19 | LED.HeadlightDutyrate = GUI.headlight_dutyrate; |
| skyyoungsik | 1:e8a99f19604e | 20 | LED.SidelightPeriod = GUI.sidelight_period; |
| skyyoungsik | 1:e8a99f19604e | 21 | LED.SidelightDutyrate = GUI.sidelight_dutyrate; |
| skyyoungsik | 1:e8a99f19604e | 22 | |
| skyyoungsik | 0:c466d770ffa7 | 23 | while(1) { |
| skyyoungsik | 0:c466d770ffa7 | 24 | GUI.pc_rx_update(); |
| skyyoungsik | 1:e8a99f19604e | 25 | LED.Update(); |
| skyyoungsik | 0:c466d770ffa7 | 26 | if(GUI.rx_bool() == true){ |
| skyyoungsik | 0:c466d770ffa7 | 27 | cnt ++; |
| skyyoungsik | 0:c466d770ffa7 | 28 | ///////////////////////////////////////////////////////////////////////////////////////////////////////// |
| skyyoungsik | 0:c466d770ffa7 | 29 | //////////////////////////////////////////// [M/S] Mode and State /////////////////////////////////////// |
| skyyoungsik | 0:c466d770ffa7 | 30 | ///////////////////////////////////////////////////////////////////////////////////////////////////////// |
| skyyoungsik | 0:c466d770ffa7 | 31 | GUI.Mode1 = 8 * sin( PI/180 + cnt/50.0) + 8; |
| skyyoungsik | 0:c466d770ffa7 | 32 | GUI.Mode2 = 8 * cos( PI/180 + cnt/50.0) + 8; |
| skyyoungsik | 0:c466d770ffa7 | 33 | GUI.MissionState = 8 * sin( PI/180 + cnt/50.0) + 8; |
| skyyoungsik | 0:c466d770ffa7 | 34 | GUI.CurrentMarker = 11 * cos( PI/180 + cnt/100.0) + 10; |
| skyyoungsik | 0:c466d770ffa7 | 35 | GUI.Bat1 = 50 * sin(PI/180 + cnt/50.0) + 50; // 21.6 ~ 24.6 ( 6cell ) |
| skyyoungsik | 0:c466d770ffa7 | 36 | GUI.Bat2 = 50 * cos(PI/180 + cnt/50.0) + 50; // 11.1 ~ 12.6 ( 3cell ) |
| skyyoungsik | 1:e8a99f19604e | 37 | // [ Button State & Home Point Chksum & Marker Chksum ] is change automatically in "ROBOFRIEN_GUI.cpp" // |
| skyyoungsik | 0:c466d770ffa7 | 38 | // You Can not change this setting, just use it /// |
| skyyoungsik | 1:e8a99f19604e | 39 | if(GUI.button[0] == true) {} |
| skyyoungsik | 1:e8a99f19604e | 40 | else {} |
| skyyoungsik | 1:e8a99f19604e | 41 | if(GUI.button[1] == true) {} |
| skyyoungsik | 1:e8a99f19604e | 42 | else {} |
| skyyoungsik | 1:e8a99f19604e | 43 | if(GUI.button[2] == true) {} |
| skyyoungsik | 1:e8a99f19604e | 44 | else {} |
| skyyoungsik | 1:e8a99f19604e | 45 | if(GUI.button[3] == true) {} |
| skyyoungsik | 1:e8a99f19604e | 46 | else {} |
| skyyoungsik | 1:e8a99f19604e | 47 | if(GUI.button[4] == true) {} |
| skyyoungsik | 1:e8a99f19604e | 48 | else {} |
| skyyoungsik | 0:c466d770ffa7 | 49 | |
| skyyoungsik | 0:c466d770ffa7 | 50 | ///////////////////////////////////////////////////////////////////////////////////////////////////////// |
| skyyoungsik | 0:c466d770ffa7 | 51 | //////////////////////////////////////////////// [GPS] GPS ////////////////////////////////////////////// |
| skyyoungsik | 0:c466d770ffa7 | 52 | ///////////////////////////////////////////////////////////////////////////////////////////////////////// |
| skyyoungsik | 1:e8a99f19604e | 53 | GUI.utc_time = cnt * 10; |
| skyyoungsik | 1:e8a99f19604e | 54 | GUI.latitude = 35117030 + 10000 * sin( PI/180 + cnt/50.0); |
| skyyoungsik | 1:e8a99f19604e | 55 | GUI.longitude = 129087896 + 10000 * cos( PI/180 + cnt/50.0); |
| skyyoungsik | 1:e8a99f19604e | 56 | GUI.altitude = 22768 + 32768 * sin( PI/180 + cnt/50.0); |
| skyyoungsik | 0:c466d770ffa7 | 57 | GUI.SatNum = 10 + 10 * sin( PI/180 + cnt/50.0); |
| skyyoungsik | 0:c466d770ffa7 | 58 | |
| skyyoungsik | 0:c466d770ffa7 | 59 | ///////////////////////////////////////////////////////////////////////////////////////////////////////// |
| skyyoungsik | 0:c466d770ffa7 | 60 | ///////////////////////////////////////////////// AHRS ////////////////////////////////////////////////// |
| skyyoungsik | 0:c466d770ffa7 | 61 | ///////////////////////////////////////////////////////////////////////////////////////////////////////// |
| skyyoungsik | 0:c466d770ffa7 | 62 | GUI.rollx100 = 4500 * sin( PI/180 + cnt/50.0); |
| skyyoungsik | 0:c466d770ffa7 | 63 | GUI.pitchx100 = -4500 * sin( PI/180 + cnt/50.0); |
| skyyoungsik | 0:c466d770ffa7 | 64 | GUI.yawx100 = 18000 * sin( PI/180 + cnt/50.0) + 18000; |
| skyyoungsik | 0:c466d770ffa7 | 65 | GUI.roll_ratex100 = 30000 * sin( PI/180 + cnt/50.0); |
| skyyoungsik | 0:c466d770ffa7 | 66 | GUI.pitch_ratex100 = 30000 * sin( PI/180 + cnt/50.0 + PI/4); |
| skyyoungsik | 0:c466d770ffa7 | 67 | GUI.yaw_ratex100 = 30000 * sin( PI/180 + cnt/50.0 + PI*3/4); |
| skyyoungsik | 0:c466d770ffa7 | 68 | GUI.VXx100 = 1000 * sin(PI/180 + cnt/50.0); |
| skyyoungsik | 0:c466d770ffa7 | 69 | GUI.VYx100 = 1000 * cos(PI/180 + cnt/50.0); |
| skyyoungsik | 0:c466d770ffa7 | 70 | GUI.VZx100 = 1000 * sin(PI/180 + cnt/50.0 + PI/4); |
| skyyoungsik | 0:c466d770ffa7 | 71 | |
| skyyoungsik | 0:c466d770ffa7 | 72 | ///////////////////////////////////////////////////////////////////////////////////////////////////////// |
| skyyoungsik | 0:c466d770ffa7 | 73 | ////////////////////////////////////////////// [C/P] CAP/PWM //////////////////////////////////////////// |
| skyyoungsik | 0:c466d770ffa7 | 74 | ///////////////////////////////////////////////////////////////////////////////////////////////////////// |
| skyyoungsik | 0:c466d770ffa7 | 75 | GUI.cap[0] = 100 * sin(PI/180 + cnt/50.0); |
| skyyoungsik | 0:c466d770ffa7 | 76 | GUI.cap[1] = 100 * sin(PI/180 + cnt/50.0 + PI/8); |
| skyyoungsik | 0:c466d770ffa7 | 77 | GUI.cap[2] = 100 * sin(PI/180 + cnt/50.0 + 2*PI/8); |
| skyyoungsik | 0:c466d770ffa7 | 78 | GUI.cap[3] = 100 * sin(PI/180 + cnt/50.0 + 3*PI/8); |
| skyyoungsik | 0:c466d770ffa7 | 79 | GUI.cap[4] = 100 * sin(PI/180 + cnt/50.0 + 4*PI/8); |
| skyyoungsik | 0:c466d770ffa7 | 80 | GUI.cap[5] = 100 * sin(PI/180 + cnt/50.0 + 5*PI/8); |
| skyyoungsik | 0:c466d770ffa7 | 81 | GUI.cap[6] = 100 * sin(PI/180 + cnt/50.0 + 6*PI/8); |
| skyyoungsik | 0:c466d770ffa7 | 82 | GUI.cap[7] = 100 * sin(PI/180 + cnt/50.0 + 7*PI/8); |
| skyyoungsik | 0:c466d770ffa7 | 83 | GUI.pwm[0] = 100 * sin(PI/180 + cnt/50.0) + 100; |
| skyyoungsik | 0:c466d770ffa7 | 84 | GUI.pwm[1] = 100 * sin(PI/180 + cnt/50.0 + PI/8) + 100; |
| skyyoungsik | 0:c466d770ffa7 | 85 | GUI.pwm[2] = 100 * sin(PI/180 + cnt/50.0 + 2*PI/8) + 100; |
| skyyoungsik | 0:c466d770ffa7 | 86 | GUI.pwm[3] = 100 * sin(PI/180 + cnt/50.0 + 3*PI/8) + 100; |
| skyyoungsik | 0:c466d770ffa7 | 87 | GUI.pwm[4] = 100 * sin(PI/180 + cnt/50.0 + 4*PI/8) + 100; |
| skyyoungsik | 0:c466d770ffa7 | 88 | GUI.pwm[5] = 100 * sin(PI/180 + cnt/50.0 + 5*PI/8) + 100; |
| skyyoungsik | 0:c466d770ffa7 | 89 | GUI.pwm[6] = 100 * sin(PI/180 + cnt/50.0 + 6*PI/8) + 100; |
| skyyoungsik | 0:c466d770ffa7 | 90 | GUI.pwm[7] = 100 * sin(PI/180 + cnt/50.0 + 7*PI/8) + 100; |
| skyyoungsik | 0:c466d770ffa7 | 91 | |
| skyyoungsik | 0:c466d770ffa7 | 92 | ///////////////////////////////////////////////////////////////////////////////////////////////////////// |
| skyyoungsik | 0:c466d770ffa7 | 93 | /////////////////////////////////////////// [E/D] Extra & Debug ///////////////////////////////////////// |
| skyyoungsik | 0:c466d770ffa7 | 94 | ///////////////////////////////////////////////////////////////////////////////////////////////////////// |
| skyyoungsik | 0:c466d770ffa7 | 95 | GUI.DEBUGx100[0] = 9000 * sin(PI/180 + cnt/50.0) + 9000; |
| skyyoungsik | 0:c466d770ffa7 | 96 | GUI.DEBUGx100[1] += 100; |
| skyyoungsik | 0:c466d770ffa7 | 97 | if(GUI.DEBUGx100[1] >= 36000) GUI.DEBUGx100[1] = 0; |
| skyyoungsik | 0:c466d770ffa7 | 98 | GUI.DEBUGx100[2] = 25000 * sin(PI/180 + cnt/50.0) + 25000; |
| skyyoungsik | 0:c466d770ffa7 | 99 | GUI.DEBUGx100[3] = 11111; |
| skyyoungsik | 0:c466d770ffa7 | 100 | GUI.DEBUGx100[4] = 22222; |
| skyyoungsik | 0:c466d770ffa7 | 101 | GUI.DEBUGx100[5] = 33333; |
| skyyoungsik | 0:c466d770ffa7 | 102 | GUI.DEBUGx100[6] = 44444; |
| skyyoungsik | 0:c466d770ffa7 | 103 | GUI.DEBUGx100[7] = 55555; |
| skyyoungsik | 0:c466d770ffa7 | 104 | |
| skyyoungsik | 0:c466d770ffa7 | 105 | ///////////////////////////////////////////////////////////////////////////////////////////////////////// |
| skyyoungsik | 1:e8a99f19604e | 106 | /////////////////////////////////////////// Configuration /////////////////////////////////////////////// |
| skyyoungsik | 1:e8a99f19604e | 107 | ///////////////////////////////////////////////////////////////////////////////////////////////////////// |
| skyyoungsik | 1:e8a99f19604e | 108 | |
| skyyoungsik | 1:e8a99f19604e | 109 | ///////////////////////////// -----------------DPN 1-------------------- //////////////////////////////// |
| skyyoungsik | 1:e8a99f19604e | 110 | // You can set the this value from "Config.h" ( EEPROM_MODEL_TYPE1, EEPROM_MODEL_TYPE2_UP, EEPROM_MODEL_TYPE2_DOWN ) // |
| skyyoungsik | 1:e8a99f19604e | 111 | |
| skyyoungsik | 1:e8a99f19604e | 112 | ///////////////////////////// -----------------DPN 2-------------------- //////////////////////////////// |
| skyyoungsik | 1:e8a99f19604e | 113 | // You can set the this value from "Config.h" ( MODEL_INFO, FIRMWARE_INFO ) // |
| skyyoungsik | 1:e8a99f19604e | 114 | |
| skyyoungsik | 1:e8a99f19604e | 115 | ///////////////////////////// -----------------DPN 3-------------------- //////////////////////////////// |
| skyyoungsik | 1:e8a99f19604e | 116 | /// You can set the original value of receiver to [raw_cap] with scale down ( -127 ~ 127 ) /// |
| skyyoungsik | 1:e8a99f19604e | 117 | /// You can use the [cap_min[8], cap_neu[8], cap_max[8]] for calibration of RC receiver value // |
| skyyoungsik | 1:e8a99f19604e | 118 | GUI.raw_cap[0] = 0; |
| skyyoungsik | 1:e8a99f19604e | 119 | GUI.raw_cap[1] = 0; |
| skyyoungsik | 1:e8a99f19604e | 120 | GUI.raw_cap[2] = 0; |
| skyyoungsik | 1:e8a99f19604e | 121 | GUI.raw_cap[3] = 0; |
| skyyoungsik | 1:e8a99f19604e | 122 | GUI.raw_cap[4] = 0; |
| skyyoungsik | 1:e8a99f19604e | 123 | GUI.raw_cap[5] = 0; |
| skyyoungsik | 1:e8a99f19604e | 124 | GUI.raw_cap[6] = 0; |
| skyyoungsik | 1:e8a99f19604e | 125 | GUI.raw_cap[7] = 0; |
| skyyoungsik | 1:e8a99f19604e | 126 | |
| skyyoungsik | 1:e8a99f19604e | 127 | ///////////////////////////// -----------------DPN 4-------------------- //////////////////////////////// |
| skyyoungsik | 1:e8a99f19604e | 128 | /// You can use the [motor_min[4]] for calibration of motor pwm value // |
| skyyoungsik | 1:e8a99f19604e | 129 | |
| skyyoungsik | 1:e8a99f19604e | 130 | ///////////////////////////// -----------------DPN 5-------------------- //////////////////////////////// |
| skyyoungsik | 1:e8a99f19604e | 131 | LED.HeadlightPeriod = GUI.headlight_period; |
| skyyoungsik | 1:e8a99f19604e | 132 | LED.HeadlightDutyrate = GUI.headlight_dutyrate; |
| skyyoungsik | 1:e8a99f19604e | 133 | LED.SidelightPeriod = GUI.sidelight_period; |
| skyyoungsik | 1:e8a99f19604e | 134 | LED.SidelightDutyrate = GUI.sidelight_dutyrate; |
| skyyoungsik | 1:e8a99f19604e | 135 | |
| skyyoungsik | 1:e8a99f19604e | 136 | ///////////////////////////// -----------------DPN 6-------------------- //////////////////////////////// |
| skyyoungsik | 1:e8a99f19604e | 137 | /// You can set the original value of receiver to [raw_cap] with scale down ( -127 ~ 127 ) /// |
| skyyoungsik | 1:e8a99f19604e | 138 | /// You can use the [cap_min[8], cap_neu[8], cap_max[8]] for calibration of RC receiver value // |
| skyyoungsik | 1:e8a99f19604e | 139 | if(GUI.attitude_configuration_bool == true){ |
| skyyoungsik | 1:e8a99f19604e | 140 | GUI.attitude_configuration_bool = false; |
| skyyoungsik | 1:e8a99f19604e | 141 | // You can calibration of attitude (Roll, Pitch) // |
| skyyoungsik | 1:e8a99f19604e | 142 | } |
| skyyoungsik | 1:e8a99f19604e | 143 | if(GUI.Compass_Calibration_Mode == 1){ |
| skyyoungsik | 1:e8a99f19604e | 144 | // You can calibration of compass (Yaw)// |
| skyyoungsik | 1:e8a99f19604e | 145 | }else if(GUI.Compass_Calibration_Mode == 2){ |
| skyyoungsik | 1:e8a99f19604e | 146 | // You can finish the calibration of compass |
| skyyoungsik | 1:e8a99f19604e | 147 | } |
| skyyoungsik | 1:e8a99f19604e | 148 | |
| skyyoungsik | 1:e8a99f19604e | 149 | ///////////////////////////// -----------------DPN 7-------------------- //////////////////////////////// |
| skyyoungsik | 1:e8a99f19604e | 150 | /// You can use the [limit_rollx100, limit_pitchx100, limit_roll_rate, limit_pitch_rate, limit_yaw_rate] for limit the angle and angular velocity // |
| skyyoungsik | 1:e8a99f19604e | 151 | |
| skyyoungsik | 1:e8a99f19604e | 152 | ///////////////////////////// -----------------DPN 8-------------------- //////////////////////////////// |
| skyyoungsik | 1:e8a99f19604e | 153 | /// You can use the [gain_px100[20], gain_dx100[20], gain_ix100[20]] for gain tuning // |
| skyyoungsik | 1:e8a99f19604e | 154 | |
| skyyoungsik | 1:e8a99f19604e | 155 | ///////////////////////////////////////////////////////////////////////////////////////////////////////// |
| skyyoungsik | 0:c466d770ffa7 | 156 | //////////////////////////////////////////////// Refresh //////////////////////////////////////////////// |
| skyyoungsik | 0:c466d770ffa7 | 157 | ///////////////////////////////////////////////////////////////////////////////////////////////////////// |
| skyyoungsik | 1:e8a99f19604e | 158 | |
| skyyoungsik | 1:e8a99f19604e | 159 | |
| skyyoungsik | 0:c466d770ffa7 | 160 | GUI.Refresh(); |
| skyyoungsik | 0:c466d770ffa7 | 161 | |
| skyyoungsik | 0:c466d770ffa7 | 162 | } |
| skyyoungsik | 0:c466d770ffa7 | 163 | |
| skyyoungsik | 0:c466d770ffa7 | 164 | } |
| skyyoungsik | 0:c466d770ffa7 | 165 | } |
