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: LSM9DS1_Library2 MotorV2 SRF05 Tracker2 mbed nRF24L01P
Fork of DUMP_TRUCK_SPR2017 by
Revision 10:cf77da9be0b8, committed 2017-02-28
- Comitter:
- simplyellow
- Date:
- Tue Feb 28 21:11:48 2017 +0000
- Parent:
- 8:9c94865bd087
- Child:
- 11:87f30625b213
- Commit message:
- updated dump truck class configured to test the dump truck's driving and object sensing capability.
Changed in this revision
--- 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
--- a/DumpTruck.h Tue Feb 14 14:46:37 2017 -0500
+++ b/DumpTruck.h Tue Feb 28 21:11:48 2017 +0000
@@ -1,110 +1,93 @@
/**
* @file DumpTruck.h
*
-* @brief DumpTruck class implements API for commanding the dump truck and
-* for implementing proprioceptive sensing.
+* @brief DumpTruck class integrates multiple sensors into one API.
*
* @author Terrabots Team
*
*/
-
#ifndef MBED_DUMP_TRUCK_H
#define MBED_DUMP_TRUCK_H
-
+
#include "mbed.h"
+#include "Tracker.h"
+//#include "IMU.h"
+#include "Motor.h"
+//#include "Transceiver.h"
+#include "SRF05.h"
+
+// ADD SWITCHES & ULTRASONIC SENSOR implementation
/**
* @class DumpTruck
*
-* @brief Interface for controlling a Dump Truck configured "robot."
+* @brief Interface for controlling a Dump truck.
*/
+
class DumpTruck {
public:
-
/**
- * Constructor for the DumpTruck object.
+ * Constructor for the Tracker object.
*
- * @param[in] truckId Not sure.
+ * @param[in] truckId The dump truck's identifier
*/
DumpTruck(int truckId);
- /**
- * Command the dump truck to drive with a desired sped for a specified
- * distance.
- *
- * @param[in] mSpeed The desired motor speed.
- * @param[in] dDist The desired driver distance.
+ // motor functions
+ /*
+ * Drive a certain distance at a desired speed.
+ */
+ void driveDistance(float speed, float distance);// frontMotor
+ /*
+ * Drive at a desired speed.
*/
- void drive(); // Drive DC motors with a desired motor speed and distance
-
- /**
- * Command the dump truck to stop.
- *
+ void drive(float speed);
+ /*
+ * Turn the rear wheels a certain angle.
*/
- void stop();
-
- /**
- * Perform calibration routine. It will ... FILL OUT
- *
+ void turn(float angle); // turnMotor
+ /*
+ * Move the dump truck's bed up/down a certain angle.
*/
- void Calibrate();
+ void moveBed(bool raise, float angle); // bedMotor
+ /*
+ * Stop driving.
+ */
+ void stop(); // all Motors
- /**
- * WHAT IS THIS ABOUT?
- *
- */
- //void RotateTo();
-
- /**
- * Move the bed to the fully down position. The down switch should
- * engage.
- *
+ // ultrasonic functions
+ /*
+ * Read from the ultrasonic sensor and determine the dump truck's
+ * proximity from objects.
*/
- void BedDown();
-
- /**
- * Move the bed to the fully up position. The up switch should
- * engage.
- *
- */
- void BedUp();
-
- /**
- * Raise the bed to the desired angle. Only effective if the bed angle
- * estimate has been zeroed out.
- *
- */
- //void raiseTo();
+ bool detect(); // returns bool for object too close
- /**
- * NOT SURE. HOW DIFFERENT FROM ABOVE? raiseTo should raise to any
- * arbitrary angle within limits.
- *
- */
- //void LowerBed();
-
-
protected:
+ Tracker *track;
+ //IMU *bed;
+ Motor *frontMotor;
+ Motor *turnMotor;
+ Motor *bedMotor;
+ //Transceiver *nrf;
+ SRF05 *srf;
+
+ // add direct control for motor, switch, and ultrasonic sensor.
+
int truckNumber;
- float speed; // desired speed to drive the robot, a number between -1 and 1
- float distance;
- float getDistance(); // 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
+
+ // motor variables
+ float speed; // drive
+ float distance; // drive
+ float potAngle; // turn
+ float bedAngle; // bed
+
+ // bed-specific variables
+ bool switchState; // BusIn the two limit switches
+
+ // ultrasonic-specific variables
+ bool tooClose;
+ float proximity;
};
#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Motor.lib Tue Feb 28 21:11:48 2017 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/teams/Terrabots/code/MotorV2/#e87768d3cd09
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SRF05.lib Tue Feb 28 21:11:48 2017 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/simon/code/SRF05/#e758665e072c
--- a/main.cpp Tue Feb 14 14:46:37 2017 -0500
+++ b/main.cpp Tue Feb 28 21:11:48 2017 +0000
@@ -1,71 +1,18 @@
-#include "mbed.h"
-
-// Define buttons
-InterruptIn button_red(p5);
-InterruptIn button_green(p6);
-InterruptIn button_blue(p7);
-
-// Define LED colors
-PwmOut led_red(p21);
-PwmOut led_green(p22);
-PwmOut led_blue(p23);
-
-// Interrupt Service Routine to increment the red color
-void inc_red() {
+#include "DumpTruck.h"
+DumpTruck dump(1);
- float pwm;
-
- // Read in current PWM value and increment it
- pwm = led_red.read();
- pwm += 0.1f;
- if (pwm > 1.0f) {
- pwm = 0.0f;
- }
- led_red.write(pwm);
-}
-
-// Interrupt Service Routine to increment the green color
-void inc_green() {
-
- float pwm;
+/*
+test code for driving and stopping when an object gets too close
+to the dump truck.
+*/
- // Read in current PWM value and increment it
- pwm = led_green.read();
- pwm += 0.1f;
- if (pwm > 1.0f) {
- pwm = 0.0f;
- }
- led_green.write(pwm);
-}
-
-// Interrupt Service Routine to increment the blue color
-void inc_blue() {
-
- float pwm;
-
- // Read in current PWM value and increment it
- pwm = led_blue.read();
- pwm += 0.1f;
- if (pwm > 1.0f) {
- pwm = 0.0f;
+int main() {
+ while(1) {
+ if(dump.detect()) {
+ dump.stop();
+ } else {
+ dump.drive(0.5f);
+ }
}
- led_blue.write(pwm);
+
}
-
-// Main loop
-int main() {
-
- // Initialize all LED colors as off
- led_red.write(0.0f);
- led_green.write(0.0f);
- led_blue.write(0.0f);
-
- // Define three interrupts - one for each color
- button_red.fall(&inc_red);
- button_green.fall(&inc_green);
- button_blue.fall(&inc_blue);
-
- // Do nothing! We wait for an interrupt to happen
- while(1) {
- }
-}
