Chetan Sharma
/
HKCC_Controller_MBed_OS
Modifying the HKCC for no readily apparent reason
Diff: main.cpp
- Revision:
- 58:c66bedfe3688
- Parent:
- 57:57a108e15b52
--- a/main.cpp Sat Feb 27 17:50:10 2021 -0800 +++ b/main.cpp Sat Feb 27 22:57:54 2021 -0800 @@ -49,7 +49,6 @@ SPI drv_spi(PA_7, PA_6, PA_5); DigitalOut drv_cs(PA_4); -//DigitalOut drv_en_gate(PA_11); DRV832x drv(&drv_spi, &drv_cs); static BufferedSerial pc{PA_2, PA_3, CONFIG_BAUD}; @@ -137,7 +136,7 @@ void enter_torque_mode(void){ drv.enable_gd(); - //gpio.enable->write(1); + controller.ovp_flag = 0; reset_foc(&controller); wait_us(1 * 1000); // Tesets integrators, and other control loop parameters @@ -150,7 +149,6 @@ void calibrate(void){ drv.enable_gd(); - //gpio.enable->write(1); gpio.led->write(1); // Turn on status LED order_phases(&spi, &gpio, &controller, &prefs); // Check phase ordering calibrate(&spi, &gpio, &controller, &prefs); // Perform calibration procedure @@ -158,13 +156,11 @@ wait_us(200 * 1000); printf("\n\r Calibration complete. Press 'esc' to return to menu\n\r"); drv.disable_gd(); - //gpio.enable->write(0); state_change = 0; } void print_encoder(void){ - printf(" Mechanical Angle: %f Electrical Angle: %f Raw: %d\n\r", spi.GetMechPosition(), spi.GetElecPosition(), spi.GetRawPosition()); - //printf("%d\n\r", spi.GetRawPosition()); + printf(" Mechanical Angle: %f.4 Electrical Angle: %f.4 Raw: %d\n\r", spi.GetMechPosition(), spi.GetElecPosition(), spi.GetRawPosition()); wait_us(1 * 1000); } @@ -175,8 +171,6 @@ static volatile int count{0}; // Initialize count variable as static ///Sample current always /// ADC1->CR2 |= 0x40000000; // Begin sample and conversion - //volatile int delay; - //for (delay = 0; delay < 55; delay++); spi.Sample(DT); // sample position sensor controller.adc2_raw = ADC2->DR; // Read ADC Data Registers @@ -384,13 +378,7 @@ drv.disable_gd(); wait_us(100 * 1000); - /* - gpio.enable->write(1); - TIM1->CCR3 = 0x708*(1.0f); // Write duty cycles - TIM1->CCR2 = 0x708*(1.0f); - TIM1->CCR1 = 0x708*(1.0f); - gpio.enable->write(0); - */ + reset_foc(&controller); // Reset current controller reset_observer(&observer); // Reset observer TIM1->CR1 ^= TIM_CR1_UDIS; @@ -423,7 +411,7 @@ memcpy(&lut, &ENCODER_LUT, sizeof(lut)); spi.WriteLUT(lut); // Set potision sensor nonlinearity lookup table init_controller_params(&controller); - // set serial baud rate + wait_us(10 * 1000); printf("\n\r\n\r HobbyKing Cheetah\n\r\n\r"); wait_us(10 * 1000); @@ -434,16 +422,6 @@ printf(" Output Zero Position: %.4f\n\r", M_OFFSET); printf(" CAN ID: %d\n\r", CAN_ID); - - - - //printf(" %d\n\r", drv.read_register(DCR)); - //wait_us(100); - //printf(" %d\n\r", drv.read_register(CSACR)); - //wait_us(100); - //printf(" %d\n\r", drv.read_register(OCPCR)); - //drv.disable_gd(); - pc.sigio(callback(serial_interrupt)); // attach serial interrupt state_change = 1; @@ -452,7 +430,7 @@ int counter = 0; while(1) { drv.print_faults(); - wait_us(100 * 1000); //printf("%.4f\n\r", controller.v_bus); + wait_us(100 * 1000); /* if(state == MOTOR_MODE) {