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 brushlessmotor by
MainController.cpp
00001 #include "MainController.h" 00002 00003 MainController::MainController() 00004 :esc1(p25), 00005 myled(LED1), 00006 mypotentiometer(p20) 00007 { 00008 wait_ms(50); 00009 amp = 0.0; 00010 frqMin = 0.8; //hardcoded 00011 frqMax = 1.8; //hardcoded 00012 dutyCycle = 0.5; 00013 esc1 = dutyCycle; 00014 esc1(); 00015 wait_ms(3000); //to arm brushless motor 00016 00017 } 00018 00019 void MainController::control() 00020 { 00021 amp = mypotentiometer.read(); 00022 myled = amp; 00023 00024 curTime = timer1.read(); 00025 00026 //set brushless motor speed 00027 dutyCycle = 0.5 + (amp/2); 00028 esc1.setThrottle(dutyCycle); 00029 esc1.pulse(); 00030 } 00031 00032 //float MainController::calculateAdj() 00033 //{ 00034 // return (ch4.dutycyclescaledup()); 00035 //} 00036 00037 void MainController::start() 00038 { 00039 timer1.start(); 00040 00041 ticker1.attach(this, &MainController::control,0.001); 00042 } 00043 00044 void MainController::stop() 00045 { 00046 timer1.stop(); 00047 ticker1.detach(); 00048 dutyCycle = 0.5; 00049 esc1 = dutyCycle; 00050 esc1(); 00051 } 00052 00053 float MainController::getDutyCycle() 00054 { 00055 return dutyCycle; 00056 } 00057 00058 float MainController::getAmplitude() 00059 { 00060 return amp; 00061 } 00062 00063 //signum function 00064 float MainController::signum(float input) //gives back the sign 00065 { 00066 if (input>0.0) 00067 return 1.0; 00068 else if (input<0.0) 00069 return (-1.0); 00070 else 00071 return 0.0; 00072 } 00073 00074 //saturate function 00075 float MainController::saturate(float input) //saturates a value at 1.0 or -1.0 00076 { 00077 if (input > 1.0) 00078 return (1.0); 00079 else if (input < -1.0) 00080 return (-1.0); 00081 else 00082 return input; 00083 }
Generated on Tue Jul 12 2022 21:22:42 by
1.7.2
