-
Notifications
You must be signed in to change notification settings - Fork 0
/
PFMotor.h
57 lines (45 loc) · 1.32 KB
/
PFMotor.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//
// Copyright (c) Dmitry Akulov. All rights reserved.
//
// Repository info: https://github.com/pink0D/TechnicPF
// Contact information: [email protected]
//
// Licensed under the MIT license. See LICENSE file in the project root for details.
//
#ifndef _PFMotor_h
#define _PFMotor_h
#include "TechnicMotor.h"
#define MOTOR_DRIVER_TB6612FNG 0
#define MOTOR_DRIVER_L298N_MINI 1
#define PWM_PROPORTIONAL 0
#define PWM_FIXED_3_POSITIONS 1
#define PWM_FIXED_15_POSITIONS 2
struct PFMotorPinConfig {
int driver_type;
int pin_c1;
int pin_c2;
int pin_pwm;
int pin_power_ctl;
};
class PFMotor : public TechnicMotor {
public:
void begin (PFMotorPinConfig pin_config, int pwm_type = PWM_PROPORTIONAL);
void set_pwm_type(int pwm_type);
void power_on();
void power_off();
protected:
// c1 and c2 must be within 0..1 range
virtual void update_output(double new_c1, double new_c2, bool brake = false);
private:
int driver_type;
int pwm_type = PWM_PROPORTIONAL;
int pin_c1;
int pin_c2;
int pin_pwm;
int pin_power_ctl;
void output_pwm_TB6612FNG(double c1, double c2, bool brake);
void output_pwm_L298N_mini(double c1, double c2, bool brake);
double convert_pwm_3(double c);
double convert_pwm_15(double c);
};
#endif