Bayley Wang
/
analoghalls
potato
Fork of analoghalls by
Revision 4:f18f6bc5e1fd, committed 2015-02-26
- Comitter:
- bwang
- Date:
- Thu Feb 26 04:49:21 2015 +0000
- Parent:
- 3:86ccde39f61b
- Commit message:
- latest;
Changed in this revision
--- a/constants.h Wed Feb 25 04:44:05 2015 +0000 +++ b/constants.h Thu Feb 26 04:49:21 2015 +0000 @@ -5,11 +5,14 @@ #undef __NATIVE #define __USE_THROTTLE -#define __SVM -#define __DEBUG +#undef __SVM + +#undef __DEBUG +#define SKIP 200 +#define DBG_BUF_SZ 2000 //sensor phase in degrees -#define SENSOR_PHASE 230 +#define SENSOR_PHASE 205 //prius brick specific quirks #define DB_COEFF 0.9f
--- a/isr.cpp Wed Feb 25 04:44:05 2015 +0000 +++ b/isr.cpp Thu Feb 26 04:49:21 2015 +0000 @@ -75,34 +75,38 @@ } void pos_update() { - float ascaled = 2 *(((float) analoga - 0.143f)/(0.618f - 0.143f) - 0.5f); - float bscaled = 2 *(((float) analogb - 0.202f)/(0.542f - 0.202f) - 0.5f); - + float ascaled = 2*(((float)analoga-0.256f)/(0.484f-0.256f)-0.5f); + float bscaled = 2*(((float)analogb-0.254f)/(0.474f-0.254f)-0.5f); + float x = bscaled / ascaled; unsigned int index = (abs(x) / ATAN_UPPER_BOUND)* ATAN_TABLE_SIZE; if(index >= ATAN_TABLE_SIZE) index = ATAN_TABLE_SIZE - 1; - - if(bscaled < 0){ - if(ascaled < 0) motor->angle = arctan[index]; - if(ascaled > 0) motor->angle = 180.0f - arctan[index]; - } - - if(bscaled > 0){ - if(ascaled > 0) motor->angle = 180.0f + arctan[index]; - if(ascaled < 0) motor->angle = 360.0f - arctan[index]; - } + + if(ascaled<0){ + if(bscaled<0) motor->angle = 90 - arctan[index]; + if(bscaled>0) motor->angle = 90 + arctan[index]; + } + + if(ascaled>0){ + if(bscaled>0) motor->angle = 270 - arctan[index]; + if(bscaled<0) motor->angle = 270 + arctan[index]; + } if(motor->angle > 360.0f) motor->angle = 360.0f; if(motor->angle < 0) motor->angle = 0; #ifdef __DEBUG - if (!motor->halt) { - fbuffer[bufidx] = motor->angle; - bufidx++; + skipidx++; + if (skipidx == SKIP) { + skipidx = 0; + if (!motor->halt) { + fbuffer[bufidx] = motor->angle; + bufidx++; + } } - if (bufidx == 10000) { + if (bufidx == DBG_BUF_SZ) { motor->debug_stop = 1; } #endif
--- a/main.cpp Wed Feb 25 04:44:05 2015 +0000 +++ b/main.cpp Thu Feb 26 04:49:21 2015 +0000 @@ -26,6 +26,7 @@ #ifdef __DEBUG float *fbuffer; int bufidx = 0; +int skipidx = 0; #endif #ifdef __USE_THROTTLE Ticker dtc_upd_ticker; @@ -34,10 +35,13 @@ float throttle_read; -int main() { +int main() { +#ifdef __DEBUG + pc.printf("%s\n", "Debug mode ON"); +#endif en = 1; #ifdef __DEBUG - fbuffer = (float*)malloc(10000*sizeof(float)); + fbuffer = (float*)malloc(DBG_BUF_SZ*sizeof(float)); #endif initTimers(); initPins(); @@ -56,7 +60,7 @@ #endif } #ifdef __DEBUG - for (int i = 0; i < 10000; i++) { + for (int i = 0; i < DBG_BUF_SZ; i++) { pc.printf("%f,", fbuffer[i]); } #endif
--- a/shared.h Wed Feb 25 04:44:05 2015 +0000 +++ b/shared.h Thu Feb 26 04:49:21 2015 +0000 @@ -13,7 +13,7 @@ extern float throttle_read; #ifdef __DEBUG extern float *fbuffer; -extern int bufidx; +extern int bufidx, skipidx; #endif #endif \ No newline at end of file