-
Notifications
You must be signed in to change notification settings - Fork 1
/
VisionArm.cpp
123 lines (99 loc) · 2.8 KB
/
VisionArm.cpp
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
#include "VisionArm.h"
#include "pins_big_robot.h"
#include "big_robot_constants.h"
const int delayActions = 4000;
int clawPos = 20;
int leftEncoderState;
int rightEncoderState;
int leftStepCount = 0;
int rightStepCount = 0;
void VisionArm::init()
{
fruitBarrier.initPin(fruitBarrierPin);
fruitBarrier.toggleNegate();
fruitColor.initPin(fruitColorSenzorPin);
horizontalLimiter.initPin(horizontalArmLimiterPin);
horizontalLimiter.setAsPullup();
horizontalAntiSlip.initPin(horizontalArmAntiSlipPin);
horizontalAntiSlip.setAsPullup();
horizontalMotor.init();
horizontalMotor.initPins(horizontalArmEnablePin, horizontalArmDirectionPin, horizontalArmStepPin);
horizontalMotor.initDelays(horizontalArmStartSpeedDelay, highPhaseDelay, pauseSpeedDelay, delayBeforeTurnOff, horizontalArmStepSpeedCounterAcceleration, horizontalArmStepSpeedCounterSlowing);
horizontalMotor.initStepCmRatio(horizontalArmCmStepRatio);
horizontalMotor.waitBeforeTurningOff = 9999;
verticalLimiter.initPin(verticalArmLimiterPin);
verticalLimiter.setAsPullup();
sensorTop.initPin(inductiveStartSensorPin);
sensorTop.initInductivePosition(3);
sensorMiddle.initPin(inductiveFruitHighSensorPin);
sensorMiddle.initInductivePosition(2);
sensorBottom.initPin(inductiveFruitLowSensorPin);
sensorBottom.initInductivePosition(0);
verticalMotor.init();
verticalMotor.initDirectionForward(LOW);
verticalMotor.initPins(verticalArmBrushlessPin, verticalArmDirectionRelayPin);
verticalMotor.initTopBottom(sensorTop, sensorBottom);
verticalMotor.initPosition(sensorTop.inductivePosition);
verticalMotor.initPwms(verticalArmStopPwm, verticalArmNormalPwm);
claw.attach(clawServoPin);
//clawRelease();
basket.attach(clawBasketPin);
basketClose();
lance.attach(lanceServoPin);
lanceRaise();
}
void VisionArm::moveHorizontal(float distance, int side)
{
horizontalMotor.setDirectionForward();
horizontalDirection = side;
if(side == BACKWARD)
horizontalMotor.toggleDirection();
horizontalMotor.setTargetDelay(horizontalArmSpeedDelay);
horizontalMotor.doDistanceInCm(distance);
}
void VisionArm::moveVertical(VisionSensor& sensor)
{
verticalMotor.moveTo(sensor);
}
void VisionArm::clawRelease()
{
claw.write(130);
}
void VisionArm::clawGrab()
{
claw.write(17);
}
void VisionArm::basketClose()
{
basket.write(3);
}
void VisionArm::basketOpen()
{
basket.write(86);
}
void VisionArm::lanceRaise()
{
lance.write(3);
}
void VisionArm::lanceLower()
{
lance.write(86);
}
boolean VisionArm::isStopped()
{
return horizontalMotor.isOff() && verticalMotor.isOff();
}
void VisionArm::disable()
{
horizontalMotor.disable();
}
void VisionArm::doLoop()
{
horizontalMotor.doLoop();
verticalMotor.doLoop();
}
void VisionArm::stopNow()
{
horizontalMotor.stopNow();
verticalMotor.stopNow();
}