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

feat/can for obstacle detector #199

Merged
merged 9 commits into from
Oct 11, 2024
Merged
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
10 changes: 8 additions & 2 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
Checks: |
-*,

bugprone-*,
clang-analyzer-*,
cppcoreguidelines-*,
misc-*,
readability-*,
-readability-identifier-length,

-clang-analyzer-optin.core.EnumCastOutOfRange,
-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling,
-cppcoreguidelines-avoid-non-const-global-variables,
-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling
-cppcoreguidelines-macro-to-enum,
-misc-include-cleaner,
-readability-identifier-length

WarningsAsErrors: '*'
HeaderFilterRegex: '.*, -subprojects'
FormatStyle: file
Expand Down
4 changes: 3 additions & 1 deletion .clangd
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
CompileFlags:
Add:
- -ferror-limit=0
- -Wno-gnu-zero-variadic-macro-arguments # Suppress FFF macro warnings
# Suppress FFF macro warnings
- -Wno-gnu-zero-variadic-macro-arguments
- -Wno-c23-extensions
9 changes: 1 addition & 8 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,10 @@ on:

jobs:
build:
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: '3.11'

- name: Cache python venv
uses: actions/cache@v4
with:
Expand Down Expand Up @@ -48,6 +44,3 @@ jobs:

- name: Build documentation
run: meson compile -C build docs

- name: Build release
run: meson compile -C build release
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Board applications utilize [FreeRTOS](https://www.freertos.org/).

This project is built using [Meson](https://mesonbuild.com/) with the Ninja backend.

Supported OS: Ubuntu 22.04. If you're using Windows, you can utilize the Ubuntu 22.04 [WSL](https://learn.microsoft.com/en-us/windows/wsl/) distribution.
Supported OS: Ubuntu 24.04. If you're using Windows, you can utilize the Ubuntu 24.04 [WSL](https://learn.microsoft.com/en-us/windows/wsl/) distribution.

### Build Steps

Expand Down
4 changes: 2 additions & 2 deletions apps/battery-monitor/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "ck-data.h"
#include "freertos-tasks.h"
#include "peripherals.h"
#include "rover.h"
#include "rover-defs.h"

// CK
#include "ck-types.h"
Expand Down Expand Up @@ -50,7 +50,7 @@ void mayor_init(void) {
ck_data_init();
ck_data_t *ck_data = get_ck_data();

uint32_t city_address = ROVER_BATTERY_MONITOR_ID;
uint32_t city_address = ROVER_CITY_BATTERY_MONITOR;

ck_id_t ck_id;

Expand Down
2 changes: 1 addition & 1 deletion apps/battery-monitor/tests/battery-fakes.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ DEFINE_FAKE_VALUE_FUNC(power_state_t, get_vbat_power_state)
DEFINE_FAKE_VALUE_FUNC(power_state_t, get_reg_out_power_state)
DEFINE_FAKE_VALUE_FUNC(int, read_file, file_t *)
DEFINE_FAKE_VALUE_FUNC(int, write_file_async, const file_t *)
// NOLINTEND

void reset_fakes(void) {
FFF_FAKES_LIST(RESET_FAKE);
FFF_RESET_HISTORY();
}
// NOLINTEND
4 changes: 2 additions & 2 deletions apps/brake/src/ck.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "wheel-speed.h"

// Libs
#include "rover.h"
#include "rover-defs.h"

// STM32Common
#include "device-id.h"
Expand Down Expand Up @@ -43,7 +43,7 @@ void mayor_init(void) {
ck_data_init();
ck_data_t *ck_data = get_ck_data();

uint32_t city_address = ROVER_WHEEL_FRONT_LEFT_ID;
uint32_t city_address = ROVER_CITY_WHEEL_FRONT_LEFT;

ck_id_t ck_id;

Expand Down
4 changes: 4 additions & 0 deletions apps/brake/src/report.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ void report(void *unused) {
xTimerChangePeriod(timer, report_period_ms, portMAX_DELAY);
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);

if (ck_get_action_mode() == CK_ACTION_MODE_FREEZE) {
continue;
}

if (ck_send_document(ck_data->wheel_speed_folder->folder_no) != CK_OK) {
printf("failed to send doc.\r\n");
}
Expand Down
2 changes: 1 addition & 1 deletion apps/obstacle-detector/include/adc.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ extern "C" {
#include <stdint.h>

#define ADC1_NUM_CHANNELS 4
#define ADC_NUM_SAMPLES 10
#define ADC_NUM_SAMPLES 100

typedef struct {
uint16_t adc1_buf[ADC1_NUM_CHANNELS];
Expand Down
45 changes: 45 additions & 0 deletions apps/obstacle-detector/include/ck-data.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#ifndef CK_DATA_H
#define CK_DATA_H

#ifdef __cplusplus
extern "C" {
#endif

#include "ck-types.h"

#define CK_DATA_TX_PAGE_COUNT 1
#define CK_DATA_TX_DOC_COUNT 1
#define CK_DATA_LIST_COUNT 2
#define CK_DATA_TX_FOLDER_COUNT 1
#define CK_DATA_RX_FOLDER_COUNT 1
#define CK_DATA_FOLDER_COUNT \
(2 + CK_DATA_TX_FOLDER_COUNT + CK_DATA_RX_FOLDER_COUNT)

typedef struct {
ck_page_t pages[CK_DATA_TX_PAGE_COUNT];
ck_document_t docs[CK_DATA_TX_DOC_COUNT];
ck_list_t lists[CK_DATA_LIST_COUNT];
ck_folder_t folders[CK_DATA_FOLDER_COUNT];

// Convenience pointers
ck_list_t *tx_list;
ck_list_t *rx_list;

ck_page_t *object_distance_page;

// Transmit
ck_folder_t *object_distance_folder;

// Receive
ck_folder_t *set_report_freq_folder;

} ck_data_t;

void ck_data_init(void);
ck_data_t *get_ck_data(void);

#ifdef __cplusplus
}
#endif

#endif /* CK_DATA_H */
16 changes: 16 additions & 0 deletions apps/obstacle-detector/include/ck.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef CK_H
#define CK_H

#ifdef __cplusplus
extern "C" {
#endif

#include <stdint.h>

void init_ck_task(uint8_t priority);

#ifdef __cplusplus
} /* extern "C" */
#endif

#endif /* end of include guard: CK_H */
16 changes: 16 additions & 0 deletions apps/obstacle-detector/include/obstacle-detector.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef OBSTACLE_DETECTOR_H
#define OBSTACLE_DETECTOR_H

#ifdef __cplusplus
extern "C" {
#endif

#include <stdint.h>

void init_obstacle_detector_task(uint8_t priority);

#ifdef __cplusplus
} /* extern "C" */
#endif

#endif /* end of include guard: OBSTACLE_DETECTOR_H */
19 changes: 19 additions & 0 deletions apps/obstacle-detector/include/report.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef REPORT_H
#define REPORT_H

#ifdef __cplusplus
extern "C" {
#endif

#include <stdint.h>

#include "ck-types.h"

void init_report_task(uint8_t priority);
int process_report_freq_letter(const ck_letter_t *letter);

#ifdef __cplusplus
} /* extern "C" */
#endif

#endif /* end of include guard: REPORT_H */
4 changes: 4 additions & 0 deletions apps/obstacle-detector/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ obstacle_detector_inc = include_directories('include')

obstacle_detector_src = files(
'src' / 'adc.c',
'src' / 'ck.c',
'src' / 'ck-data.c',
'src' / 'interrupts.c',
'src' / 'main.c',
'src' / 'obstacle-detector.c',
'src' / 'peripherals.c',
'src' / 'report.c',
)

obstacle_detector_elf = executable(
Expand Down
11 changes: 7 additions & 4 deletions apps/obstacle-detector/src/adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,21 @@ void adc_average_samples(adc_reading_t *average,
sum_adc1[i % ADC1_NUM_CHANNELS] += samples->adc1_buf[i];
}

for (uint8_t j = 0; j < ADC1_NUM_CHANNELS; j++) {
average->adc1_buf[j] = sum_adc1[j] / ADC_NUM_SAMPLES;
for (uint32_t i = 0; i < ADC1_NUM_CHANNELS; i++) {
average->adc1_buf[i] = sum_adc1[i] / ADC_NUM_SAMPLES;
}
}

// Datasheet says multiply by 6 for 10-bit ADC.
// Since we have 12 bit ADC, we divide by 4 as well.
// Since we have 12 bit ADC, we divide by 4 to convert to 10 bit.
float adc_value_to_distance(uint16_t adc_value) {
const float scale_factor = 6 / 4.0F;
const float offset = -300.0F;

float distance = scale_factor * (float)adc_value + offset;
float distance = (scale_factor * (float)adc_value) + offset;
if (distance < 0) {
distance = 0;
}

return distance;
}
Loading