Skip to content

Commit

Permalink
Fix Comments More
Browse files Browse the repository at this point in the history
I further clarified my comments and also renamed index to dataStart to
make it more clear what it was.
  • Loading branch information
mfs16101 committed May 10, 2020
1 parent 6bb6f9c commit 45ae105
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions bfs/implementations/breadcrumbs/io_procs/AHRSInputIOProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,15 @@ void AHRSInputIOProcessor::loop()
std::cerr << "Error occured while trying to read bytes." << std::endl;
}

/* This gets the index of the bytes for the Euler angles in the captured buffer
* szBuff. The 14 index of the message is where the last byte of the roll angle is.
* It finds the first byte of the message and then finds where the data is. This
* allows me loop backward through each group of bytes since the order needs to
* be reversed because the AHRS is in Big Endian.
/* This gets the index of the bytes for the Euler angles in the captured
* buffer (szBuff). First, it finds the first byte of the message (i). Then,
* it finds the 14th index of the message (dataStart). This is where the last
* byte of the roll angle is. This allows me loop backward through each group
* of bytes, since the order needs to be reversed because the AHRS is in Big
* Endian.
* i is where the message starts in the buffer.
* index = i + 14, which is where the data we want starts (for Roll).
* dataStart = i + 14, which is where the data we want starts (for Roll).
* To find Pitch and Yaw, we add 8 and 16 respectivly.
*
* MESSAGE STRUCTURE:
Expand All @@ -142,12 +143,12 @@ void AHRSInputIOProcessor::loop()
* | index| index + 8| index + 16|
* +-------------------------+-------------------------+-------------------------+
*/
int index = -1;
int dataStart = -1;
for (int i=0; i < 32; i++)
{
if (szBuff[i] == 0xFA && szBuff[i+1] == 0xFF && szBuff[i+2] == 0x36)
{
index = i + 14;
dataStart = i + 14;
break;
}
}
Expand All @@ -156,13 +157,13 @@ void AHRSInputIOProcessor::loop()
unsigned char pitchArray[8];
unsigned char yawArray[8];
// Puts the bytes for each angle in their own array backwards, since they are sent in big endian
if (index != -1)
if (dataStart != -1)
{
for (int i = 0; i < 8; i++)
{
rollArray[i] = szBuff[index - i];
pitchArray[i] = szBuff[index - i + 8];
yawArray[i] = szBuff[index - i + 16];
rollArray[i] = szBuff[dataStart - i];
pitchArray[i] = szBuff[dataStart - i + 8];
yawArray[i] = szBuff[dataStart - i + 16];
}
}

Expand Down

0 comments on commit 45ae105

Please sign in to comment.