test program

Dependencies:   LSM9DS1_Library2 MotorV2 SRF05 Tracker2 mbed nRF24L01P

Fork of DUMP_TRUCK_SPR2017 by Terrabots

Committer:
jcallahan1
Date:
Sun Apr 23 18:59:43 2017 +0000
Revision:
14:192e103d5246
Parent:
13:112b6543909a
Test for dump truck

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pvela 6:5cc6a9b6f60e 1 /**
pvela 6:5cc6a9b6f60e 2 * @file DumpTruck.h
pvela 6:5cc6a9b6f60e 3 *
simplyellow 10:cf77da9be0b8 4 * @brief DumpTruck class integrates multiple sensors into one API.
pvela 6:5cc6a9b6f60e 5 *
pvela 6:5cc6a9b6f60e 6 * @author Terrabots Team
pvela 6:5cc6a9b6f60e 7 *
pvela 6:5cc6a9b6f60e 8 */
pvela 6:5cc6a9b6f60e 9
Josahty 0:6942f0e2198c 10 #ifndef MBED_DUMP_TRUCK_H
Josahty 0:6942f0e2198c 11 #define MBED_DUMP_TRUCK_H
simplyellow 10:cf77da9be0b8 12
Josahty 0:6942f0e2198c 13 #include "mbed.h"
simplyellow 10:cf77da9be0b8 14 #include "Tracker.h"
simplyellow 10:cf77da9be0b8 15 //#include "IMU.h"
simplyellow 10:cf77da9be0b8 16 #include "Motor.h"
simplyellow 12:502cf4fc6d98 17 #include "nRF24L01P.h" //Transceiver library
simplyellow 10:cf77da9be0b8 18 #include "SRF05.h"
jcallahan1 14:192e103d5246 19 #include "LSM9DS1.h"
simplyellow 10:cf77da9be0b8 20
simplyellow 13:112b6543909a 21 //using strings to process commands
simplyellow 13:112b6543909a 22 #include <string>
simplyellow 13:112b6543909a 23 #include <stdio.h>
simplyellow 13:112b6543909a 24 using namespace std;
simplyellow 13:112b6543909a 25
simplyellow 12:502cf4fc6d98 26 #define TRANSFER_SIZE 8
simplyellow 12:502cf4fc6d98 27
simplyellow 10:cf77da9be0b8 28 // ADD SWITCHES & ULTRASONIC SENSOR implementation
Josahty 0:6942f0e2198c 29
pvela 7:dd3a7dcc5c84 30 /**
pvela 7:dd3a7dcc5c84 31 * @class DumpTruck
pvela 7:dd3a7dcc5c84 32 *
simplyellow 10:cf77da9be0b8 33 * @brief Interface for controlling a Dump truck.
pvela 7:dd3a7dcc5c84 34 */
simplyellow 10:cf77da9be0b8 35
Josahty 0:6942f0e2198c 36 class DumpTruck {
Josahty 0:6942f0e2198c 37 public:
pvela 6:5cc6a9b6f60e 38 /**
simplyellow 10:cf77da9be0b8 39 * Constructor for the Tracker object.
pvela 6:5cc6a9b6f60e 40 *
simplyellow 10:cf77da9be0b8 41 * @param[in] truckId The dump truck's identifier
pvela 6:5cc6a9b6f60e 42 */
Josahty 0:6942f0e2198c 43 DumpTruck(int truckId);
pvela 6:5cc6a9b6f60e 44
simplyellow 12:502cf4fc6d98 45 /*
simplyellow 13:112b6543909a 46 * Process command
simplyellow 13:112b6543909a 47 */
simplyellow 13:112b6543909a 48 void processCommand();
simplyellow 13:112b6543909a 49
simplyellow 13:112b6543909a 50 /*
simplyellow 13:112b6543909a 51 * Send not acknowledge
simplyellow 13:112b6543909a 52 */
simplyellow 13:112b6543909a 53
simplyellow 13:112b6543909a 54 void sendNack();
simplyellow 13:112b6543909a 55
simplyellow 13:112b6543909a 56 /*
simplyellow 13:112b6543909a 57 * Send acknowledge
simplyellow 13:112b6543909a 58 */
simplyellow 13:112b6543909a 59
simplyellow 13:112b6543909a 60 void sendAck();
simplyellow 13:112b6543909a 61
simplyellow 13:112b6543909a 62 /*
simplyellow 12:502cf4fc6d98 63 * Initialize transceiver.
simplyellow 12:502cf4fc6d98 64 */
simplyellow 12:502cf4fc6d98 65 void startComms();
simplyellow 12:502cf4fc6d98 66
simplyellow 12:502cf4fc6d98 67 /*
simplyellow 12:502cf4fc6d98 68 * Receive a command from base station.
simplyellow 12:502cf4fc6d98 69 */
simplyellow 12:502cf4fc6d98 70 void getCommand();
simplyellow 12:502cf4fc6d98 71
simplyellow 12:502cf4fc6d98 72 /*
simplyellow 12:502cf4fc6d98 73 * Send important data back to the base station.
simplyellow 12:502cf4fc6d98 74 */
simplyellow 12:502cf4fc6d98 75 void reportData();
simplyellow 12:502cf4fc6d98 76
simplyellow 10:cf77da9be0b8 77 // motor functions
simplyellow 10:cf77da9be0b8 78 /*
simplyellow 10:cf77da9be0b8 79 * Drive a certain distance at a desired speed.
simplyellow 10:cf77da9be0b8 80 */
simplyellow 10:cf77da9be0b8 81 void driveDistance(float speed, float distance);// frontMotor
simplyellow 10:cf77da9be0b8 82 /*
simplyellow 10:cf77da9be0b8 83 * Drive at a desired speed.
pvela 6:5cc6a9b6f60e 84 */
simplyellow 10:cf77da9be0b8 85 void drive(float speed);
simplyellow 10:cf77da9be0b8 86 /*
simplyellow 10:cf77da9be0b8 87 * Turn the rear wheels a certain angle.
pvela 6:5cc6a9b6f60e 88 */
simplyellow 10:cf77da9be0b8 89 void turn(float angle); // turnMotor
simplyellow 10:cf77da9be0b8 90 /*
simplyellow 10:cf77da9be0b8 91 * Move the dump truck's bed up/down a certain angle.
pvela 6:5cc6a9b6f60e 92 */
jcallahan1 14:192e103d5246 93 void moveBed(bool upper, bool lower, float angle); // bedMotor
simplyellow 10:cf77da9be0b8 94 /*
simplyellow 10:cf77da9be0b8 95 * Stop driving.
simplyellow 10:cf77da9be0b8 96 */
jcallahan1 14:192e103d5246 97 void stopDrive(); // all Motors
simplyellow 13:112b6543909a 98
simplyellow 13:112b6543909a 99 /*
simplyellow 13:112b6543909a 100 * Stop turning.
simplyellow 13:112b6543909a 101 */
jcallahan1 14:192e103d5246 102 void stopTurn(); // all Motors
simplyellow 13:112b6543909a 103
simplyellow 13:112b6543909a 104 /*
simplyellow 13:112b6543909a 105 * Stop bed.
simplyellow 13:112b6543909a 106 */
jcallahan1 14:192e103d5246 107 void stopBed(); // all Motors
pvela 6:5cc6a9b6f60e 108
simplyellow 10:cf77da9be0b8 109 // ultrasonic functions
simplyellow 10:cf77da9be0b8 110 /*
simplyellow 10:cf77da9be0b8 111 * Read from the ultrasonic sensor and determine the dump truck's
simplyellow 10:cf77da9be0b8 112 * proximity from objects.
pvela 6:5cc6a9b6f60e 113 */
simplyellow 10:cf77da9be0b8 114 bool detect(); // returns bool for object too close
simplyellow 13:112b6543909a 115
simplyellow 13:112b6543909a 116 int txDataCnt;
simplyellow 13:112b6543909a 117 int rxDataCnt;
simplyellow 13:112b6543909a 118 char txData[TRANSFER_SIZE], rxData[TRANSFER_SIZE];
simplyellow 13:112b6543909a 119 char acked[TRANSFER_SIZE];
simplyellow 13:112b6543909a 120 char nacked[TRANSFER_SIZE];
simplyellow 13:112b6543909a 121 bool received;
pvela 6:5cc6a9b6f60e 122
pvela 6:5cc6a9b6f60e 123
Josahty 0:6942f0e2198c 124 protected:
simplyellow 10:cf77da9be0b8 125 Tracker *track;
simplyellow 10:cf77da9be0b8 126 //IMU *bed;
simplyellow 10:cf77da9be0b8 127 Motor *frontMotor;
simplyellow 10:cf77da9be0b8 128 Motor *turnMotor;
simplyellow 10:cf77da9be0b8 129 Motor *bedMotor;
simplyellow 12:502cf4fc6d98 130 nRF24L01P *nrf; //Transceiver *nrf;
simplyellow 10:cf77da9be0b8 131 SRF05 *srf;
jcallahan1 14:192e103d5246 132 LSM9DS1 *IMU;
simplyellow 10:cf77da9be0b8 133
simplyellow 10:cf77da9be0b8 134 // add direct control for motor, switch, and ultrasonic sensor.
simplyellow 10:cf77da9be0b8 135
Josahty 0:6942f0e2198c 136 int truckNumber;
simplyellow 10:cf77da9be0b8 137
simplyellow 10:cf77da9be0b8 138 // motor variables
simplyellow 10:cf77da9be0b8 139 float speed; // drive
simplyellow 10:cf77da9be0b8 140 float distance; // drive
jcallahan1 14:192e103d5246 141 float startDist; // drive
jcallahan1 14:192e103d5246 142 float curDist; // drive
simplyellow 10:cf77da9be0b8 143 float potAngle; // turn
simplyellow 10:cf77da9be0b8 144 float bedAngle; // bed
simplyellow 10:cf77da9be0b8 145
simplyellow 10:cf77da9be0b8 146 // bed-specific variables
simplyellow 10:cf77da9be0b8 147 bool switchState; // BusIn the two limit switches
jcallahan1 14:192e103d5246 148 float ax0;
jcallahan1 14:192e103d5246 149 float ay0;
jcallahan1 14:192e103d5246 150 float az0;
jcallahan1 14:192e103d5246 151 float ax;
jcallahan1 14:192e103d5246 152 float ay;
jcallahan1 14:192e103d5246 153 float az;
simplyellow 10:cf77da9be0b8 154
simplyellow 10:cf77da9be0b8 155 // ultrasonic-specific variables
simplyellow 10:cf77da9be0b8 156 bool tooClose;
simplyellow 10:cf77da9be0b8 157 float proximity;
simplyellow 12:502cf4fc6d98 158
simplyellow 13:112b6543909a 159 /*int txDataCnt;
simplyellow 12:502cf4fc6d98 160 int rxDataCnt;
simplyellow 12:502cf4fc6d98 161 char txData[TRANSFER_SIZE], rxData[TRANSFER_SIZE];
simplyellow 13:112b6543909a 162 bool received;*/
Josahty 0:6942f0e2198c 163 };
simplyellow 5:dc4cf6cc24b3 164 #endif