Modified Motor Driver Firmware to include Flash + Thermal
Dependencies: FastPWM3 mbed-dev-STM-lean
main.cpp@58:32e8927fe39f, 2020-02-04 (annotated)
- Committer:
- saloutos
- Date:
- Tue Feb 04 14:19:58 2020 +0000
- Revision:
- 58:32e8927fe39f
- Parent:
- 57:0795d2add37e
- Child:
- 60:0c8caaa91182
Still need to figure out GR, motor config constants
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
benkatz | 22:60276ba87ac6 | 1 | /// high-bandwidth 3-phase motor control, for robots |
benkatz | 45:26801179208e | 2 | /// Written by benkatz, with much inspiration from Bayley Wang, Nick Kirkby, Shane Colton, David Otten, and others |
benkatz | 22:60276ba87ac6 | 3 | /// Hardware documentation can be found at build-its.blogspot.com |
benkatz | 22:60276ba87ac6 | 4 | /// Written for the STM32F446, but can be implemented on other STM32 MCU's with some further register-diddling |
benkatz | 47:e1196a851f76 | 5 | /// Version for the TI DRV8323 Everything Chip |
benkatz | 22:60276ba87ac6 | 6 | |
benkatz | 55:c4c9fec8539c | 7 | #define REST_MODE 0 |
benkatz | 55:c4c9fec8539c | 8 | #define CALIBRATION_MODE 1 |
benkatz | 55:c4c9fec8539c | 9 | #define MOTOR_MODE 2 |
benkatz | 55:c4c9fec8539c | 10 | #define SETUP_MODE 4 |
benkatz | 55:c4c9fec8539c | 11 | #define ENCODER_MODE 5 |
benkatz | 55:c4c9fec8539c | 12 | #define INIT_TEMP_MODE 6 |
benkatz | 22:60276ba87ac6 | 13 | |
benkatz | 55:c4c9fec8539c | 14 | #define VERSION_NUM "1.10" |
benkatz | 26:2b865c00d7e9 | 15 | |
benkatz | 18:f1d56f4acb39 | 16 | |
benkatz | 26:2b865c00d7e9 | 17 | float __float_reg[64]; // Floats stored in flash |
benkatz | 26:2b865c00d7e9 | 18 | int __int_reg[256]; // Ints stored in flash. Includes position sensor calibration lookup table |
benkatz | 17:3c5df2982199 | 19 | |
benkatz | 0:4e1c4df6aabd | 20 | #include "mbed.h" |
benkatz | 0:4e1c4df6aabd | 21 | #include "PositionSensor.h" |
benkatz | 20:bf9ea5125d52 | 22 | #include "structs.h" |
benkatz | 55:c4c9fec8539c | 23 | #include "foc.h" |
benkatz | 22:60276ba87ac6 | 24 | #include "calibration.h" |
benkatz | 20:bf9ea5125d52 | 25 | #include "hw_setup.h" |
benkatz | 23:2adf23ee0305 | 26 | #include "math_ops.h" |
benkatz | 20:bf9ea5125d52 | 27 | #include "current_controller_config.h" |
benkatz | 20:bf9ea5125d52 | 28 | #include "hw_config.h" |
benkatz | 20:bf9ea5125d52 | 29 | #include "motor_config.h" |
benkatz | 23:2adf23ee0305 | 30 | #include "stm32f4xx_flash.h" |
benkatz | 23:2adf23ee0305 | 31 | #include "FlashWriter.h" |
benkatz | 23:2adf23ee0305 | 32 | #include "user_config.h" |
benkatz | 23:2adf23ee0305 | 33 | #include "PreferenceWriter.h" |
benkatz | 42:738fa01b0346 | 34 | #include "CAN_com.h" |
benkatz | 44:8040fa2fcb0d | 35 | #include "DRV.h" |
benkatz | 26:2b865c00d7e9 | 36 | |
benkatz | 23:2adf23ee0305 | 37 | PreferenceWriter prefs(6); |
benkatz | 9:d7eb815cb057 | 38 | |
benkatz | 20:bf9ea5125d52 | 39 | GPIOStruct gpio; |
benkatz | 20:bf9ea5125d52 | 40 | ControllerStruct controller; |
benkatz | 48:74a40481740c | 41 | ObserverStruct observer; |
benkatz | 20:bf9ea5125d52 | 42 | COMStruct com; |
benkatz | 43:dfb72608639c | 43 | Serial pc(PA_2, PA_3); |
benkatz | 9:d7eb815cb057 | 44 | |
benkatz | 17:3c5df2982199 | 45 | |
benkatz | 45:26801179208e | 46 | CAN can(PB_8, PB_9, 1000000); // CAN Rx pin name, CAN Tx pin name |
benkatz | 26:2b865c00d7e9 | 47 | CANMessage rxMsg; |
benkatz | 26:2b865c00d7e9 | 48 | CANMessage txMsg; |
benkatz | 23:2adf23ee0305 | 49 | |
benkatz | 20:bf9ea5125d52 | 50 | |
benkatz | 44:8040fa2fcb0d | 51 | SPI drv_spi(PA_7, PA_6, PA_5); |
benkatz | 44:8040fa2fcb0d | 52 | DigitalOut drv_cs(PA_4); |
benkatz | 44:8040fa2fcb0d | 53 | //DigitalOut drv_en_gate(PA_11); |
benkatz | 44:8040fa2fcb0d | 54 | DRV832x drv(&drv_spi, &drv_cs); |
benkatz | 8:10ae7bc88d6e | 55 | |
saloutos | 58:32e8927fe39f | 56 | //PositionSensoriCMU spi(16777216, 0.0, NPP); // Read 24 bits off the sensor |
saloutos | 58:32e8927fe39f | 57 | PositionSensoriCMU spi(524288, 0.0, NPP); // Read 24 bits off the sensor, only 19bits are encoder data |
benkatz | 20:bf9ea5125d52 | 58 | |
benkatz | 23:2adf23ee0305 | 59 | volatile int count = 0; |
benkatz | 23:2adf23ee0305 | 60 | volatile int state = REST_MODE; |
benkatz | 23:2adf23ee0305 | 61 | volatile int state_change; |
benkatz | 20:bf9ea5125d52 | 62 | |
benkatz | 26:2b865c00d7e9 | 63 | void onMsgReceived() { |
benkatz | 26:2b865c00d7e9 | 64 | //msgAvailable = true; |
benkatz | 53:e85efce8c1eb | 65 | //printf("%d\n\r", rxMsg.id); |
saloutos | 58:32e8927fe39f | 66 | gpio.led->write(1); |
benkatz | 26:2b865c00d7e9 | 67 | can.read(rxMsg); |
benkatz | 28:8c7e29f719c5 | 68 | if((rxMsg.id == CAN_ID)){ |
benkatz | 28:8c7e29f719c5 | 69 | controller.timeout = 0; |
benkatz | 28:8c7e29f719c5 | 70 | if(((rxMsg.data[0]==0xFF) & (rxMsg.data[1]==0xFF) & (rxMsg.data[2]==0xFF) & (rxMsg.data[3]==0xFF) & (rxMsg.data[4]==0xFF) & (rxMsg.data[5]==0xFF) & (rxMsg.data[6]==0xFF) & (rxMsg.data[7]==0xFC))){ |
benkatz | 28:8c7e29f719c5 | 71 | state = MOTOR_MODE; |
benkatz | 28:8c7e29f719c5 | 72 | state_change = 1; |
benkatz | 28:8c7e29f719c5 | 73 | } |
benkatz | 28:8c7e29f719c5 | 74 | else if(((rxMsg.data[0]==0xFF) & (rxMsg.data[1]==0xFF) & (rxMsg.data[2]==0xFF) & (rxMsg.data[3]==0xFF) * (rxMsg.data[4]==0xFF) & (rxMsg.data[5]==0xFF) & (rxMsg.data[6]==0xFF) & (rxMsg.data[7]==0xFD))){ |
benkatz | 28:8c7e29f719c5 | 75 | state = REST_MODE; |
benkatz | 28:8c7e29f719c5 | 76 | state_change = 1; |
benkatz | 37:c0f352d6e8e3 | 77 | gpio.led->write(0);; |
benkatz | 28:8c7e29f719c5 | 78 | } |
benkatz | 28:8c7e29f719c5 | 79 | else if(((rxMsg.data[0]==0xFF) & (rxMsg.data[1]==0xFF) & (rxMsg.data[2]==0xFF) & (rxMsg.data[3]==0xFF) * (rxMsg.data[4]==0xFF) & (rxMsg.data[5]==0xFF) & (rxMsg.data[6]==0xFF) & (rxMsg.data[7]==0xFE))){ |
benkatz | 28:8c7e29f719c5 | 80 | spi.ZeroPosition(); |
benkatz | 28:8c7e29f719c5 | 81 | } |
benkatz | 28:8c7e29f719c5 | 82 | else if(state == MOTOR_MODE){ |
benkatz | 28:8c7e29f719c5 | 83 | unpack_cmd(rxMsg, &controller); |
benkatz | 28:8c7e29f719c5 | 84 | } |
saloutos | 58:32e8927fe39f | 85 | pack_reply(&txMsg, controller.theta_mech, controller.dtheta_mech, controller.i_q_filt*KT_OUT); // multiply theta, dtheta_mech by GR here? |
saloutos | 58:32e8927fe39f | 86 | //pack_reply(&txMsg, 3.14159f, 6.28318f, 1.00f); // test values |
benkatz | 37:c0f352d6e8e3 | 87 | can.write(txMsg); |
benkatz | 28:8c7e29f719c5 | 88 | } |
saloutos | 58:32e8927fe39f | 89 | gpio.led->write(0); |
benkatz | 26:2b865c00d7e9 | 90 | |
benkatz | 26:2b865c00d7e9 | 91 | } |
benkatz | 26:2b865c00d7e9 | 92 | |
benkatz | 23:2adf23ee0305 | 93 | void enter_menu_state(void){ |
benkatz | 44:8040fa2fcb0d | 94 | drv.disable_gd(); |
benkatz | 55:c4c9fec8539c | 95 | reset_foc(&controller); |
benkatz | 47:e1196a851f76 | 96 | //gpio.enable->write(0); |
benkatz | 23:2adf23ee0305 | 97 | printf("\n\r\n\r\n\r"); |
benkatz | 23:2adf23ee0305 | 98 | printf(" Commands:\n\r"); |
benkatz | 44:8040fa2fcb0d | 99 | wait_us(10); |
benkatz | 26:2b865c00d7e9 | 100 | printf(" m - Motor Mode\n\r"); |
benkatz | 44:8040fa2fcb0d | 101 | wait_us(10); |
benkatz | 23:2adf23ee0305 | 102 | printf(" c - Calibrate Encoder\n\r"); |
benkatz | 44:8040fa2fcb0d | 103 | wait_us(10); |
benkatz | 23:2adf23ee0305 | 104 | printf(" s - Setup\n\r"); |
benkatz | 44:8040fa2fcb0d | 105 | wait_us(10); |
benkatz | 23:2adf23ee0305 | 106 | printf(" e - Display Encoder\n\r"); |
benkatz | 44:8040fa2fcb0d | 107 | wait_us(10); |
benkatz | 37:c0f352d6e8e3 | 108 | printf(" z - Set Zero Position\n\r"); |
benkatz | 44:8040fa2fcb0d | 109 | wait_us(10); |
benkatz | 23:2adf23ee0305 | 110 | printf(" esc - Exit to Menu\n\r"); |
benkatz | 44:8040fa2fcb0d | 111 | wait_us(10); |
benkatz | 23:2adf23ee0305 | 112 | state_change = 0; |
benkatz | 37:c0f352d6e8e3 | 113 | gpio.led->write(0); |
benkatz | 23:2adf23ee0305 | 114 | } |
benkatz | 24:58c2d7571207 | 115 | |
benkatz | 24:58c2d7571207 | 116 | void enter_setup_state(void){ |
benkatz | 24:58c2d7571207 | 117 | printf("\n\r\n\r Configuration Options \n\r\n\n"); |
benkatz | 44:8040fa2fcb0d | 118 | wait_us(10); |
benkatz | 51:6cd89bd6fcaa | 119 | printf(" %-4s %-31s %-5s %-6s %-2s\n\r\n\r", "prefix", "parameter", "min", "max", "current value"); |
benkatz | 44:8040fa2fcb0d | 120 | wait_us(10); |
benkatz | 28:8c7e29f719c5 | 121 | printf(" %-4s %-31s %-5s %-6s %.1f\n\r", "b", "Current Bandwidth (Hz)", "100", "2000", I_BW); |
benkatz | 44:8040fa2fcb0d | 122 | wait_us(10); |
benkatz | 28:8c7e29f719c5 | 123 | printf(" %-4s %-31s %-5s %-6s %-5i\n\r", "i", "CAN ID", "0", "127", CAN_ID); |
benkatz | 44:8040fa2fcb0d | 124 | wait_us(10); |
benkatz | 28:8c7e29f719c5 | 125 | printf(" %-4s %-31s %-5s %-6s %-5i\n\r", "m", "CAN Master ID", "0", "127", CAN_MASTER); |
benkatz | 44:8040fa2fcb0d | 126 | wait_us(10); |
benkatz | 51:6cd89bd6fcaa | 127 | printf(" %-4s %-31s %-5s %-6s %.1f\n\r", "l", "Current Limit (A)", "0.0", "40.0", I_MAX); |
benkatz | 51:6cd89bd6fcaa | 128 | wait_us(10); |
benkatz | 51:6cd89bd6fcaa | 129 | printf(" %-4s %-31s %-5s %-6s %.1f\n\r", "f", "FW Current Limit (A)", "0.0", "33.0", I_FW_MAX); |
benkatz | 44:8040fa2fcb0d | 130 | wait_us(10); |
benkatz | 28:8c7e29f719c5 | 131 | printf(" %-4s %-31s %-5s %-6s %d\n\r", "t", "CAN Timeout (cycles)(0 = none)", "0", "100000", CAN_TIMEOUT); |
benkatz | 44:8040fa2fcb0d | 132 | wait_us(10); |
benkatz | 55:c4c9fec8539c | 133 | printf(" %-4s %-31s %-5s %-6s %.1f\n\r", "h", "Temp Cutoff (C) (0 = none)", "0", "150", TEMP_MAX); |
benkatz | 55:c4c9fec8539c | 134 | wait_us(10); |
benkatz | 55:c4c9fec8539c | 135 | printf(" %-4s %-31s %-5s %-6s %.1f\n\r", "c", "Continuous Current (A)", "0", "40.0", I_MAX_CONT); |
benkatz | 55:c4c9fec8539c | 136 | wait_us(10); |
benkatz | 24:58c2d7571207 | 137 | printf("\n\r To change a value, type 'prefix''value''ENTER'\n\r i.e. 'b1000''ENTER'\n\r\n\r"); |
benkatz | 44:8040fa2fcb0d | 138 | wait_us(10); |
benkatz | 24:58c2d7571207 | 139 | state_change = 0; |
benkatz | 24:58c2d7571207 | 140 | } |
benkatz | 22:60276ba87ac6 | 141 | |
benkatz | 23:2adf23ee0305 | 142 | void enter_torque_mode(void){ |
benkatz | 44:8040fa2fcb0d | 143 | drv.enable_gd(); |
benkatz | 47:e1196a851f76 | 144 | //gpio.enable->write(1); |
benkatz | 37:c0f352d6e8e3 | 145 | controller.ovp_flag = 0; |
benkatz | 28:8c7e29f719c5 | 146 | reset_foc(&controller); // Tesets integrators, and other control loop parameters |
benkatz | 28:8c7e29f719c5 | 147 | wait(.001); |
benkatz | 23:2adf23ee0305 | 148 | controller.i_d_ref = 0; |
benkatz | 50:ba72df25d10f | 149 | controller.i_q_ref = 0; // Current Setpoints |
benkatz | 37:c0f352d6e8e3 | 150 | gpio.led->write(1); // Turn on status LED |
benkatz | 25:f5741040c4bb | 151 | state_change = 0; |
benkatz | 28:8c7e29f719c5 | 152 | printf("\n\r Entering Motor Mode \n\r"); |
benkatz | 23:2adf23ee0305 | 153 | } |
benkatz | 22:60276ba87ac6 | 154 | |
benkatz | 23:2adf23ee0305 | 155 | void calibrate(void){ |
benkatz | 44:8040fa2fcb0d | 156 | drv.enable_gd(); |
benkatz | 47:e1196a851f76 | 157 | //gpio.enable->write(1); |
benkatz | 37:c0f352d6e8e3 | 158 | gpio.led->write(1); // Turn on status LED |
benkatz | 25:f5741040c4bb | 159 | order_phases(&spi, &gpio, &controller, &prefs); // Check phase ordering |
benkatz | 25:f5741040c4bb | 160 | calibrate(&spi, &gpio, &controller, &prefs); // Perform calibration procedure |
benkatz | 37:c0f352d6e8e3 | 161 | gpio.led->write(0);; // Turn off status LED |
benkatz | 55:c4c9fec8539c | 162 | wait(.05); |
benkatz | 55:c4c9fec8539c | 163 | R_NOMINAL = 0; |
benkatz | 55:c4c9fec8539c | 164 | state = INIT_TEMP_MODE; |
saloutos | 58:32e8927fe39f | 165 | printf("\n\r Calibration complete. Press 'esc' to return to menu\n\r"); |
benkatz | 55:c4c9fec8539c | 166 | //drv.disable_gd(); |
saloutos | 58:32e8927fe39f | 167 | state_change = 0; |
benkatz | 55:c4c9fec8539c | 168 | |
benkatz | 23:2adf23ee0305 | 169 | } |
benkatz | 23:2adf23ee0305 | 170 | |
benkatz | 23:2adf23ee0305 | 171 | void print_encoder(void){ |
benkatz | 48:74a40481740c | 172 | printf(" Mechanical Angle: %f Electrical Angle: %f Raw: %d\n\r", spi.GetMechPosition(), spi.GetElecPosition(), spi.GetRawPosition()); |
benkatz | 48:74a40481740c | 173 | //printf("%d\n\r", spi.GetRawPosition()); |
benkatz | 47:e1196a851f76 | 174 | wait(.001); |
benkatz | 22:60276ba87ac6 | 175 | } |
benkatz | 20:bf9ea5125d52 | 176 | |
benkatz | 23:2adf23ee0305 | 177 | /// Current Sampling Interrupt /// |
benkatz | 23:2adf23ee0305 | 178 | /// This runs at 40 kHz, regardless of of the mode the controller is in /// |
benkatz | 55:c4c9fec8539c | 179 | //float testing[1000]; |
benkatz | 55:c4c9fec8539c | 180 | //float testing2[1000]; |
benkatz | 2:8724412ad628 | 181 | extern "C" void TIM1_UP_TIM10_IRQHandler(void) { |
benkatz | 2:8724412ad628 | 182 | if (TIM1->SR & TIM_SR_UIF ) { |
benkatz | 55:c4c9fec8539c | 183 | //gpio.led->write(1); |
benkatz | 23:2adf23ee0305 | 184 | ///Sample current always /// |
benkatz | 25:f5741040c4bb | 185 | ADC1->CR2 |= 0x40000000; // Begin sample and conversion |
benkatz | 22:60276ba87ac6 | 186 | //volatile int delay; |
benkatz | 20:bf9ea5125d52 | 187 | //for (delay = 0; delay < 55; delay++); |
benkatz | 55:c4c9fec8539c | 188 | |
benkatz | 47:e1196a851f76 | 189 | spi.Sample(DT); // sample position sensor |
benkatz | 56:fe5056ac6740 | 190 | /* |
benkatz | 56:fe5056ac6740 | 191 | if(count < 10){printf("%d\n\r", spi.GetRawPosition());} |
benkatz | 56:fe5056ac6740 | 192 | count ++; |
benkatz | 56:fe5056ac6740 | 193 | */ |
benkatz | 37:c0f352d6e8e3 | 194 | controller.adc2_raw = ADC2->DR; // Read ADC Data Registers |
benkatz | 23:2adf23ee0305 | 195 | controller.adc1_raw = ADC1->DR; |
benkatz | 37:c0f352d6e8e3 | 196 | controller.adc3_raw = ADC3->DR; |
benkatz | 37:c0f352d6e8e3 | 197 | controller.theta_elec = spi.GetElecPosition(); |
saloutos | 58:32e8927fe39f | 198 | controller.theta_mech = (1.0f/GR)*spi.GetMechPosition(); // should these be divided by gear ratio??? |
saloutos | 58:32e8927fe39f | 199 | controller.dtheta_mech = (1.0f/GR)*spi.GetMechVelocity(); // mech pos isn't pre-multiplied by GR in position sensor function... |
benkatz | 37:c0f352d6e8e3 | 200 | controller.dtheta_elec = spi.GetElecVelocity(); |
benkatz | 51:6cd89bd6fcaa | 201 | controller.v_bus = 0.95f*controller.v_bus + 0.05f*((float)controller.adc3_raw)*V_SCALE; //filter the dc link voltage measurement |
benkatz | 55:c4c9fec8539c | 202 | |
benkatz | 55:c4c9fec8539c | 203 | |
benkatz | 55:c4c9fec8539c | 204 | |
benkatz | 23:2adf23ee0305 | 205 | /// |
benkatz | 20:bf9ea5125d52 | 206 | |
benkatz | 23:2adf23ee0305 | 207 | /// Check state machine state, and run the appropriate function /// |
benkatz | 23:2adf23ee0305 | 208 | switch(state){ |
benkatz | 37:c0f352d6e8e3 | 209 | case REST_MODE: // Do nothing |
benkatz | 23:2adf23ee0305 | 210 | if(state_change){ |
benkatz | 23:2adf23ee0305 | 211 | enter_menu_state(); |
benkatz | 23:2adf23ee0305 | 212 | } |
benkatz | 55:c4c9fec8539c | 213 | update_observer(&controller, &observer); |
benkatz | 23:2adf23ee0305 | 214 | break; |
benkatz | 22:60276ba87ac6 | 215 | |
benkatz | 23:2adf23ee0305 | 216 | case CALIBRATION_MODE: // Run encoder calibration procedure |
benkatz | 23:2adf23ee0305 | 217 | if(state_change){ |
benkatz | 23:2adf23ee0305 | 218 | calibrate(); |
benkatz | 23:2adf23ee0305 | 219 | } |
benkatz | 23:2adf23ee0305 | 220 | break; |
benkatz | 55:c4c9fec8539c | 221 | case INIT_TEMP_MODE: |
benkatz | 55:c4c9fec8539c | 222 | if(state_change){ |
benkatz | 55:c4c9fec8539c | 223 | enter_torque_mode(); |
benkatz | 55:c4c9fec8539c | 224 | count = 0; |
benkatz | 55:c4c9fec8539c | 225 | observer.resistance = 0.0f; |
benkatz | 55:c4c9fec8539c | 226 | } |
benkatz | 55:c4c9fec8539c | 227 | controller.i_d_ref = -10.0f; |
benkatz | 55:c4c9fec8539c | 228 | controller.i_q_ref = 0.0f; |
benkatz | 55:c4c9fec8539c | 229 | commutate(&controller, &observer, &gpio, controller.theta_elec); |
benkatz | 55:c4c9fec8539c | 230 | |
benkatz | 55:c4c9fec8539c | 231 | if(count > 200) |
benkatz | 55:c4c9fec8539c | 232 | { |
benkatz | 55:c4c9fec8539c | 233 | float r_meas = controller.v_d*(DTC_MAX-DTC_MIN)/(controller.i_d*SQRT3); |
benkatz | 55:c4c9fec8539c | 234 | //testing2[count-100] = controller.i_d; |
benkatz | 55:c4c9fec8539c | 235 | observer.resistance += .001f*r_meas; |
benkatz | 55:c4c9fec8539c | 236 | } |
benkatz | 55:c4c9fec8539c | 237 | if(count > 1200) |
benkatz | 55:c4c9fec8539c | 238 | { |
benkatz | 55:c4c9fec8539c | 239 | count = 0; |
benkatz | 55:c4c9fec8539c | 240 | state = REST_MODE; |
benkatz | 55:c4c9fec8539c | 241 | state_change = 1; |
benkatz | 55:c4c9fec8539c | 242 | gpio.led->write(0); |
benkatz | 55:c4c9fec8539c | 243 | observer.temperature = (double)(T_AMBIENT + ((observer.resistance/R_NOMINAL) - 1.0f)*254.5f); |
benkatz | 55:c4c9fec8539c | 244 | printf("Winding Resistance: %f\n\r", observer.resistance); |
benkatz | 55:c4c9fec8539c | 245 | printf("Winding Temperature: %f\n\r", observer.temperature); |
benkatz | 55:c4c9fec8539c | 246 | |
benkatz | 55:c4c9fec8539c | 247 | if(R_NOMINAL==0) |
benkatz | 55:c4c9fec8539c | 248 | { |
benkatz | 55:c4c9fec8539c | 249 | printf("Saving winding resistance\n\r"); |
benkatz | 55:c4c9fec8539c | 250 | R_NOMINAL = observer.resistance; |
benkatz | 55:c4c9fec8539c | 251 | if (!prefs.ready()) prefs.open(); |
benkatz | 55:c4c9fec8539c | 252 | prefs.flush(); // write offset and lookup table to flash |
benkatz | 55:c4c9fec8539c | 253 | prefs.close(); |
benkatz | 55:c4c9fec8539c | 254 | } |
benkatz | 55:c4c9fec8539c | 255 | //for(int i = 0; i<1000; i++){printf("%f \n\r", testing[i]);} |
benkatz | 55:c4c9fec8539c | 256 | } |
benkatz | 55:c4c9fec8539c | 257 | |
benkatz | 55:c4c9fec8539c | 258 | count++; |
benkatz | 55:c4c9fec8539c | 259 | break; |
benkatz | 26:2b865c00d7e9 | 260 | case MOTOR_MODE: // Run torque control |
benkatz | 25:f5741040c4bb | 261 | if(state_change){ |
benkatz | 25:f5741040c4bb | 262 | enter_torque_mode(); |
benkatz | 28:8c7e29f719c5 | 263 | count = 0; |
benkatz | 25:f5741040c4bb | 264 | } |
benkatz | 28:8c7e29f719c5 | 265 | else{ |
benkatz | 37:c0f352d6e8e3 | 266 | /* |
benkatz | 37:c0f352d6e8e3 | 267 | if(controller.v_bus>28.0f){ //Turn of gate drive if bus voltage is too high, to prevent FETsplosion if the bus is cut during regen |
benkatz | 47:e1196a851f76 | 268 | gpio. |
benkatz | 47:e1196a851f76 | 269 | ->write(0); |
benkatz | 37:c0f352d6e8e3 | 270 | controller.ovp_flag = 1; |
benkatz | 37:c0f352d6e8e3 | 271 | state = REST_MODE; |
benkatz | 37:c0f352d6e8e3 | 272 | state_change = 1; |
benkatz | 37:c0f352d6e8e3 | 273 | printf("OVP Triggered!\n\r"); |
benkatz | 37:c0f352d6e8e3 | 274 | } |
benkatz | 37:c0f352d6e8e3 | 275 | */ |
benkatz | 37:c0f352d6e8e3 | 276 | |
benkatz | 28:8c7e29f719c5 | 277 | if((controller.timeout > CAN_TIMEOUT) && (CAN_TIMEOUT > 0)){ |
benkatz | 28:8c7e29f719c5 | 278 | controller.i_d_ref = 0; |
benkatz | 28:8c7e29f719c5 | 279 | controller.i_q_ref = 0; |
benkatz | 37:c0f352d6e8e3 | 280 | controller.kp = 0; |
benkatz | 37:c0f352d6e8e3 | 281 | controller.kd = 0; |
benkatz | 37:c0f352d6e8e3 | 282 | controller.t_ff = 0; |
benkatz | 28:8c7e29f719c5 | 283 | } |
benkatz | 55:c4c9fec8539c | 284 | |
benkatz | 50:ba72df25d10f | 285 | torque_control(&controller); |
benkatz | 55:c4c9fec8539c | 286 | update_observer(&controller, &observer); |
benkatz | 55:c4c9fec8539c | 287 | field_weaken(&controller); |
benkatz | 49:83d83040ea51 | 288 | commutate(&controller, &observer, &gpio, controller.theta_elec); // Run current loop |
benkatz | 49:83d83040ea51 | 289 | controller.timeout++; |
benkatz | 55:c4c9fec8539c | 290 | |
benkatz | 55:c4c9fec8539c | 291 | if(controller.otw_flag) |
benkatz | 55:c4c9fec8539c | 292 | { |
benkatz | 55:c4c9fec8539c | 293 | state = REST_MODE; |
benkatz | 55:c4c9fec8539c | 294 | state_change = 1; |
benkatz | 55:c4c9fec8539c | 295 | gpio.led->write(0); |
benkatz | 55:c4c9fec8539c | 296 | } |
benkatz | 55:c4c9fec8539c | 297 | |
benkatz | 49:83d83040ea51 | 298 | count++; |
benkatz | 55:c4c9fec8539c | 299 | } |
benkatz | 55:c4c9fec8539c | 300 | |
benkatz | 55:c4c9fec8539c | 301 | |
benkatz | 55:c4c9fec8539c | 302 | break; |
benkatz | 37:c0f352d6e8e3 | 303 | |
benkatz | 23:2adf23ee0305 | 304 | case SETUP_MODE: |
benkatz | 23:2adf23ee0305 | 305 | if(state_change){ |
benkatz | 24:58c2d7571207 | 306 | enter_setup_state(); |
benkatz | 23:2adf23ee0305 | 307 | } |
benkatz | 23:2adf23ee0305 | 308 | break; |
benkatz | 23:2adf23ee0305 | 309 | case ENCODER_MODE: |
benkatz | 23:2adf23ee0305 | 310 | print_encoder(); |
benkatz | 23:2adf23ee0305 | 311 | break; |
benkatz | 37:c0f352d6e8e3 | 312 | } |
benkatz | 2:8724412ad628 | 313 | } |
benkatz | 55:c4c9fec8539c | 314 | //gpio.led->write(0); |
benkatz | 23:2adf23ee0305 | 315 | TIM1->SR = 0x0; // reset the status register |
benkatz | 2:8724412ad628 | 316 | } |
benkatz | 0:4e1c4df6aabd | 317 | |
benkatz | 25:f5741040c4bb | 318 | |
benkatz | 24:58c2d7571207 | 319 | char cmd_val[8] = {0}; |
benkatz | 24:58c2d7571207 | 320 | char cmd_id = 0; |
benkatz | 25:f5741040c4bb | 321 | char char_count = 0; |
benkatz | 24:58c2d7571207 | 322 | |
benkatz | 25:f5741040c4bb | 323 | /// Manage state machine with commands from serial terminal or configurator gui /// |
benkatz | 25:f5741040c4bb | 324 | /// Called when data received over serial /// |
benkatz | 23:2adf23ee0305 | 325 | void serial_interrupt(void){ |
benkatz | 23:2adf23ee0305 | 326 | while(pc.readable()){ |
benkatz | 23:2adf23ee0305 | 327 | char c = pc.getc(); |
benkatz | 25:f5741040c4bb | 328 | if(c == 27){ |
benkatz | 25:f5741040c4bb | 329 | state = REST_MODE; |
benkatz | 25:f5741040c4bb | 330 | state_change = 1; |
benkatz | 25:f5741040c4bb | 331 | char_count = 0; |
benkatz | 25:f5741040c4bb | 332 | cmd_id = 0; |
benkatz | 55:c4c9fec8539c | 333 | gpio.led->write(0);; |
benkatz | 25:f5741040c4bb | 334 | for(int i = 0; i<8; i++){cmd_val[i] = 0;} |
benkatz | 25:f5741040c4bb | 335 | } |
benkatz | 24:58c2d7571207 | 336 | if(state == REST_MODE){ |
benkatz | 23:2adf23ee0305 | 337 | switch (c){ |
benkatz | 23:2adf23ee0305 | 338 | case 'c': |
benkatz | 23:2adf23ee0305 | 339 | state = CALIBRATION_MODE; |
benkatz | 23:2adf23ee0305 | 340 | state_change = 1; |
benkatz | 23:2adf23ee0305 | 341 | break; |
benkatz | 26:2b865c00d7e9 | 342 | case 'm': |
benkatz | 26:2b865c00d7e9 | 343 | state = MOTOR_MODE; |
benkatz | 23:2adf23ee0305 | 344 | state_change = 1; |
benkatz | 23:2adf23ee0305 | 345 | break; |
benkatz | 23:2adf23ee0305 | 346 | case 'e': |
benkatz | 23:2adf23ee0305 | 347 | state = ENCODER_MODE; |
benkatz | 23:2adf23ee0305 | 348 | state_change = 1; |
benkatz | 23:2adf23ee0305 | 349 | break; |
benkatz | 23:2adf23ee0305 | 350 | case 's': |
benkatz | 23:2adf23ee0305 | 351 | state = SETUP_MODE; |
benkatz | 23:2adf23ee0305 | 352 | state_change = 1; |
benkatz | 23:2adf23ee0305 | 353 | break; |
benkatz | 37:c0f352d6e8e3 | 354 | case 'z': |
benkatz | 37:c0f352d6e8e3 | 355 | spi.SetMechOffset(0); |
benkatz | 47:e1196a851f76 | 356 | spi.Sample(DT); |
benkatz | 37:c0f352d6e8e3 | 357 | wait_us(20); |
benkatz | 37:c0f352d6e8e3 | 358 | M_OFFSET = spi.GetMechPosition(); |
benkatz | 37:c0f352d6e8e3 | 359 | if (!prefs.ready()) prefs.open(); |
benkatz | 37:c0f352d6e8e3 | 360 | prefs.flush(); // Write new prefs to flash |
benkatz | 37:c0f352d6e8e3 | 361 | prefs.close(); |
benkatz | 37:c0f352d6e8e3 | 362 | prefs.load(); |
benkatz | 37:c0f352d6e8e3 | 363 | spi.SetMechOffset(M_OFFSET); |
benkatz | 37:c0f352d6e8e3 | 364 | printf("\n\r Saved new zero position: %.4f\n\r\n\r", M_OFFSET); |
benkatz | 37:c0f352d6e8e3 | 365 | |
benkatz | 37:c0f352d6e8e3 | 366 | break; |
benkatz | 37:c0f352d6e8e3 | 367 | } |
benkatz | 37:c0f352d6e8e3 | 368 | |
benkatz | 24:58c2d7571207 | 369 | } |
benkatz | 24:58c2d7571207 | 370 | else if(state == SETUP_MODE){ |
benkatz | 25:f5741040c4bb | 371 | if(c == 13){ |
benkatz | 24:58c2d7571207 | 372 | switch (cmd_id){ |
benkatz | 24:58c2d7571207 | 373 | case 'b': |
benkatz | 24:58c2d7571207 | 374 | I_BW = fmaxf(fminf(atof(cmd_val), 2000.0f), 100.0f); |
benkatz | 24:58c2d7571207 | 375 | break; |
benkatz | 24:58c2d7571207 | 376 | case 'i': |
benkatz | 24:58c2d7571207 | 377 | CAN_ID = atoi(cmd_val); |
benkatz | 24:58c2d7571207 | 378 | break; |
benkatz | 26:2b865c00d7e9 | 379 | case 'm': |
benkatz | 26:2b865c00d7e9 | 380 | CAN_MASTER = atoi(cmd_val); |
benkatz | 26:2b865c00d7e9 | 381 | break; |
benkatz | 24:58c2d7571207 | 382 | case 'l': |
benkatz | 51:6cd89bd6fcaa | 383 | I_MAX = fmaxf(fminf(atof(cmd_val), 40.0f), 0.0f); |
benkatz | 51:6cd89bd6fcaa | 384 | break; |
benkatz | 51:6cd89bd6fcaa | 385 | case 'f': |
benkatz | 51:6cd89bd6fcaa | 386 | I_FW_MAX = fmaxf(fminf(atof(cmd_val), 33.0f), 0.0f); |
benkatz | 24:58c2d7571207 | 387 | break; |
benkatz | 28:8c7e29f719c5 | 388 | case 't': |
benkatz | 28:8c7e29f719c5 | 389 | CAN_TIMEOUT = atoi(cmd_val); |
benkatz | 28:8c7e29f719c5 | 390 | break; |
benkatz | 55:c4c9fec8539c | 391 | case 'h': |
benkatz | 55:c4c9fec8539c | 392 | TEMP_MAX = fmaxf(fminf(atof(cmd_val), 150.0f), 0.0f); |
benkatz | 55:c4c9fec8539c | 393 | break; |
benkatz | 55:c4c9fec8539c | 394 | case 'c': |
benkatz | 55:c4c9fec8539c | 395 | I_MAX_CONT = fmaxf(fminf(atof(cmd_val), 40.0f), 0.0f); |
benkatz | 55:c4c9fec8539c | 396 | break; |
benkatz | 24:58c2d7571207 | 397 | default: |
benkatz | 24:58c2d7571207 | 398 | printf("\n\r '%c' Not a valid command prefix\n\r\n\r", cmd_id); |
benkatz | 24:58c2d7571207 | 399 | break; |
benkatz | 24:58c2d7571207 | 400 | } |
benkatz | 24:58c2d7571207 | 401 | |
benkatz | 24:58c2d7571207 | 402 | if (!prefs.ready()) prefs.open(); |
benkatz | 24:58c2d7571207 | 403 | prefs.flush(); // Write new prefs to flash |
benkatz | 24:58c2d7571207 | 404 | prefs.close(); |
benkatz | 24:58c2d7571207 | 405 | prefs.load(); |
benkatz | 24:58c2d7571207 | 406 | state_change = 1; |
benkatz | 24:58c2d7571207 | 407 | char_count = 0; |
benkatz | 24:58c2d7571207 | 408 | cmd_id = 0; |
benkatz | 24:58c2d7571207 | 409 | for(int i = 0; i<8; i++){cmd_val[i] = 0;} |
benkatz | 24:58c2d7571207 | 410 | } |
benkatz | 24:58c2d7571207 | 411 | else{ |
benkatz | 24:58c2d7571207 | 412 | if(char_count == 0){cmd_id = c;} |
benkatz | 24:58c2d7571207 | 413 | else{ |
benkatz | 24:58c2d7571207 | 414 | cmd_val[char_count-1] = c; |
benkatz | 24:58c2d7571207 | 415 | |
benkatz | 24:58c2d7571207 | 416 | } |
benkatz | 24:58c2d7571207 | 417 | pc.putc(c); |
benkatz | 24:58c2d7571207 | 418 | char_count++; |
benkatz | 23:2adf23ee0305 | 419 | } |
benkatz | 23:2adf23ee0305 | 420 | } |
benkatz | 24:58c2d7571207 | 421 | else if (state == ENCODER_MODE){ |
benkatz | 24:58c2d7571207 | 422 | switch (c){ |
benkatz | 24:58c2d7571207 | 423 | case 27: |
benkatz | 24:58c2d7571207 | 424 | state = REST_MODE; |
benkatz | 24:58c2d7571207 | 425 | state_change = 1; |
benkatz | 24:58c2d7571207 | 426 | break; |
benkatz | 24:58c2d7571207 | 427 | } |
benkatz | 24:58c2d7571207 | 428 | } |
benkatz | 49:83d83040ea51 | 429 | else if (state == MOTOR_MODE){ |
benkatz | 49:83d83040ea51 | 430 | switch (c){ |
benkatz | 49:83d83040ea51 | 431 | case 'd': |
benkatz | 49:83d83040ea51 | 432 | controller.i_q_ref = 0; |
benkatz | 49:83d83040ea51 | 433 | controller.i_d_ref = 0; |
benkatz | 49:83d83040ea51 | 434 | } |
benkatz | 49:83d83040ea51 | 435 | } |
benkatz | 24:58c2d7571207 | 436 | |
benkatz | 24:58c2d7571207 | 437 | } |
benkatz | 22:60276ba87ac6 | 438 | } |
benkatz | 0:4e1c4df6aabd | 439 | |
benkatz | 0:4e1c4df6aabd | 440 | int main() { |
benkatz | 20:bf9ea5125d52 | 441 | controller.v_bus = V_BUS; |
benkatz | 22:60276ba87ac6 | 442 | controller.mode = 0; |
benkatz | 23:2adf23ee0305 | 443 | Init_All_HW(&gpio); // Setup PWM, ADC, GPIO |
benkatz | 55:c4c9fec8539c | 444 | wait_us(100); |
benkatz | 44:8040fa2fcb0d | 445 | |
benkatz | 44:8040fa2fcb0d | 446 | gpio.enable->write(1); |
benkatz | 44:8040fa2fcb0d | 447 | wait_us(100); |
benkatz | 45:26801179208e | 448 | drv.calibrate(); |
benkatz | 45:26801179208e | 449 | wait_us(100); |
benkatz | 55:c4c9fec8539c | 450 | drv.write_DCR(0x0, DIS_GDF_DIS, 0x0, PWM_MODE_3X, 0x0, 0x0, 0x0, 0x0, 0x1); |
benkatz | 55:c4c9fec8539c | 451 | wait_us(100); |
benkatz | 55:c4c9fec8539c | 452 | drv.write_CSACR(0x0, 0x1, 0x0, CSA_GAIN_40, 0x0, 0x1, 0x1, 0x1, SEN_LVL_1_0); // calibrate shunt amplifiers |
benkatz | 44:8040fa2fcb0d | 453 | wait_us(100); |
benkatz | 55:c4c9fec8539c | 454 | zero_current(&controller.adc1_offset, &controller.adc2_offset); |
benkatz | 44:8040fa2fcb0d | 455 | wait_us(100); |
benkatz | 55:c4c9fec8539c | 456 | drv.write_CSACR(0x0, 0x1, 0x0, CSA_GAIN_40, 0x1, 0x0, 0x0, 0x0, SEN_LVL_1_0); |
benkatz | 55:c4c9fec8539c | 457 | wait_us(100); |
benkatz | 55:c4c9fec8539c | 458 | drv.write_OCPCR(TRETRY_50US, DEADTIME_50NS, OCP_NONE, OCP_DEG_8US, VDS_LVL_1_88); |
benkatz | 45:26801179208e | 459 | |
benkatz | 45:26801179208e | 460 | //drv.enable_gd(); |
benkatz | 47:e1196a851f76 | 461 | drv.disable_gd(); |
benkatz | 55:c4c9fec8539c | 462 | //zero_current(&controller.adc1_offset, &controller.adc2_offset); // Measure current sensor zero-offset |
benkatz | 55:c4c9fec8539c | 463 | //drv.enable_gd(); |
benkatz | 20:bf9ea5125d52 | 464 | |
benkatz | 55:c4c9fec8539c | 465 | wait_us(100); |
benkatz | 55:c4c9fec8539c | 466 | |
benkatz | 23:2adf23ee0305 | 467 | reset_foc(&controller); // Reset current controller |
benkatz | 48:74a40481740c | 468 | reset_observer(&observer); // Reset observer |
benkatz | 26:2b865c00d7e9 | 469 | //TIM1->CR1 |= TIM_CR1_UDIS; //enable interrupt |
benkatz | 20:bf9ea5125d52 | 470 | |
benkatz | 55:c4c9fec8539c | 471 | wait_us(100); |
benkatz | 37:c0f352d6e8e3 | 472 | NVIC_SetPriority(TIM1_UP_TIM10_IRQn, 2); // commutation > communication |
benkatz | 37:c0f352d6e8e3 | 473 | NVIC_SetPriority(CAN1_RX0_IRQn, 3); |
benkatz | 53:e85efce8c1eb | 474 | // attach 'CAN receive-complete' interrupt handler |
benkatz | 53:e85efce8c1eb | 475 | |
benkatz | 53:e85efce8c1eb | 476 | // If preferences haven't been user configured yet, set defaults |
benkatz | 53:e85efce8c1eb | 477 | prefs.load(); // Read flash |
benkatz | 55:c4c9fec8539c | 478 | can.filter(CAN_ID , 0xFFF, CANStandard, 0); |
benkatz | 28:8c7e29f719c5 | 479 | txMsg.id = CAN_MASTER; |
benkatz | 28:8c7e29f719c5 | 480 | txMsg.len = 6; |
benkatz | 26:2b865c00d7e9 | 481 | rxMsg.len = 8; |
benkatz | 53:e85efce8c1eb | 482 | can.attach(&onMsgReceived); |
benkatz | 23:2adf23ee0305 | 483 | |
benkatz | 37:c0f352d6e8e3 | 484 | if(isnan(E_OFFSET)){E_OFFSET = 0.0f;} |
benkatz | 37:c0f352d6e8e3 | 485 | if(isnan(M_OFFSET)){M_OFFSET = 0.0f;} |
benkatz | 48:74a40481740c | 486 | if(isnan(I_BW) || I_BW==-1){I_BW = 1000;} |
benkatz | 51:6cd89bd6fcaa | 487 | if(isnan(I_MAX) || I_MAX ==-1){I_MAX=40;} |
benkatz | 55:c4c9fec8539c | 488 | if(isnan(I_FW_MAX) || I_FW_MAX ==-1){I_FW_MAX=12;} |
benkatz | 48:74a40481740c | 489 | if(isnan(CAN_ID) || CAN_ID==-1){CAN_ID = 1;} |
benkatz | 48:74a40481740c | 490 | if(isnan(CAN_MASTER) || CAN_MASTER==-1){CAN_MASTER = 0;} |
benkatz | 55:c4c9fec8539c | 491 | if(isnan(CAN_TIMEOUT) || CAN_TIMEOUT==-1){CAN_TIMEOUT = 1000;} |
benkatz | 55:c4c9fec8539c | 492 | if(isnan(R_NOMINAL) || R_NOMINAL==-1){R_NOMINAL = 0.0f;} |
benkatz | 55:c4c9fec8539c | 493 | if(isnan(TEMP_MAX) || TEMP_MAX==-1){TEMP_MAX = 125.0f;} |
benkatz | 55:c4c9fec8539c | 494 | if(isnan(I_MAX_CONT) || I_MAX_CONT==-1){I_MAX_CONT = 14.0f;} |
benkatz | 25:f5741040c4bb | 495 | spi.SetElecOffset(E_OFFSET); // Set position sensor offset |
benkatz | 37:c0f352d6e8e3 | 496 | spi.SetMechOffset(M_OFFSET); |
benkatz | 56:fe5056ac6740 | 497 | spi.Sample(1.0f); |
benkatz | 56:fe5056ac6740 | 498 | if(spi.GetMechPosition() > PI){spi.SetMechOffset(M_OFFSET+2.0f*PI);} // now zeroes to +- 30 degrees about nominal, independent of rollover point |
benkatz | 56:fe5056ac6740 | 499 | else if (spi.GetMechPosition() < -PI){spi.SetMechOffset(M_OFFSET-2.0f*PI);} |
benkatz | 56:fe5056ac6740 | 500 | |
benkatz | 23:2adf23ee0305 | 501 | int lut[128] = {0}; |
benkatz | 23:2adf23ee0305 | 502 | memcpy(&lut, &ENCODER_LUT, sizeof(lut)); |
benkatz | 25:f5741040c4bb | 503 | spi.WriteLUT(lut); // Set potision sensor nonlinearity lookup table |
benkatz | 45:26801179208e | 504 | init_controller_params(&controller); |
benkatz | 55:c4c9fec8539c | 505 | |
benkatz | 45:26801179208e | 506 | |
benkatz | 26:2b865c00d7e9 | 507 | pc.baud(921600); // set serial baud rate |
benkatz | 20:bf9ea5125d52 | 508 | wait(.01); |
benkatz | 23:2adf23ee0305 | 509 | pc.printf("\n\r\n\r HobbyKing Cheetah\n\r\n\r"); |
benkatz | 20:bf9ea5125d52 | 510 | wait(.01); |
benkatz | 23:2adf23ee0305 | 511 | printf("\n\r Debug Info:\n\r"); |
benkatz | 32:ccac5da77844 | 512 | printf(" Firmware Version: %s\n\r", VERSION_NUM); |
benkatz | 23:2adf23ee0305 | 513 | printf(" ADC1 Offset: %d ADC2 Offset: %d\n\r", controller.adc1_offset, controller.adc2_offset); |
benkatz | 23:2adf23ee0305 | 514 | printf(" Position Sensor Electrical Offset: %.4f\n\r", E_OFFSET); |
benkatz | 37:c0f352d6e8e3 | 515 | printf(" Output Zero Position: %.4f\n\r", M_OFFSET); |
benkatz | 24:58c2d7571207 | 516 | printf(" CAN ID: %d\n\r", CAN_ID); |
benkatz | 44:8040fa2fcb0d | 517 | |
benkatz | 44:8040fa2fcb0d | 518 | |
benkatz | 55:c4c9fec8539c | 519 | TIM1->CR1 ^= TIM_CR1_UDIS; |
benkatz | 44:8040fa2fcb0d | 520 | |
benkatz | 44:8040fa2fcb0d | 521 | |
benkatz | 23:2adf23ee0305 | 522 | pc.attach(&serial_interrupt); // attach serial interrupt |
benkatz | 50:ba72df25d10f | 523 | |
benkatz | 20:bf9ea5125d52 | 524 | |
benkatz | 44:8040fa2fcb0d | 525 | int counter = 0; |
benkatz | 0:4e1c4df6aabd | 526 | while(1) { |
benkatz | 55:c4c9fec8539c | 527 | //drv.print_faults(); |
benkatz | 53:e85efce8c1eb | 528 | wait(.1); |
benkatz | 57:0795d2add37e | 529 | |
benkatz | 55:c4c9fec8539c | 530 | if(controller.otw_flag){gpio.led->write(!gpio.led->read());} |
benkatz | 55:c4c9fec8539c | 531 | /* |
benkatz | 47:e1196a851f76 | 532 | if(state == MOTOR_MODE) |
benkatz | 47:e1196a851f76 | 533 | { |
benkatz | 55:c4c9fec8539c | 534 | if(controller.otw_flag){gpio.led->write(!gpio.led->read());} |
benkatz | 55:c4c9fec8539c | 535 | //printf("%f %f\n\r", controller.dtheta_mech, controller.i_d_ref); |
benkatz | 48:74a40481740c | 536 | //printf("%.3f %.3f %.3f\n\r", (float)observer.temperature, (float)observer.temperature2, observer.resistance); |
benkatz | 49:83d83040ea51 | 537 | //printf("%.3f %.3f %.3f %.3f %.3f\n\r", controller.v_d, controller.v_q, controller.i_d_filt, controller.i_q_filt, controller.dtheta_elec); |
benkatz | 55:c4c9fec8539c | 538 | //printf("%.3f %.3f %.3f %.3f\n\r", controller.dtheta_elec, observer.resistance, observer.temperature, observer.temp_measured); |
benkatz | 55:c4c9fec8539c | 539 | //printf("%.3f %.3f\n\r" , observer.temperature, observer.temp_measured); |
benkatz | 47:e1196a851f76 | 540 | } |
benkatz | 55:c4c9fec8539c | 541 | |
benkatz | 50:ba72df25d10f | 542 | */ |
benkatz | 47:e1196a851f76 | 543 | |
benkatz | 0:4e1c4df6aabd | 544 | } |
benkatz | 0:4e1c4df6aabd | 545 | } |