-
Notifications
You must be signed in to change notification settings - Fork 0
/
Motor.h
67 lines (50 loc) · 1.43 KB
/
Motor.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
58
59
60
61
62
63
64
65
66
67
/*
* File: Motor.h
* Author: josh
*
* Created on March 11, 2020, 9:30 PM
*/
#pragma once
#define DEBUG
#include "L298N_Jetson.hpp"
#include "Servo.hpp"
#include <memory>
#include <iostream>
#include <string>
#include "JetsonGPIO.h"
#include "definitions.h"
typedef enum {FORWARD, BACKWARD, STOP} Direction;
typedef enum {DRIVE, TURNLEFT, TURNRIGHT, CHANGEDIRECTION, BRAKE } Command;
class Motor {
public:
Motor(
int DrivePWMPin,
int DriveIn1Pin,
int DriveIn2Pin,
int SteeringPWMPin);
Motor(
int DrivePWMPin,
int DriveIn1Pin,
int DriveIn2Pin,
int SteeringPWMPin,
const unsigned short mapMin,
const unsigned short mapMax);
~Motor();
short setDriveSpeed(const unsigned short speed);
void setDirection(Direction d);
void run();
void run(Direction d);
void stop();
void turnAbsolute(short angle);
void turnRight(short angle);
void turnLeft(short angle);
private:
std::shared_ptr<GPIO::PWM> steer_pwm;
std::shared_ptr<GPIO::PWM> drive_pwm;
std::unique_ptr<Servo_Jetson> steer;
std::unique_ptr<L298N_Jetson> drive;
short currentSpeed;
Direction currentDirection;
unsigned short map(const unsigned short val, const unsigned short minInput, const unsigned short maxInput,
const unsigned short minOutput, const unsigned short maxOutput);
};