SmartWheels self-driving race car. Designed for NXP Cup. Uses FRDM-KL25Z, area-scan camera, and simple image processing to detect and navigate any NXP spec track.
Dependencies: TSI USBDevice mbed-dev
Fork of SmartWheels by
Hardwares/Motor.h@100:ffbeefc9e218, 2017-04-20 (annotated)
- Committer:
- hazheng
- Date:
- Thu Apr 20 21:04:10 2017 +0000
- Revision:
- 100:ffbeefc9e218
- Parent:
- 91:7b1910ca3ad6
Better version of Intersection detection.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hazheng | 91:7b1910ca3ad6 | 1 | /** |
hazheng | 91:7b1910ca3ad6 | 2 | * @file Motor.h |
hazheng | 91:7b1910ca3ad6 | 3 | * @brief The header file for all functions that control the motors. |
hazheng | 91:7b1910ca3ad6 | 4 | * @author Jordan Brack <jabrack@mix.wvu.edu>, Haofan Zheng <hazheng@mix.wvu.edu> |
hazheng | 91:7b1910ca3ad6 | 5 | * |
hazheng | 91:7b1910ca3ad6 | 6 | */ |
Bobymicjohn | 4:25e028102625 | 7 | #pragma once |
hazheng | 91:7b1910ca3ad6 | 8 | #ifndef MOTOR_H |
hazheng | 91:7b1910ca3ad6 | 9 | #define MOTOR_H |
Bobymicjohn | 8:92f6baeea027 | 10 | |
Bobymicjohn | 8:92f6baeea027 | 11 | #include <mbed.h> |
Bobymicjohn | 8:92f6baeea027 | 12 | |
hazheng | 91:7b1910ca3ad6 | 13 | #define MotorDir uint8_t /*!< @brief Define the MotorDir type as a alias to the uint8_t. */ |
hazheng | 91:7b1910ca3ad6 | 14 | #define MDIR_Forward 0 /*!< @brief Move forward is low voltage level. */ |
hazheng | 91:7b1910ca3ad6 | 15 | #define MDIR_Backward 1 /*!< @brief Move backward is high voltage level. */ |
Bobymicjohn | 8:92f6baeea027 | 16 | |
hazheng | 46:a5eb9bd3bb55 | 17 | |
hazheng | 100:ffbeefc9e218 | 18 | #define MOTOR_MAX_SPEED_LIMIT 0.55f /*!< @brief The percentage of the max speed (power) level for the motor driver. (This will be multiply to the speed that finally set to the motor driver) */ |
hazheng | 53:36d9335fec96 | 19 | |
hazheng | 91:7b1910ca3ad6 | 20 | #define MOTOR_DIFF_MIN_SPEED 0.55f /*!< @brief The percentage of the digital rear differential. (It should be used outside of these functions.) */ |
hazheng | 52:078b521c9edf | 21 | |
hazheng | 46:a5eb9bd3bb55 | 22 | #ifdef __cplusplus |
hazheng | 46:a5eb9bd3bb55 | 23 | extern "C" { |
hazheng | 46:a5eb9bd3bb55 | 24 | #endif |
hazheng | 46:a5eb9bd3bb55 | 25 | |
hazheng | 91:7b1910ca3ad6 | 26 | /** |
hazheng | 91:7b1910ca3ad6 | 27 | * @brief Init the motors. There is only one pair of motors in the system, thus, this function is required to be called only once during the system initialization. |
hazheng | 91:7b1910ca3ad6 | 28 | */ |
hazheng | 46:a5eb9bd3bb55 | 29 | void motor_init(); |
hazheng | 46:a5eb9bd3bb55 | 30 | |
hazheng | 91:7b1910ca3ad6 | 31 | /** |
hazheng | 91:7b1910ca3ad6 | 32 | * @brief Set the left motor speed (power) level. |
hazheng | 91:7b1910ca3ad6 | 33 | * @param speed The percentage (between 0 ~ 1) of the speed (power) level. Positive for forward, and negative for backward. |
hazheng | 91:7b1910ca3ad6 | 34 | */ |
hazheng | 46:a5eb9bd3bb55 | 35 | void motor_set_left_speed(const float speed); |
hazheng | 46:a5eb9bd3bb55 | 36 | |
hazheng | 91:7b1910ca3ad6 | 37 | /** |
hazheng | 91:7b1910ca3ad6 | 38 | * @brief Set the right motor speed (power) level. |
hazheng | 91:7b1910ca3ad6 | 39 | * @param speed The percentage (between 0 ~ 1) of the speed (power) level. Positive for forward, and negative for backward. |
hazheng | 91:7b1910ca3ad6 | 40 | */ |
hazheng | 46:a5eb9bd3bb55 | 41 | void motor_set_right_speed(const float speed); |
hazheng | 46:a5eb9bd3bb55 | 42 | |
hazheng | 91:7b1910ca3ad6 | 43 | /** |
hazheng | 91:7b1910ca3ad6 | 44 | * @brief Set the motor speed (power) level for both motors. |
hazheng | 91:7b1910ca3ad6 | 45 | * @param speed_left The percentage (between 0 ~ 1) of the speed (power) level. Positive for forward, and negative for backward. |
hazheng | 91:7b1910ca3ad6 | 46 | * @param speed_right The percentage (between 0 ~ 1) of the speed (power) level. Positive for forward, and negative for backward. |
hazheng | 91:7b1910ca3ad6 | 47 | */ |
hazheng | 46:a5eb9bd3bb55 | 48 | inline void motor_set_speeds(const float speed_left, const float speed_right) |
Bobymicjohn | 11:676ea42afd56 | 49 | { |
hazheng | 46:a5eb9bd3bb55 | 50 | motor_set_left_speed(speed_left); |
hazheng | 46:a5eb9bd3bb55 | 51 | motor_set_right_speed(speed_right); |
Bobymicjohn | 11:676ea42afd56 | 52 | } |
Bobymicjohn | 4:25e028102625 | 53 | |
hazheng | 91:7b1910ca3ad6 | 54 | /** |
hazheng | 91:7b1910ca3ad6 | 55 | * @brief Set the left motor direction. |
hazheng | 91:7b1910ca3ad6 | 56 | * @param dir The direction of the motor. For the datatype and available parameter values, please reference to the defines above. |
hazheng | 91:7b1910ca3ad6 | 57 | */ |
hazheng | 46:a5eb9bd3bb55 | 58 | void motor_set_left_direction(MotorDir dir); |
hazheng | 46:a5eb9bd3bb55 | 59 | |
hazheng | 91:7b1910ca3ad6 | 60 | /** |
hazheng | 91:7b1910ca3ad6 | 61 | * @brief Set the right motor direction. |
hazheng | 91:7b1910ca3ad6 | 62 | * @param dir The direction of the motor. For the datatype and available parameter values, please reference to the defines above. |
hazheng | 91:7b1910ca3ad6 | 63 | */ |
hazheng | 46:a5eb9bd3bb55 | 64 | void motor_set_right_direction(MotorDir dir); |
Bobymicjohn | 4:25e028102625 | 65 | |
hazheng | 91:7b1910ca3ad6 | 66 | /** |
hazheng | 91:7b1910ca3ad6 | 67 | * @brief Set the motor direction for both motors. |
hazheng | 91:7b1910ca3ad6 | 68 | * @param dirL The direction of the left motor. For the datatype and available parameter values, please reference to the defines above. |
hazheng | 91:7b1910ca3ad6 | 69 | * @param dirR The direction of the right motor. For the datatype and available parameter values, please reference to the defines above. |
hazheng | 91:7b1910ca3ad6 | 70 | */ |
hazheng | 46:a5eb9bd3bb55 | 71 | inline void motor_set_direction(MotorDir dirL, MotorDir dirR) |
hazheng | 46:a5eb9bd3bb55 | 72 | { |
hazheng | 46:a5eb9bd3bb55 | 73 | motor_set_left_direction(dirL); |
hazheng | 46:a5eb9bd3bb55 | 74 | motor_set_right_direction(dirR); |
hazheng | 46:a5eb9bd3bb55 | 75 | } |
Bobymicjohn | 4:25e028102625 | 76 | |
hazheng | 46:a5eb9bd3bb55 | 77 | #ifdef __cplusplus |
hazheng | 46:a5eb9bd3bb55 | 78 | } |
hazheng | 91:7b1910ca3ad6 | 79 | #endif |
hazheng | 91:7b1910ca3ad6 | 80 | |
hazheng | 91:7b1910ca3ad6 | 81 | #endif //MOTOR_H |