mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-16 10:23:34 +08:00
Features and fixes
* added the trace function for a SquareMatrix * added Vector3.hat() and it's counterpart Dcm.vee() for skewsymskew symmetric matrix operations in relation to the cross product see https://en.wikipedia.org/wiki/Hat_operator * Matrix::write_string produced runtime errors when I used it in PX4 posix simulation, i simplified it * a Matrix3f is a SquareMatrix * added tests for SquareMatrix.trace, Vector3.hat and Dcm.vee * added a test for quaternion initialisation from array * preventing buffer overflows in Matrix.write_string method
This commit is contained in:
committed by
James Goppert
parent
07fba8322a
commit
65679fbcbb
+3
-19
@@ -274,28 +274,14 @@ public:
|
||||
|
||||
void write_string(char * buf, size_t n) const
|
||||
{
|
||||
buf[0] = '\0'; // make an empty string to begin with (we need the '\0' for strlen to work)
|
||||
const Matrix<Type, M, N> &self = *this;
|
||||
char data_buf[500] = {0};
|
||||
for (size_t i = 0; i < M; i++) {
|
||||
char data_line[100] = {0};
|
||||
char data_line_formatted[100] = {0};
|
||||
for (size_t j = 0; j < N; j++) {
|
||||
char val_buf[15];
|
||||
if (j == N-1) {
|
||||
snprintf(val_buf, 15, "\t%10g", double(self(i, j)));
|
||||
} else {
|
||||
snprintf(val_buf, 15, "\t%10g,", double(self(i, j)));
|
||||
}
|
||||
strncat(data_line, val_buf, 300);
|
||||
snprintf(buf + strlen(buf), n - strlen(buf), "\t%.2g", double(self(i, j))); // directly append to the string buffer
|
||||
}
|
||||
if (i == M-1) {
|
||||
snprintf(data_line_formatted, n, "[%s]", data_line);
|
||||
} else {
|
||||
snprintf(data_line_formatted, n, "[%s],\n", data_line);
|
||||
}
|
||||
strncat(data_buf, data_line_formatted, n);
|
||||
snprintf(buf + strlen(buf), n - strlen(buf), "\n");
|
||||
}
|
||||
snprintf(buf, n, "[%s]", data_buf);
|
||||
}
|
||||
|
||||
void print() const
|
||||
@@ -511,8 +497,6 @@ std::ostream& operator<<(std::ostream& os,
|
||||
}
|
||||
#endif // defined(SUPPORT_STDIOSTREAM)
|
||||
|
||||
typedef Matrix<float, 3, 3> Matrix3f;
|
||||
|
||||
} // namespace matrix
|
||||
|
||||
/* vim: set et fenc=utf-8 ff=unix sts=0 sw=4 ts=4 : */
|
||||
|
||||
Reference in New Issue
Block a user