Skip to content

Commit

Permalink
Merge pull request #58 from larus-breeze/Klaus_work
Browse files Browse the repository at this point in the history
Klaus work
  • Loading branch information
MaxBaex authored Apr 6, 2023
2 parents 9a38853 + 117c972 commit 91ba1a3
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 54 deletions.
2 changes: 1 addition & 1 deletion .cproject
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<configuration artifactExtension="elf" artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.debug" cleanCommand="rm -rf" description="Release" errorParsers="org.eclipse.cdt.core.GASErrorParser;org.eclipse.cdt.core.GmakeErrorParser;org.eclipse.cdt.core.GLDErrorParser;org.eclipse.cdt.core.CWDLocator;org.eclipse.cdt.core.GCCErrorParser" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.config.exe.debug.29276544.1029160395.2017222313" name="Release" parent="com.st.stm32cube.ide.mcu.gnu.managedbuild.config.exe.debug" preannouncebuildStep="Update version info within Core/Inc/git-commit-version.h" prebuildStep="cd .. &amp;&amp; bash githooks/post-checkout">
<configuration artifactExtension="elf" artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.debug" cleanCommand="rm -rf" description="Release" errorParsers="org.eclipse.cdt.core.GASErrorParser;org.eclipse.cdt.core.GmakeErrorParser;org.eclipse.cdt.core.GLDErrorParser;org.eclipse.cdt.core.CWDLocator;org.eclipse.cdt.core.GCCErrorParser" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.config.exe.debug.29276544.1029160395.2017222313" name="Release" parent="com.st.stm32cube.ide.mcu.gnu.managedbuild.config.exe.debug" preannouncebuildStep="Update version info within Core/Inc/git-commit-version.h" prebuildStep="cd .. &amp;&amp; bash scripts/create-git-info-header.sh">
<folderInfo id="com.st.stm32cube.ide.mcu.gnu.managedbuild.config.exe.debug.29276544.1029160395.2017222313." name="/" resourcePath="">
<toolChain id="com.st.stm32cube.ide.mcu.gnu.managedbuild.toolchain.exe.debug.2038395236" name="MCU ARM GCC" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.toolchain.exe.debug">
<option id="com.st.stm32cube.ide.mcu.option.internal.toolchain.type.86626326" name="Internal Toolchain Type" superClass="com.st.stm32cube.ide.mcu.option.internal.toolchain.type" useByScannerDiscovery="false" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.toolchain.base.gnu-tools-for-stm32" valueType="string"/>
Expand Down
7 changes: 3 additions & 4 deletions Communication/communicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,12 @@ void communicator_runnable (void*)
compass_ground_calibration.feed(output_data.m.mag);
if( 0 == magnetic_ground_calibrator_countdown)
{
compass_calibration_t new_calibration;
compass_calibration_t <int64_t, float> new_calibration;
compass_ground_calibration.get_calibration_result(new_calibration.calibration);
new_calibration.calibration_done = true;
new_calibration.write_into_EEPROM();
magnetic_calibration_done.signal();
magnetic_gound_calibration = false;
magnetic_gound_calibration = false; // stop this procedure
}
}

Expand Down Expand Up @@ -251,8 +251,7 @@ void communicator_runnable (void*)
}

organizer.report_data ( output_data);
if( logger_is_enabled)
sync_logger (); // kick logger @ 100 Hz
sync_logger (); // kick logger @ 100 Hz
}
}

Expand Down
22 changes: 17 additions & 5 deletions Communication/sensor_dump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@
#include "NMEA_format.h"
#include "embedded_math.h"
#include "uSD_handler.h"
#include "pt2.h"

uint64_t pabs_sum, samples, noise_energy;
COMMON uint64_t pabs_sum, samples, noise_energy;
COMMON pt2 <float, float> heading_decimator( 0.01);
COMMON pt2 <float, float> inclination_decimator( 0.01);

#define RAD_2_DEGREES_100 5729.6f

Expand All @@ -45,6 +48,8 @@ void decimate_sensor_observations( const output_data_t &output_data)
pabs_sum += (uint64_t)(output_data.m.static_pressure);
++samples;
noise_energy += SQR( (uint64_t)(output_data.m.static_pressure + 0.5f) - pabs_sum / samples);
heading_decimator.respond( output_data.euler.y);
inclination_decimator.respond( ATAN2( output_data.nav_induction_gnss.e[DOWN], output_data.nav_induction_gnss.e[NORTH]));
}

statistics get_sensor_data( void)
Expand Down Expand Up @@ -149,11 +154,18 @@ void format_sensor_dump( const output_data_t &output_data, string_buffer_t &NMEA
s = integer_to_ascii_2_decimals( 100.0f * output_data.nav_induction_gnss.abs(), s);
s=append_string( s, "\r\n");

s=append_string( s, "Mag. Inclination: ");
float inclination = ATAN2( output_data.nav_induction_gnss.e[DOWN], output_data.nav_induction_gnss.e[NORTH]);
s = integer_to_ascii_2_decimals( RAD_2_DEGREES_100 * inclination, s);
float heading = heading_decimator.get_output();
if( heading < 0.0f)
heading += 2.0f * M_PI_F;
s=append_string( s, "True Heading= ");
s = integer_to_ascii_2_decimals( RAD_2_DEGREES_100 * heading, s);

s=append_string( s, "\r\n");
s=append_string( s, " Inclination= ");
s = integer_to_ascii_2_decimals( RAD_2_DEGREES_100 * inclination_decimator.get_output(), s);

s=append_string( s, " MagAnomaly= ");
s = integer_to_ascii_2_decimals( output_data.magnetic_disturbance * 10000.0f, s);
s=append_string( s, " %\r\n");

// here we report a fake vario value indicating the maximum magnetic field strength
if( magnetic_gound_calibration)
Expand Down
85 changes: 47 additions & 38 deletions Communication/uSD_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
**************************************************************************/

#include "system_configuration.h"
#include "system_configuration.h"
#include "main.h"
#include "FreeRTOS_wrapper.h"
#include "fatfs.h"
Expand All @@ -37,21 +37,19 @@
#include "uSD_handler.h"
#include "watchdog_handler.h"
#include "EEPROM_defaults.h"
#include "magnetic_induction_report.h"

extern Semaphore setup_file_handling_completed;
extern uint32_t UNIQUE_ID[4];
extern bool reset_by_watchdog_requested;

COMMON Queue< linear_least_square_result<float>[3] > magnetic_calibration_queue(4,"M_CALIB");
COMMON char *crashfile;
COMMON unsigned crashline;
COMMON bool logger_is_enabled;
COMMON bool magnetic_gound_calibration;
COMMON bool dump_sensor_readings;

COMMON Semaphore magnetic_calibration_done;

#if RUN_DATA_LOGGER
COMMON magnetic_induction_report_t magnetic_induction_report;

FATFS fatfs;
extern SD_HandleTypeDef hsd;
Expand Down Expand Up @@ -271,20 +269,21 @@ bool write_EEPROM_dump( const char * filename)
return FR_OK;
}

void write_magnetic_calibration_file (const coordinates_t &c)
void write_magnetic_calibration_file ( void)
{
FRESULT fresult;
FILINFO filinfo;
FIL fp;
char buffer[50];
char buffer[100];
char *next = buffer;
linear_least_square_result<float> data[3];
int32_t writtenBytes = 0;

if (false == magnetic_calibration_queue.receive (data, 0))
return;
fresult = f_stat("magnetic", &filinfo);
if( (fresult != FR_OK) || ((filinfo.fattrib & AM_DIR)==0))
return; // directory does not exist -> do not write file

next = append_string( next, "magnetic/");
next = format_date_time( next);
*next++ = (char)(data[0].id);
append_string(next, ".mcl");

fresult = f_open (&fp, buffer, FA_CREATE_ALWAYS | FA_WRITE);
Expand All @@ -294,19 +293,30 @@ void write_magnetic_calibration_file (const coordinates_t &c)
for( unsigned i=0; i<3; ++i)
{
char *next = buffer;
next = my_ftoa (next, data[i].y_offset);
*next++='\t';
next = my_ftoa (next, data[i].slope);
*next++='\t';
next = my_ftoa (next, data[i].variance_offset);
*next++='\t';
next = my_ftoa (next, data[i].variance_slope);
*next++='\t';
next = my_ftoa (next, magnetic_induction_report.calibration[i].offset);
*next++=' ';
next = my_ftoa (next, magnetic_induction_report.calibration[i].scale);
*next++=' ';
next = my_ftoa (next, SQRT( magnetic_induction_report.calibration[i].variance));
*next++=' ';
fresult = f_write (&fp, buffer, next-buffer, (UINT*) &writtenBytes);
if( (fresult != FR_OK) || (writtenBytes != (next-buffer)))
return;
}
f_write (&fp, "\r\n", 2, (UINT*) &writtenBytes);

next = buffer;
float3vector induction = magnetic_induction_report.nav_induction;
for( unsigned i=0; i<3; ++i)
{
next = my_ftoa (next, induction[i]);
*next++=' ';
}

next = my_ftoa (next, magnetic_induction_report.nav_induction_std_deviation);
*next++='\r';
*next++='\n';

f_write (&fp, buffer, next-buffer, (UINT*) &writtenBytes);
f_close(&fp);
}

Expand Down Expand Up @@ -400,9 +410,15 @@ void uSD_handler_runnable (void*)
}
}

fresult = f_open (&the_file, (char *)"enable.logger", FA_READ);
logger_is_enabled = (fresult == FR_OK);
f_close( &the_file); // as this is just a dummy file
FILINFO filinfo;
fresult = f_stat("logger", &filinfo);
if( (fresult != FR_OK) || ((filinfo.fattrib & AM_DIR)==0))
while( 1)
{
notify_take (true); // wait for synchronization by crash detection
if( crashfile)
write_crash_dump();
}

// wait until a GNSS timestamp is available.
while (output_data.c.sat_fix_type == 0)
Expand All @@ -414,21 +430,11 @@ void uSD_handler_runnable (void*)

// generate filename based on timestamp
char out_filename[30];
char * next = out_filename;
char * next = append_string( out_filename, "logger/");
next = format_date_time( next);

write_EEPROM_dump( out_filename); // now we have date+time, start logging

if( ! logger_is_enabled) // in this case we only wait for a possible crash dump
{
while( true)
{
notify_take (true); // wait for synchronization by crash detection
if( crashfile)
write_crash_dump();
}
}

*next++ = '.';
*next++ = 'f';
next = format_2_digits( next, (sizeof(coordinates_t) + sizeof(measurement_data_t)) / sizeof(float));
Expand Down Expand Up @@ -486,9 +492,8 @@ void uSD_handler_runnable (void*)
{
sync_counter = 0;
f_sync (&the_file);
#if LOG_MAGNETIC_CALIBRATION
write_magnetic_calibration_file ( output_data.c);
#endif
if( magnetic_calibration_done.wait( 0))
write_magnetic_calibration_file ();
}
}
}
Expand Down Expand Up @@ -578,4 +583,8 @@ extern "C" void handle_watchdog_trigger( void)
amok_running_task_killer.resume_from_ISR();
}

#endif
void report_magnetic_calibration_has_changed(magnetic_induction_report_t * p_magnetic_induction_report, char)
{
magnetic_induction_report = *p_magnetic_induction_report;
magnetic_calibration_done.signal();
}
1 change: 1 addition & 0 deletions Communication/uSD_handler.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef USD_HANDLER_H_
#define USD_HANDLER_H_

#include "FreeRTOS_wrapper.h"
#include "embedded_memory.h"

extern bool logger_is_enabled;
Expand Down
5 changes: 0 additions & 5 deletions Core/Inc/system_configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,8 @@
#include "persistent_data.h"
#include "git-commit-version.h"

#define RUN_DATA_LOGGER 1

#define PARALLEL_MAGNETIC_AHRS 0 // run second AHRS without SAT compass usage
#define INCLUDING_NANO 1

#define WRITE_MAG_CALIB_EEPROM 1
#define LOG_MAGNETIC_CALIBRATION 0
#define WRITE_EEPROM_DEFAULTS 0
#define USE_HARDWARE_EEPROM 1
#define WITH_DENSITY_DATA 0
Expand Down
17 changes: 17 additions & 0 deletions Core/Src/watchdog_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,18 @@
#include "system_configuration.h"
#include "main.h"
#include "FreeRTOS_wrapper.h"
#include "stm32f4xx_hal.h"

#define SD_DETECT_PIN GPIO_PIN_13
#define SD_DETECT_GPIO_PORT GPIOC

static COMMON WWDG_HandleTypeDef WwdgHandle;

bool SD_is_plugged_in( void)
{
return HAL_GPIO_ReadPin(SD_DETECT_GPIO_PORT, SD_DETECT_PIN) == GPIO_PIN_SET;
}

void heartbeat (void)
{
bool set = GPIO_PIN_SET
Expand Down Expand Up @@ -67,6 +76,8 @@ void watchdog_runnable (void*)

#endif // ACTIVATE_WATCHDOG

bool sd_was_plugged = SD_is_plugged_in();

uint8_t rythm = 0;
for (synchronous_timer t (40); true;)
{
Expand All @@ -83,6 +94,12 @@ void watchdog_runnable (void*)
watchdog_min = watchdog_actual;
#endif
HAL_WWDG_Refresh (&WwdgHandle);

if( (false == sd_was_plugged) && SD_is_plugged_in())
while( true)
; // let the watchdog reset the system

sd_was_plugged = SD_is_plugged_in();
#endif
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib
Submodule lib updated from 233ead to 4f7a94

0 comments on commit 91ba1a3

Please sign in to comment.