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: mbed
DumpTruck.cpp
00001 #include "DumpTruck.h" 00002 00003 DumpTruck::DumpTruck(int truckId) : truckNumber(truckId) { 00004 truckNumber = truckId; 00005 } 00006 00007 PwmOut DrivePin(p22); 00008 DigitalOut DirPin(p29); 00009 00010 void Calibrate(){} 00011 00012 void DumpTruck::drive() { 00013 // get desired distance and speed 00014 distance = setTruckDistance(); 00015 speed = setTruckSpeed(); 00016 // terminal confirmation of distance and speed 00017 pc.printf("Truck will drive a distance of %f at a speed of %f",distance,speed); 00018 00019 // insert while loop here which relates to distance travelled 00020 00021 // if the speed is greater than zero, go forward at specified speed 00022 if (speed >= 0) { 00023 DirPin = 1; 00024 DrivePin = speed; 00025 } // else, go backwards at specified speed 00026 else { 00027 DirPin = 0; 00028 DrivePin = -1 * speed; 00029 } 00030 // stop motors 00031 stop(); 00032 // calibrate motors 00033 Calibrate(); 00034 } 00035 00036 float DumpTruck::setTruckDistance(){ 00037 // terminal prompt for distance 00038 pc.printf("Please enter the truck distance:"); 00039 // sets return value to given value 00040 float input = pc.getc(); 00041 // returns value 00042 return input; 00043 } 00044 00045 float DumpTruck::setTruckSpeed(){ 00046 // terminal prompt for speed 00047 pc.printf("Please enter the truck speed:"); 00048 // sets return value to given value 00049 float input = pc.getc(); 00050 // returns value 00051 return input; 00052 } 00053 00054 void DumpTruck::stop(){ 00055 pc.printf("Truck will now stop."); 00056 //stop motors 00057 DrivePin = 0; 00058 } 00059 00060 void DumpTruck::RotateTo() { 00061 pc.printf("Desired Angle: "); 00062 DesiredPivotAngle = pc.getc(); 00063 float CurrentPivotAngle = getPivotAngle(); 00064 Difference = DesiredPivotAngle-CurrentPivotAngle; 00065 if (Difference > limit) 00066 { 00067 PivotSpeed = setPivotSpeed(); 00068 pc.printf("Rotating to %s /n", DesiredPivotAngle); 00069 //Drive Motors 00070 } 00071 else 00072 {stop()} 00073 00074 } 00075 00076 void DumpTruck::BedDown() { 00077 SwitchState = bool GetBedUpperSwitch(); 00078 if SwitchState 00079 {return 0;} 00080 else 00081 00082 while(SwitchState == 0) 00083 { 00084 //driveMotor 00085 } 00086 calibrate(); 00087 } 00088 void DumpTruck::LowerBed() { 00089 SwitchState = bool GetLowerUpperSwitch(); 00090 if SwitchState 00091 {return 0;} 00092 else 00093 00094 while(SwitchState == 0) 00095 { 00096 //driveMotor 00097 } 00098 calibrate(); 00099 } 00100 } 00101 void DumpTruck::raiseTo(int angle) { 00102 pc.printf("Desired Angle: "); 00103 DesiredBedAngle = pc.getc(); 00104 float CurrentBedAngle = getBedAngle(); 00105 Difference = DesiredBedAngle-CurrentBedAngle; 00106 if (Difference > limit) 00107 { 00108 BedSpeed = setBedSpeed(); 00109 pc.printf("Rotating to %s /n", DesiredBedAngle); 00110 //Drive Motors 00111 } 00112 else 00113 {stop()} 00114 } 00115 00116 float DumpTruck::getPivotAngle(){ 00117 float input = AnalogIn(x); 00118 return input 00119 } 00120 float DumpTruck::setPivotSpeed(){ 00121 pc.printf("Please enter the Pivot speed /n"); 00122 float input = pc.getc(); 00123 return input; 00124 } 00125 00126 float DumpTruck::setBedSpeed(){ 00127 pc.printf("Please enter the Bed speed /n"); 00128 float input = pc.getc(); 00129 return input; 00130 } 00131 float DumpTruck::getBedAngle(){ 00132 float input = AnalogIn(x); // data from potentiometer 00133 return input; 00134 } 00135 00136
Generated on Fri Jul 22 2022 08:02:34 by
1.7.2