-
Notifications
You must be signed in to change notification settings - Fork 0
/
mshuffle_motors.ic
134 lines (126 loc) · 2.24 KB
/
mshuffle_motors.ic
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
126
127
128
129
130
131
132
133
134
/** File: mshuffle_motors.ic
Purpose: Subroutines for motor control.
Parameters: See config.ic
Author: Gabriel Krell
Initial commit date: 9/30
**/
void scaleSpeedBy(float val) {
MOTOR_L_SPEED = (int) (val * (float)MOTOR_L_SPEED);
MOTOR_R_SPEED = (int) (val * (float)MOTOR_R_SPEED);
}
void forwardFor(float seconds) {
forward();
sleep(seconds);
stop();
deliberate();
}
void backwardFor(float seconds) {
backward();
sleep(seconds);
stop();
deliberate();
}
void forward() {
fdL();
fdR();
}
void backward() {
bkL();
bkR();
}
void leftFor(float seconds) {
left();
sleep(seconds);
stop();
deliberate();
}
void hardLeftFor(float seconds) {
hardLeft();
sleep(seconds);
stop();
deliberate();
}
void rightFor(float seconds) {
right();
sleep(seconds);
stop();
deliberate();
}
void hardRightFor(float seconds) {
hardRight();
sleep(seconds);
stop();
deliberate();
}
/*Hard turns are full power instead of respecting motor speed
to avoid rolling over the line too fast when running followLine().
They do not respect BACKUP_MODE. */
void hardLeft() {
fd(MOTOR_R);
bk(MOTOR_L);
}
void hardRight() {
fd(MOTOR_L);
bk(MOTOR_R);
}
// use for general navigation, not line following
void left() {
fdR();
if (BACKUP_MODE) {
bkL();
} else {
off(MOTOR_L);
}
}
void right() {
fdL();
if (BACKUP_MODE) {
bkR();
} else {
off(MOTOR_R);
}
}
void fdR() {
motor(MOTOR_R,MOTOR_R_SPEED);
}
void fdL() {
motor(MOTOR_L,MOTOR_L_SPEED);
}
void bkL() {
motor(MOTOR_L,-1*MOTOR_L_SPEED);
}
void bkR() {
motor(MOTOR_R,-1*MOTOR_R_SPEED);
}
void stop() {
off(MOTOR_L);
off(MOTOR_R);
}
void adj_motor() {
while (1) {
MOTOR_L_SPEED = norm_knob();
MOTOR_R_SPEED = norm_knob();
printf("%d\n",norm_knob());
defer();
}
}
/* "Deliberate mode" briefly pauses the robot in place after movement
actions, to avoid rolling stops and strange turns. It can be
disabled for just the next action with fastNext() or for an
arbitrary number of actions with fastNextN(). */
void deliberate() {
if (DELIBERATE) {
if (fast_actions_remaining) {
fast_actions_remaining--;
} else {
sleep(.5);
}
}
// gotta go fast
}
void fastNext() {
fast_actions_remaining++;
}
void fastNextN(int numFastActions) {
fast_actions_remaining+=numFastActions;
}