test program
Dependencies: LSM9DS1_Library2 MotorV2 SRF05 Tracker2 mbed nRF24L01P
Fork of DUMP_TRUCK_SPR2017 by
Diff: DumpTruck.cpp
- Revision:
- 10:cf77da9be0b8
- Parent:
- 6:5cc6a9b6f60e
- Child:
- 11:87f30625b213
--- a/DumpTruck.cpp Tue Feb 14 14:46:37 2017 -0500 +++ b/DumpTruck.cpp Tue Feb 28 21:11:48 2017 +0000 @@ -1,17 +1,48 @@ #include "DumpTruck.h" -/*#include "stdlib.h" -#include "stdio.h" -#include "string.h"*/ - -//Serial pc(USBTX, USBRX); DumpTruck::DumpTruck(int truckId) : truckNumber(truckId) { truckNumber = truckId; + track = new Tracker(p29, p30, p15); + // PWM: 21, 22, 23 + // DIR: 27, 28, 29 + frontMotor = new Motor(p21, p27); + turnMotor = new Motor(p22, p28); + bedMotor = new Motor(p23, p29); + //bed = new IMU(@@@@@@@); + //nrf = new Transceiver(@@@@@@); + srf = new SRF05(p15, p16); + tooClose = false; +} + +void DumpTruck::driveDistance(float speed, float distance) { + frontMotor->write(speed); +} + +void DumpTruck::drive(float speed) { + frontMotor->write(speed); } -PwmOut DrivePin(p24); -DigitalOut DirPin(p30); -float travelled; +void DumpTruck::turn(float angle) { + return; +} + +void DumpTruck::moveBed(bool raise, float angle) { + return; +} + +void DumpTruck::stop() { + frontMotor->write(0.0f); +} + +bool DumpTruck::detect() { + proximity = srf->read(); + if(proximity < 100) { //cm + tooClose = true; + } else { + tooClose = false; + } + return tooClose; +} //void Calibrate(){} @@ -30,7 +61,7 @@ // if (speed >= 0) { // DirPin = 1; // DrivePin = speed; -// } // else, go backwards at specified speed +// } // else, go backwards at specified speed // else { // DirPin = 0; // DrivePin = -1*speed; @@ -44,8 +75,7 @@ // travelled = 0; //} - -void DumpTruck::drive() { +/*void DumpTruck::drive() { // get desired distance and speed // placeholder // speed = 0.5; @@ -57,7 +87,7 @@ // insert while loop here which relates to distance travelled travelled = getDistance(); //pc.printf("Check 1: %f, %f\r\n", distance, travelled); - while(travelled < distance) { + while(travelled < distance) { //pc.printf("Check 2:\r\n"); travelled = getDistance(); pc.printf("Travelling...: %f\n\r", (distance - travelled)); @@ -65,7 +95,7 @@ if (speed >= 0) { DirPin = 1; DrivePin = speed; - } // else, go backwards at specified speed + } // else, go backwards at specified speed else { DirPin = 0; DrivePin = -1*speed; @@ -89,13 +119,13 @@ //input = input - 48; // returns value //return input; - + char c; - char buffer[128]; + char buffer[128]; pc.gets(buffer, 4); float input = strtod(buffer,NULL); return input; - + } float DumpTruck::setTruckSpeed(){ @@ -110,8 +140,8 @@ // if (dir == 48) { // mod = -1; } // else { -// mod = 1; } -// +// mod = 1; } +// // // terminal prompt for speed // pc.printf("Please enter a truck speed from 0-9 or F for full speed:\r\n"); // // sets return value to given value @@ -129,33 +159,33 @@ // input = input * (1/div); // // returns value // input = input * mod; - - - pc.printf("Enter a speed from -10 to +10:\r\n"); + + + pc.printf("Enter a speed from -10 to +10:\r\n"); char c; - char buffer[128]; + char buffer[128]; pc.gets(buffer, 4); float input = strtod(buffer,NULL); - + while ((buffer[0] < 43) || (buffer[0] > 45)) { pc.printf("Invalid input. Please correct input and try again:\r\n"); setTruckSpeed(); } - + pc.printf("buffer[0]: %d\r\n",buffer[0]); pc.printf("buffer[1]: %d\r\n",buffer[1]); pc.printf("buffer[2]: %d\r\n",buffer[2]); input = input / 10; return input;} - - + + void DumpTruck::stop(){ pc.printf("Truck will now stop.\r\n"); //stop motors DrivePin = 0; } - + float DumpTruck::getDistance() { //while(1){ pulseCount = (float) wheel.getPulses(); @@ -164,11 +194,11 @@ //pc.printf("Inches travelled: %f\n\r", travelled); return travelled; //(pulse count / X * N) * (1 / PPI) - + //} -} +}*/ -//void DumpTruck::RotateTo() { +//void DumpTruck::RotateTo() { // pc.printf("Desired Angle: "); // DesiredPivotAngle = pc.getc(); // float CurrentPivotAngle = getPivotAngle(); @@ -181,16 +211,10 @@ // } // else // {stop()} -// -//} // - -void DumpTruck::BedUp() -{ -} - -void DumpTruck::BedDown() -{ +//} +// +//void DumpTruck::BedDown() { // SwitchState = bool GetBedUpperSwitch(); // if SwitchState // {return 0;} @@ -201,10 +225,7 @@ // //driveMotor // } // calibrate(); -} - - - +// } //void DumpTruck::LowerBed() { // SwitchState = bool GetLowerUpperSwitch(); // if SwitchState @@ -218,10 +239,7 @@ // calibrate(); // } //} - - - -void DumpTruck::raiseTo(int angle) { +//void DumpTruck::raiseTo(int angle) { // pc.printf("Desired Angle: "); // DesiredBedAngle = pc.getc(); // float CurrentBedAngle = getBedAngle(); @@ -234,8 +252,7 @@ // } // else // {stop()} -} - +//} // //float DumpTruck::getPivotAngle(){ // float input = AnalogIn(x); @@ -256,7 +273,4 @@ // float input = AnalogIn(x); // data from potentiometer // return input; // } -// - -*/ - +// \ No newline at end of file