E=MC
/
e=mc
.
Diff: main.cpp
- Revision:
- 11:d07a4a683289
- Parent:
- 10:de7a56fb94bc
- Child:
- 12:46d0ff953a3f
diff -r de7a56fb94bc -r d07a4a683289 main.cpp --- a/main.cpp Fri Mar 06 06:01:27 2015 +0000 +++ b/main.cpp Fri Mar 06 09:16:02 2015 +0000 @@ -2,7 +2,8 @@ DigitalOut myled(LED1); PwmOut servo(PTA5); -PwmOut motor(PTA4); +PwmOut motor1(PTA4); +PwmOut motor2(PTA12); Serial pc(USBTX, USBRX); // tx, rx // encoder setup and variables @@ -100,7 +101,8 @@ tuning_val = 1; stall_check = avg_speed; } - motor.pulsewidth(.0025 * duty_cyc * tuning_val); + motor1.pulsewidth(.0025 * duty_cyc * tuning_val); + motor2.pulsewidth(.0025 * duty_cyc * tuning_val); pc.printf("speed: %f\n\rtuning val: %f\n\r", avg_speed, tuning_val); wait(.2); @@ -145,31 +147,35 @@ int main() { servo.period(0.005); - motor.period(.0025); + motor1.period(.0025); + motor2.period(.0025); interrupt.fall(&fallInterrupt); interrupt.rise(&riseInterrupt); t.start(); while(1){ - char choice = pc.getc(); + char choice = '2';//pc.getc(); pc.putc(choice); switch(choice){ case '0': - motor.pulsewidth(0.0); + motor1.pulsewidth(0.0); + motor2.pulsewidth(0.0); pc.printf("0% \n\r"); break; case '1': - motor.pulsewidth(.0025); + motor1.pulsewidth(.0025); + motor2.pulsewidth(.0025); pc.printf("100% \n\r"); wait(.5); pc.printf("speed: %f",get_avg_speed(num_samples_small, delay_small)); break; case '2': - motor.pulsewidth(.0025*.2); + motor1.pulsewidth(.0025*.2); + motor2.pulsewidth(.0025*.2); pc.printf("\n\r20% \n\r"); wait(.5); pc.printf("speed: %f\n\rtuning val: %f\n\r", get_avg_speed(num_samples_small, delay_small)); @@ -192,7 +198,8 @@ //break; case '3': - motor.pulsewidth(.0025*.3); + motor1.pulsewidth(.0025*.3); + motor2.pulsewidth(.0025*.3); pc.printf("\n\r30% \n\r"); wait(.5); pc.printf("speed: %f",get_avg_speed(num_samples_small, delay_small)); @@ -203,7 +210,8 @@ //break; case '5': - motor.pulsewidth(.0025*.5); + motor1.pulsewidth(.0025*.5); + motor2.pulsewidth(.0025*.5); pc.printf("\n\r50% \n\r"); wait(.5); pc.printf("speed: %f",get_avg_speed(num_samples_small, delay_small)); @@ -221,17 +229,20 @@ switch(choice){ case '2': - motor.pulsewidth(.0025*0.2f); + motor1.pulsewidth(.0025*0.2f); + motor2.pulsewidth(.0025*0.2f); pc.printf("\n\rLongterm average speed at 20 Duty Cycle: %f\n\r", get_avg_speed(num_samples_large, delay_large)); break; case '3': - motor.pulsewidth(.0025*0.3f); + motor1.pulsewidth(.0025*0.3f); + motor2.pulsewidth(.0025*0.3f); pc.printf("\n\rLongterm average speed at 30 Duty Cycle: %f\n\r", get_avg_speed(num_samples_large, delay_large)); break; case '5': - motor.pulsewidth(.0025*0.5f); + motor1.pulsewidth(.0025*0.5f); + motor2.pulsewidth(.0025*0.5f); pc.printf("\n\rLongterm average speed at 50 Duty Cycle: %f\n\r", get_avg_speed(num_samples_large, delay_large)); break; @@ -241,7 +252,8 @@ break; default: - motor.pulsewidth(.0025*0); + motor1.pulsewidth(.0025*0); + motor2.pulsewidth(.0025*0); pc.printf("default\n\r"); break; }