test program

Dependencies:   LSM9DS1_Library2 MotorV2 SRF05 Tracker2 mbed nRF24L01P

Fork of DUMP_TRUCK_SPR2017 by Terrabots

DumpTruck.h

Committer:
simplyellow
Date:
2017-04-13
Revision:
13:112b6543909a
Parent:
12:502cf4fc6d98
Child:
14:192e103d5246

File content as of revision 13:112b6543909a:

/**
*   @file   DumpTruck.h
*
*   @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 "nRF24L01P.h" //Transceiver library
#include "SRF05.h"

//using strings to process commands
#include <string> 
#include <stdio.h>
using namespace std;

#define TRANSFER_SIZE   8

// ADD SWITCHES & ULTRASONIC SENSOR implementation

/**
*   @class DumpTruck
*
*   @brief  Interface for controlling a Dump truck.
*/

class DumpTruck {
public:
    /**
    *   Constructor for the Tracker object.
    *
    *   @param[in]  truckId     The dump truck's identifier
    */
    DumpTruck(int truckId);

    /*
    *   Process command
    */
    void processCommand();

    /*
    *   Send not acknowledge
    */

    void sendNack();

    /*
    *   Send acknowledge
    */

    void sendAck();
    
    /*
    *   Initialize transceiver.
    */
    void startComms();
    
    /*
    *   Receive a command from base station.
    */
    void getCommand();
    
    /*
    *   Send important data back to the base station.
    */
    void reportData();

    // motor functions
    /*
    *   Drive a certain distance at a desired speed.
    */
    void driveDistance(float speed, float distance);// frontMotor
    /*
    *   Drive at a desired speed.
    */
    void drive(float speed);
    /*
    *   Turn the rear wheels a certain angle.
    */
    void turn(float angle);                 // turnMotor
    /*
    *   Move the dump truck's bed up/down a certain angle.
    */
    void moveBed(bool raise, float angle);  // bedMotor
    /*
    *   Stop driving.
    */
    int stopDrive();                            // all Motors
    
    /*
    *   Stop turning.
    */
    int stopTurn();                            // all Motors

    /*
    *   Stop bed.
    */
    int stopBed();                            // all Motors

    // ultrasonic functions
    /*
    *   Read from the ultrasonic sensor and determine the dump truck's
    *   proximity from objects.
    */
    bool detect();                          // returns bool for object too close
    
    int txDataCnt;
    int rxDataCnt;
    char txData[TRANSFER_SIZE], rxData[TRANSFER_SIZE];
    char acked[TRANSFER_SIZE];
    char nacked[TRANSFER_SIZE]; 
    bool received;


protected:
    Tracker *track;
    //IMU *bed;
    Motor *frontMotor;
    Motor *turnMotor;
    Motor *bedMotor;
    nRF24L01P *nrf; //Transceiver *nrf;
    SRF05 *srf;

    // add direct control for motor, switch, and ultrasonic sensor.

    int truckNumber;

    // 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;
    
    /*int txDataCnt;
    int rxDataCnt;
    char txData[TRANSFER_SIZE], rxData[TRANSFER_SIZE];
    bool received;*/
};
#endif