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 Boboobooo by
motor_api.cpp
00001 #include "mbed.h" 00002 #include "motor_api.h" 00003 00004 #define init_v 10 // period in 1.35 ~170ms 00005 00006 00007 00008 00009 00010 00011 00012 00013 BX_motor::BX_motor(char type){ 00014 00015 00016 00017 00018 00019 //need N level???? 00020 engine_enable = new DigitalOut(PTE21); 00021 00022 *engine_enable=1; 00023 00024 Type=type; 00025 switch (type){ 00026 00027 case 'A': 00028 forward_A = new PwmOut(PTC3); 00029 backward_A = new PwmOut(PTC4); 00030 00031 forward_A->period_ms(init_v); 00032 backward_A->period_ms(init_v); 00033 *forward_A=0.5f; 00034 *backward_A=0.5f; 00035 00036 break; 00037 00038 00039 case 'B': 00040 00041 forward_B = new PwmOut(PTC1); 00042 backward_B = new PwmOut(PTC2); 00043 forward_B->period_ms(init_v); 00044 backward_B->period_ms(init_v); 00045 *forward_B=0.5f; 00046 *backward_B=0.5f; 00047 break; 00048 00049 00050 00051 } 00052 00053 } 00054 00055 00056 // level: -1.0 ~1.0 00057 void BX_motor::rotate(float level){ 00058 00059 Level=level; 00060 00061 if(level >0){ 00062 00063 switch(Type){ 00064 00065 case 'A': 00066 *forward_A=level; 00067 *backward_A=0; 00068 break; 00069 case 'B': 00070 *forward_B=level; 00071 *backward_B=0; 00072 break; 00073 } 00074 00075 }else if(level <0){ 00076 00077 level=-1.0*level; 00078 00079 switch(Type){ 00080 00081 case 'A': 00082 *forward_A=0; 00083 *backward_A=level; 00084 break; 00085 case 'B': 00086 *forward_B=0; 00087 *backward_B=level; 00088 break; 00089 } 00090 00091 } 00092 else{ 00093 switch(Type){ 00094 00095 case 'A': 00096 *forward_A=1.0f; 00097 *backward_A=1.0f; 00098 00099 break; 00100 case 'B': 00101 *forward_B=1.0f; 00102 *backward_B=1.0f; 00103 break; 00104 } 00105 00106 00107 } 00108 00109 00110 00111 00112 00113 00114 00115 00116 00117 } 00118 00119 00120
Generated on Wed Jul 20 2022 19:27:32 by
1.7.2
