Merge pull request #79 from alanbjohnston/bp-gps

Bp gps
bp
alanbjohnston 5 years ago committed by GitHub
commit 2c4420e637
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -94,6 +94,7 @@ void config_x25();
void trans_x25();
int upper_digit(int number);
int lower_digit(int number);
float toAprsFormat(float input);
static int init_rf();
int socket_open = 0;
int sock = 0;
@ -138,7 +139,7 @@ int sampleTime = 0, frames_sent = 0;
int cw_id = ON;
int vB4 = FALSE, vB5 = FALSE, vB3 = FALSE, ax5043 = FALSE, transmit = FALSE, onLed, onLedOn, onLedOff, txLed, txLedOn, txLedOff, payload = OFF;
float batteryThreshold = 3.0, batteryVoltage;
float latitude = 39.027702f, longitude = -77.078064f;
float latitude = 39.027702f, longitude = -77.078064f; // 100x for now
float lat_file, long_file;
float axis[3], angle[3], volts_max[3], amps_max[3], batt, speed, period, tempS, temp_max, temp_min, eclipse;
@ -210,8 +211,10 @@ mode = AFSK;
if ((fabs(lat_file) > 0) && (fabs(lat_file) < 90.0) && (fabs(long_file) > 0) && (fabs(long_file) < 180.0)) {
printf("Valid latitude and longitude in config file\n");
latitude = lat_file;
longitude = long_file;
// convert to APRS DDMM.MM format
latitude = toAprsFormat(lat_file);
longitude = toAprsFormat(long_file);
printf("Lat/Long in APRS DDMM.MM format: %f/%f\n", latitude, longitude);
}
wiringPiSetup();
@ -370,7 +373,7 @@ mode = AFSK;
for (i = 0; i < 2; i++) {
serialPutchar(uart_fd, 'R');
printf("Querying payload with R to reset\n");
waitTime = millis() + 500;
waitTime = millis() + 5000; // increased from 500 with GPS
while ((millis() < waitTime) && (payload != ON)) {
if (serialDataAvail(uart_fd)) {
printf("%c", c = (char) serialGetchar(uart_fd));
@ -824,7 +827,7 @@ void get_tlm(void) {
char header_str4[] = "hi hi ";
char footer_str1[] = "\' > t.txt && echo \'";
// char footer_str[] = ">CQ:010101/hi hi ' >> t.txt && gen_packets -o telem.wav t.txt -r 48000 > /dev/null 2>&1 && cat telem.wav | csdr convert_i16_f | csdr gain_ff 7000 | csdr convert_f_samplerf 20833 | sudo /home/pi/rpitx/rpitx -i- -m RF -f 434.9e3 > /dev/null 2>&1";
char footer_str[] = ">CQ:010101/hi hi ' >> t.txt && gen_packets -o telem.wav t.txt -r 48000 > /dev/null 2>&1 && cat telem.wav | csdr convert_i16_f | csdr gain_ff 7000 | csdr convert_f_samplerf 20833 | sudo /home/pi/rpitx/rpitx -i- -m RF -f 144.29e3 > /dev/null 2>&1";
char footer_str[] = ">CQ:010101/hi hi ' >> t.txt && gen_packets -o telem.wav t.txt -r 48000 > /dev/null 2>&1 && cat telem.wav | csdr convert_i16_f | csdr gain_ff 7000 | csdr convert_f_samplerf 20833 | sudo /home/pi/rpitx/rpitx -i- -m RF -f 144.39e3 > /dev/null 2>&1";
if (ax5043) {
strcpy(str, header_str);
@ -835,16 +838,19 @@ void get_tlm(void) {
strcat(str, header_str2);
// sprintf(header_str2b, "=%7.2f%c%c%c%08.2f%cShi hi ",4003.79,'N',0x5c,0x5c,07534.33,'W'); // add APRS lat and long
if (latitude > 0)
sprintf(header_lat, "%7.2f%c", latitude * 100.0, 'N'); // lat
sprintf(header_lat, "%7.2f%c", latitude, 'N'); // lat
else
sprintf(header_lat, "%7.2f%c", latitude * (-100.0), 'S'); // lat
sprintf(header_lat, "%7.2f%c", latitude * (-1.0), 'S'); // lat
if (longitude > 0)
sprintf(header_long, "%08.2f%c", longitude * 100.0, 'E'); // long
sprintf(header_long, "%08.2f%c", longitude, 'E'); // long
else
sprintf(header_long, "%08.2f%c", longitude * (-100.0), 'W'); // long
sprintf(header_long, "%08.2f%c", longitude * (-1.0), 'W'); // long
sprintf(header_str2b, "=%s%c%c%sShi hi ", header_lat, 0x5c, 0x5c, header_long); // add APRS lat and long
printf("\n\nString is %s \n\n", header_str2b);
// sprintf(header_str2b, "=%s%c%c%sShi hi ", header_lat, 0x5c, 0x5c, header_long); // APRS satellite symbol with escaped \ as \\
printf("lat: %s long: %s \n", &header_lat, &header_long);
// sprintf(header_str2b, "=3910.10N/07500.32WOhi hi %f %f", latitude, longitude); // APRS balloon symbol
sprintf(header_str2b, "=%s%c%s%chi hi ", &header_lat, '/', &header_long, 'O'); // APRS balloon symbol
printf("\n\nString is %s \n\n", &header_str2b);
strcat(str, header_str2b);
} else {
strcat(str, header_str4);
@ -913,6 +919,30 @@ void get_tlm(void) {
printf("Payload string: %s", sensor_payload);
strcat(str, sensor_payload); // append to telemetry string for transmission
// parse sensor payload
float sensor[17];
if ((sensor_payload[0] == 'O') && (sensor_payload[1] == 'K')) // only process if valid payload response
{
int count1;
char * token;
const char space[2] = " ";
token = strtok(sensor_payload, space);
for (count1 = 0; count1 < 17; count1++) {
if (token != NULL) {
sensor[count1] = (float) atof(token);
#ifdef DEBUG_LOGGING
printf("sensor: %f ", sensor[count1]);
#endif
token = strtok(NULL, space);
}
}
printf("\n");
if (sensor[XS1] != 0)
latitude = toAprsFormat(sensor[XS1]);
if (sensor[XS2] != 0)
longitude = toAprsFormat(sensor[XS2]);
}
}
digitalWrite(txLed, txLedOn);
@ -1972,3 +2002,12 @@ int test_i2c_bus(int bus)
}
return(output); // return bus number or -1 if there is a problem with the bus
}
float toAprsFormat(float input) {
// converts decimal coordinate (lattitude or longitude) to APRS DDMM.MM format
int dd = (int) input;
int mm1 = (int)((input - dd) * 60.0);
int mm2 = (int)((input - dd - (float)mm1/60.0) * 60.0 * 60.0);
float output = dd * 100 + mm1 + (float)mm2 * 0.01;
return(output);
}

@ -1,10 +1,3 @@
// Payload software for CubeSatSim STEM Payload Board
// Arduino software for STM32 or Arduino Pro Micro
//
// BME280 code based on
// MPU6050 code based on
// GPS code based on TinyGPS simple_test example
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
@ -19,14 +12,13 @@ MPU6050 mpu6050(Wire);
TinyGPS gps;
long timer = 0;
int bmePresent = 0;
int mpuPresent = 0;
int bmePresent;
int RXLED = 17; // The RX LED has a defined Arduino pin
int greenLED = 9;
int blueLED = 8;
float Sensor1 = 0.0;
float Sensor2 = 0.0;
float Sensor3 = 0.0;
float Sensor1 = 0;
float Sensor2 = 0;
float Sensor3 = 0;
void eeprom_word_write(int addr, int val);
short eeprom_word_read(int addr);
float lat = 0.0, lon = 0.0, alt = 0.0;
@ -48,23 +40,13 @@ void setup() {
blink(500);
delay(250);
/**/
if (bme.begin(0x76)) {
bmePresent = 1;
} else {
Serial.println("Could not find a valid BME280 sensor, check wiring!");
bmePresent = 0;
}
/**/
Wire.beginTransmission(0x68);
// Serial.print(address, HEX);
byte error = Wire.endTransmission();
if (error == 0)
mpuPresent = 1;
else
Serial.println("Could not find a valid MPU6050 sensor, check wiring!");
/**/
if (mpuPresent) {
/*
mpu6050.begin();
if (eeprom_word_read(0) == 0xA07)
@ -97,9 +79,7 @@ if (mpuPresent) {
Serial.println(((float)eeprom_word_read(2)) / 100.0, DEC);
Serial.println(((float)eeprom_word_read(3)) / 100.0, DEC);
}
}
pinMode(greenLED, OUTPUT);
pinMode(blueLED, OUTPUT);
*/
}
void loop() {
@ -130,10 +110,7 @@ void loop() {
{
Serial.print("OK BME280 0.0 0.0 0.0 0.0");
}
if (mpuPresent) {
mpu6050.update();
// mpu6050.update();
Serial.print(" MPU6050 ");
Serial.print(mpu6050.getGyroX());
@ -148,9 +125,6 @@ void loop() {
Serial.print(mpu6050.getAccY());
Serial.print(" ");
Serial.print(mpu6050.getAccZ());
} else {
Serial.print(" MPU6050 0.0 0.0 0.0 0.0 0.0 0.0");
}
Serial.print(" XS ");
Serial.print(Sensor1);
@ -158,16 +132,31 @@ void loop() {
Serial.print(Sensor2);
Serial.print(" ");
Serial.println(Sensor3);
/*
Serial.print(" GPS "); // return previous GPS data (can't wait due to 1 sec delay)
Serial.print(lat);
Serial.print(" ");
Serial.print(lon);
Serial.print(" ");
Serial.println(alt);
*/
/*
bool newData = false;
unsigned long chars;
unsigned short sentences, failed;
// For one second we parse GPS data and report some key values
for (unsigned long start = millis(); millis() - start < 1000;) // 1000;)
{
while (Serial2.available())
{
char c = Serial2.read();
// Serial.write(c); // uncomment this line if you want to see the GPS data flowing
if (gps.encode(c)) // Did a new valid sentence come in?
newData = true;
}
}
if (newData)
{
float flon, flat;
unsigned long age;
gps.f_get_position(&flat, &flon, &age);
Sensor1 = flat;
Sensor2 = flon;
Sensor3 = (float) gps.altitude()/100.0;
}
float rotation = sqrt(mpu6050.getGyroX()*mpu6050.getGyroX() + mpu6050.getGyroY()*mpu6050.getGyroY() + mpu6050.getGyroZ()*mpu6050.getGyroZ());
float acceleration = sqrt(mpu6050.getAccX()*mpu6050.getAccX() + mpu6050.getAccY()*mpu6050.getAccY() + mpu6050.getAccZ()*mpu6050.getAccZ());
// Serial.print(rotation);
@ -183,7 +172,6 @@ void loop() {
digitalWrite(blueLED, HIGH);
else
digitalWrite(blueLED, LOW);
*/
}
}
@ -214,8 +202,7 @@ void loop() {
{
Serial1.print("OK BME280 0.0 0.0 0.0 0.0");
}
if (mpuPresent) {
mpu6050.update();
// mpu6050.update();
Serial1.print(" MPU6050 ");
Serial1.print(mpu6050.getGyroX());
@ -230,21 +217,14 @@ void loop() {
Serial1.print(mpu6050.getAccY());
Serial1.print(" ");
Serial1.print(mpu6050.getAccZ());
} else {
Serial1.print(" MPU6050 0.0 0.0 0.0 0.0 0.0 0.0");
}
Serial1.print(" XS ");
Serial1.print(Sensor1);
Serial1.print(" ");
Serial1.print(Sensor2);
Serial1.print(" ");
Serial1.print(Sensor3);
// Serial1.println(" GPS 0.0 0.0");
Serial1.println(Sensor3);
}
}
bool newData = false;
unsigned long chars;
unsigned short sentences, failed;
@ -265,21 +245,11 @@ void loop() {
float flon, flat;
unsigned long age;
gps.f_get_position(&flat, &flon, &age);
Sensor1 = flat * 100;
Sensor2 = flon * 100;
Sensor1 = flat;
Sensor2 = flon;
Sensor3 = (float) gps.altitude()/100.0;
/*
Serial.print("LAT=");
Serial.print(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flat, 6);
Serial.print(" LON=");
Serial.print(flon == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flon, 6);
Serial.print(" SAT=");
Serial.print(gps.satellites() == TinyGPS::GPS_INVALID_SATELLITES ? 0 : gps.satellites());
Serial.print(" PREC=");
Serial.print(gps.hdop() == TinyGPS::GPS_INVALID_HDOP ? 0 : gps.hdop());
*/
}
float rotation = sqrt(mpu6050.getGyroX()*mpu6050.getGyroX() + mpu6050.getGyroY()*mpu6050.getGyroY() + mpu6050.getGyroZ()*mpu6050.getGyroZ());
float acceleration = sqrt(mpu6050.getAccX()*mpu6050.getAccX() + mpu6050.getAccY()*mpu6050.getAccY() + mpu6050.getAccZ()*mpu6050.getAccZ());
// Serial.print(rotation);
@ -295,6 +265,9 @@ void loop() {
digitalWrite(blueLED, HIGH);
else
digitalWrite(blueLED, LOW);
}
}
// delay(100);
}
@ -341,6 +314,6 @@ void blink(int length)
#if defined __AVR_ATmega32U4__
digitalWrite(RXLED, HIGH); // set the RX LED OFF
TXLED0; //TX LED macro to turn LED ON
TXLED0; //TX LED is not tied to a normally controlled pin so a macro is needed, turn LED OFF
#endif
}

Loading…
Cancel
Save

Powered by TurnKey Linux.