my
Fork of ESC by
Embed:
(wiki syntax)
Show/hide line numbers
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=10); // Constructor(pwmPinOut,period_ms) 00062 bool setThrottle(int); // range 0-100 00063 void pulse(void); 00064 00065 private: 00066 PwmOut esc; // pinout from MCU 00067 int period; 00068 int throttle; 00069 }; 00070 00071 #endif // end of ESC
Generated on Wed Jul 13 2022 22:16:38 by 1.7.2