Miya Miyagawa
/
NRP2020_main
Outher...Miura Souta
Motor/Motor.h@2:32d2cd7d744b, 2020-01-23 (annotated)
- Committer:
- M_souta
- Date:
- Thu Jan 23 09:16:38 2020 +0000
- Revision:
- 2:32d2cd7d744b
- Parent:
- 1:5b0303768126
- Child:
- 3:8790e69f8c59
lll
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
M_souta | 2:32d2cd7d744b | 1 | #ifndef MOTOR_H_ |
M_souta | 2:32d2cd7d744b | 2 | #define MOTOR_H_ |
M_souta | 2:32d2cd7d744b | 3 | |
M_souta | 2:32d2cd7d744b | 4 | #include <stdint.h> |
M_souta | 0:db8d4af513c0 | 5 | |
M_souta | 2:32d2cd7d744b | 6 | //#define USE_MOTOR0_SENSOR |
M_souta | 2:32d2cd7d744b | 7 | namespace MOTOR |
M_souta | 2:32d2cd7d744b | 8 | { |
M_souta | 2:32d2cd7d744b | 9 | #define FREE 0 |
M_souta | 2:32d2cd7d744b | 10 | #define BACK 1 |
M_souta | 2:32d2cd7d744b | 11 | #define FOR 2 |
M_souta | 2:32d2cd7d744b | 12 | #define BRAKE 3 |
M_souta | 2:32d2cd7d744b | 13 | |
M_souta | 2:32d2cd7d744b | 14 | #define MOUNTING_MOTOR_NUM 5 |
M_souta | 0:db8d4af513c0 | 15 | |
M_souta | 2:32d2cd7d744b | 16 | #define MOTOR0_D1 directions[0] |
M_souta | 2:32d2cd7d744b | 17 | #define MOTOR0_D2 directions[1] |
M_souta | 2:32d2cd7d744b | 18 | #define MOTOR1_D1 directions[2] |
M_souta | 2:32d2cd7d744b | 19 | #define MOTOR1_D2 directions[3] |
M_souta | 2:32d2cd7d744b | 20 | #define MOTOR2_D1 directions[4] |
M_souta | 2:32d2cd7d744b | 21 | #define MOTOR2_D2 directions[5] |
M_souta | 2:32d2cd7d744b | 22 | #define MOTOR3_D1 directions[6] |
M_souta | 2:32d2cd7d744b | 23 | #define MOTOR3_D2 directions[7] |
M_souta | 2:32d2cd7d744b | 24 | #define MOTOR4_D1 directions[8] |
M_souta | 2:32d2cd7d744b | 25 | #define MOTOR4_D2 directions[9] |
M_souta | 2:32d2cd7d744b | 26 | |
M_souta | 2:32d2cd7d744b | 27 | #define MOTOR0_D1_PIN D3 |
M_souta | 2:32d2cd7d744b | 28 | #define MOTOR0_D2_PIN D4 |
M_souta | 2:32d2cd7d744b | 29 | #define MOTOR1_D1_PIN D5 |
M_souta | 2:32d2cd7d744b | 30 | #define MOTOR1_D2_PIN D6 |
M_souta | 2:32d2cd7d744b | 31 | #define MOTOR2_D1_PIN D8 |
M_souta | 2:32d2cd7d744b | 32 | #define MOTOR2_D2_PIN D9 |
M_souta | 2:32d2cd7d744b | 33 | #define MOTOR3_D1_PIN D12 |
M_souta | 2:32d2cd7d744b | 34 | #define MOTOR3_D2_PIN A3 |
M_souta | 2:32d2cd7d744b | 35 | #define MOTOR4_D1_PIN A1 |
M_souta | 2:32d2cd7d744b | 36 | #define MOTOR4_D2_PIN A0 |
M_souta | 0:db8d4af513c0 | 37 | |
M_souta | 2:32d2cd7d744b | 38 | #define MOTOR0_PWM_PIN D2 |
M_souta | 2:32d2cd7d744b | 39 | #define MOTOR1_PWM_PIN D7 |
M_souta | 2:32d2cd7d744b | 40 | #define MOTOR2_PWM_PIN D10 |
M_souta | 2:32d2cd7d744b | 41 | #define MOTOR3_PWM_PIN D11 |
M_souta | 2:32d2cd7d744b | 42 | #define MOTOR4_PWM_PIN A2 |
M_souta | 2:32d2cd7d744b | 43 | |
M_souta | 2:32d2cd7d744b | 44 | #ifdef USE_MOTOR0_SENSOR |
M_souta | 2:32d2cd7d744b | 45 | #define MOTOR_START_NUM 1 |
M_souta | 2:32d2cd7d744b | 46 | #else |
M_souta | 2:32d2cd7d744b | 47 | #define MOTOR_START_NUM 0 |
M_souta | 2:32d2cd7d744b | 48 | #endif |
M_souta | 0:db8d4af513c0 | 49 | |
M_souta | 2:32d2cd7d744b | 50 | typedef struct |
M_souta | 2:32d2cd7d744b | 51 | { |
M_souta | 2:32d2cd7d744b | 52 | union |
M_souta | 2:32d2cd7d744b | 53 | { |
M_souta | 2:32d2cd7d744b | 54 | struct |
M_souta | 2:32d2cd7d744b | 55 | { |
M_souta | 2:32d2cd7d744b | 56 | unsigned int d2 : 1; |
M_souta | 2:32d2cd7d744b | 57 | unsigned int d1 : 1; |
M_souta | 2:32d2cd7d744b | 58 | unsigned int : 6; |
M_souta | 2:32d2cd7d744b | 59 | }; |
M_souta | 2:32d2cd7d744b | 60 | uint8_t dir; |
M_souta | 2:32d2cd7d744b | 61 | }; |
M_souta | 2:32d2cd7d744b | 62 | float pwm; |
M_souta | 2:32d2cd7d744b | 63 | }MotorStatus; |
M_souta | 0:db8d4af513c0 | 64 | |
M_souta | 2:32d2cd7d744b | 65 | class Motor |
M_souta | 2:32d2cd7d744b | 66 | { |
M_souta | 2:32d2cd7d744b | 67 | public: |
M_souta | 2:32d2cd7d744b | 68 | static void Initialize(void); |
M_souta | 2:32d2cd7d744b | 69 | static void Update(MotorStatus *status); |
M_souta | 2:32d2cd7d744b | 70 | static void SetDefault(void); |
M_souta | 2:32d2cd7d744b | 71 | static int SetStatus(float pwm); |
M_souta | 2:32d2cd7d744b | 72 | static float SetPWM(float pwm); |
M_souta | 2:32d2cd7d744b | 73 | }; |
M_souta | 2:32d2cd7d744b | 74 | } |
M_souta | 2:32d2cd7d744b | 75 | |
M_souta | 2:32d2cd7d744b | 76 | #endif |