Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Wip]Diagnostics #336

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions scripts/connect_bluetooth.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ def get_battery_voltage(self):
self.send_bt('battery\0')
return float(self.wait_filtered()[-1])

def get_diagnostics_matrix(self):
self.filter_next(function='log_diagnostics_matrix')
self.send_bt('diagnostics_matrix\0')
return float(self.wait_filtered()[-1])

def get_configuration_variables(self):
self.filter_next(function='log_configuration_variables')
self.send_bt('configuration_variables\0')
Expand Down Expand Up @@ -251,6 +256,10 @@ def do_battery(self, *args):
"""Get battery voltage."""
print(self.proxy.get_battery_voltage())

def do_diagnostics_matrix(self, *args):
"""Get diagnostics matrix."""
print(self.proxy.get_diagnostics_matrix())

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should not have this method. It would print unintelligible characters and the output may be huge.

def do_configuration_variables(self, *args):
"""Get configuration variables."""
pprint(self.proxy.get_configuration_variables())
Expand Down
79 changes: 79 additions & 0 deletions src/diagnostics.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#include "diagnostics.h"

static volatile float log_matrix[NUM_LOG_ELEMENTS];
static volatile int log_set_index = -1;
static volatile int log_get_index = -1;
static volatile int num_elements_counter;
static volatile bool enable_diagnostics;
static volatile bool enable_read_log;

static int inc_log_set_index(void)
{
if (log_set_index == (NUM_LOG_ELEMENTS - 1)) {
log_set_index = 0;
} else {
log_set_index++;
}
LOG_INFO("%d set_index", log_set_index);
return log_set_index;
}

static int inc_log_get_index(void)
{
if (log_get_index == (NUM_LOG_ELEMENTS - 1)) {
log_get_index = 0;
} else {
log_get_index++;
}
LOG_INFO("%d get_index", log_get_index);
return log_get_index;
}

bool get_enable_diagnostics(void)
{
return enable_diagnostics;
}

void set_enable_diagnostics(bool value)
{
enable_diagnostics = value;
}

int get_log_set_index(void)
{
return log_set_index;
}

/**
* @brief Function to set the sensors distance.
*/
void set_log_matrix(void)
{
if (get_enable_diagnostics()) {
log_matrix[inc_log_set_index()] = get_front_left_distance();
}
}

/**
* @brief Function to get the sensors distance.
*
*@return The log_matrix
*/
float get_log_matrix_element(void)
{
if (num_elements_counter < NUM_LOG_ELEMENTS) {
num_elements_counter++;
return log_matrix[inc_log_get_index()];
}
return 0;
}

/**
* @brief Function to reset the buffer.
*/
void reset_log_matrix(void)
{
log_set_index = -1;
log_get_index = -1;
num_elements_counter = 0;
}
17 changes: 17 additions & 0 deletions src/diagnostics.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef __DIAGNOSTICS_H
#define __DIAGNOSTICS_H

#include "detection.h"
#include "formatting.h"

#define NUM_LOG_ELEMENTS 2000

void set_log_matrix(void);
float get_log_matrix_element(void);
void set_enable_diagnostics(bool value);
bool get_enable_diagnostics(void);
int get_log_set_index(void);
void reset_log_matrix(void);


#endif /* __DIAGNOSTICS_H */
10 changes: 10 additions & 0 deletions src/logging.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,13 @@ void log_gyro_degrees_pub(void)
{
LOG_INFO("PUB,line,gyro_degrees,%f", get_gyro_z_degrees());
}

/**
* @brief Log diagnostic matrix, published for real time.
*/
void log_diagnostic_matrix(void)
{
for (int i= 0; i < NUM_LOG_ELEMENTS; i++){
LOG_INFO("PUB,line,element,%f", get_log_matrix_element());
}
}
2 changes: 2 additions & 0 deletions src/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "battery.h"
#include "control.h"
#include "detection.h"
#include "diagnostics.h"
#include "encoder.h"
#include "formatting.h"
#include "move.h"
Expand All @@ -26,5 +27,6 @@ void log_walls_detection(void);
void log_gyro_raw_pub(void);
void log_gyro_dps_pub(void);
void log_gyro_degrees_pub(void);
void log_diagnostic_matrix(void);

#endif /* __LOGGING_H */
21 changes: 18 additions & 3 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "clock.h"
#include "control.h"
#include "detection.h"
#include "diagnostics.h"
#include "eeprom.h"
#include "encoder.h"
#include "hmi.h"
Expand Down Expand Up @@ -29,6 +30,7 @@ void sys_tick_handler(void)
update_gyro_readings();
update_encoder_readings();
motor_control();
set_log_matrix();
}

/**
Expand Down Expand Up @@ -165,11 +167,24 @@ int main(void)
setup();
set_speed_mode(0, false);
systick_interrupt_enable();
competition();
/* LOG_INFO("diagnostics disabled, index %d", get_log_set_index());
sleep_seconds(1);
LOG_INFO("diagnostics enabled, index %d", get_log_set_index());
set_enable_diagnostics(true);
sleep_seconds(0.01);
LOG_INFO("diagnostics disabled, index %d", get_log_set_index());
set_enable_diagnostics(false);
sleep_seconds(1);
LOG_INFO("diagnostics disabled, index %d", get_log_set_index());*/
log_diagnostic_matrix();
//competition();
while (1) {
if (button_left_read_consecutive(500))
/* if (button_left_read_consecutive(500))
training();
execute_commands();
execute_commands();*/
// LOG_INFO("%d",get_log_matrix());
//sleep_seconds(0.1);

}

return 0;
Expand Down
2 changes: 2 additions & 0 deletions src/serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ static void process_command(void)
run_static_turn_right_profile_signal = true;
else if (!strcmp(buffer.data, "run front_sensors_calibration"))
run_front_sensors_calibration_signal = true;
else if (!strcmp(buffer.data, "get diagnostics_matrix"))
log_diagnostic_matrix();
else if (starts_with("move "))
strcpy(run_movement_sequence_signal, buffer.data);
else if (starts_with("set micrometers_per_count "))
Expand Down