new version
Dependencies: mbed
Revision 3:844e9730b38e, committed 2016-10-25
- Comitter:
- Josahty
- Date:
- Tue Oct 25 20:35:43 2016 +0000
- Parent:
- 2:35282815cbea
- Commit message:
- Updated drive functions, edited syntax, added comments
Changed in this revision
| DumpTruck.cpp | Show annotated file Show diff for this revision Revisions of this file |
| DumpTruck.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/DumpTruck.cpp Tue Oct 25 20:05:12 2016 +0000
+++ b/DumpTruck.cpp Tue Oct 25 20:35:43 2016 +0000
@@ -4,16 +4,59 @@
truckNumber = truckId;
}
+PwmOut DrivePin(p22);
+DigitalOut DirPin(p29);
+
void Calibrate(){}
+
void DumpTruck::drive() {
+ // get desired distance and speed
+ distance = setTruckDistance();
speed = setTruckSpeed();
- distance = setTruckDistance(); //converts input to appropriate numher of rotations using encoder
- pc.printf("drive %f at %f",distance,speed);
- //Drive Motors
- stop();
- calibrate();
+ // terminal confirmation of distance and speed
+ pc.printf("Truck will drive a distance of %f at a speed of %f",distance,speed);
+
+ // insert while loop here which relates to distance travelled
+
+ // if the speed is greater than zero, go forward at specified speed
+ if (speed >= 0) {
+ DirPin = 1;
+ DrivePin = speed;
+ } // else, go backwards at specified speed
+ else {
+ DirPin = 0;
+ DrivePin = -1 * speed;
+ }
+ // stop motors
+ stop();
+ // calibrate motors
+ Calibrate();
}
+float DumpTruck::setTruckDistance(){
+ // terminal prompt for distance
+ pc.printf("Please enter the truck distance:");
+ // sets return value to given value
+ float input = pc.getc();
+ // returns value
+ return input;
+ }
+
+float DumpTruck::setTruckSpeed(){
+ // terminal prompt for speed
+ pc.printf("Please enter the truck speed:");
+ // sets return value to given value
+ float input = pc.getc();
+ // returns value
+ return input;
+ }
+
+void DumpTruck::stop(){
+ pc.printf("Truck will now stop.");
+ //stop motors
+ DrivePin = 0;
+ }
+
void DumpTruck::RotateTo() {
pc.printf("Desired Angle: ");
DesiredPivotAngle = pc.getc();
@@ -69,16 +112,7 @@
else
{stop()}
}
-float setTruckSpeed(){
- pc.printf("Please enter the truck speed");
- float input = pc.getc();
- return input;
- }
-float setTruckDistance(){
- pc.printf("Please enter the truck distance");
- float input = pc.getc();
- return input;
- }
+
float DumpTruck::getPivotAngle(){
float input = AnalogIn(x);
return input
@@ -99,7 +133,4 @@
return input;
}
-void DumpTruck::stop(){
- pc.printf("STOP");
- //stop motors
- }
+
--- a/DumpTruck.h Tue Oct 25 20:05:12 2016 +0000
+++ b/DumpTruck.h Tue Oct 25 20:35:43 2016 +0000
@@ -30,8 +30,6 @@
bool GetBedUpperSwitch(); //Checks if bed is all the way up
bool GetBedLowerSwitch(); //Checks if bed is all the way down
bool SwitchState; //Switch state variable for Up and down bed functions
- float distance; //desired distance to have the robot drive
- float speed; //value between 0 and 1 times the full speed of the robot
float DesiredPivotAngle; // User Input of desired angle for the bed to be pivoted
float DesiredBedAngle; //User Input of desired bed angle to be raised.
float BedSpeed; //User input of desired speed for the dump truck's bed to rotate