Dijital Girdiler ve Yazılım
Not
Bu bölüm yazılımdaki dijital girişler hakkındadır. Dijital girişlere yönelik bir donanım kılavuzu için bkz. Dijital Girişler - Donanım.
roboRIO’nun FPGA’sı 26 adede kadar dijital giriş desteklemektedir. Bu girişlerin 10 tanesi RIO’nun üzerindeki gömülü DIO bağlantı noktaları tarafından, geri kalan 16 tanesi ise MXP ara bağlantı noktaları tarafından sağlanmaktadır.
Digital inputs read one of two states - “high” or “low.” By default, the built-in ports on the RIO will read “high” due to internal pull-up resistors (for more information, see Dijital Girişler - Donanım). Accordingly, digital inputs are most-commonly used with switches of some sort. Support for this usage is provided through the DigitalInput class (Java, C++).
DigitalInput sınıfı
Bir DigitalInput aşağıdaki gibi başlatılabilmektedir:
// Initializes a DigitalInput on DIO 0
DigitalInput m_input = new DigitalInput(0);
// Initializes a DigitalInput on DIO 0
frc::DigitalInput m_input{0};
DigitalInput değerinin okunması
DigitalInput durumu, get metoduyla sorgulanabilmektedir:
// Gets the value of the digital input. Returns true if the circuit is open.
m_input.get();
// Gets the value of the digital input. Returns true if the circuit is
// open.
m_input.Get();
AnalogInput’dan DigitalInput Oluşturmak
Not
An AnalogTrigger constructed with a port number argument can share that analog port with a separate AnalogInput, but two AnalogInput objects may not share the same port.
Sometimes, it is desirable to use an analog input as a digital input. This can be easily achieved using the AnalogTrigger class (Java, C++).
An AnalogTrigger may be initialized as follows. As with AnalogPotentiometer, an AnalogInput may be passed explicitly if the user wishes to customize the sampling settings:
// Initializes an AnalogTrigger on port 0
AnalogTrigger m_trigger0 = new AnalogTrigger(0);
// Initializes an AnalogInput on port 1
AnalogInput m_input = new AnalogInput(1);
// Initializes an AnalogTrigger using the above input
AnalogTrigger m_trigger1 = new AnalogTrigger(m_input);
// Initializes an AnalogTrigger on port 0
frc::AnalogTrigger trigger0{0};
// Initializes an AnalogInput on port 1
frc::AnalogInput input{1};
// Initializes an AnalogTrigger using the above input
frc::AnalogTrigger trigger1{input};
Setting the trigger points
Not
For details on the scaling of “raw” AnalogInput values, see Analog Girişler - Yazılım.
To convert the analog signal to a digital one, it is necessary to specify at what values the trigger will enable and disable. These values may be different to avoid “dithering” around the transition point:
// Enables 2-bit oversampling
m_input.setAverageBits(2);
// Sets the trigger to enable at a raw value of 3500, and disable at a value of 1000
m_trigger0.setLimitsRaw(1000, 3500);
// Sets the trigger to enable at a voltage of 4 volts, and disable at a value of 1.5 volts
m_trigger0.setLimitsVoltage(1.5, 4);
// Enables 2-bit oversampling
input.SetAverageBits(2);
// Sets the trigger to enable at a raw value of 3500, and disable at a value
// of 1000
trigger0.SetLimitsRaw(1000, 3500);
// Sets the trigger to enable at a voltage of 4 volts, and disable at a
// value of 1.5 volts
trigger0.SetLimitsVoltage(1.5, 4);
Kod içerisinde DigitalInputs’un kullanımı
Robot üzerindeki neredeyse tüm anahtarlar bir DigitalInput aracılığıyla kullanılacağı için, bu sınıf etkili robot kontrolü söz konusu olduğunda son derece önemlidir.
Bir düzenekteki hareketin sınırlandırılması
FRC®’deki neredeyse tüm (kollar ve asansörler gibi) motorlu düzeneklere, hareket aralıklarının sonunda kendilerine zarar vermemeleri için, bir çeşit “limit anahtarı” verilmelidir. Bu anahtarların bir örneği için bkz. Limit Anahtarlarının Programlanması.
Bir düzeneğin özgüdümlenmesi
Limit anahtarları bir düzeneğin, bir kodlayıcı aracılığıyla, öz güdümlenmesi için çok önemlidir. Bu duruma bir örnek için bkz. Homing a Mechanism.