You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As almost all switches on the robot will be used through a :code:`DigitalInput`. This class is extremely important for effective robot control.
98
76
99
77
### Limiting the motion of a mechanism
100
78
101
-
Nearly all motorized mechanisms (such as arms and elevators) in FRC\ |reg| should be given some form of "limit switch" to prevent them from damaging themselves at the end of their range of motions. A short example is given below:
102
-
103
-
.. tab-set-code::
104
-
105
-
```java
106
-
Spark spark = new Spark(0);
107
-
// Limit switch on DIO 2
108
-
DigitalInput limit = new DigitalInput(2);
109
-
public void autonomousPeriodic() {
110
-
// Runs the motor forwards at half speed, unless the limit is pressed
111
-
if(!limit.get()) {
112
-
spark.set(.5);
113
-
} else {
114
-
spark.set(0);
115
-
}
116
-
}
117
-
```
118
-
119
-
```c++
120
-
// Motor for the mechanism
121
-
frc::Spark spark{0};
122
-
// Limit switch on DIO 2
123
-
frc::DigitalInput limit{2};
124
-
void AutonomousPeriodic() {
125
-
// Runs the motor forwards at half speed, unless the limit is pressed
126
-
if(!limit.Get()) {
127
-
spark.Set(.5);
128
-
} else {
129
-
spark.Set(0);
130
-
}
131
-
}
132
-
```
79
+
Nearly all motorized mechanisms (such as arms and elevators) in FRC\ |reg| should be given some form of "limit switch" to prevent them from damaging themselves at the end of their range of motions. For an example of this, see :doc:`/docs/software/hardware-apis/sensors/limit-switch`.
0 commit comments