-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMotor_Jetson.cpp
125 lines (98 loc) · 2.96 KB
/
Motor_Jetson.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
* MIT License
*/
/*
* File: Motor_Jetson.cpp
* Author: josh- -JKI757
*
* Created on May 24, 2020, 7:49 PM
*/
#include "Motor_Jetson.hpp"
Motor_Jetson::Motor_Jetson(
int DrivePWMPin,
int DriveIn1Pin,
int DriveIn2Pin,
int SteeringPWMPin){
GPIO::setmode(GPIO::BOARD);
GPIO::setup(DrivePWMPin, GPIO::OUT, GPIO::HIGH);
GPIO::setup(SteeringPWMPin, GPIO::OUT, GPIO::HIGH);
this->steer_pwm = std::make_shared<GPIO::PWM>(SteeringPWMPin, 1500);
this->drive_pwm = std::make_shared<GPIO::PWM>(DrivePWMPin, 50);
drive = std::make_unique<L298N_Jetson> (this->steer_pwm,
DriveIn1Pin,
DriveIn2Pin, false);
steer = std::make_unique<Servo_Jetson> (this->steer_pwm, false);
currentSpeed = 0;
currentDirection = STOP;
}
Motor_Jetson::Motor_Jetson(
int DrivePWMPin,
int DriveIn1Pin,
int DriveIn2Pin,
int SteeringPWMPin,
const unsigned short minUs,
const unsigned short maxUs,
const unsigned short mapMin,
const unsigned short mapMax) {
drive = std::make_unique<L298N_Jetson> (DrivePWMPin,
DriveIn1Pin,
DriveIn2Pin);
std::cerr << "after make driver" << std::endl;
std::cerr << "steering pin: " << SteeringPWMPin << std::endl;
steer = std::make_unique<Servo_Jetson> (SteeringPWMPin,
minUs, maxUs,
mapMin, mapMax);
currentSpeed = 0;
currentDirection = STOP;
}
Motor_Jetson::~Motor_Jetson() {
this->steer_pwm->stop();
this->drive_pwm->stop();
GPIO::cleanup();
}
Motor_Jetson::Motor_Jetson(const Motor_Jetson& other) // copy constructor
{
}
Motor_Jetson::Motor_Jetson(Motor_Jetson&& other) // move constructor
{
}
Motor_Jetson& Motor_Jetson::operator=(const Motor_Jetson& other) // copy assignment
{
}
Motor_Jetson& Motor_Jetson::operator=(Motor_Jetson&& other) // move assignment
{
}
short Motor_Jetson::setDriveSpeed(const unsigned short speed) {
currentSpeed = speed;
drive->setSpeed(speed);
drive->run();
}
void Motor_Jetson::setDirection(Direction d) {
currentDirection = d;
switch(currentDirection){
case FORWARD:
drive->forward();
break;
case BACKWARD:
drive->backward();
break;
case STOP:
drive->stop();
break;
};
drive->run();
}
void Motor_Jetson::run() {
drive->run();
}
void Motor_Jetson::stop() {
drive->stop();
}
void Motor_Jetson::turnAbsolute(short angle) {
std::cout << "steering value passed in: " << angle << std::endl;
steer->writeMappedValue(angle);
}
void Motor_Jetson::turnRight(short angle) {
}
void Motor_Jetson::turnLeft(short angle) {
}