Skip to content

Commit

Permalink
🔧 adds config in demo file
Browse files Browse the repository at this point in the history
  • Loading branch information
acarrou committed Oct 2, 2023
1 parent 21a11d2 commit 3882abe
Showing 1 changed file with 64 additions and 48 deletions.
112 changes: 64 additions & 48 deletions demos/applications/telemetry-recorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <libhal-util/spi.hpp>

#include "../hardware_map.hpp"
#include<telemetry-recorder/telemetry-recorder.hpp>
#include <telemetry-recorder/telemetry-recorder.hpp>

hal::status application(hardware_map& p_map)
{
Expand All @@ -36,77 +36,93 @@ hal::status application(hardware_map& p_map)
auto spi2 = HAL_CHECK(hal::lpc40::spi::get(2));
auto chip_select = HAL_CHECK(hal::lpc40::output_pin::get(1, 8));

hal::print(console, "Demo Telemetry Recorder Starting...\n\n");

// Device initialization
auto micro_sd =
HAL_CHECK(hal::microsd::microsd_card::create(spi2, chip_select));
(void)hal::delay(clock, 200ms);
auto neoGPS = HAL_CHECK(hal::neo::neo_GPS::create(gps));
(void)hal::delay(clock, 200ms);
auto xbee_module = HAL_CHECK(hal::xbee::xbee_radio::create(xbee));
(void)hal::delay(clock, 200ms);
auto mpl_device = HAL_CHECK(hal::mpl::mpl3115a2::create(i2c));
(void)hal::delay(clock, 200ms);
auto icm_device = HAL_CHECK(hal::icm::icm20948::create(i2c, 0x69));
(void)hal::delay(clock, 200ms);
hal::delay(clock, 500ms);

xbee_module.configure_xbee("C", "2015"); // Channel C, PANID 2015
// device configuration
icm_device.auto_offsets();

int8_t alt_offset = 0;
mpl_device.set_altitude_offset(alt_offset);
// Set sea level pressure to 30 Hg
float slp = 101325; // Default is 101325 Pa

mpl_device.set_sea_pressure(slp);

xbee_module.configure_xbee("C", "2015"); // Channel C, PANID 2015

auto telemetry_recorder =
HAL_CHECK(hal::telemetry_recorder::telemetry_recorder::create(
icm_device, neoGPS, mpl_device, micro_sd, xbee_module));
hal::delay(clock, 500ms);

hal::print(console, "Demo Telemetry Recorder Starting...\n\n");

while (true) {
hal::delay(clock, 500ms);
hal::print(console, "\n=================== Data ===================\n");
auto telemetry_recorder_data = HAL_CHECK(telemetry_recorder.record());

char telem_data[512];
snprintf(telem_data, sizeof(telem_data),
"G-Accel Values: x = %fg, y = %fg, z = %fg\n"
"Gyro Values: x = %f, y = %f, z = %f\n"
"IMU Temperature: %f°C\n"
"Barometer Temperature: % f°C\n"
"Measured Pressure: %fPa\n"
"Barometer Measured Altitude: %fm\n"
"Latitude: %f\n"
"Longitude: %f\n"
"Number of satellites seen: %d\n"
"Altitude: %f meters\n"
"Time: %f\n",
telemetry_recorder_data.accel_x,
telemetry_recorder_data.accel_y,
telemetry_recorder_data.accel_z,
telemetry_recorder_data.gyro_x,
telemetry_recorder_data.gyro_y,
telemetry_recorder_data.gyro_z,
telemetry_recorder_data.imu_temp,
telemetry_recorder_data.baro_temp,
telemetry_recorder_data.baro_pressure,
telemetry_recorder_data.baro_altitude,
telemetry_recorder_data.gps_lat,
telemetry_recorder_data.gps_long,
telemetry_recorder_data.gps_sats,
telemetry_recorder_data.gps_alt,
telemetry_recorder_data.gps_time
);

hal::delay(clock, 100ms);

char telem_data[512];
snprintf(telem_data,
sizeof(telem_data),
"G-Accel Values: x = %fg, y = %fg, z = %fg\n"
"Gyro Values: x = %f, y = %f, z = %f\n"
"IMU Temperature: %f°C\n"
"Barometer Temperature: % f°C\n"
"Measured Pressure: %fPa\n"
"Barometer Measured Altitude: %fm\n"
"Latitude: %f\n"
"Longitude: %f\n"
"Number of satellites seen: %d\n"
"Altitude: %f meters\n"
"Time: %f\n",
telemetry_recorder_data.accel_x,
telemetry_recorder_data.accel_y,
telemetry_recorder_data.accel_z,
telemetry_recorder_data.gyro_x,
telemetry_recorder_data.gyro_y,
telemetry_recorder_data.gyro_z,
telemetry_recorder_data.imu_temp,
telemetry_recorder_data.baro_temp,
telemetry_recorder_data.baro_pressure,
telemetry_recorder_data.baro_altitude,
telemetry_recorder_data.gps_lat,
telemetry_recorder_data.gps_long,
telemetry_recorder_data.gps_sats,
telemetry_recorder_data.gps_alt,
telemetry_recorder_data.gps_time);

hal::print<512>(console, telem_data);

hal::print(console, "============================================\n\n");

hal::print(console, "Transmitting Data to Ground Station...\n\n");
telemetry_recorder.transmit("Here is some data!\n");
telemetry_recorder.transmit(telem_data);
hal::print(console, "Transmitting Data to Ground Station...\n\n");
telemetry_recorder.transmit("Here is some data!\n");
telemetry_recorder.transmit(telem_data);

hal::print(console, "Storing Data to SD Card...\n\n");
telemetry_recorder.store(telem_data);
hal::delay(clock, 500ms);
hal::print(console, "Storing Data to SD Card...\n\n");
telemetry_recorder.store(telem_data);

hal::print(console, "Recieveing Data from Ground Station...\n\n");
auto recieved_data = HAL_CHECK(telemetry_recorder.recieve());
hal::print(console, "\n=================== RECIEVED DATA ===================\n");
hal::print(console, recieved_data);
hal::print(console, "======================================================\n\n");
hal::print(console, "Recieveing Data from Ground Station...\n\n");
auto recieved_data = HAL_CHECK(telemetry_recorder.recieve());
hal::print(console,
"\n=================== RECIEVED DATA ===================\n");
hal::print(console, recieved_data);
hal::print(console,
"======================================================\n\n");
}

return hal::success();
}

0 comments on commit 3882abe

Please sign in to comment.