potato

Dependencies:   mbed

Fork of analoghalls by N K

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 
00004 #include "constants.h"
00005 #include "shared.h"
00006 #include "util.h"
00007 #include "math.h"
00008 #include "isr.h"
00009 
00010 Serial pc(SERIAL_TX, SERIAL_RX);
00011 
00012 PwmOut pha(_PH_A);
00013 PwmOut phb(_PH_B);
00014 PwmOut phc(_PH_C);
00015 
00016 DigitalOut en(_EN);
00017 
00018 DigitalIn dummy(D5);
00019 
00020 AnalogIn throttle(_THROTTLE);
00021 AnalogIn analoga(_ANALOGA);
00022 AnalogIn analogb(_ANALOGB);
00023 
00024 Motor* motor;
00025 
00026 #ifdef __DEBUG
00027 float *fbuffer;
00028 int bufidx = 0;
00029 int skipidx = 0;
00030 #endif
00031 #ifdef __USE_THROTTLE
00032     Ticker dtc_upd_ticker;
00033     Ticker throttle_upd_ticker;
00034 #endif
00035 
00036 float throttle_read;
00037 
00038 int main() {
00039 #ifdef __DEBUG
00040     pc.printf("%s\n", "Debug mode ON");
00041 #endif
00042     en = 1;
00043 #ifdef __DEBUG
00044     fbuffer = (float*)malloc(DBG_BUF_SZ*sizeof(float));
00045 #endif
00046     initTimers();
00047     initPins();
00048     initData();
00049     
00050     while(1) {
00051 #ifdef __USE_THROTTLE
00052         throttle_read = throttle;
00053 #endif
00054         pos_update();
00055 #ifndef __USE_THROTTLE
00056         dtc_update();
00057 #endif
00058 #ifdef __DEBUG
00059         if (motor->debug_stop) break;
00060 #endif
00061     }
00062 #ifdef __DEBUG
00063     for (int i = 0; i < DBG_BUF_SZ; i++) {
00064         pc.printf("%f,", fbuffer[i]);
00065     }
00066 #endif
00067 }