Merge pull request #7 from Devoalda/main

This commit is contained in:
Richie Wang 2023-10-28 15:51:25 +08:00 committed by GitHub
commit 05b5872a6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 81 additions and 45 deletions

View File

@ -10,6 +10,18 @@
#define ALPHA ( 0.01f ) // Complementary
// Filter Constant
// LSM303DLHC temperature compensation coefficients
#define SCALE_Z ( 1.0f ) // Scale for Z-axis
#define OFFSET_Z ( 3.0f ) // Offset for Z-axis
#define TEMPERATURE_OFFSET ( 25.0f ) // Reference
// temperature for
// calibration
#define TEMPERATURE_COEFFICIENT_Z ( 0.33f ) // Temperature
// coefficient for
// Z-axis
/**
* @brief The orientation of the car
*/

View File

@ -14,13 +14,34 @@
*
* @param params
*/
//void
//monitor_left_sensor_task(__unused void *params) {
// for (;;)
// {
// if (xSemaphoreTake(g_left_sensor_sem, portMAX_DELAY) == pdTRUE)
// {
// if (left_sensor_triggered == pdTRUE)
// {
// printf("left sensor triggered\n");
// // Get Current State
// state_t state = gpio_get(LEFT_SENSOR_PIN);
//
// xMessageBufferSend(left_sensor_msg_buffer,
// &state,
// sizeof(state_t),
// 0);
// // Reset the flag
// left_sensor_triggered = pdFALSE;
// }
// }
// }
//}
void
monitor_left_sensor_task(__unused void *params) {
for (;;)
{
if (xSemaphoreTake(g_left_sensor_sem, portMAX_DELAY) == pdTRUE)
{
if (left_sensor_triggered == pdTRUE)
{
printf("left sensor triggered\n");
// Get Current State
@ -30,9 +51,6 @@ monitor_left_sensor_task(__unused void *params) {
&state,
sizeof(state_t),
0);
// Reset the flag
left_sensor_triggered = pdFALSE;
}
}
}
}
@ -45,12 +63,32 @@ monitor_left_sensor_task(__unused void *params) {
*
* @param params
*/
//void
//monitor_right_sensor_task(void *params) {
// for (;;) {
// if (xSemaphoreTake(g_right_sensor_sem, portMAX_DELAY) == pdTRUE) {
// // Check the flag or receive the message
// if (right_sensor_triggered == pdTRUE) {
// printf("right sensor triggered\n");
// // Get Current State
// state_t state = gpio_get(RIGHT_SENSOR_PIN);
//
// xMessageBufferSend(right_sensor_msg_buffer,
// &state,
// sizeof(state_t),
// 0);
// // Reset the flag
// right_sensor_triggered = pdFALSE;
// }
// }
// }
//}
void
monitor_right_sensor_task(void *params) {
for (;;) {
if (xSemaphoreTake(g_right_sensor_sem, portMAX_DELAY) == pdTRUE) {
// Check the flag or receive the message
if (right_sensor_triggered == pdTRUE) {
printf("right sensor triggered\n");
// Get Current State
state_t state = gpio_get(RIGHT_SENSOR_PIN);
@ -59,14 +97,10 @@ monitor_right_sensor_task(void *params) {
&state,
sizeof(state_t),
0);
// Reset the flag
right_sensor_triggered = pdFALSE;
}
}
}
}
/**
* @brief Monitor the direction and Oritentation of the car
*

View File

@ -10,26 +10,26 @@ void
launch()
{
// isr to detect left line sensor
gpio_set_irq_enabled(LEFT_SENSOR_PIN, GPIO_IRQ_EDGE_FALL, true);
gpio_add_raw_irq_handler(LEFT_SENSOR_PIN, h_line_sensor_handler);
// isr to detect right line sensor
gpio_set_irq_enabled(RIGHT_SENSOR_PIN, GPIO_IRQ_EDGE_FALL, true);
gpio_add_raw_irq_handler(RIGHT_SENSOR_PIN, h_line_sensor_handler);
irq_set_enabled(IO_IRQ_BANK0, true);
// struct repeating_timer g_left_sensor_timer;
// add_repeating_timer_ms(LINE_SENSOR_READ_DELAY,
// h_left_sensor_timer_handler,
// NULL,
// &g_left_sensor_timer);
// gpio_set_irq_enabled(LEFT_SENSOR_PIN, GPIO_IRQ_EDGE_FALL, true);
// gpio_add_raw_irq_handler(LEFT_SENSOR_PIN, h_line_sensor_handler);
//
// struct repeating_timer g_right_sensor_timer;
// add_repeating_timer_ms(LINE_SENSOR_READ_DELAY,
// h_right_sensor_timer_handler,
// NULL,
// &g_right_sensor_timer);
// // isr to detect right line sensor
// gpio_set_irq_enabled(RIGHT_SENSOR_PIN, GPIO_IRQ_EDGE_FALL, true);
// gpio_add_raw_irq_handler(RIGHT_SENSOR_PIN, h_line_sensor_handler);
//
// irq_set_enabled(IO_IRQ_BANK0, true);
struct repeating_timer g_left_sensor_timer;
add_repeating_timer_ms(LINE_SENSOR_READ_DELAY,
h_left_sensor_timer_handler,
NULL,
&g_left_sensor_timer);
struct repeating_timer g_right_sensor_timer;
add_repeating_timer_ms(LINE_SENSOR_READ_DELAY,
h_right_sensor_timer_handler,
NULL,
&g_right_sensor_timer);
TaskHandle_t h_monitor_left_sensor_task;
xTaskCreate(monitor_left_sensor_task,

View File

@ -28,15 +28,7 @@
#define LSM303_TEMP_OUT_H_M 0x31
#define LSM303_TEMP_OUT_L_M 0x32
// LSM303DLHC temperature compensation coefficients
#define SCALE_Z 0.9 // Scale factor for Z-axis
#define OFFSET_Z 5.0 // Offset for Z-axis
#define TEMPERATURE_OFFSET 25.0 // Reference temperature for calibration
#define TEMPERATURE_COEFFICIENT_Z 0.33
#define OFFSET_Z 5.0
#define SCALE_Z 0.9
#define ACCEL_ADDR 0x19
#define MAG_ADDR 0x1E

View File

@ -6,15 +6,13 @@
*
* @details The direction of the car is calculated using the roll, pitch and yaw
* The roll and pitch are calculated using the accelerometer data
* The yaw is calculated using the magnetometer data
* The yaw is calculated using the magnetometer and accelerometer data
* The roll, pitch and yaw are combined to calculate the direction
* of the car
*
* The direction of the car is calculated using the complementary
* filter
* of the car with a complementary filter and compensating for the
* temperature.
*
* The complementary filter is used to combine the accelerometer
* and magnetometer data to calculate the direction of the car
* and magnetometer data (yaw) to calculate the direction of the car
*
* Source:
* https://www.nxp.com/docs/en/application-note/AN3461.pdf

View File

@ -30,9 +30,9 @@ main (void)
{
stdio_usb_init();
sleep_ms(2000);
// sleep_ms(2000);
printf("Test started!\n");
// printf("Test started!\n");
magnetometer_init();
launch();