aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcel van Workum <Marcel.vanWorkum@gmail.com>2016-06-18 16:10:06 +1200
committerGitHub <noreply@github.com>2016-06-18 16:10:06 +1200
commit3a3820cf0a6c97aad136bd0532715c0012f2781d (patch)
treed7d6c4601bf16941e7da4bbe7f012ba63255ea36
parent52eb6adda3a3846e017932d610eaa3c673dbc46a (diff)
parent68b76135f011fc4b683b4baa36008f93e4bbef6e (diff)
downloadmetis-1-onboard-structure_update.tar.gz
metis-1-onboard-structure_update.tar.bz2
metis-1-onboard-structure_update.zip
Merge pull request #7 from team-rocket-vuw/radio-commsstructure_update
Basic radio comms
-rw-r--r--README.md5
-rw-r--r--test_flight_basic_logging/test_flight_basic_logging.ino87
2 files changed, 72 insertions, 20 deletions
diff --git a/README.md b/README.md
index f15eb97..45f0abb 100644
--- a/README.md
+++ b/README.md
@@ -4,6 +4,9 @@ A repo containing code for the teams initial flight. This has no control over th
Code used with the MPU-9825 board was found in this repo: https://github.com/kriswiner/MPU-9250
Included is a libraries folder, which must be copied into the Arduino global libraries folder for this code to run.
-This code also requires the TinyGPS++ library. More information here http://arduiniana.org/libraries/tinygpsplus/
+This code requires the TinyGPS++ library. More information here http://arduiniana.org/libraries/tinygpsplus/
+
+This code requires the now deprecated RF22 library found here http://www.airspayce.com/mikem/arduino/RF22/index.html
+Note: the use of a deprecated library is not ideal, however for initial implementation the use of naive radio is required, where the SDR on the ground station does not send back an acknowledge.
To run, build circuit and upload code to Teensy of other Arduino compatable microcontroller, with pin numbers adjusted in code to suit your circuit.
diff --git a/test_flight_basic_logging/test_flight_basic_logging.ino b/test_flight_basic_logging/test_flight_basic_logging.ino
index 7c9f06c..552ba30 100644
--- a/test_flight_basic_logging/test_flight_basic_logging.ino
+++ b/test_flight_basic_logging/test_flight_basic_logging.ino
@@ -44,6 +44,17 @@
#include <SPI.h>
#include <MPU9250_helper.h>
#include <TinyGPS++.h>
+#include <RF22.h>
+
+// REGION RFM22B
+#define RCS 9
+#define radioIntPin 0
+
+RF22 rf22(RCS, radioIntPin);
+
+
+uint8_t radioDataBuffer[64];
+// END REGION
// REGION GPS
#define gpsSerial Serial3
@@ -52,19 +63,6 @@ TinyGPSPlus gps;
boolean gpsLocked = false;
// END REGION
-// REGION CONFIGURATION
-uint8_t OSR = ADC_8192;
-int8_t Ascale = AFS_16G;
-int8_t Gscale = GFS_250DPS;
-int8_t Mscale = MFS_16BITS; // Choose either 14-bit or 16-bit magnetometer resolution
-int8_t Mmode = 0x02; // 2 for 8Hz, 6 for 100Hz continuous
-
-boolean serialDebug = true;
-
-const int sdChipSelect = 10;
-const int radioChipSelect = 9;
-// END REGION
-
// REGION SENSOR FIELDS
uint16_t Pcal[8]; // calibration constants from MS5637 PROM registers
unsigned char nCRC; // calculated check sum to ensure PROM integrity
@@ -102,11 +100,28 @@ int writeCount = 0;
String dataBuffer = "";
// END REGION
+// REGION CONFIGURATION
+uint8_t OSR = ADC_8192;
+int8_t Ascale = AFS_16G;
+int8_t Gscale = GFS_250DPS;
+int8_t Mscale = MFS_16BITS; // Choose either 14-bit or 16-bit magnetometer resolution
+int8_t Mmode = 0x02; // 2 for 8Hz, 6 for 100Hz continuous
+
+boolean serialDebug = false;
+
+const int sdChipSelect = 10;
+const int radioChipSelect = 9;
+// END REGION
+
MPU9250_helper helper(Ascale, Gscale, Mscale, Mmode);
void setup() {
gpsSerial.begin(9600);
+ pinMode(radioIntPin, INPUT);
+ pinMode(9, OUTPUT);
+ pinMode(10, OUTPUT);
+
Wire1.begin(I2C_MASTER, 0x00, I2C_PINS_29_30, I2C_PULLUP_EXT, I2C_RATE_400);
if (serialDebug) {
@@ -119,6 +134,7 @@ void setup() {
setupMPU9250();
setupAK8963();
setupMS5637();
+ setupRFM22B();
// Block if not initialised properly (Also set LED state)
while (!initialiseOK);
@@ -181,10 +197,14 @@ void loop() {
printData(String(millis()) + ",\n");
if (gps.location.isUpdated()) {
- // TODO: Change this to utilise radio
+ sendViaRadio(getGPSString());
}
}
+// -------------------------------------------------
+// Setup functions
+// -------------------------------------------------
+
void setupMPU9250() {
printData("Reading who-am-i byte of MPU9250\n");
byte c = helper.readByte(MPU9250_ADDRESS, WHO_AM_I_MPU9250); // Read WHO_AM_I register for MPU-9250
@@ -238,7 +258,7 @@ void setupSD() {
} else {
// Detect init file on card
// Same number of init files as there are data files
- Serial.println("Initialising card");
+ printData("Initialising card");
int fileCount = 1;
(initFileName + String(fileCount) + ".txt").toCharArray(fileNameBuffer, 20);
while(SD.exists(fileNameBuffer)) {
@@ -284,6 +304,19 @@ void setupMS5637(){
altInit = true;
}
+void setupRFM22B() {
+ if (!rf22.init()) {
+ initialiseOK = false;
+ printData("\nRFM22B failed to initialise\n");
+ } else {
+ printData("\nRFM22B initialisation success\n");
+ }
+}
+
+// -------------------------------------------------
+// Data processing functions
+// -------------------------------------------------
+
float getAltitude(){
if (!altInit || altitudeCount == 256) {
D1 = helper.MS5637Read(ADC_D1, OSR); // get raw pressure value
@@ -329,6 +362,13 @@ float getAltitude(){
return altitudeBuffer;
}
+String getLogString(float x, float y, float z) {
+ return (String(x, DEC) + "," + String(y, DEC) + "," + String(z, DEC) + ",");
+}
+
+String getGPSString() {
+ return (String(gps.location.lat(), 6) + "," + String(gps.location.lng(), 6) + "," + String(gps.altitude.meters()) + ",");
+}
// -------------------------------------------------
// Utility functions
@@ -356,11 +396,20 @@ void printData(String data) {
}
}
-String getLogString(float x, float y, float z) {
- return (String(x, DEC) + "," + String(y, DEC) + "," + String(z, DEC) + ",");
+boolean sendViaRadio(String dataString) {
+ getArrayFromString(dataString, radioDataBuffer);
+ boolean success = rf22.send(radioDataBuffer, sizeof(radioDataBuffer));
+ if (success) {
+ rf22.waitPacketSent();
+ }
+ return success;
}
-String getGPSString() {
- return (String(gps.location.lat(), 6) + "," + String(gps.location.lng(), 6) + "," + String(gps.altitude.meters()) + ",");
+void getArrayFromString(String in, uint8_t * dest) {
+ uint8_t out[in.length()];
+ for (uint8_t i = 0; i < in.length(); i++) {
+ out[i] = (uint8_t) in.charAt(i);
+ }
+ dest = out;
}