Main repository for dump truck API development in Spring 2017
Dependencies: Tracker mbed MotorV2 SRF05 nRF24L01P
Fork of DUMP_TRUCK_TEST_V1 by
Activities
This Week
If needed, please contact Milo Pan at mpan9@gatech.edu for rights and access to this repository.
Diff: DumpTruck.cpp
- Revision:
- 12:502cf4fc6d98
- Parent:
- 11:87f30625b213
- Child:
- 13:112b6543909a
diff -r 87f30625b213 -r 502cf4fc6d98 DumpTruck.cpp --- a/DumpTruck.cpp Tue Mar 14 20:10:27 2017 +0000 +++ b/DumpTruck.cpp Thu Mar 30 17:27:21 2017 +0000 @@ -9,9 +9,61 @@ //turnMotor = new Motor(p22, p29); //bedMotor = new Motor(p23, p28); //bed = new IMU(@@@@@@@); - //nrf = new Transceiver(@@@@@@); srf = new SRF05(p15, p16); //trigger, echo. tooClose = false; + + nrf = new nRF24L01P(p5, p6, p7, p8, p9, p10); // transceiver + //transceiver set up, similar to one on base station code + txDataCnt = 0; + rxDataCnt = 0; +} + +void DumpTruck::startComms() { + nrf->powerUp(); + printf( "nRF24L01+ Frequency : %d MHz\r\n", nrf->getRfFrequency() ); + printf( "nRF24L01+ Output power : %d dBm\r\n", nrf->getRfOutputPower() ); + printf( "nRF24L01+ Data Rate : %d kbps\r\n", nrf->getAirDataRate() ); + printf( "nRF24L01+ TX Address : 0x%010llX\r\n", nrf->getTxAddress() ); + printf( "nRF24L01+ RX Address : 0x%010llX\r\n", nrf->getRxAddress() ); + nrf->setTransferSize( TRANSFER_SIZE ); + nrf->setReceiveMode(); + nrf->enable(); + received = false; +} + +void DumpTruck::getCommand() { + received = false; + //called at the end of each executable command + //print statement saying dump truck is ready to receive + //have print statement appear in base station code + //dump truck transceiver sends a code to base station, opening the channel + //code is all 0's + for(int i = 0; i < TRANSFER_SIZE; i++) { + txData[i] = 0; + } + nrf->write(NRF24L01P_PIPE_P0, txData, TRANSFER_SIZE); + //possibly implement kill switch/stop current action + //... + //code for receiving + while(!received) { + if (nrf->readable() ) { + rxDataCnt = nrf->read(NRF24L01P_PIPE_P0, rxData, sizeof(rxData)); + /* + either go char by char to determine command or switch statement + for ( int j = 0; rxDataCnt > 0; rxDataCnt--, i++ ) { + + pc.putc( rxData[j] ); + }*/ + } + //received = true after receiving command + } + //switch statement, sorting all commands + +} + +void DumpTruck::reportData() { + //should run last in main thread + } void DumpTruck::driveDistance(float speed, float distance) {