Entrées numériques - Partie logicielle
Note
Cette section couvre le logiciel relatif aux entrées numériques. Pour un guide sur le branchement électrique aux entrées numériques, voir Entrées numériques.
The roboRIO’s FPGA supports up to 26 digital inputs. 10 of these are made available through the built-in DIO ports on the RIO itself, while the other 16 are available through the MXP breakout port.
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 Entrées numériques). Accordingly, digital inputs are most-commonly used with switches of some sort. Support for this usage is provided through the DigitalInput class (Java, C++).
La classe DigitalInput
Une entrée DigitalInput peut être initialisée comme suit:
// Initializes a DigitalInput on DIO 0
DigitalInput m_input = new DigitalInput(0);
// Initializes a DigitalInput on DIO 0
frc::DigitalInput m_input{0};
Lecture de la valeur du DigitalInput
L’état de DigitalInput peut être interrogé avec la méthode get:
// 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();
Création d’une entrée numérique à partir d’une entrée analogique
Note
Un AnalogTrigger construit avec un argument de numéro de port peut partager ce port analogique avec un AnalogInput séparé, mais deux objets AnalogInput peuvent ne pas partager le même 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++).
Un AnalogTrigger peut être initialisé comme suit. Comme avec AnalogPotentiometer, un AnalogInput peut être transmis explicitement si l’utilisateur souhaite personnaliser les paramètres d’échantillonnage:
// 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};
Définition des points de déclenchement
Note
Pour plus de détails sur la mise à l’échelle des données « brutes » AnalogInput, voir Entrées analogiques - Partie logicielle.
Pour convertir le signal analogique en signal numérique, il est nécessaire de spécifier à quelles valeurs le déclencheur sera activé et désactivé. Ces valeurs sont préférablement différentes, pour que les changement d’états autour du point de transition se fassent de façon nette (sans oscillations):
// 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);
Utilisation de DigitalInputs dans le code
As almost all switches on the robot will be used through a DigitalInput. This class is extremely important for effective robot control.
Limiter le mouvement d’un mécanisme
Nearly all motorized mechanisms (such as arms and elevators) in FRC® 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 Programmation des interrupteurs de fin de course.
La mise à zéro d’un mécanisme
Limit switches are very important for being able to « home » a mechanism with an encoder. For an example of this, see La mise à zéro d’un mécanisme.