-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCopy of MyRobot.cpp.bak
161 lines (123 loc) · 2.57 KB
/
Copy of MyRobot.cpp.bak
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#include "Robot.h"
class RobotDemo : public SimpleRobot
{
AnalogChannel range;
AnalogChannel feederAngle;
RobotDrive myRobot;
Joystick stick1;
Relay light;
DigitalInput limitSwitch;
Victor feederArm;
Victor feederWheel;
public:
RobotDemo():
range(1),
feederAngle(2),
myRobot(1, 2),
stick1(1),
light(1),
limitSwitch(1),
feederArm(6),
feederWheel(8)
{
myRobot.SetExpiration(0.1);
light.Set(light.kOn);
}
void Autonomous()
{
myRobot.SetSafetyEnabled(false);
Wait(0.075);
AxisCamera &camera = AxisCamera::GetInstance();
while(IsAutonomous() && IsEnabled())
if(true){
Wait(0.075);
ColorImage *image;
image = camera.GetImage();
light.Set(light.kForward);
Wait(0.125);
BinaryImage *bimage2 = image->ThresholdRGB(0,50, 200, 255, 0, 255);
delete ℑ
delete image;
Wait(0.075);
if(bimage2->GetNumberParticles()<2){
//light.Set(light.kOn);
}
else{
light.Set(light.kOff);
//Wait(1000);
/*vector< ParticleAnalysisReport > * reports = bimage->GetOrderedParticleAnalysisReports();
for(int i = 0; i<2; i++){
Rect rect = reports->at(i).boundingRect;
//vertical
if(rect.height>rect.width){
light.Set(light.kOff);
}
//horizontal
else{
}
}*/
}
delete &bimage2;
delete bimage2;
}
}
void OperatorControl()
{
SmartDashboard::init();
myRobot.SetSafetyEnabled(true);
//int n = 0;
//float sum = 0;
bool buttonState = stick1.GetRawButton(6);
bool lightState = false;
bool changed = false;
while(IsOperatorControl())
{
bool state = stick1.GetRawButton(6);
if (state != buttonState)
{
if (state)
{
lightState = !lightState;
changed = true;
}
}
if (lightState)
{
light.Set(light.kForward);
}
else
{
light.Set(light.kOff);
}
changed = false;
buttonState=state;
myRobot.TankDrive(-stick1.GetRawAxis(5), -stick1.GetRawAxis(2));
float distance = getInch(range.GetAverageVoltage());
bool limswitch = limitSwitch.Get();
SmartDashboard::PutNumber("distance", distance);
//SmartDashboard::PutNumber("angle", angle);
SmartDashboard::PutNumber("limit switch", limswitch);
//sum+=distance;
//if(n%100==0){
//SmartDashboard::PutNumber("distance", sum/100.);
//sum=0;
//}
//n++;
Wait(0.005);
}
}
/**
* Runs during test mode
*/
void Test() {
}
float getInch(float voltage){
float scale = 5./512.;
return voltage/scale;
}
float getAngle(float voltage){
float scale = 5.0/250.0;
return voltage/scale;
}
};
START_ROBOT_CLASS(RobotDemo);