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: Tracker mbed MotorV2 SRF05 nRF24L01P
Fork of DUMP_TRUCK_TEST_V1 by
Revision 12:502cf4fc6d98, committed 2017-03-30
- Comitter:
- simplyellow
- Date:
- Thu Mar 30 17:27:21 2017 +0000
- Parent:
- 11:87f30625b213
- Child:
- 13:112b6543909a
- Commit message:
- began work on transceiver
Changed in this revision
--- 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) {
--- a/DumpTruck.h Tue Mar 14 20:10:27 2017 +0000
+++ b/DumpTruck.h Thu Mar 30 17:27:21 2017 +0000
@@ -14,9 +14,11 @@
#include "Tracker.h"
//#include "IMU.h"
#include "Motor.h"
-//#include "Transceiver.h"
+#include "nRF24L01P.h" //Transceiver library
#include "SRF05.h"
+#define TRANSFER_SIZE 8
+
// ADD SWITCHES & ULTRASONIC SENSOR implementation
/**
@@ -34,6 +36,21 @@
*/
DumpTruck(int truckId);
+ /*
+ * 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.
@@ -70,7 +87,7 @@
Motor *frontMotor;
Motor *turnMotor;
Motor *bedMotor;
- //Transceiver *nrf;
+ nRF24L01P *nrf; //Transceiver *nrf;
SRF05 *srf;
// add direct control for motor, switch, and ultrasonic sensor.
@@ -89,5 +106,10 @@
// ultrasonic-specific variables
bool tooClose;
float proximity;
+
+ int txDataCnt;
+ int rxDataCnt;
+ char txData[TRANSFER_SIZE], rxData[TRANSFER_SIZE];
+ bool received;
};
#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/commands.h Thu Mar 30 17:27:21 2017 +0000 @@ -0,0 +1,1 @@ +#define DR \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nRF24L01P.lib Thu Mar 30 17:27:21 2017 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/Owen/code/nRF24L01P/#8ae48233b4e4
