-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuser.c
143 lines (118 loc) · 3.46 KB
/
user.c
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
135
136
137
138
139
140
141
142
143
#include <stdbool.h>
#include <stdio.h>
#include <hax.h>
#include "auton.h"
#include "encoder.h"
#include "ports.h"
#include "robot.h"
#include "state.h"
#include "ru_ir.h"
#include "misc.h"
#include "user.h"
/* User-override for arm and ramp potentiometers. */
static bool override = false;
void init(void) {
/* Initialize autonomous mode. */
auto_current->cb_init(auto_current, &auto_mutable);
fputs("[STATE ", stdout);
fputs(auto_current->name, stdout);
fputs("]\n", stdout);
#if defined(ROBOT_NITISH)
digital_setup(BUT_B_L, DIGITAL_IN);
digital_setup(BUT_B_R, DIGITAL_IN);
#endif
override = false;
/* Initialize the encoder API; from now on we can use the logical mappings
* ENC_L, ENC_R, and ENC_S without worrying about the wiring of the robot.
*/
encoder_init(ENC_L, INT_ENC_L1, INT_ENC_L2); /* Left */
encoder_init(ENC_R, INT_ENC_R1, INT_ENC_R2); /* Right */
}
void disable_loop(void) {
}
void disable_spin(void) {
}
void auton_loop(void) {
state_t const __rom *next = auto_current;
index_t i;
/* Remove outliers from the IR distance sensor data. */
#if defined(ROBOT_KEVIN)
ir_filter_routine();
#endif
/* Start each autonomous slow loop with a clean slate. */
for (i = IX_MOTOR(1); i < MTR_NUM; ++i) {
motor_set(i, 0);
}
/* Update the current state. */
auto_current->cb_loop(auto_current, &auto_mutable);
/* We just changed states and need to call the initialization routine for
* the new state. Additionally, printf() an alert.
*/
next = auto_current->cb_next(auto_current, &auto_mutable);
/* Use the state-specific trasition function to get the next state. */
if (auto_current != next) {
uint8_t *bytes = (uint8_t *)&auto_mutable;
uint8_t i;
auto_current = next;
fputs("[STATE ", stdout);
fputs(auto_current->name, stdout);
fputs("]\n", stdout);
/* Perform auto_mutable initialization for the new state; replacing the
* non-functioning memset() implementation on the PIC.
*/
for (i = 0; i < sizeof(mutable_t); ++i) {
bytes[i] = 0;
}
next->cb_init(auto_current, &auto_mutable);
} else {
++auto_mutable.timer;
}
}
void auton_spin(void) {
encoder_update();
}
void telop_loop(void)
{
int8_t left = oi_group_get(OI_L_Y);
int8_t right = oi_group_get(OI_R_Y);
int8_t arm = ARM_SPEEDMAX * oi_rocker_get(OI_L_B);
int8_t ramp = 127 * oi_rocker_get(OI_R_B);
#if defined(ARCH_PIC)
#elif defined(ARCH_CORTEX)
/* Override potentiometer motor limits. */
bool override_set = oi_button_get(OI_BUT_L_D) && oi_button_get(OI_BUT_R_D);
bool override_reset = oi_button_get(OI_BUT_L_U) && oi_button_get(OI_BUT_R_U);
override = override_set || (override && !override_reset);
printf("OVERRIDE %d ", override);
#endif
/* Disable ramp and arm potientiometer checks. */
if (override) {
drive_raw(left, right);
arm_raw(arm);
ramp_raw(ramp, ramp);
}
/* Prevent dangerous ramp and arm movement in software. */
else {
drive_raw(left, right);
arm_smart(arm);
ramp_smart(ramp);
}
#if defined(ROBOT_KEVIN)
ir_filter_routine();
printf((char *)"ARM %4d LIFT %4d ENCL %5d ENCR %5d BACKIR %5d\n",
(int)analog_get(POT_ARM),
(int)analog_get(POT_LIFT),
(int)encoder_get(ENC_L),
(int)encoder_get(ENC_R),
(int)Get_Rear_IR());
#elif defined(ROBOT_NITISH)
printf((char *)"ARM %4d LIFTL %4d LIFTR %4d ENCL %5d ENCR %5d\n",
(int)analog_get(POT_ARM),
(int)analog_get(POT_LIFT_L),
(int)analog_get(POT_LIFT_R),
(int)encoder_get(ENC_L),
(int)encoder_get(ENC_R));
#endif
}
void telop_spin(void) {
}