add redeclare prevent

This commit is contained in:
Richie 2023-11-08 15:11:42 +08:00
parent 32ddff1e97
commit a066bd06a6
4 changed files with 70 additions and 47 deletions

View File

@ -20,6 +20,8 @@
#define DIRECTION_FORWARD (DIRECTION_LEFT_FORWARD | DIRECTION_RIGHT_FORWARD) #define DIRECTION_FORWARD (DIRECTION_LEFT_FORWARD | DIRECTION_RIGHT_FORWARD)
#define DIRECTION_BACKWARD (DIRECTION_LEFT_BACKWARD | DIRECTION_RIGHT_BACKWARD) #define DIRECTION_BACKWARD (DIRECTION_LEFT_BACKWARD | DIRECTION_RIGHT_BACKWARD)
#define DIRECTION_LEFT (DIRECTION_LEFT_BACKWARD | DIRECTION_RIGHT_FORWARD)
#define DIRECTION_RIGHT (DIRECTION_LEFT_FORWARD | DIRECTION_RIGHT_BACKWARD)
#define DIRECTION_MASK (DIRECTION_FORWARD | DIRECTION_BACKWARD) #define DIRECTION_MASK (DIRECTION_FORWARD | DIRECTION_BACKWARD)

View File

@ -4,8 +4,12 @@
* @author Richie * @author Richie
*/ */
#ifndef MOTOR_DIRECTION_H
#define MOTOR_DIRECTION_H
#include "motor_init.h" #include "motor_init.h"
#include "magnetometer_init.h" #include "magnetometer_init.h"
#include "magnetometer_direction.h"
/*! /*!
* @brief Set the direction of the wheels; can use bitwise OR to set both * @brief Set the direction of the wheels; can use bitwise OR to set both
@ -124,36 +128,44 @@ turn_right_90()
// g_motor_left.speed.distance_cm = initial; // g_motor_left.speed.distance_cm = initial;
//} //}
//void void
//spin_to_yaw(float target_yaw) spin_to_yaw(float target_yaw)
//{ {
// float initial_yaw = g_direction.yaw; float initial_yaw = g_direction.yaw;
//
// // if it will to turn more than 180 degrees, turn the other way // if it will to turn more than 180 degrees, turn the other way
// if ((target_yaw > initial_yaw) && (target_yaw - initial_yaw < 180.f) if ((target_yaw > initial_yaw) && (target_yaw - initial_yaw < 180.f)
// || ((target_yaw < initial_yaw) && (initial_yaw - target_yaw >= 180.f))) || ((target_yaw < initial_yaw) && (initial_yaw - target_yaw >= 180.f)))
// { {
// set_wheel_direction(DIRECTION_LEFT); set_wheel_direction(DIRECTION_LEFT);
// } }
// else if ((target_yaw > initial_yaw) && (target_yaw - initial_yaw >= 180.f) else if ((target_yaw > initial_yaw) && (target_yaw - initial_yaw >= 180.f)
// || ((target_yaw < initial_yaw) || ((target_yaw < initial_yaw)
// && (initial_yaw - target_yaw < 180.f))) && (initial_yaw - target_yaw < 180.f)))
// { {
// set_wheel_direction(DIRECTION_RIGHT); set_wheel_direction(DIRECTION_RIGHT);
// } }
//
// set_wheel_speed_synced(90u); set_wheel_speed_synced(50u);
//
// g_use_pid = false; g_use_pid = false;
//
// for (;;) for (;;)
// { {
// if (initial_yaw == target_yaw) // if (xSemaphoreTake(g_direction_sem, portMAX_DELAY) == pdTRUE)
// { // {
// set_wheel_speed_synced(0u); // updateDirection();
// break;
// } // }
// vTaskDelay(pdMS_TO_TICKS(5)); updateDirection();
// } print_orientation_data();
// g_use_pid = true; if (initial_yaw == target_yaw)
//} {
set_wheel_speed_synced(0u);
break;
}
vTaskDelay(pdMS_TO_TICKS(5));
}
g_use_pid = true;
}
#endif /* MOTOR_DIRECTION_H */

View File

@ -5,6 +5,9 @@
* @author Richie * @author Richie
*/ */
#ifndef MOTOR_PID_H
#define MOTOR_PID_H
// #include "magnetometer_init.h" // #include "magnetometer_init.h"
/*! /*!
@ -113,4 +116,6 @@ repeating_i_handler(__unused struct repeating_timer *t)
set_wheel_speed((uint32_t)temp, &g_motor_right); set_wheel_speed((uint32_t)temp, &g_motor_right);
return true; return true;
} }
#endif /* MOTOR_PID_H */

View File

@ -3,6 +3,8 @@
* @brief monitor and update the speed of the wheels * @brief monitor and update the speed of the wheels
* @author Richie * @author Richie
*/ */
#ifndef MOTOR_SPEED_H
#define MOTOR_SPEED_H
#include "motor_init.h" #include "motor_init.h"
@ -84,21 +86,21 @@ set_wheel_speed(uint32_t pwm_level, motor_t * motor)
motor->pwm.level); motor->pwm.level);
} }
///*! /*!
// * @brief Set the speed of the wheels * @brief Set the speed of the wheels
// * @param pwm_level The pwm_level of the wheels, from 0 to 99 * @param pwm_level The pwm_level of the wheels, from 0 to 99
// */ */
//void void
//set_wheel_speed_synced(uint32_t pwm_level) set_wheel_speed_synced(uint32_t pwm_level)
//{ {
// if (pwm_level > MAX_PWM_LEVEL) if (pwm_level > MAX_PWM_LEVEL)
// { {
// pwm_level = MAX_PWM_LEVEL; pwm_level = MAX_PWM_LEVEL;
// } }
//
// set_wheel_speed(pwm_level, &g_motor_left); set_wheel_speed(pwm_level, &g_motor_left);
// set_wheel_speed(pwm_level, &g_motor_right); set_wheel_speed(pwm_level, &g_motor_right);
//} }
///*! ///*!
// * @brief Set the distance to travel before stopping, must be called after // * @brief Set the distance to travel before stopping, must be called after
@ -122,3 +124,5 @@ set_wheel_speed(uint32_t pwm_level, motor_t * motor)
// vTaskDelay(pdMS_TO_TICKS(1000)); // vTaskDelay(pdMS_TO_TICKS(1000));
// g_motor_right.speed.distance_cm = g_motor_left.speed.distance_cm; // g_motor_right.speed.distance_cm = g_motor_left.speed.distance_cm;
//} //}
#endif /* MOTOR_SPEED_H */