PDA

View Full Version : Error in AX12.cpp?



tigakub
04-11-2015, 06:19 PM
Pretty much a NOOB to robotics and have been trying to figure out how to get status back from ax12a's. While I've been digging around, I think I've noticed an error in ax12.cpp but would like to run it by the community to make sure I'm not on crack.

In the ax12GetRegister function, is the checksum calculation correct? The length of the message is 4, and indeed, that is what is encoded in the message, but it seems that the checksum is being calculated using a length of 6?

Wouldn't that cause a checksum alarm every time the controller tried to retrieve a register value?


int ax12GetRegister(int id, int regstart, int length) {
...
int checksum = ~((id + 6 + regstart + length)%256);
ax12writeB(0xFF);
ax12writeB(0xFF);
ax12writeB(id);
ax12writeB(4); // length
ax12writeB(AX_READ_DATA);
ax12writeB(regstart);
ax12writeB(length);
ax12writeB(checksum);
...
}

Xevel
04-11-2015, 11:50 PM
Hi!

The code uses one number (6) for length + instruction (which is part of the checksum computation). Since the instruction READ_DATA is 2, there you have it :)

tigakub
04-12-2015, 03:02 AM
OMG. I see it now. I am on crack. Thanks for the intervention Xevel!