by adrianovrm » Mon 13. Apr 2015, 16:13
Good Morning, l having the same problemss with servos getting crazy at some moment , with my hexapod servos, getting crazy, sometimes it works, what sends a suspicious of serial errors cause without checksum , and l didnt discover how to make uso send the checksum byte ,
l know that ~a01~ is the axis value , l used 6 informations ( 25, 27 and 26 ) Vertical, longintudinal and lateral g forces to computer the translations and rotarion movements at my code and more speed, gear and rpm, gear l put in binary(8) , the left values at 16 bits. my data pacjet string is
X~A01~~A02~~A03~~A04~~A05~~A06~ , in the X-PID l saw the flowwing two functions
bool CheckChecksum() //Atmel chips have a comport error rate of 2%, so we need here a checksum
{
byte checksum=0;
for(int z=0; z < 3; z++)
{
byte val=commandbuffer[z];
checksum ^= val;
}
if(checksum==commandbuffer[3]){return true;}
return false;
}
void SerialWorker()
{
while(Serial.available())
{
if(buffercount==-1)
{
buffer = Serial.read();
if(buffer != 'X'){buffercount=-1;}else{buffercount=0;}
}
else
{
buffer = Serial.read();
commandbuffer[buffercount]=buffer;
buffercount++;
if(buffercount > 3)
{
if(CheckChecksum()==true){ParseCommand();}else{errorcount++;}
buffercount=-1;
}
}
}
}
and l notice that at the end of funcntion checkchecksum a variable computed "Checksum" is compared with the last byte received , am l right ? so , what l dont understand is how to make the USO sends this caculate byte over serial to my arduino interface, cou you aid me , guys ?
l what want to put a checksum byte for my string data packet that is now "X~A01~~A02~~A03~~A04~~A05~~A06~" how l do this ! l search at manuals l didnt found out how do it