zhouhang shao
/
test
test
Diff: main.cpp
- Revision:
- 3:34a763e93423
- Parent:
- 2:b78dfa2afe92
- Child:
- 4:86927e61e1e3
diff -r b78dfa2afe92 -r 34a763e93423 main.cpp --- a/main.cpp Sat May 06 23:10:06 2017 +0000 +++ b/main.cpp Sun May 07 01:31:52 2017 +0000 @@ -3,8 +3,8 @@ */ #include "mbed.h" #include "IRSensor.h" -//#include "encoder.h" -#include "motor.h" +#include "encoder.h" +//#include "motor.h" Serial serial (PA_9, PA_10); //IRSensor testIR_RIGHT(PB_0, PA_4); //emmiter and receiver right most sensor // IRSensor testIR_LEFT(PA_8, PC_5); //emmiter and receiver left most sensor @@ -14,8 +14,17 @@ DigitalOut testLed4(PB_15); AnalogIn Ain(PA_3); //Motor leftMotor(PB_7, PB_6); -Motor rightMotor(PB_9, PB_8); -//Encoder leftEncoder(PC_9, PC_8); + +// pwm +PwmOut motor_pwm_left_sig(PB_7); +DigitalOut dir_left(PB_6); +//// dir +PwmOut motor_pwm_right_sig(PB_9); +DigitalOut dir_right(PB_8); + + +//Motor rightMotor(PB_9, PB_8); +Encoder leftEncoder(PC_9, PC_8); int main () { @@ -28,15 +37,24 @@ wait (0.2); testLed2 = 0; wait (0.2); +// + motor_pwm_left_sig.period(0.001f); + motor_pwm_left_sig.write(0.3f); + motor_pwm_right_sig.period(0.001f); + motor_pwm_right_sig.write(0.5f); + dir_left = 1; + dir_right = 1; + //serial.printf("start"); + // for (int i = 0; i < 3; i++) { -// leftMotor.speed(0); - rightMotor.speed(-0.02f); + // leftMotor.speed(0.15f); + // rightMotor.speed(0.15f); // rightMotor.dir // leftMotor.stop(); -// rightMotor.stop(); -// serial.printf("Left Motor speed is at: %f \n", leftMotor.read()); - serial.printf("Right Motor speed is at: %f \n", rightMotor.read()); + // rightMotor.stop(); + // serial.printf("Left Motor speed is at: %f \n", leftMotor.read()); + // serial.printf("Right Motor speed is at: %f \n", rightMotor.read()); //} @@ -52,6 +70,6 @@ } //int dist = leftEncoder.getEncoderDistance(); - //serial.printf("Encoder %d \r\n", getEncoderDistance()); + serial.printf("Encoder %d \r\n", getEncoderDistance()); } } \ No newline at end of file