-
Notifications
You must be signed in to change notification settings - Fork 0
/
HCMIUIOT_CAR.cpp
79 lines (70 loc) · 2.01 KB
/
HCMIUIOT_CAR.cpp
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
hcmiuiot_car.cpp - Library to manage the movements of a DC motor with the L298N module
Author: HCMIU Internet of Things Club
Web: https://www.facebook.com/hcmiuiot/
*/
#include "Arduino.h"
#include "HCMIUIOT_CAR.h"
#include "L298N.h"
#define DEBUG 0
// Car::Car(
// uint8_t pinEnable_A,
// uint8_t pinIN1_A,
// uint8_t pinIN2_A,
// uint8_t pinEnable_B,
// uint8_t pinIN1_B,
// uint8_t pinIN2_B,
// float wheelRadius,
// float halfWheelsDistance,
// uint8_t numberOfEncoderPulses) : _motorA(pinEnable_A,
// pinIN1_A,
// pinIN2_A),
// _motorB(pinEnable_B,
// pinIN1_B,
// pinIN2_B)
// {
// }
// Car::Car(
// uint8_t pinIN1_A,
// uint8_t pinIN2_A,
// uint8_t pinIN1_B,
// uint8_t pinIN2_B,
// float wheelRadius,
// float halfWheelsDistance,
// uint8_t numberOfEncoderPulses) : _motorA(pinIN1_A,
// pinIN2_A),
// _motorB(pinIN1_B,
// pinIN2_B)
// {
// //
// }
Car::Car() : _motorA(DF_PIN_ENABLE_A,
DF_PIN_IN1_A,
DF_PIN_IN2_A),
_motorB(DF_PIN_ENABLE_B,
DF_PIN_IN1_B,
DF_PIN_IN2_B)
{
_distancePerPulse = 6.283185 * _wheelRadius / _numberOfPulse;
}
void Car::setSpeed(uint8_t speed)
{
_speed = map(speed, 0, 100, 70, 255);
_motorA.setSpeed(_speed);
_motorB.setSpeed(_speed);
}
void Car::forward(float distance_in_cm)
{
// float
_motorA.forward();
_motorB.forward();
}
void Car::turnLeft(float angle_in_deg){};
void Car::turnRight(float angle_in_deg){};
void Car::turnArcLeft(/* some params here */){};
void Car::turnArcRight(/* some params here */){};
void Car::stop()
{
_motorA.stop();
_motorB.stop();
}