Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions LSM303/LSM303.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,31 @@ void LSM303::read(void)
readMag();
}

int LSM303::pitch(void)
{
vector temp_a = a;
// normalize
vector_normalize(&temp_a);
//vector_normalize(&m);
int pitch = round(atan2(temp_a.y,((temp_a.z > 0) - (temp_a.z < 0))*sqrt(pow(temp_a.x,2.0)+pow(temp_a.z,2.0)))* 180 / M_PI);
if (pitch < 0) pitch += 360;
pitch = 360 - pitch;
return pitch;
}

int LSM303::roll(void)
{
vector temp_a = a;
// normalize
vector_normalize(&temp_a);
//vector_normalize(&m);
int roll = round(atan2(-1*temp_a.x,temp_a.z)* 180 / M_PI);
if (roll < 0) roll += 360;
roll = 360 - roll;
return roll;

}

// Returns the number of degrees from the -Y axis that it
// is pointing.
int LSM303::heading(void)
Expand Down
5 changes: 2 additions & 3 deletions LSM303/LSM303.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ class LSM303
bool timeoutOccurred(void);

int heading(void);
int pitch(void);
int roll(void);
int heading(vector from);

// vector functions
Expand All @@ -157,6 +159,3 @@ class LSM303
};

#endif