Clears the watchdog state after expiration.
Namespace:
Quanser.HardwareAssembly: Quanser.Hardware.Hil (in Quanser.Hardware.Hil.dll)
Syntax
| Visual Basic (Declaration) |
|---|
Public Sub WatchdogClear |
| C# |
|---|
public void WatchdogClear() |
| Visual C++ |
|---|
public: void WatchdogClear() |
| JavaScript |
|---|
function watchdogClear(); |
Remarks
When the watchdog timer expires, it prevents further access to the hardware after setting the outputs to the configured expiration states. In order to clear this "protected" state and allow access to the hardware again, the WatchdogClear method must be called. This method restores the hardware to its state prior to the watchdog timer expiring, if possible.
For example, for the Q8-series cards it reprograms the digital directions and analog modes to their original values since these are reset by the watchdog expiration (if the analog and digital output expiration states have been configured).
Examples
This example configures a watchdog timer that will expire every 0.1 seconds and reset the
analog outputs to 0V and the digital outputs to tristate upon expiration.
Also create a task for performing real-time control that reads
four encoder channels every millisecond. The watchdog is reloaded every sampling
instant. It also keeps track of how may times the watchdog expired.
Exceptions are ignored for simplicity.
| C# | |
|---|---|
int [] encoderChannels = { 0, 1, 2, 3 };
double frequency = 1000;
int samples = 5000;
int samplesInBuffer = frequency;
int samplesToRead = 1;
double timeout = 0.1;
int expirations = 0;
int index;
int [] counts = new int [samplesToRead * encoderChannels.Length];
int [] digitalChannels = new int [16];
Hil.DigitalState [] digitalStates = new Hil.DigitalState [digitalChannels.Length];
int [] analogChannels = new int [4];
double [] analogStates = new double [analogChannels.Length];
Hil.Task task;
for (index = 0; index < analogChannels.Length; index++) {
analogChannels[index] = index;
analogStates[index] = 0;
}
for (index = 0; index < digitalChannels.Length; index++) {
digitalChannels[index] = index;
digitalStates[index] = Hil.DigitalState.Tristate;
}
card.WatchdogSetAnalogExpirationState(analogChannels, analogStates);
card.WatchdogSetDigitalExpirationState(digitalChannels, digitalStates);
task = card.TaskCreateEncoderReader(samplesInBuffer, channels);
card.WatchdogStart(timeout);
task.Start(Hil.Clock.Hardware0, frequency, samples);
for (int index = 0; index < samples; index += samplesToRead) {
/*
Block (if necessary) waiting for next samplesToRead samples.
Returns every millisecond (since samplesToRead is 1 and frequency is 1000)
with the next sample.
*/
task.ReadEncoder(samplesToRead, buffer);
/* Reload watchdog before using counts for control */
if (!card.WatchdogReload()) {
/*
Watchdog expired before we managed to reload it. Keep track
of how many times this occurs.
*/
expirations++;
/* Clear watchdog state so we can continue to control the hardware */
card.WatchdogClear();
}
/* ... do control calculations and output motor torques using WriteAnalog(array<Int32>[]()[], array<Double>[]()[]) ... */
}
task.Stop();
card.WatchdogStop();
| |
| Visual Basic | |
|---|---|
Dim encoderChannels() As Integer = {0, 1, 2, 3}
Dim frequency As Double = 1000
Dim samples As Integer = 5000
Dim samplesInBuffer As Integer = frequency
Dim samplesToRead As Integer = 1
Dim timeout As Double = 0.1
Dim expirations As Integer = 0
Dim index As Integer
Dim counts(samplesToRead * encoderChannels.Length - 1) As Integer
Dim digitalChannels(15) As Integer
Dim digitalStates(digitalChannels.Length - 1) As Hil.DigitalState
Dim analogChannels(4) As Integer
Dim analogStates(analogChannels.Length - 1) As Double
Hil.Task task
For index = 0 To analogChannels.Length
analogChannels(index) = index
analogStates(index) = 0
Next
For index = 0 To digitalChannels.Length
digitalChannels(index) = index
digitalStates(index) = Hil.DigitalState.Tristate
Next
card.WatchdogSetAnalogExpirationState(analogChannels, analogStates)
card.WatchdogSetDigitalExpirationState(digitalChannels, digitalStates)
task = card.TaskCreateEncoderReader(samplesInBuffer, channels)
card.WatchdogStart(timeout)
task.Start(Hil.Clock.Hardware0, frequency, samples)
For index = 0 To samples Step samplesToRead
' Block (if necessary) waiting for next samplesToRead samples.
' Returns every millisecond (since samplesToRead is 1 and frequency is 1000)
' with the next sample.
task.ReadEncoder(samplesToRead, buffer)
' Reload watchdog before using counts for control
If Not card.WatchdogReload() Then
' Watchdog expired before we managed to reload it. Keep track
' of how many times this occurs.
expirations = expirations + 1
' Clear watchdog state so we can continue to control the hardware
card.WatchdogClear()
End If
' ... do control calculations and output motor torques using WriteAnalog(array<Int32>[]()[], array<Double>[]()[]) ...
Next
task.Stop()
card.WatchdogStop()
| |
| Visual C++ | |
|---|---|
array<int>^ encoderChannels = { 0, 1, 2, 3 };
double frequency = 1000;
int samples = 5000;
int samplesInBuffer = frequency;
int samplesToRead = 1;
double timeout = 0.1;
int expirations = 0;
int index;
array<int>^ counts = gcnew array<int>(samplesToRead * encoderChannels->Length);
array<int>^ digitalChannels = gcnew array<int>(16);
array<Hil::DigitalState>^ digitalStates = gcnew array<Hil::DigitalState>(digitalChannels->Length);
array<int>^ analogChannels = gcnew array<int>(4);
array<double>^ analogStates = gcnew array<double>(analogChannels->Length);
Hil::Task^ task;
for (index = 0; index < analogChannels->Length; index++) {
analogChannels[index] = index;
analogStates[index] = 0;
}
for (index = 0; index < digitalChannels->Length; index++) {
digitalChannels[index] = index;
digitalStates[index] = Hil::DigitalState::Tristate;
}
card->WatchdogSetAnalogExpirationState(analogChannels, analogStates);
card->WatchdogSetDigitalExpirationState(digitalChannels, digitalStates);
task = card->TaskCreateEncoderReader(samplesInBuffer, channels);
card->WatchdogStart(timeout);
task->Start(Hil::Clock::Hardware0, frequency, samples);
for (int index = 0; index < samples; index += samplesToRead) {
/*
Block (if necessary) waiting for next samplesToRead samples.
Returns every millisecond (since samplesToRead is 1 and frequency is 1000)
with the next sample.
*/
task->ReadEncoder(samplesToRead, buffer);
/* Reload watchdog before using counts for control */
if (!card->WatchdogReload()) {
/*
Watchdog expired before we managed to reload it. Keep track
of how many times this occurs.
*/
expirations++;
/* Clear watchdog state so we can continue to control the hardware */
card->WatchdogClear();
}
/* ... do control calculations and output motor torques using WriteAnalog(array<Int32>[]()[], array<Double>[]()[]) ... */
}
task->Stop();
card->WatchdogStop();
| |
Exceptions
| Exception | Condition |
|---|---|
| Quanser.Hardware..::.HilException | If the watchdog expiration state cannot be cleared then an exception is thrown. |