This repository has been archived by the owner on Sep 12, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
systemscheck.c
147 lines (128 loc) · 3.13 KB
/
systemscheck.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
144
145
146
147
#pragma config(Sensor, S1, , sensorI2CCustom)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
string textToAdd;
#include "libraries/I2C.h"
#include "libraries/Arm.c"
void addLog()
{
string str = textToAdd;
eraseDisplay();
nxtDisplayString(0, str);
writeDebugStreamLine(str);
}
void testEncoder(int daisychain, int motornumber)
{
int encoderposition = I2C_GetEncoderPosition(S1, daisychain, motornumber);
// if it's not 0 it must have moved sometime earlier, indicating that the encoder is working
if (encoderposition != 0) return;
I2C_SetMotorSpeed(S1, daisychain, motornumber, 10);
Sleep(150);
I2C_SetMotorSpeed(S1, daisychain, motornumber, 0);
if (encoderposition == I2C_GetEncoderPosition(S1, daisychain, motornumber))
{
textToAdd = "FATAL: encoder test failed. aborting.";
addLog();
StopAllTasks();
}
textToAdd = "success: encoder test passed. continuing.";
addLog();
}
void testMotor(int daisychain, int motornumber)
{
I2C_SetMotorSpeed(S1, daisychain, motornumber, 100);
Sleep(100);
I2C_SetMotorSpeed(S1, daisychain, motornumber, 0);
}
void wait()
{
textToAdd = "waiting 1 second.";
addLog();
Sleep(1000);
}
void wait5()
{
textToAdd = "waiting 5 seconds.";
addLog();
Sleep(5000);
}
void testservo(int daisychain, int servonumber)
{
I2C_MoveServo(S1, daisychain, servonumber, 1);
Sleep(100);
I2C_MoveServo(S1, daisychain, servonumber, 255);
Sleep(100);
I2C_MoveServo(S1, daisychain, servonumber, 1);
Sleep(100);
I2C_MoveServo(S1, daisychain, servonumber, 268);
}
task main()
{
textToAdd = "system test initialized.";
addLog();
textToAdd = "using I2C functions.";
addLog();
textToAdd = "waiting 5 seconds for the arm to reset...";
addLog();
for (int i = 0; i < 5000; i++)
{
Arm_Update();
Sleep(1);
}
textToAdd = "moving the arm to a sane place...";
addLog();
Arm_SetSpeed(15);
for (int i = 0; i < 30; i++)
{
Arm_Update();
Sleep(1);
}
textToAdd = "testing encoders...";
addLog();
textToAdd = "using daisychain 1, motor 1.";
addLog();
testEncoder(1, 1);
textToAdd = "using daisychain 1, motor 2.";
addLog();
testEncoder(1, 2);
textToAdd = "using daisychain 2, motor 1.";
addLog();
testEncoder(2, 1);
textToAdd = "using daisychain 2, motor 2.";
addLog();
testEncoder(2, 2);
wait5();
textToAdd = "testing motors...";
addLog();
textToAdd = "using daisychain 1, motor 1.";
addLog();
textToAdd = "running at power level 100.";
addLog();
testMotor(1, 1);
textToAdd = "using daisychain 1, motor 1.";
addLog();
textToAdd = "running at power level 100.";
addLog();
testMotor(1, 2);
textToAdd = "using daisychain 1, motor 1.";
addLog();
textToAdd = "running at power level 100.";
addLog();
testMotor(2, 1);
textToAdd = "using daisychain 2, motor 2.";
addLog();
textToAdd = "running at power level 100.";
addLog();
testMotor(2, 2);
wait5();
textToAdd = "testing servos...";
addLog();
textToAdd = "using daisychain 3, servo 1.";
addLog();
testservo(3, 1);
textToAdd = "physical systems check complete.";
addLog();
textToAdd = "software systems check unimplemented.";
addLog();
textToAdd = "systems check complete.";
addLog();
}