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.
Dependencies: Tracker mbed MotorV2 SRF05 nRF24L01P
Fork of DUMP_TRUCK_TEST_V1 by
Revision 2:7811df5a6052, committed 2016-11-15
- Comitter:
- Josahty
- Date:
- Tue Nov 15 20:04:54 2016 +0000
- Parent:
- 1:90b640c90506
- Child:
- 3:cd6e2d7c7c9c
- Commit message:
- corrected drive function
Changed in this revision
| DumpTruck.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- 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;
}
