-
Notifications
You must be signed in to change notification settings - Fork 0
/
motors.h
77 lines (66 loc) · 1.5 KB
/
motors.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
68
69
70
71
72
73
74
75
76
77
#ifndef MOTORS_H
#define MOTORS_H
#include <stdint.h> /* Declarations of uint_32 and the like */
#include <pic32mx.h> /* Declarations of system-specific addresses etc */
#include "mipslab.h" /* Declatations for these labs */
#include <stdbool.h> // need this for bool
#include "utils.h"
/* Pin definition for motors
Left wheel
33 PMD7/RE7 forward
32 PMD6/RE6 backward
Right wheel
31 PMD5/RE5 forward
30 PMD4/RE4 backward
*/
void leftWheelForward(){
PORTESET = 0x80;
PORTECLR = 0x40; //the backward movement must be cancelled to avoid paralysis
}
void leftWheelStop(){
PORTECLR = 0x80; //cancel forward
PORTECLR = 0x40; //cancel backward
}
void leftWheelBackward(){
PORTESET = 0x40;
PORTECLR = 0x80; //forward movement cancelled
}
void rightWheelForward(){
PORTESET = 0x20;
PORTECLR = 0x10; //backward movement cancelled
}
void rightWheelStop(){
PORTECLR = 0x20; //cancel right forward
PORTECLR = 0x10; //cancel right backward
}
void rightWheelBackward(){
PORTESET = 0x10;
PORTECLR = 0x20; //forward movement cancelled
}
void bothWheelsForward(){
leftWheelForward();
rightWheelForward();
}
void bothWheelsStop(){
leftWheelStop();
rightWheelStop();
}
void bothWheelsBackward(){
leftWheelBackward();
rightWheelBackward();
}
bool carIsOn(){
return isBitSet(PORTD,8);
}
bool carGoesForward(){
return isBitSet(PORTD,9);
}
void turnLeft(){
leftWheelStop();
rightWheelForward();
}
void turnRight(){
rightWheelStop();
leftWheelForward();
}
#endif