Skip to content

Commit

Permalink
update serialize
Browse files Browse the repository at this point in the history
  • Loading branch information
cameron-goddard committed Mar 5, 2024
1 parent 98c3a50 commit a8f16d1
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 25 deletions.
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ board = atmega328p
build_flags = -D VERBOSE
upload_protocol = custom
upload_speed = 19200
upload_command = avrdude -C /Users/camerongoddard/Library/Arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/etc/avrdude.conf -P /dev/cu.usbmodem1301 -b 19200 -v -V -p atmega328p -c stk500v1 $UPLOAD_FLAGS -U flash:w:$SOURCE:i
upload_command = avrdude -C /Users/camerongoddard/Library/Arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/etc/avrdude.conf -P /dev/cu.usbmodem21301 -b 19200 -v -V -p atmega328p -c stk500v1 $UPLOAD_FLAGS -U flash:w:$SOURCE:i
31 changes: 21 additions & 10 deletions src/ControlTasks/RadioControlTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,23 +259,23 @@ void RadioControlTask::execute()

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

uint8_t flags = ((sfr::radio::mode == radio_mode_type::listen) ? 0xF0 : 0x00) | (sfr::gps::valid_msg ? 0x0F : 0x00);

uint8_t dlink[] = {
(uint8_t)(lat >> 8), (uint8_t)lat,
(uint8_t)(lon >> 8), (uint8_t)lon,
(uint8_t)(alt >> 8), (uint8_t)alt,
(uint8_t)round(map(sfr::imu::gyro_x, constants::imu::gyro_min, constants::imu::gyro_max, 0, 255)),
(uint8_t)round(map(sfr::imu::gyro_y, constants::imu::gyro_min, constants::imu::gyro_max, 0, 255)),
(uint8_t)round(map(sfr::imu::gyro_z, constants::imu::gyro_min, constants::imu::gyro_max, 0, 255)),
(uint8_t)round(map(sfr::imu::acc_x, constants::imu::acc_min, constants::imu::acc_max, 0, 255)),
(uint8_t)round(map(sfr::imu::acc_y, constants::imu::acc_min, constants::imu::acc_max, 0, 255)),
(uint8_t)round(map(sfr::imu::acc_z, constants::imu::acc_min, constants::imu::acc_max, 0, 255)),
(uint8_t)round(map(sfr::temperature::temp_c, constants::temperature::min, constants::temperature::max, 0, 255)),
map_range(sfr::imu::gyro_x, constants::imu::gyro_min, constants::imu::gyro_max),
map_range(sfr::imu::gyro_y, constants::imu::gyro_min, constants::imu::gyro_max),
map_range(sfr::imu::gyro_z, constants::imu::gyro_min, constants::imu::gyro_max),
map_range(sfr::imu::acc_x, constants::imu::acc_min, constants::imu::acc_max),
map_range(sfr::imu::acc_y, constants::imu::acc_min, constants::imu::acc_max),
map_range(sfr::imu::acc_z, constants::imu::acc_min, constants::imu::acc_max),
map_range(sfr::temperature::temp_c, constants::temperature::min, constants::temperature::max),
flags};

#ifdef VERBOSE
Expand All @@ -288,6 +288,17 @@ bool RadioControlTask::executeDownlink()
return transmit(dlink, sizeof(dlink));
}

uint8_t RadioControlTask::map_range(float value, int min, int max) {
long raw = map(value, min, max, 0, 255);
if (raw > 255) {
raw = 255;
}
if (raw < 0) {
raw = 0;
}
return (uint8_t)raw;
}

void RadioControlTask::processUplink()
{

Expand Down
1 change: 1 addition & 0 deletions src/ControlTasks/RadioControlTask.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class RadioControlTask
bool transmit(uint8_t *packet, uint8_t size);
bool receive();
bool executeDownlink();
uint8_t map_range(float value, int min, int max);
void processUplink();
uint8_t *received;
};
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
8 changes: 6 additions & 2 deletions src/sfr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ namespace sfr {

namespace imu {

float gyro_x, gyro_y, gyro_z;
float gyro_x = -250;
float gyro_y = 250;
float gyro_z = 500;

float acc_x, acc_y, acc_z;
float acc_x = 30;
float acc_y = -30;
float acc_z = -50;

bool initialized = false;
uint16_t failed_times = 0;
Expand Down

0 comments on commit a8f16d1

Please sign in to comment.