Skip to content

Commit

Permalink
Make lat and lon fields in degrees
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanjma committed Mar 15, 2024
1 parent 70fa2db commit 2d1a973
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 70 deletions.
8 changes: 4 additions & 4 deletions src/ControlTasks/RadioControlTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,8 @@ void RadioControlTask::execute()

bool RadioControlTask::executeDownlink()
{
uint16_t lat = map_range_16(sfr::gps::latitude, constants::gps::lat_min, constants::gps::lat_max);
uint16_t lon = map_range_16(sfr::gps::longitude, constants::gps::lon_min, constants::gps::lon_max);
uint16_t lat = map_range_16(sfr::gps::latitude * 10, constants::gps::lat_min, constants::gps::lat_max);
uint16_t lon = map_range_16(sfr::gps::longitude * 10, constants::gps::lon_min, constants::gps::lon_max);
uint16_t alt = map_range_16(sfr::gps::altitude / 10, constants::gps::alt_min, constants::gps::alt_max);

uint8_t flags = ((sfr::radio::mode == radio_mode_type::listen) ? 0xF0 : 0x00) | (sfr::gps::valid_msg ? 0x0F : 0x00);
Expand Down Expand Up @@ -302,9 +302,9 @@ uint8_t RadioControlTask::map_range(float value, int min_val, int max_val)

uint16_t RadioControlTask::map_range_16(float value, int min_val, int max_val)
{
long raw = map(value, min_val, max_val, 0, 65536);
long raw = map(value, min_val, max_val, 0, 65535);
Serial.println(raw);
raw = min(raw, 65536);
raw = min(raw, 65535);
raw = max(raw, 0);
return (uint16_t)raw;
}
Expand Down
13 changes: 0 additions & 13 deletions src/MainControlLoop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@ MainControlLoop::MainControlLoop()
{
}

int freeRam()
{
extern int __heap_start, *__brkval;
int v;
return (int)&v - (__brkval == 0 ? (int)&__heap_start : (int)__brkval);
}

void MainControlLoop::execute()
{

Expand Down Expand Up @@ -56,9 +49,6 @@ void MainControlLoop::execute()
Serial.print("UTC Time: ");
Serial.println(sfr::gps::utc_time);

Serial.print("Free RAM: ");
Serial.println(freeRam());

#endif

temp_monitor.execute();
Expand All @@ -68,9 +58,6 @@ void MainControlLoop::execute()

wdt_reset();

// delay(5000);
// Serial.println("you should not be seeing this");

#ifdef VERBOSE
Serial.println(F("-------------------- END LOOP --------------------"));
#endif
Expand Down
45 changes: 26 additions & 19 deletions src/Monitors/GPSMonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,46 +71,52 @@ bool GPSMonitor::encode(char c)
strncpy(temp_buf, term_buffer, 10);
temp_buf[10] = '\0';
sfr::gps::utc_time = atof(temp_buf);
Serial.println(atof(temp_buf));
Serial.println(sfr::gps::utc_time);

break;
case 2: // Latitude value
{
Serial.println("Latitude val");
Serial.println("Latitude");

char temp_buf[11];
strncpy(temp_buf, term_buffer, 10);
temp_buf[10] = '\0';
// sfr::gps::latitude = atof(temp_buf);
Serial.println(atof(temp_buf));
char dd_buf[3] = {term_buffer[0], term_buffer[1], '\0'};
char mm_buf[3] = {term_buffer[2], term_buffer[3], '\0'};
// char dd_buf[3];
// char mm_buf[3];
// strncpy(dd_buf, term_buffer, 2);
// strncpy(mm_buf, term_buffer + 2, 2);
// dd_buf[2] = '\0';
// mm_buf[2] = '\0';

sfr::gps::latitude = atoi(dd_buf) + atoi(mm_buf) / 60.0;
Serial.println(sfr::gps::latitude);

break;
}
case 3: // Latitude hemisphere
{
if (term_buffer[0] == 'S') {
// sfr::gps::latitude = -sfr::gps::latitude;
// Serial.println(latitude);
sfr::gps::latitude = -sfr::gps::latitude;
Serial.println(sfr::gps::latitude);
}
break;
}
case 4: // Longitude value
{
Serial.println("Longitude val");
Serial.println("Longitude");

char ddd_buf[4] = {term_buffer[0], term_buffer[1], term_buffer[2], '\0'};
char mm_buf[3] = {term_buffer[3], term_buffer[4], '\0'};

char temp_buf[12];
strncpy(temp_buf, term_buffer, 11);
temp_buf[11] = '\0';
// sfr::gps::longitude = atof(temp_buf);
Serial.println(atof(temp_buf));
sfr::gps::longitude = atoi(ddd_buf) + atoi(mm_buf) / 60.0;
Serial.println(sfr::gps::longitude);

break;
}
case 5: // Longitude hemisphere
{
if (term_buffer[0] == 'W') {
// sfr::gps::longitude = -sfr::gps::longitude;
// Serial.println(longitude);
sfr::gps::longitude = -sfr::gps::longitude;
Serial.println(sfr::gps::longitude);
}
break;
}
Expand All @@ -121,8 +127,9 @@ bool GPSMonitor::encode(char c)
char temp_buf[char_count];
strncpy(temp_buf, term_buffer, char_count - 1);
temp_buf[char_count - 1] = '\0';
// sfr::gps::altitude = atof(temp_buf);
Serial.println(atof(temp_buf));

sfr::gps::altitude = atof(temp_buf);
Serial.println(sfr::gps::altitude);

break;
}
Expand Down
24 changes: 12 additions & 12 deletions src/Monitors/IMUMonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,19 @@ void IMUMonitor::execute()
void IMUMonitor::capture_imu_values()
{

// if (IMU.gyroscopeAvailable()) { // check if the gyroscope has new data available
// IMU.readGyroscope(
// sfr::imu::gyro_x,
// sfr::imu::gyro_y,
// sfr::imu::gyro_z); // data is in degrees/s
// }
if (IMU.gyroscopeAvailable()) { // check if the gyroscope has new data available
IMU.readGyroscope(
sfr::imu::gyro_x,
sfr::imu::gyro_y,
sfr::imu::gyro_z); // data is in degrees/s
}

// if (IMU.accelerationAvailable()) { // check if accelerometer is available
// IMU.readAcceleration(
// sfr::imu::acc_x,
// sfr::imu::acc_y,
// sfr::imu::acc_z); // data is in m/s^2
// }
if (IMU.accelerationAvailable()) { // check if accelerometer is available
IMU.readAcceleration(
sfr::imu::acc_x,
sfr::imu::acc_y,
sfr::imu::acc_z); // data is in m/s^2
}
}

void IMUMonitor::transition_to_normal()
Expand Down
6 changes: 3 additions & 3 deletions src/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ namespace constants {
constexpr int tx_pin = 3;
constexpr int buffer_size = 11;

constexpr int lat_min = -9000;
constexpr int lat_min = -9000; // In (10 * degrees)
constexpr int lat_max = 9000;
constexpr int lon_min = -18000;
constexpr int lon_min = -18000; // In (10 * degrees)
constexpr int lon_max = 18000;
constexpr int alt_min = 0;
constexpr int alt_max = 50000; // In 10's of meters
} // namespace gps
} // namespace gps
namespace opcodes {
constexpr int no_op = 0x00;
constexpr int change_downlink_period = 0x11;
Expand Down
5 changes: 1 addition & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

MainControlLoop mcl;

#ifndef UNIT_TEST

void setup()
{
wdt_disable();
Expand All @@ -16,5 +14,4 @@ void setup()
void loop()
{
mcl.execute();
}
#endif
}
18 changes: 3 additions & 15 deletions src/sfr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,8 @@ namespace sfr {

namespace imu {

// TEMP Values
float gyro_x = -250;
float gyro_y = 250;
float gyro_z = 500;

float acc_x = 30;
float acc_y = 0;
float acc_z = -50;
float gyro_x, gyro_y, gyro_z;
float acc_x, acc_y, acc_z;

bool initialized = false;
uint16_t failed_times = 0;
Expand All @@ -25,13 +19,7 @@ namespace sfr {
float temp_c;
} // namespace temperature
namespace gps {
float utc_time;

// TEMP values
float latitude = 9000;
float longitude = 18000;
float altitude = 500000;

float utc_time, latitude, longitude, altitude;
bool valid_msg = false;

} // namespace gps
Expand Down

0 comments on commit 2d1a973

Please sign in to comment.