If I want to log a value from this signal between every point the robot moves to, do I send a readOutput or readSignal command between every point..?
Nope, nothing special needed. At the program level, any multi-bit SIGNAL you declare looks and acts just like a typical INT variable. It's just that the Input SIGNALs are updated by the operating system.
So, doing this:
Would constantly update your output byte to match your input byte.
Or, if you want to scale or directly set your output byte, you can do any math on it that you would on an ordinary INT variable.
Also, I found a bug in my precious example:
DECL INT VIn1
SIGNAL AIn1 $IN[1] TO $IN[8]
VIn1 = AIn1 * 0.039
DECL INT VIn1 should be DECL REAL VIn1. An INT variable will always be an integer value, even if you do floating-point math on it. So IntegerVariable=5/2 will always return 2, not 2.5.
We were able to find that the analog signal is communicated across a given set of bits. The values we're looking at are signed (+/-).
Okay, signed values get a bit tricky. In KRL, all INT variables (which multi-bit SIGNALs are) are treated as signed 32-bit numbers, even if the SIGNAL is declared as something smaller than 32 bits.
Which means that, for an 8-bit SIGNAL, you need to handle the sign bit yourself. There's a few ways to do this, but one way would be:
SIGNAL MyAnalogInput $IN[1] TO $IN[7]
SIGNAL MySignBit $IN[8] ; the 8th bit of the signed 8-bit word
DECL INT MyIntegerVariable
DECL REAL MyRealVariable
CONST REAL MyConversionFactor = 0.039 ; mV per integer value
MyIntegerVariable = MyAnalogInput
IF MySignBit==TRUE THEN
MyAnalogInput = 0 - MyIntegerVariable ; negate the value
ENDIF
MyRealVariable = MyIntegerVariable * MyConversionFactor ; convert binary to volts
Display More
Or there's things you can do with the B_AND operator to mask off a particular bit(s) of a word.
Note: For 32-bit words, there's a special case encoding (IEEE 754, IIRC) that PLCs do automatically when sending/receiving real/float values over binary words. KRL doesn't do this naturally, but current KSS versions support the CAST_TO and CAST_FROM functions (check the forum archives) that will handle this.