Skip to content

Commit

Permalink
quaternions in urdf (PR 51 new attempt) + bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Doisy committed Jan 20, 2024
1 parent 424643d commit 077703e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ if(APPEND_PROJECT_NAME_TO_INCLUDEDIR)
endif()

set (URDF_MAJOR_VERSION 1)
set (URDF_MINOR_VERSION 1)
set (URDF_PATCH_VERSION 1)
set (URDF_MINOR_VERSION 2)
set (URDF_PATCH_VERSION 0)

set (URDF_VERSION ${URDF_MAJOR_VERSION}.${URDF_MINOR_VERSION}.${URDF_PATCH_VERSION})

Expand Down
49 changes: 49 additions & 0 deletions include/urdf_model/pose.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,43 @@ class Vector3
};
};

class Vector4
{
public:
Vector4(double _x,double _y, double _z, double _w) {this->x=_x;this->y=_y;this->z=_z;this->w=_w;};
Vector4() {this->clear();};
double x;
double y;
double z;
double w;

void clear() {this->x=this->y=this->z=this->w=0.0;};
void init(const std::string &vector_str)
{
this->clear();
std::vector<std::string> pieces;
std::vector<double> xyzw;
urdf::split_string( pieces, vector_str, " ");
for (unsigned int i = 0; i < pieces.size(); ++i){
if (pieces[i] != ""){
try {
xyzw.push_back(strToDouble(pieces[i].c_str()));
} catch(std::runtime_error &) {
throw ParseError("Unable to parse component [" + pieces[i] + "] to a double (while parsing a vector value)");
}
}
}

if (xyzw.size() != 4)
throw ParseError("Parser found " + std::to_string(xyzw.size()) + " elements but 4 expected while parsing vector [" + vector_str + "]");

this->x = xyzw[0];
this->y = xyzw[1];
this->z = xyzw[2];
this->w = xyzw[3];
}
};

class Rotation
{
public:
Expand Down Expand Up @@ -163,6 +200,18 @@ class Rotation
rpy.init(rotation_str);
setFromRPY(rpy.x, rpy.y, rpy.z);
}

void initQuaternion(const std::string &rotation_str)
{
this->clear();
Vector4 xyzw_quat;
xyzw_quat.init(rotation_str);
this->x = xyzw_quat.x;
this->y = xyzw_quat.y;
this->z = xyzw_quat.z;
this->w = xyzw_quat.w;
this->normalize();
}

void clear() { this->x=this->y=this->z=0.0;this->w=1.0; }

Expand Down

0 comments on commit 077703e

Please sign in to comment.