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 ESC by
esc.h
00001 #ifndef UWBQuad__ESC__H 00002 #define UWBQuad__ESC__H 00003 00004 /** ESC Class Example: 00005 * 00006 * @code 00007 * 00008 #include "mbed.h" 00009 #include "esc.h" 00010 00011 ESC esc1(PTD4); 00012 ESC esc2(PTA12); 00013 ESC esc3(PTA4); 00014 ESC esc4(PTA5); 00015 00016 Serial pc(USBTX, USBRX); // tx, rx 00017 00018 int main() { 00019 00020 char c; 00021 int var = 0; 00022 00023 while(1) { 00024 c = pc.getc(); 00025 00026 if (c == 'u') { 00027 if (var < 100) { 00028 var++; 00029 } 00030 if (esc1.setThrottle(var) && esc2.setThrottle(var) && esc3.setThrottle(var) && esc4.setThrottle(var)) { 00031 printf("%i\r\n", var); 00032 } 00033 } 00034 else if (c == 'd') { 00035 if (var > 0) { 00036 var--; 00037 } 00038 if (esc1.setThrottle(var) && esc2.setThrottle(var) && esc3.setThrottle(var) && esc4.setThrottle(var)) { 00039 printf("%i\r\n", var); 00040 } 00041 } 00042 else if (c == 'r') { 00043 var = 0; 00044 if (esc1.setThrottle(var) && esc2.setThrottle(var) && esc3.setThrottle(var) && esc4.setThrottle(var)) { 00045 printf("%i\r\n", var); 00046 } 00047 } 00048 00049 esc1.pulse(); 00050 esc2.pulse(); 00051 esc3.pulse(); 00052 esc4.pulse(); 00053 wait_ms(20); // 20ms is the default period of the ESC pwm 00054 } 00055 } 00056 * @endcode 00057 */ 00058 00059 class ESC { 00060 public: 00061 ESC(PwmOut,int=20,int=1000); // Constructor(pwmPinOut,period_ms) 00062 bool setThrottle(int); // range 0-100 00063 void pulse(void); 00064 void failsafe(void); 00065 00066 private: 00067 PwmOut esc; // pinout from MCU 00068 int period; 00069 int throttle; 00070 }; 00071 00072 #endif // end of ESC
Generated on Fri Jul 15 2022 04:22:40 by
