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 Impedance_Fast_Circuitry by
Diff: main.cpp
- Revision:
- 33:9806eb964362
- Parent:
- 32:bf1e079a2ee3
- Child:
- 34:44cc9b76a507
--- a/main.cpp Thu Jan 08 20:16:19 2015 +0000 +++ b/main.cpp Fri Jan 09 20:07:09 2015 +0000 @@ -123,7 +123,7 @@ void timed_sampling(); -int motorVal = 50; +int motorVal = 0; void releaseMallet() { motorA = 0; @@ -360,96 +360,104 @@ } break; - case '1': // run motor and sample + case '3': // run motor and sample { - // release mallet - motorA = 0; - motorB = 1; - wait_ms(10); - motorB = 0; - wait_ms(75); - - motorA = 0.7; - wait_ms(8); - motorA = 0; - - // wait for mallet to drop some before beginning to sample - wait_ms(50); - - // begin sampling - BW_ADC_SC1n_ADCH(0, 0, kAdcChannel12); // This corresponds to starting an ADC conversion on channel 12 of ADC 0 - which is A0 (PTB2) - BW_ADC_SC1n_ADCH(1, 0, kAdcChannel14); // This corresponds to starting an ADC conversion on channel 14 of ADC 1 - which is A2 (PTB10) - client[index].write((void *)"Data\n",5); - - TotalInd = 1; + // set angle to 0 + led_blue = 0; + while(!angle_encoder.set_zero()) {} + led_blue = 1; - uint32_t AMT20_AB; - rotary_count = 0; - __disable_irq(); - SampleInd = 0; - for(int i = 0; i < TOTAL_SAMPLES; i++) - { - SampleInd = !SampleInd; - sample_array1[i] = adc_hal_get_conversion_value(0, 0); - sample_array2[i] = adc_hal_get_conversion_value(1, 0); - BW_ADC_SC1n_ADCH(0, 0, kAdcChannel12); // This corresponds to starting an ADC conversion on channel 12 of ADC 0 - which is A0 (PTB2) - BW_ADC_SC1n_ADCH(1, 0, kAdcChannel14); // This corresponds to starting an ADC conversion on channel 14 of ADC 1 - which is A2 (PTB10) - - // The following updates the rotary counter for the AMT20 sensor - // Put A on PTC0 - // Put B on PTC1 - AMT20_AB = HW_GPIO_PDIR_RD(HW_PORTC) & 0x03; - - if (AMT20_AB != last_AMT20_AB_read) - { - // change "INVERT_ANGLE" to change whether relative angle counts up or down. - if ((AMT20_AB >> 1)^(last_AMT20_AB_read) & 1U) - #if INVERT_ANGLE == 1 - {rotary_count--;} - else - {rotary_count++;} - #else - {rotary_count++;} - else - {rotary_count--;} - #endif - - last_AMT20_AB_read = AMT20_AB; - } - angle_array[i] = rotary_count; - wait_us(8); - } - __enable_irq(); + // release mallet + wait(1); + // reset mallet motorA = 0; - motorB = 1; - wait_ms(138); + int angleVar = 1; + int counter = 0; + while(angleVar) + { + counter++; + angleVar = angle_encoder.absolute_angle(); + //angleVar -= motorVal; + if(angleVar == 0x00ff0000) {} // do nothing + else if(angleVar > 340) motorB.pulsewidth_us(8000); // max speed + else if(angleVar < motorVal) { + angleVar = 0; // exit loop + motorB.pulsewidth_us(0);} // min speed + else motorB.pulsewidth_us(angleVar*800/34); + } motorB = 0; + char buf[29]; + sprintf(buf,"MotorVal: %i\n",motorVal); + client[index].write((void *) buf,29); + - NVIC_SetPriority(ENET_1588_Timer_IRQn,0); - NVIC_SetPriority(ENET_Transmit_IRQn,0); - NVIC_SetPriority(ENET_Receive_IRQn,0); - NVIC_SetPriority(ENET_Error_IRQn,0); - TotalInd = 1; - client[index].write((void *)&sample_array1,2*TOTAL_SAMPLES); - client[index].write((void *)&sample_array2,2*TOTAL_SAMPLES); - client[index].write((void *)&angle_array,2*TOTAL_SAMPLES); - TotalInd = 0; - - NVIC_SetPriority(ENET_1588_Timer_IRQn,1); - NVIC_SetPriority(ENET_Transmit_IRQn,1); - NVIC_SetPriority(ENET_Receive_IRQn,1); - NVIC_SetPriority(ENET_Error_IRQn,1); - + /* + int tempDutyCycle = 2000; + for(int i = counter; i > 0; i--) + { + motorA.pulsewidth_us(tempDutyCycle); + } + */ + // make sure motors are off + motorA = 0; + motorB = 0; + //wait_ms(138); + motorB = 0; } break; + case '1': + { + // set angle to 0 + led_blue = 0; + while(!angle_encoder.set_zero()) {} + led_blue = 1; - case '2': // just reset the mallet + // release mallet + wait(1); + + + // reset mallet + motorA = 0; + int angleVar = 1; + int counter = 0; + while(angleVar) + { + counter++; + angleVar = angle_encoder.absolute_angle(); + angleVar -= motorVal; + if(angleVar == 0x00ff0000) {} // do nothing + else if(angleVar > 340) motorB.pulsewidth_us(8000); // max speed + else if(angleVar < 43) { + angleVar = 0; // exit loop + motorB.pulsewidth_us(0);} // min speed + else motorB.pulsewidth_us(angleVar*800/34); + } + motorB = 0; + + char buf[29]; + sprintf(buf,"MotorVal: %i\n",motorVal); + client[index].write((void *) buf,29); + + + + /* + int tempDutyCycle = 2000; + for(int i = counter; i > 0; i--) + { + motorA.pulsewidth_us(tempDutyCycle); + } + */ + // make sure motors are off + motorA = 0; + motorB = 0; + } + break; + case '2': { - // release mallet motorA = 0; motorB = 1; @@ -552,10 +560,19 @@ break; case '+': motorVal++; + if(motorVal > 8000) motorVal = 43; + char buf[29]; + sprintf(buf,"MotorVal: %i\n",motorVal); + client[index].write((void *) buf,29); + break; case '-': motorVal--; if(motorVal < 0) motorVal = 0; + char buf[29]; + sprintf(buf,"MotorVal: %i\n",motorVal); + client[index].write((void *) buf,29); + break; case 'a': if(angle_encoder.set_zero(&rotary_count)) {