Main repository for dump truck API development in Spring 2017
Dependencies: Tracker mbed MotorV2 SRF05 nRF24L01P
Fork of DUMP_TRUCK_TEST_V1 by
Activities
This Week
If needed, please contact Milo Pan at mpan9@gatech.edu for rights and access to this repository.
Diff: DumpTruck.cpp
- Revision:
- 2:7811df5a6052
- Parent:
- 1:90b640c90506
- Child:
- 3:cd6e2d7c7c9c
diff -r 90b640c90506 -r 7811df5a6052 DumpTruck.cpp --- a/DumpTruck.cpp Tue Nov 01 20:19:20 2016 +0000 +++ b/DumpTruck.cpp Tue Nov 15 20:04:54 2016 +0000 @@ -9,7 +9,7 @@ PwmOut DrivePin(p24); DigitalOut DirPin(p30); -int i; +int travelled; void Calibrate(){} @@ -31,7 +31,7 @@ } // else, go backwards at specified speed else { DirPin = 0; - DrivePin = -1 * speed; + DrivePin = -1*speed; } } // stop motors @@ -39,7 +39,7 @@ // calibrate motors Calibrate(); // - i = 0; + travelled = 0; } //float DumpTruck::setTruckDistance(){ @@ -52,24 +52,41 @@ // } // float DumpTruck::setTruckSpeed(){ - + float mod = 0; float div = 10; + pc.printf("Enter a direction - 1 = forward, 0 = backward:\r\n"); + float dir = pc.getc(); + while ((dir<48)||(dir>49)){ + pc.printf("Invalid input. Please enter a valid direction, 1 or 0: \r\n"); + dir = pc.getc(); + } + if (dir == 48) { + mod = -1; } + else { + mod = 1; } + // terminal prompt for speed - pc.printf("Please enter the truck speed: \n"); + pc.printf("Please enter a truck speed from 0-9 or F for full speed:\r\n"); // sets return value to given value float input = pc.getc(); while ((input<48)||(input>57)){ - pc.printf("Fix your input sir: \r\n"); + if((input == 70) || (input == 102)) { + input = 1; + input = input * mod; + return input; + } + pc.printf("Invalid input. Please enter a valid speed from 0-9 or F: \r\n"); input = pc.getc(); } input = input - 48; input = input * (1/div); // returns value + input = input * mod; return input;} void DumpTruck::stop(){ - pc.printf("Truck will now stop."); + pc.printf("Truck will now stop.\r\n"); //stop motors DrivePin = 0; }