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:
- 31:09e7a8b3c7e7
- Parent:
- 30:6a4ef939a93e
- Child:
- 32:bf1e079a2ee3
--- a/main.cpp Thu Dec 11 13:20:07 2014 +0000 +++ b/main.cpp Fri Dec 19 21:39:42 2014 +0000 @@ -28,7 +28,7 @@ * Take the time to set these constants * *****************************************/ -#define MALLET 6 // set mallet to a value between 1-7 +#define MALLET 5 // set mallet to a value between 1-7 #define STATIC 1 // set STATIC to 1 for static ip, set STATIC to 0 for dynamic #define PORT 22 // set to a random port number. All the mallets can use the same port number. #define MAX_CLIENTS 2 // set the max number of clients to at least 2 (first client is MATLAB, second is the distance unit) @@ -93,7 +93,9 @@ DigitalOut led_blue(LED_BLUE); // motor control and angle encoder -MotorControl motor(PTC2, PTA2, PERIOD, ON_OFF_TIME); // forward, backward, period, safetyPeriod +PwmOut motorA(PTC2); +PwmOut motorB(PTA2); +//MotorControl motor(PTC2, PTA2, PERIOD, ON_OFF_TIME); // forward, backward, period, safetyPeriod AngleEncoder angle_encoder(PTD2, PTD3, PTD1, PTD0, 8, 0, 1000000); // mosi, miso, sclk, cs, bit_width, mode, hz DigitalIn AMT20_A(PTC0); // input for quadrature encoding from angle encoder DigitalIn AMT20_B(PTC1); // input for quadrature encoding from angle encoder @@ -133,24 +135,61 @@ led_blue = 1; led_green = 0; led_red = 1; - + motorA = 0; + motorB = 0; + motorA.period_ms(8); + motorB.period_ms(8); pc.baud(230400); pc.printf("Starting %s\r\n",NAME); + + /* + wait(1); + + + motorB = 1; // 0.6 gets it around quickly enough + wait_us(10000); + motorB = 0; + + wait_us(60000); + + motorA = 0.75; + wait_us(5000); + motorA = 0; + + wait_ms(300); + + motorA = 1; + wait_us(50000); + motorA = 0; + + wait_us(45000); + + motorB = 0.75; + wait_us(8000); + motorB = 0; + + + //motorB = 0.2; + //wait_us(5000); + + + motorB = 0; + motorA = 0; + // make sure motors are off + wait_us(PERIOD); + + + + while(1) {} + */ + for(int i = 0; i < 86; i++) { if(NVIC_GetPriority((IRQn_Type) i) == 0) NVIC_SetPriority((IRQn_Type) i, 2); } - //NVIC_SetPriority(SWI_IRQn,0); - - //NVIC_SetPriority(Watchdog_IRQn,0); - //NVIC_SetPriority(MCM_IRQn,0); - //NVIC_SetPriority(PIT0_IRQn,0); - //NVIC_SetPriority(PIT1_IRQn,0); - //NVIC_SetPriority(PIT2_IRQn,0); NVIC_SetPriority(PIT3_IRQn,0); - //NVIC_SetPriority(LPTimer_IRQn,0); NVIC_SetPriority(ADC1_IRQn,0); NVIC_SetPriority(ADC0_IRQn,0); @@ -202,10 +241,6 @@ //NVIC_SetPriority(TIMER3_IRQn,0); //pc.printf("Ticker IRQ: %i\r\n", Sampler.irq()); - // corresponding duty 1 0 0.7 1 0.75 - uint32_t duration[8] = {0, 0, 0, 0, 0, 0, 0, 0}; - - double duty_cycle = 0.25; network::Select select; network::tcp::Socket server; @@ -341,7 +376,9 @@ case '1': // run motor and sample { - + motorA = 1; + wait_us(10000); + motorA = 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) client[index].write((void *)"Data\n",5); @@ -406,24 +443,7 @@ case '2': // run just the motor { - pc.printf("All duration settings 2:\r\n"); - for(int i = 0; i < 8; i++) - { - pc.printf("Duration[%i]: %i\r\n", i, duration[i]); - } - // release mallet - motor.forward(duration[0]); // move motor forward - wait_us(duration[1]); // wait - motor.backward(0.7, duration[2]); // stop motor using reverse - - // time for sampling - wait_us(SAMPLING_RATE*TOTAL_SAMPLES); - - // reset mallet - motor.backward(duration[3]); // move motor backward - motor.backward(0.75, duration[4]); - motor.backward(duty_cycle, duration[5]); } break; case 'a':