How to read relay state?

How can I read the relay state?

the light on the relay. orange means no value, green means true and red means false

I think he’s asking how to have his code know how the relay is current set, rather than his eyes.

You can see how it’s done in the default project by looking at the Build Dashboard Data.vi. That retrieves the values of the Relays and sends it off to be displayed by the default Dashboard.

Close. These Spike relays had me confused for a while. First you must think of them as 2 relays,each with one contact. Each contact connects its output terminal (M+ or M-) to either the 12V or the GND terminal.

When the light is orange both are connected to GND.

When the light is green M+ is connected to +12 and M- is connected to GND.

When the light is red M+ is connected to GND and M- is connected to +12.

When the light is off M+ and M- are connected to +12

The PWM cable can be confusing also as it is not really PWM. It is connected to a relay output on the Digital Sidecar. The black wire is tied to the negative. The red and white wires are connected to + 5 when the cRIO wants to activate a contact. I cannot remember which controls which.

Here is a link to the manual: http://www.robotmarketplace.com/products/images/SpikeBLUEUsersManual.pdf

(If you are right, Mark, Maybe my explanation will help someone)

in code, if you run debug mode(running robot main) to your robot, than you can probe your relay state by clicking on the wire while the code is running.

so I looked in the dashboard build code and there are two sections under digital IO Relay forward and relay reverse witch output an unsigned integer 0 to 255 but I cannot find out how this is correlated to the relay states

The short answer is, each Relay has a Forward side as well as a Reverse side.
We have 8 Relays per Digital Sidecar.
So we can represent the state of all Relays by using just two 8-bit integers where each bit indicates if the Relay position is on or off (1 or 0).

Instead of thinking of it as a number 0-255, think of each bit position being on or off. The first bit of the Forward integer represents Relay 1’s forward setting (on=1, off=0). The 8th bit represents Relay 8.
The same with the Reverse bit values.

There are two distinct parts to a Spike relay that kstl99 referred to in his description earlier. Essentially, a Spike is really two relays in one.

So, because there are two parts, each Spike has 4 states where each of the two parts is either on or off. These are the enumerated choices you get in the code for a Relay:

  1. Off (all off)
  2. On (all on)
  3. Forward (one side on, the other off)
  4. Reverse (one side off, the other on)
    If you look at the Digital Sidecar while your Relays are in use, you will see a double row of LEDs with green lights going on when any of the Relays are set to Forward, red lights when the Relays are set to Reverse, and both on if both are set at the same time.
    Those rows of green and red lights are the bit values in your integers.

One way to use these numbers is to run the integer through a “Number to Boolean Array” function and an “Array to Cluster” followed by an Unbundle (from the right-click cluster menu).
An alternative is to use the array index functions to pick out the values you want.
I’ve attached an example. Beware, the array starts with zero, so the Relay 1 is zero and Relay 8 is seven.
The “Number to Boolean Array” function can be found in the block diagram palette under Programming->Boolean
The “Array to Cluster” function is under Programming->Array

RelayValues.png


RelayValues.png

thanks!