Terrabots / Mbed 2 deprecated DUMP_TRUCK_Test

Dependencies:   LSM9DS1_Library2 MotorV2 SRF05 Tracker2 mbed nRF24L01P

Fork of DUMP_TRUCK_SPR2017 by Terrabots

Files at this revision

API Documentation at this revision

Comitter:
Josahty
Date:
Tue Nov 01 20:13:57 2016 +0000
Child:
1:90b640c90506
Commit message:
DUMP_TRUCK V4 with commented areas

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
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DumpTruck.cpp	Tue Nov 01 20:13:57 2016 +0000
@@ -0,0 +1,153 @@
+#include "DumpTruck.h"
+#include "stdlib.h"
+
+Serial pc(USBTX, USBRX);
+
+DumpTruck::DumpTruck(int truckId) : truckNumber(truckId) {
+    truckNumber = truckId;
+}
+
+PwmOut DrivePin(p24);
+DigitalOut DirPin(p30);
+int i;
+
+
+void Calibrate(){}
+
+void DumpTruck::drive() {
+    // get desired distance and speed
+    distance = 0; // placeholder
+    // speed = 0.5;
+    // distance = setTruckDistance();
+    speed = setTruckSpeed();
+    // terminal confirmation of distance and speed
+    pc.printf("Truck will drive a distance of %f at a speed of %f\r\n",distance,speed);
+    // insert while loop here which relates to distance travelled
+    while(1) {
+    // 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();
+    //
+    i = 0;
+}
+
+//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(){
+    
+      float div = 10;
+      // terminal prompt for speed
+      pc.printf("Please enter the truck speed: \n");
+      // sets return value to given value
+      float input = pc.getc();
+      while ((input<48)&&(input>57)){
+          pc.printf("Fix your input sir: \r\n");
+          float input = pc.getc();
+          }
+      input = input - 48;
+      input = input * (1/div);
+      // 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();
+//    float CurrentPivotAngle =  getPivotAngle();
+//    Difference = DesiredPivotAngle-CurrentPivotAngle;
+//    if (Difference > limit)
+//    {
+//        PivotSpeed = setPivotSpeed();
+//        pc.printf("Rotating to %s /n", DesiredPivotAngle);
+//        //Drive Motors
+//        }
+//    else
+//    {stop()}
+//    
+//}    
+//
+//void DumpTruck::BedDown() {
+//     SwitchState = bool GetBedUpperSwitch();
+//     if SwitchState
+//     {return 0;}
+//     else
+//
+//     while(SwitchState == 0)
+//     {
+//         //driveMotor
+//         }
+//         calibrate();
+//    }
+//void DumpTruck::LowerBed() {
+//    SwitchState = bool GetLowerUpperSwitch();
+//     if SwitchState
+//     {return 0;}
+//     else
+//
+//     while(SwitchState == 0)
+//     {
+//         //driveMotor
+//         }
+//         calibrate();
+//    }
+//}
+//void DumpTruck::raiseTo(int angle) {
+//      pc.printf("Desired Angle: ");
+//    DesiredBedAngle = pc.getc();
+//    float CurrentBedAngle =  getBedAngle();
+//    Difference = DesiredBedAngle-CurrentBedAngle;
+//    if (Difference > limit)
+//    {
+//        BedSpeed = setBedSpeed();
+//        pc.printf("Rotating to %s /n", DesiredBedAngle);
+//        //Drive Motors
+//        }
+//    else
+//    {stop()}
+//}
+//
+//float DumpTruck::getPivotAngle(){
+//    float input = AnalogIn(x);
+//    return input
+//    }
+//float DumpTruck::setPivotSpeed(){
+//     pc.printf("Please enter the Pivot speed /n");
+//    float input = pc.getc();
+//    return input;
+//    }
+//
+//float DumpTruck::setBedSpeed(){
+//    pc.printf("Please enter the Bed speed /n");
+//    float input = pc.getc();
+//    return input;
+//    }
+//float DumpTruck::getBedAngle(){
+//    float input = AnalogIn(x); // data from potentiometer
+//    return input;
+//    }
+//    
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DumpTruck.h	Tue Nov 01 20:13:57 2016 +0000
@@ -0,0 +1,39 @@
+#ifndef MBED_DUMP_TRUCK_H
+#define MBED_DUMP_TRUCK_H
+ 
+#include "mbed.h"
+
+class DumpTruck {
+public:
+    DumpTruck(int truckId);
+    void drive(); // Drive DC motors with a desired motor speed and distance
+    void stop();
+    void Calibrate();
+    //void RotateTo();
+    //void BedDown(); 
+    //void BedUp();   
+    //void raiseTo();
+    //void LowerBed();
+  
+protected:
+    int truckNumber;
+    float speed;                 // desired speed to drive the robot, a number between -1 and 1
+    float distance;              // input of desired distance to be traveled
+    float setTruckSpeed();       // set truck speed
+    float setTruckDistance();    // set distance to be traveled
+    //getBedAngle(); //Get data from Bed potentiometer, Hari is looking into the component for this
+    //getPivotAngle(double PivotAngle); //Get data from potentiometer
+    //SetPivotSpeed(double PivotSpeed); //Set arbitrary rotation of servo motor
+    //SetBedSpeed(); //Set arbitrary rotation of DC Motor
+    //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 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
+    //float PivotSpeed; //User input of desired speed for the dump truck to pivot its back at
+    
+    //bool isCalibrated;// returns 0 and 1 to check if the robot has been calibrated
+};
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Nov 01 20:13:57 2016 +0000
@@ -0,0 +1,11 @@
+#include "mbed.h"
+#include "DumpTruck.h"
+
+DigitalOut myled(LED1);
+
+
+int main() {
+    DumpTruck foo(1);
+    foo.drive();
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Nov 01 20:13:57 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/25aea2a3f4e3
\ No newline at end of file