View Single Post
  #7   Spotlight this post!  
Unread 04-04-2012, 14:47
Mark McLeod's Avatar
Mark McLeod Mark McLeod is offline
Just Itinerant
AKA: Hey dad...Father...MARK
FRC #0358 (Robotic Eagles)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Hauppauge, Long Island, NY
Posts: 8,795
Mark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond repute
Re: How to read relay state?

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
Attached Thumbnails
Click image for larger version

Name:	RelayValues.png
Views:	32
Size:	15.8 KB
ID:	12538  
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle

Last edited by Mark McLeod : 04-04-2012 at 20:41.
Reply With Quote