-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathRobot.cpp
More file actions
94 lines (84 loc) · 1.99 KB
/
Robot.cpp
File metadata and controls
94 lines (84 loc) · 1.99 KB
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
//
//
//
#include "Robot.h"
Robot::Robot()
:timerDrive(1000 / DRIVEFREQ), oscilloscope(8), collisionAvoidance(11, 12, 145, &propulsion),
timerScoop(1000/SCOOPFREQ), timerACS(1000/ACSFREQ)
{
}
void Robot::run()
{
oscilloscope.checkButton();
if (timerACS.fire())
{
collisionAvoidance.run();
/*
if (progress == 0)
{
propulsion.setForwards(540);
}
else if (progress == 1)
{
propulsion.setBackwards(540);
}
else if (progress == 2)
{
propulsion.setLeftRotation(100);
}
else if (progress == 3)
{
propulsion.setRightRotation(100);
}
else
{
delay(500);
}
*/
}
if (timerDrive.fire())
{
int motorSpeed = analogRead(POTPIN) / 45;
if (motorSpeed <= 1)
{
propulsion.reset();
//propulsion.setProgress(0);
}
else if (propulsion.getAllowSpeedControll())
{
propulsion.setSpeed(motorSpeed);
}
if (propulsion.drive())
{
propulsion.incrementProgress();
propulsion.reset();
}
}
if (oscilloscope.getSampling_on() && timerScoop.fire())
{
noInterrupts();
oscilloscope.setSensorReading(0, int(propulsion.getPointerToMotorL()->getPointerToEncoder()->getEncoderTicks()));
oscilloscope.setSensorReading(1, int(propulsion.getPointerToMotorR()->getPointerToEncoder()->getEncoderTicks()));
oscilloscope.setSensorReading(2, propulsion.getPointerToMotorL()->getPWM_val());
oscilloscope.setSensorReading(3, propulsion.getPointerToMotorR()->getPWM_val());
oscilloscope.setSensorReading(4, propulsion.getProgress());
oscilloscope.setSensorReading(5, propulsion.getPointerToMotorL()->getPointerToEncoder()->getSpeed());
oscilloscope.setSensorReading(6, propulsion.getPointerToMotorR()->getPointerToEncoder()->getSpeed());
oscilloscope.setTime();
interrupts();
oscilloscope.sendData();
}
}
void Robot::initialize()
{
oscilloscope.initializeSerial();
collisionAvoidance.initialize(9);
}
Motor* Robot::getPointerToMotorL()
{
return propulsion.getPointerToMotorL();
}
Motor* Robot::getPointerToMotorR()
{
return propulsion.getPointerToMotorR();
}