|
From: <is...@us...> - 2009-03-03 20:39:24
|
Revision: 12041
http://personalrobots.svn.sourceforge.net/personalrobots/?rev=12041&view=rev
Author: isucan
Date: 2009-03-03 20:39:23 +0000 (Tue, 03 Mar 2009)
Log Message:
-----------
functionality for defining meshes
Modified Paths:
--------------
pkg/trunk/motion_planning/planning_models/CMakeLists.txt
pkg/trunk/motion_planning/planning_models/include/planning_models/shapes.h
pkg/trunk/motion_planning/planning_models/src/kinematic.cpp
Added Paths:
-----------
pkg/trunk/motion_planning/planning_models/src/load_mesh.cpp
Modified: pkg/trunk/motion_planning/planning_models/CMakeLists.txt
===================================================================
--- pkg/trunk/motion_planning/planning_models/CMakeLists.txt 2009-03-03 19:58:37 UTC (rev 12040)
+++ pkg/trunk/motion_planning/planning_models/CMakeLists.txt 2009-03-03 20:39:23 UTC (rev 12041)
@@ -5,7 +5,8 @@
set(CMAKE_BUILD_TYPE Release)
-rospack_add_library(planning_models src/kinematic.cpp)
+rospack_add_library(planning_models src/kinematic.cpp
+ src/load_mesh.cpp)
# Unit tests
rospack_add_gtest(test_kinematic test/test_kinematic.cpp)
Modified: pkg/trunk/motion_planning/planning_models/include/planning_models/shapes.h
===================================================================
--- pkg/trunk/motion_planning/planning_models/include/planning_models/shapes.h 2009-03-03 19:58:37 UTC (rev 12040)
+++ pkg/trunk/motion_planning/planning_models/include/planning_models/shapes.h 2009-03-03 20:39:23 UTC (rev 12041)
@@ -37,6 +37,8 @@
#ifndef PLANNING_MODELS_SHAPES_
#define PLANNING_MODELS_SHAPES_
+#include <cstdlib>
+
namespace planning_models
{
@@ -56,7 +58,7 @@
{
}
- enum { UNKNOWN, SPHERE, CYLINDER, BOX }
+ enum { UNKNOWN, SPHERE, CYLINDER, BOX, MESH }
type;
};
@@ -122,6 +124,52 @@
double size[3];
};
+ /** Definition of a mesh */
+ class Mesh : public Shape
+ {
+ public:
+ Mesh(void) : Shape()
+ {
+ type = MESH;
+ vertexCount = 0;
+ vertices = NULL;
+ triangleCount = 0;
+ triangles = NULL;
+ normals = NULL;
+ }
+
+ Mesh(unsigned int vCount, unsigned int tCount) : Shape()
+ {
+ type = MESH;
+ vertexCount = vCount;
+ vertices = new double[vCount * 3];
+ triangleCount = tCount;
+ triangles = new unsigned int[tCount * 3];
+ normals = new double[tCount * 3];
+ }
+
+ virtual ~Mesh(void)
+ {
+ if (vertices)
+ delete[] vertices;
+ if (triangles)
+ delete[] triangles;
+ if (normals)
+ delete[] normals;
+ }
+
+ unsigned int vertexCount; // the number of available vertices
+ double *vertices; // the position for each vertex
+ // vertex k has values at index (3k, 3k+1, 3k+2) = (x,y,z)
+
+ unsigned int triangleCount; // the number of triangles formed with the vertices
+ unsigned int *triangles; // the vertex indices for each triangle
+ // triangle k has vertices at index (3k, 3k+1, 3k+2) = (v1, v2, v3)
+
+ double *normals; // the normal to each triangle
+ // unit vector represented as (x,y,z)
+ };
+
}
}
Modified: pkg/trunk/motion_planning/planning_models/src/kinematic.cpp
===================================================================
--- pkg/trunk/motion_planning/planning_models/src/kinematic.cpp 2009-03-03 19:58:37 UTC (rev 12040)
+++ pkg/trunk/motion_planning/planning_models/src/kinematic.cpp 2009-03-03 20:39:23 UTC (rev 12041)
@@ -38,16 +38,23 @@
#include <algorithm>
#include <cmath>
-/** Operator for sorting objects by name */
-template<typename T>
-struct SortByName
+namespace planning_models
{
- bool operator()(const T *a, const T *b) const
+
+ /** Operator for sorting objects by name */
+ template<typename T>
+ struct SortByName
{
- return a->name < b->name;
- }
-};
+ bool operator()(const T *a, const T *b) const
+ {
+ return a->name < b->name;
+ }
+ };
+ // load a mesh
+ shapes::Mesh* load_binary_stl(const char *filename);
+}
+
const std::string& planning_models::KinematicModel::getModelName(void) const
{
return m_name;
Added: pkg/trunk/motion_planning/planning_models/src/load_mesh.cpp
===================================================================
--- pkg/trunk/motion_planning/planning_models/src/load_mesh.cpp (rev 0)
+++ pkg/trunk/motion_planning/planning_models/src/load_mesh.cpp 2009-03-03 20:39:23 UTC (rev 12041)
@@ -0,0 +1,225 @@
+/*********************************************************************
+* Software License Agreement (BSD License)
+*
+* Copyright (c) 2008, Willow Garage, Inc.
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+*
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+* * Neither the name of the Willow Garage nor the names of its
+* contributors may be used to endorse or promote products derived
+* from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+* POSSIBILITY OF SUCH DAMAGE.
+*********************************************************************/
+
+#include <cstdio>
+#include <cmath>
+#include <cassert>
+#include <LinearMath/btVector3.h>
+#include <algorithm>
+#include <vector>
+#include <set>
+#include "planning_models/shapes.h"
+
+// \author Ioan Sucan ; based on stl_to_mesh
+
+namespace planning_models
+{
+
+ struct myVertex
+ {
+ btVector3 point;
+ unsigned int index;
+ };
+
+ struct ltVertexValue
+ {
+ bool operator()(const myVertex &p1, const myVertex &p2) const
+ {
+ const btVector3 &v1 = p1.point;
+ const btVector3 &v2 = p2.point;
+ if (v1.getX() < v2.getX())
+ return true;
+ if (v1.getX() > v2.getX())
+ return false;
+ if (v1.getY() < v2.getY())
+ return true;
+ if (v1.getY() > v2.getY())
+ return false;
+ if (v1.getZ() < v2.getZ())
+ return true;
+ return false;
+ }
+ };
+
+ struct ltVertexIndex
+ {
+ bool operator()(const myVertex &p1, const myVertex &p2) const
+ {
+ return p1.index < p2.index;
+ }
+ };
+
+ shapes::Mesh* load_binary_stl(const char *filename)
+ {
+
+ FILE* input = fopen(filename, "r");
+ if (!input)
+ return NULL;
+
+ fseek(input, 0, SEEK_END);
+ long fileSize = ftell(input);
+ fseek(input, 0, SEEK_SET);
+
+ char* buffer = new char[fileSize];
+ size_t rd = fread(buffer, fileSize, 1, input);
+
+ fclose(input);
+
+ if (rd == 1)
+ {
+ char* pos = buffer;
+ pos += 80; // skip the 80 byte header
+
+ unsigned int numTriangles = *(unsigned int*)pos;
+ pos += 4;
+
+ // make sure we have read enough data
+ if (50 * numTriangles + 84 <= fileSize)
+ {
+
+ std::set<myVertex, ltVertexValue> vertices;
+ std::vector<unsigned int> triangles;
+
+ for (unsigned int currentTriangle = 0 ; currentTriangle < numTriangles ; ++currentTriangle)
+ {
+ // skip the normal
+ pos += 12;
+
+ // read vertices
+ btVector3 v1(0,0,0);
+ btVector3 v2(0,0,0);
+ btVector3 v3(0,0,0);
+
+ v1.setX(*(float*)pos);
+ pos += 4;
+ v1.setY(*(float*)pos);
+ pos += 4;
+ v1.setZ(*(float*)pos);
+ pos += 4;
+
+ v2.setX(*(float*)pos);
+ pos += 4;
+ v2.setY(*(float*)pos);
+ pos += 4;
+ v2.setZ(*(float*)pos);
+ pos += 4;
+
+ v3.setX(*(float*)pos);
+ pos += 4;
+ v3.setY(*(float*)pos);
+ pos += 4;
+ v3.setZ(*(float*)pos);
+ pos += 4;
+
+ // skip attribute
+ pos += 2;
+
+ // check if we have new vertices
+ myVertex vt;
+
+ vt.point = v1;
+ std::set<myVertex, ltVertexValue>::iterator p1 = vertices.find(vt);
+ if (p1 == vertices.end())
+ {
+ vt.index = vertices.size();
+ vertices.insert(vt);
+ }
+ else
+ vt.index = p1->index;
+ triangles.push_back(vt.index);
+
+ vt.point = v2;
+ std::set<myVertex, ltVertexValue>::iterator p2 = vertices.find(vt);
+ if (p2 == vertices.end())
+ {
+ vt.index = vertices.size();
+ vertices.insert(vt);
+ }
+ else
+ vt.index = p2->index;
+ triangles.push_back(vt.index);
+
+ vt.point = v3;
+ std::set<myVertex, ltVertexValue>::iterator p3 = vertices.find(vt);
+ if (p3 == vertices.end())
+ {
+ vt.index = vertices.size();
+ vertices.insert(vt);
+ }
+ else
+ vt.index = p3->index;
+ triangles.push_back(vt.index);
+ }
+
+ delete[] buffer;
+
+ // sort our vertices
+ std::vector<myVertex> vt;
+ vt.insert(vt.begin(), vertices.begin(), vertices.end());
+ std::sort(vt.begin(), vt.end(), ltVertexIndex());
+
+
+ // copy the data to a mesh structure
+ unsigned int nt = triangles.size() / 3;
+
+ shapes::Mesh *mesh = new shapes::Mesh(vt.size(), nt);
+ for (unsigned int i = 0 ; i < vt.size() ; ++i)
+ {
+ mesh->vertices[3 * i ] = vt[i].point.getX();
+ mesh->vertices[3 * i + 1] = vt[i].point.getY();
+ mesh->vertices[3 * i + 2] = vt[i].point.getZ();
+ }
+
+ std::copy(triangles.begin(), triangles.end(), mesh->triangles);
+
+ // compute normals
+ for (unsigned int i = 0 ; i < nt ; ++i)
+ {
+ btVector3 s1 = vt[triangles[i * 3 ]].point - vt[triangles[i * 3 + 1]].point;
+ btVector3 s2 = vt[triangles[i * 3 + 1]].point - vt[triangles[i * 3 + 2]].point;
+ btVector3 normal = s1.cross(s2);
+ normal.normalize();
+ mesh->normals[3 * i ] = normal.getX();
+ mesh->normals[3 * i + 1] = normal.getY();
+ mesh->normals[3 * i + 2] = normal.getZ();
+ }
+
+ return mesh;
+ }
+ }
+
+ return NULL;
+ }
+
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <is...@us...> - 2009-03-04 14:54:05
|
Revision: 12110
http://personalrobots.svn.sourceforge.net/personalrobots/?rev=12110&view=rev
Author: isucan
Date: 2009-03-04 14:53:56 +0000 (Wed, 04 Mar 2009)
Log Message:
-----------
fiing test failure
Modified Paths:
--------------
pkg/trunk/motion_planning/planning_models/src/load_mesh.cpp
pkg/trunk/motion_planning/planning_models/test/test_kinematic.cpp
Modified: pkg/trunk/motion_planning/planning_models/src/load_mesh.cpp
===================================================================
--- pkg/trunk/motion_planning/planning_models/src/load_mesh.cpp 2009-03-04 14:50:35 UTC (rev 12109)
+++ pkg/trunk/motion_planning/planning_models/src/load_mesh.cpp 2009-03-04 14:53:56 UTC (rev 12110)
@@ -185,7 +185,7 @@
pos += 4;
// make sure we have read enough data
- if (50 * numTriangles + 84 <= fileSize)
+ if ((long)(50 * numTriangles + 84) <= fileSize)
{
std::vector<btVector3> vertices;
Modified: pkg/trunk/motion_planning/planning_models/test/test_kinematic.cpp
===================================================================
--- pkg/trunk/motion_planning/planning_models/test/test_kinematic.cpp 2009-03-04 14:50:35 UTC (rev 12109)
+++ pkg/trunk/motion_planning/planning_models/test/test_kinematic.cpp 2009-03-04 14:53:56 UTC (rev 12110)
@@ -822,18 +822,6 @@
delete model;
}
-namespace planning_models
-{
- shapes::Mesh* create_mesh_from_binary_stl(const char *filename);
-}
-
-TEST(Loading, Mesh)
-{
- planning_models::shapes::Mesh *m = planning_models::create_mesh_from_binary_stl("/home/isucan/base.stl");
- EXPECT_TRUE(m != NULL);
- delete m;
-}
-
int main(int argc, char **argv)
{
testing::InitGoogleTest(&argc, argv);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <is...@us...> - 2009-06-05 19:59:51
|
Revision: 16776
http://personalrobots.svn.sourceforge.net/personalrobots/?rev=16776&view=rev
Author: isucan
Date: 2009-06-05 19:59:01 +0000 (Fri, 05 Jun 2009)
Log Message:
-----------
removed check for repeated calls (same params)
Modified Paths:
--------------
pkg/trunk/motion_planning/planning_models/CMakeLists.txt
pkg/trunk/motion_planning/planning_models/include/planning_models/kinematic.h
pkg/trunk/motion_planning/planning_models/src/kinematic.cpp
Modified: pkg/trunk/motion_planning/planning_models/CMakeLists.txt
===================================================================
--- pkg/trunk/motion_planning/planning_models/CMakeLists.txt 2009-06-05 19:47:49 UTC (rev 16775)
+++ pkg/trunk/motion_planning/planning_models/CMakeLists.txt 2009-06-05 19:59:01 UTC (rev 16776)
@@ -3,7 +3,7 @@
rospack(planning_models)
rospack_add_boost_directories()
-set(ROS_BUILD_TYPE Debug)
+set(ROS_BUILD_TYPE Release)
rospack_add_library(planning_models src/kinematic.cpp
src/load_mesh.cpp)
Modified: pkg/trunk/motion_planning/planning_models/include/planning_models/kinematic.h
===================================================================
--- pkg/trunk/motion_planning/planning_models/include/planning_models/kinematic.h 2009-06-05 19:47:49 UTC (rev 16775)
+++ pkg/trunk/motion_planning/planning_models/include/planning_models/kinematic.h 2009-06-05 19:59:01 UTC (rev 16776)
@@ -557,15 +557,10 @@
m_ignoreSensors = false;
m_verbose = false;
m_built = false;
- m_lastTransformParams = NULL;
- m_lastTransformGroup = -2;
}
virtual ~KinematicModel(void)
{
- if (m_lastTransformParams)
- delete[] m_lastTransformParams;
-
for (unsigned int i = 0 ; i < m_robots.size() ; ++i)
delete m_robots[i];
}
@@ -652,11 +647,6 @@
boost::mutex m_lock;
- /* Subsequent calls with the same argument should not redo computation;
- * We simply store this state information and compare against it for next time */
- double *m_lastTransformParams;
- int m_lastTransformGroup;
-
private:
/** Build the needed datastructure for a joint */
Modified: pkg/trunk/motion_planning/planning_models/src/kinematic.cpp
===================================================================
--- pkg/trunk/motion_planning/planning_models/src/kinematic.cpp 2009-06-05 19:47:49 UTC (rev 16775)
+++ pkg/trunk/motion_planning/planning_models/src/kinematic.cpp 2009-06-05 19:59:01 UTC (rev 16776)
@@ -80,7 +80,6 @@
params[i] = 0.0;
else
params[i] = (m_mi.stateBounds[2 * i] + m_mi.stateBounds[2 * i + 1]) / 2.0;
- m_lastTransformGroup = -2;
computeTransformsGroup(params, -1);
}
@@ -92,23 +91,7 @@
void planning_models::KinematicModel::computeTransformsGroup(const double *params, int groupID)
{
assert(m_built);
-
- const unsigned int gdim = getGroupDimension(groupID);
- if (m_lastTransformGroup == groupID)
- {
- bool same = true;
- for (unsigned int i = 0 ; i < gdim ; ++i)
- if (params[i] != m_lastTransformParams[i])
- {
- same = false;
- break;
- }
- if (same)
- return;
- }
- m_lastTransformGroup = groupID;
- memcpy(m_lastTransformParams, params, gdim * sizeof(double));
-
+
if (groupID >= 0)
{
for (unsigned int i = 0 ; i < m_mi.groupChainStart[groupID].size() ; ++i)
@@ -454,8 +437,6 @@
m_jointMap[m_robots[i]->joints[j]->name] = m_robots[i]->joints[j];
}
- m_lastTransformParams = new double[m_mi.stateDimension];
-
computeParameterNames();
defaultState();
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <is...@us...> - 2009-06-13 04:45:00
|
Revision: 17063
http://personalrobots.svn.sourceforge.net/personalrobots/?rev=17063&view=rev
Author: isucan
Date: 2009-06-13 04:44:58 +0000 (Sat, 13 Jun 2009)
Log Message:
-----------
one more utility function
Modified Paths:
--------------
pkg/trunk/motion_planning/planning_models/include/planning_models/kinematic.h
pkg/trunk/motion_planning/planning_models/src/kinematic.cpp
Modified: pkg/trunk/motion_planning/planning_models/include/planning_models/kinematic.h
===================================================================
--- pkg/trunk/motion_planning/planning_models/include/planning_models/kinematic.h 2009-06-13 04:44:13 UTC (rev 17062)
+++ pkg/trunk/motion_planning/planning_models/include/planning_models/kinematic.h 2009-06-13 04:44:58 UTC (rev 17063)
@@ -585,7 +585,7 @@
unsigned int getRobotCount(void) const;
Robot* getRobot(unsigned int index) const;
- /** Get the array of groups, indexed by their group ID */
+ /** Get the array of planning groups, indexed by their group ID */
void getGroups(std::vector<std::string> &groups) const;
/** Get the number of groups */
@@ -614,6 +614,9 @@
same as in the group state */
void getJointsInGroup(std::vector<std::string> &names, const std::string &name) const;
+ /** Return the index of a joint in the complete state vector */
+ int getJointIndex(const std::string &name) const;
+
/** Get the index for the parameter of a joint in a given group */
int getJointIndexInGroup(const std::string &name, const std::string &group) const;
Modified: pkg/trunk/motion_planning/planning_models/src/kinematic.cpp
===================================================================
--- pkg/trunk/motion_planning/planning_models/src/kinematic.cpp 2009-06-13 04:44:13 UTC (rev 17062)
+++ pkg/trunk/motion_planning/planning_models/src/kinematic.cpp 2009-06-13 04:44:58 UTC (rev 17063)
@@ -826,6 +826,15 @@
return m_params;
}
+int planning_models::KinematicModel::getJointIndex(const std::string &name) const
+{
+ std::map<std::string, unsigned int>::const_iterator it = m_mi.parameterIndex.find(name);
+ if (it != m_mi.parameterIndex.end())
+ return it->second;
+ m_msg.error("Joint " + name + " not found");
+ return -1;
+}
+
int planning_models::KinematicModel::getJointIndexInGroup(const std::string &name, const std::string &group) const
{
return getJointIndexInGroup(name, getGroupID(group));
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <is...@us...> - 2009-06-19 03:22:48
|
Revision: 17340
http://personalrobots.svn.sourceforge.net/personalrobots/?rev=17340&view=rev
Author: isucan
Date: 2009-06-19 02:02:25 +0000 (Fri, 19 Jun 2009)
Log Message:
-----------
operators for ease of use
Modified Paths:
--------------
pkg/trunk/motion_planning/planning_models/include/planning_models/kinematic_state_params.h
pkg/trunk/motion_planning/planning_models/src/kinematic_state_params.cpp
pkg/trunk/motion_planning/planning_models/test/test_kinematic.cpp
Modified: pkg/trunk/motion_planning/planning_models/include/planning_models/kinematic_state_params.h
===================================================================
--- pkg/trunk/motion_planning/planning_models/include/planning_models/kinematic_state_params.h 2009-06-19 01:35:31 UTC (rev 17339)
+++ pkg/trunk/motion_planning/planning_models/include/planning_models/kinematic_state_params.h 2009-06-19 02:02:25 UTC (rev 17340)
@@ -56,8 +56,13 @@
public:
StateParams(KinematicModel *model);
+ StateParams(const StateParams &sp);
virtual ~StateParams(void);
+ StateParams &operator=(const StateParams &rhs);
+
+ bool operator==(const StateParams &rhs) const;
+
/** \brief Mark all values as unseen */
void reset(void);
@@ -166,11 +171,14 @@
protected:
+ /** \brief Copy data from another instance of this class */
+ void copyFrom(const StateParams &sp);
+
KinematicModel *m_owner;
- msg::Interface m_msg;
KinematicModel::ModelInfo &m_mi;
double *m_params;
std::map<unsigned int, bool> m_seen;
+ msg::Interface m_msg;
};
}
Modified: pkg/trunk/motion_planning/planning_models/src/kinematic_state_params.cpp
===================================================================
--- pkg/trunk/motion_planning/planning_models/src/kinematic_state_params.cpp 2009-06-19 01:35:31 UTC (rev 17339)
+++ pkg/trunk/motion_planning/planning_models/src/kinematic_state_params.cpp 2009-06-19 02:02:25 UTC (rev 17340)
@@ -40,7 +40,7 @@
#include <sstream>
#include <cmath>
-planning_models::StateParams::StateParams(KinematicModel *model) : m_owner(model), m_mi(model->getModelInfo())
+planning_models::StateParams::StateParams(KinematicModel *model) : m_owner(model), m_mi(model->getModelInfo()), m_params(NULL)
{
assert(model->isBuilt());
m_params = m_mi.stateDimension > 0 ? new double[m_mi.stateDimension] : NULL;
@@ -50,12 +50,47 @@
setInRobotFrame();
}
+planning_models::StateParams::StateParams(const StateParams &sp) : m_owner(sp.m_owner), m_mi(sp.m_mi), m_params(NULL)
+{
+ copyFrom(sp);
+}
+
planning_models::StateParams::~StateParams(void)
{
if (m_params)
delete[] m_params;
}
+planning_models::StateParams& planning_models::StateParams::operator=(const StateParams &rhs)
+{
+ if (this != &rhs)
+ copyFrom(rhs);
+ return *this;
+}
+
+bool planning_models::StateParams::operator==(const StateParams &rhs) const
+{
+ if (m_mi.stateDimension != rhs.m_mi.stateDimension)
+ return false;
+ for (unsigned int i = 0 ; i < m_mi.stateDimension ; ++i)
+ if (fabs(m_params[i] - rhs.m_params[i]) > DBL_MIN)
+ return false;
+ return true;
+}
+
+void planning_models::StateParams::copyFrom(const StateParams &sp)
+{
+ m_owner = sp.m_owner;
+ m_mi = sp.m_mi;
+ if (m_params)
+ delete[] m_params;
+ m_params = m_mi.stateDimension > 0 ? new double[m_mi.stateDimension] : NULL;
+ if (m_params)
+ for (unsigned int i = 0 ; i < m_mi.stateDimension ; ++i)
+ m_params[i] = sp.m_params[i];
+ m_seen = sp.m_seen;
+}
+
void planning_models::StateParams::reset(void)
{
for (unsigned int i = 0 ; i < m_mi.stateDimension ; ++i)
Modified: pkg/trunk/motion_planning/planning_models/test/test_kinematic.cpp
===================================================================
--- pkg/trunk/motion_planning/planning_models/test/test_kinematic.cpp 2009-06-19 01:35:31 UTC (rev 17339)
+++ pkg/trunk/motion_planning/planning_models/test/test_kinematic.cpp 2009-06-19 02:02:25 UTC (rev 17340)
@@ -436,6 +436,7 @@
tmpParam[0] = 0.1;
sp->setParamsJoint(tmpParam, "link_a_joint");
EXPECT_FALSE(sp->seenAll());
+ EXPECT_TRUE(sp->seenJoint("link_a_joint"));
tmpParam[0] = -1.0;
sp->setParamsJoint(tmpParam, "link_c_joint");
@@ -451,6 +452,9 @@
EXPECT_EQ(0.1, sp->getParams()[3]);
EXPECT_EQ(-1.0, sp->getParams()[4]);
+ planning_models::StateParams sp_copy = *sp;
+ EXPECT_TRUE(sp_copy == *sp);
+
delete sp;
delete model;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <is...@us...> - 2009-06-30 05:23:28
|
Revision: 17954
http://personalrobots.svn.sourceforge.net/personalrobots/?rev=17954&view=rev
Author: isucan
Date: 2009-06-30 05:22:26 +0000 (Tue, 30 Jun 2009)
Log Message:
-----------
some documentation on planning models
Modified Paths:
--------------
pkg/trunk/motion_planning/planning_models/include/planning_models/kinematic.h
pkg/trunk/motion_planning/planning_models/include/planning_models/kinematic_state_params.h
pkg/trunk/motion_planning/planning_models/include/planning_models/output.h
Added Paths:
-----------
pkg/trunk/motion_planning/planning_models/mainpage.dox
Modified: pkg/trunk/motion_planning/planning_models/include/planning_models/kinematic.h
===================================================================
--- pkg/trunk/motion_planning/planning_models/include/planning_models/kinematic.h 2009-06-30 05:22:08 UTC (rev 17953)
+++ pkg/trunk/motion_planning/planning_models/include/planning_models/kinematic.h 2009-06-30 05:22:26 UTC (rev 17954)
@@ -49,30 +49,29 @@
#include <string>
#include <map>
-/** Describing a kinematic robot model loaded from URDF. Visual geometry is ignored */
-/** Main namespace */
+/** \brief Main namespace */
namespace planning_models
{
class StateParams;
- /** Definition of a kinematic model. This class is not thread
+ /** \brief Definition of a kinematic model. This class is not thread
safe, however multiple instances can be created */
class KinematicModel
{
public:
- /** Forward definition of a joint */
+ /** \brief Forward definition of a joint */
class Joint;
- /** Forward definition of a link */
+ /** \brief Forward definition of a link */
class Link;
- /** Forward definition of a robot */
+ /** \brief Forward definition of a robot */
class Robot;
- /** A joint from the robot. Contains the transform applied by the joint type */
+ /** \brief A joint from the robot. Contains the transform applied by the joint type */
class Joint
{
friend class KinematicModel;
@@ -92,27 +91,27 @@
}
- /** Name of the joint */
+ /** \brief Name of the joint */
std::string name;
- /** The robot that owns this joint */
+ /** \brief The robot that owns this joint */
Robot *owner;
- /** the links that this joint connects */
+ /** \brief the links that this joint connects */
Link *before;
Link *after;
- /** The range of indices in the parameter vector that
+ /** \brief The range of indices in the parameter vector that
needed to access information about the position of this
joint */
unsigned int usedParams;
- /** Bitvector identifying which groups this joint is part of */
+ /** \brief Bitvector identifying which groups this joint is part of */
std::vector<bool> inGroup;
protected:
- /** the local transform (computed by forward kinematics) */
+ /** \brief the local transform (computed by forward kinematics) */
btTransform varTrans;
/* Compute the parameter names from this joint; the
@@ -121,30 +120,30 @@
vector of parameters */
unsigned int computeParameterNames(unsigned int pos);
- /** Update varTrans if this joint is part of the group indicated by groupID
+ /** \brief Update varTrans if this joint is part of the group indicated by groupID
* and recompute globalTrans using varTrans */
const double* computeTransform(const double *params, int groupID);
- /** Update the value of VarTrans using the information from params */
+ /** \brief Update the value of VarTrans using the information from params */
virtual void updateVariableTransform(const double *params) = 0;
- /** Extract the information needed by the joint given the URDF description */
+ /** \brief Extract the information needed by the joint given the URDF description */
virtual void extractInformation(const robot_desc::URDF::Link *urdfLink, Robot *robot) = 0;
};
- /** A fixed joint */
+ /** \brief A fixed joint */
class FixedJoint : public Joint
{
protected:
- /** Update the value of varTrans using the information from params */
+ /** \brief Update the value of varTrans using the information from params */
virtual void updateVariableTransform(const double *params);
- /** Extract the information needed by the joint given the URDF description */
+ /** \brief Extract the information needed by the joint given the URDF description */
virtual void extractInformation(const robot_desc::URDF::Link *urdfLink, Robot *robot);
};
- /** A planar joint */
+ /** \brief A planar joint */
class PlanarJoint : public Joint
{
public:
@@ -155,14 +154,14 @@
}
protected:
- /** Update the value of varTrans using the information from params */
+ /** \brief Update the value of varTrans using the information from params */
virtual void updateVariableTransform(const double *params);
- /** Extract the information needed by the joint given the URDF description */
+ /** \brief Extract the information needed by the joint given the URDF description */
virtual void extractInformation(const robot_desc::URDF::Link *urdfLink, Robot *robot);
};
- /** A floating joint */
+ /** \brief A floating joint */
class FloatingJoint : public Joint
{
public:
@@ -174,14 +173,14 @@
protected:
- /** Update the value of varTrans using the information from params */
+ /** \brief Update the value of varTrans using the information from params */
virtual void updateVariableTransform(const double *params);
- /** Extract the information needed by the joint given the URDF description */
+ /** \brief Extract the information needed by the joint given the URDF description */
virtual void extractInformation(const robot_desc::URDF::Link *urdfLink, Robot *robot);
};
- /** A prismatic joint */
+ /** \brief A prismatic joint */
class PrismaticJoint : public Joint
{
public:
@@ -196,15 +195,15 @@
double limit[2];
protected:
- /** Update the value of varTrans using the information from params */
+ /** \brief Update the value of varTrans using the information from params */
virtual void updateVariableTransform(const double *params);
- /** Extract the information needed by the joint given the URDF description */
+ /** \brief Extract the information needed by the joint given the URDF description */
virtual void extractInformation(const robot_desc::URDF::Link *urdfLink, Robot *robot);
};
- /** A revolute joint */
+ /** \brief A revolute joint */
class RevoluteJoint : public Joint
{
public:
@@ -223,15 +222,15 @@
protected:
- /** Update the value of varTrans using the information from params */
+ /** \brief Update the value of varTrans using the information from params */
virtual void updateVariableTransform(const double *params);
- /** Extract the information needed by the joint given the URDF description */
+ /** \brief Extract the information needed by the joint given the URDF description */
virtual void extractInformation(const robot_desc::URDF::Link *urdfLink, Robot *robot);
};
- /** Class defining bodies that can be attached to robot
+ /** \brief Class defining bodies that can be attached to robot
links. This is useful when handling objects picked up by
the robot. */
class AttachedBody
@@ -252,22 +251,22 @@
delete shape;
}
- /** The constant transform applied to the link (needs to be specified by user) */
+ /** \brief The constant transform applied to the link (needs to be specified by user) */
btTransform attachTrans;
- /** The geometry of the attached body */
+ /** \brief The geometry of the attached body */
shapes::Shape* shape;
- /** The global transform for this link (computed by forward kinematics) */
+ /** \brief The global transform for this link (computed by forward kinematics) */
btTransform globalTrans;
protected:
- /** recompute globalTrans */
+ /** \brief recompute globalTrans */
void computeTransform(btTransform &parentTrans);
};
- /** A link from the robot. Contains the constant transform applied to the link and its geometry */
+ /** \brief A link from the robot. Contains the constant transform applied to the link and its geometry */
class Link
{
friend class KinematicModel;
@@ -294,36 +293,36 @@
delete attachedBodies[i];
}
- /** Name of the link */
+ /** \brief Name of the link */
std::string name;
- /** The model that owns this link */
+ /** \brief The model that owns this link */
Robot *owner;
- /** Joint that connects this link to the parent link */
+ /** \brief Joint that connects this link to the parent link */
Joint *before;
- /** List of descending joints (each connects to a child link) */
+ /** \brief List of descending joints (each connects to a child link) */
std::vector<Joint*> after;
- /** The constant transform applied to the link (local) */
+ /** \brief The constant transform applied to the link (local) */
btTransform constTrans;
- /** The constant transform applied to the collision geometry of the link (local) */
+ /** \brief The constant transform applied to the collision geometry of the link (local) */
btTransform constGeomTrans;
- /** The geometry of the link */
+ /** \brief The geometry of the link */
shapes::Shape *shape;
- /** Attached bodies */
+ /** \brief Attached bodies */
std::vector<AttachedBody*> attachedBodies;
/* ----------------- Computed data -------------------*/
- /** The global transform this link forwards (computed by forward kinematics) */
+ /** \brief The global transform this link forwards (computed by forward kinematics) */
btTransform globalTransFwd;
- /** The global transform for this link (computed by forward kinematics) */
+ /** \brief The global transform for this link (computed by forward kinematics) */
btTransform globalTrans;
protected:
@@ -331,15 +330,15 @@
/* compute the parameter names from this link */
unsigned int computeParameterNames(unsigned int pos);
- /** recompute globalTrans */
+ /** \brief recompute globalTrans */
const double* computeTransform(const double *params, int groupID);
- /** Extract the information needed by the joint given the URDF description */
+ /** \brief Extract the information needed by the joint given the URDF description */
void extractInformation(const robot_desc::URDF::Link *urdfLink, Robot *robot);
};
- /** A robot structure */
+ /** \brief A robot structure */
struct Robot
{
Robot(KinematicModel *model)
@@ -356,38 +355,38 @@
delete chain;
}
- /** The model that owns this robot */
+ /** \brief The model that owns this robot */
KinematicModel *owner;
- /** A transform that is applied to the entire robot */
+ /** \brief A transform that is applied to the entire robot */
btTransform rootTransform;
- /** List of links in the robot */
+ /** \brief List of links in the robot */
std::vector<Link*> links;
- /** List of joints in the robot */
+ /** \brief List of joints in the robot */
std::vector<Joint*> joints;
- /** The first joint in the robot -- the root */
+ /** \brief The first joint in the robot -- the root */
Joint *chain;
- /** Number of parameters needed to define the joints */
+ /** \brief Number of parameters needed to define the joints */
unsigned int stateDimension;
- /** The bounding box for the set of parameters describing the
+ /** \brief The bounding box for the set of parameters describing the
* joints. This array contains 2 * stateDimension elements:
* positions 2*i and 2*i+1 define the minimum and maximum
* values for the parameter. If both minimum and maximum are
* set to 0, the parameter is unbounded. */
std::vector<double> stateBounds;
- /** The list of index values where floating joints
+ /** \brief The list of index values where floating joints
start. These joints need special attention in motion
planning, so the indices are provided here for
convenience. */
std::vector<int> floatingJoints;
- /** The list of index values where planar joints
+ /** \brief The list of index values where planar joints
start. These joints need special attention in motion
planning, so the indices are provided here for
convenience. */
@@ -403,32 +402,32 @@
};
- /** State information */
+ /** \brief State information */
struct ModelInfo
{
- /** Cumulative list of floating joints */
+ /** \brief Cumulative list of floating joints */
std::vector<int> floatingJoints;
- /** Cumulative list of planar joints */
+ /** \brief Cumulative list of planar joints */
std::vector<int> planarJoints;
- /** Cumulative state dimension */
+ /** \brief Cumulative state dimension */
unsigned int stateDimension;
- /** Cumulative state bounds */
+ /** \brief Cumulative state bounds */
std::vector<double> stateBounds;
- /** A map defining the parameter names in the complete state */
+ /** \brief A map defining the parameter names in the complete state */
std::map<std::string, unsigned int> parameterIndex;
std::map<unsigned int, std::string> parameterName;
- /** Cumulative index list */
+ /** \brief Cumulative index list */
std::vector< std::vector<unsigned int> > groupStateIndexList;
- /** Cumulative list of group roots */
+ /** \brief Cumulative list of group roots */
std::vector< std::vector<Joint*> > groupChainStart;
- /** True if this model has been set in the robot frame */
+ /** \brief True if this model has been set in the robot frame */
bool inRobotFrame;
};
@@ -455,79 +454,79 @@
void setVerbose(bool verbose);
- /** General the model name **/
+ /** \brief General the model name **/
const std::string& getModelName(void) const;
- /** Get the number of robots in the model */
+ /** \brief Get the number of robots in the model */
unsigned int getRobotCount(void) const;
- /** Get the datastructure associated to a specific robot */
+ /** \brief Get the datastructure associated to a specific robot */
Robot* getRobot(unsigned int index) const;
- /** Get the array of planning groups, indexed by their group ID */
+ /** \brief Get the array of planning groups, indexed by their group ID */
void getGroups(std::vector<std::string> &groups) const;
- /** Get the number of groups */
+ /** \brief Get the number of groups */
unsigned int getGroupCount(void) const;
- /** Get the group ID of a group */
+ /** \brief Get the group ID of a group */
int getGroupID(const std::string &group) const;
- /** Get a link by its name */
+ /** \brief Get a link by its name */
Link* getLink(const std::string &link) const;
- /** Get the array of links, in no particular order */
+ /** \brief Get the array of links, in no particular order */
void getLinks(std::vector<Link*> &links) const;
- /** Get a joint by its name */
+ /** \brief Get a joint by its name */
Joint* getJoint(const std::string &joint) const;
- /** Get the array of joints, ordered in the same way as in the state vector */
+ /** \brief Get the array of joints, ordered in the same way as in the state vector */
void getJoints(std::vector<Joint*> &joints) const;
- /** Get the names of the joints in a specific group. Only joints with paramteres are returned and the order is the
+ /** \brief Get the names of the joints in a specific group. Only joints with paramteres are returned and the order is the
same as in the group state */
void getJointsInGroup(std::vector<std::string> &names, int groupID) const;
- /** Get the names of the joints in a specific group. Only joints with parameters are returned and the order is the
+ /** \brief Get the names of the joints in a specific group. Only joints with parameters are returned and the order is the
same as in the group state */
void getJointsInGroup(std::vector<std::string> &names, const std::string &name) const;
- /** Return the index of a joint in the complete state vector */
+ /** \brief Return the index of a joint in the complete state vector */
int getJointIndex(const std::string &name) const;
- /** Get the index for the parameter of a joint in a given group */
+ /** \brief Get the index for the parameter of a joint in a given group */
int getJointIndexInGroup(const std::string &name, const std::string &group) const;
- /** Get the index for the parameter of a joint in a given group */
+ /** \brief Get the index for the parameter of a joint in a given group */
int getJointIndexInGroup(const std::string &name, int groupID) const;
- /** Returns the dimension of the group (as a state, not number of joints) */
+ /** \brief Returns the dimension of the group (as a state, not number of joints) */
unsigned int getGroupDimension(int groupID) const;
- /** Returns the dimension of the group (as a state, not number of joints) */
+ /** \brief Returns the dimension of the group (as a state, not number of joints) */
unsigned int getGroupDimension(const std::string &name) const;
- /** Bring the robot to a default state */
+ /** \brief Bring the robot to a default state */
void defaultState(void);
- /** Apply the transforms to a group, based on the params */
+ /** \brief Apply the transforms to a group, based on the params */
void computeTransformsGroup(const double *params, int groupID);
- /** Apply the transforms to the entire robot, based on the params */
+ /** \brief Apply the transforms to the entire robot, based on the params */
void computeTransforms(const double *params);
- /** Add transforms to the rootTransform such that the robot is in its planar/floating link frame.
+ /** \brief Add transforms to the rootTransform such that the robot is in its planar/floating link frame.
* Such a transform is needed only if the root joint of the robot is planar or floating */
void reduceToRobotFrame(void);
- /** Provide interface to a lock. Use carefully! */
+ /** \brief Provide interface to a lock. Use carefully! */
void lock(void)
{
m_lock.lock();
}
- /** Provide interface to a lock. Use carefully! */
+ /** \brief Provide interface to a lock. Use carefully! */
void unlock(void)
{
m_lock.unlock();
@@ -541,7 +540,7 @@
protected:
- /** The name of the model */
+ /** \brief The name of the model */
std::string m_name;
ModelInfo m_mi;
@@ -564,22 +563,22 @@
private:
- /** Build the needed datastructure for a joint */
+ /** \brief Build the needed datastructure for a joint */
void buildChainJ(Robot *robot, Link *parent, Joint *joint, const robot_desc::URDF::Link *urdfLink, const robot_desc::URDF &model);
- /** Build the needed datastructure for a link */
+ /** \brief Build the needed datastructure for a link */
void buildChainL(Robot *robot, Joint *parent, Link *link, const robot_desc::URDF::Link *urdfLink, const robot_desc::URDF &model);
- /** Construct the list of groups the model knows about (the ones marked with the 'plan' attribute) */
+ /** \brief Construct the list of groups the model knows about (the ones marked with the 'plan' attribute) */
void constructGroupList();
/* compute the parameter names */
void computeParameterNames(void);
- /** Get the index for the parameter of a joint in a given group */
+ /** \brief Get the index for the parameter of a joint in a given group */
int getJointIndexInGroupSlow(const std::string &name, int groupID) const;
- /** Allocate a joint of appropriate type, depending on the loaded link */
+ /** \brief Allocate a joint of appropriate type, depending on the loaded link */
Joint* createJoint(const robot_desc::URDF::Link* urdfLink);
};
Modified: pkg/trunk/motion_planning/planning_models/include/planning_models/kinematic_state_params.h
===================================================================
--- pkg/trunk/motion_planning/planning_models/include/planning_models/kinematic_state_params.h 2009-06-30 05:22:08 UTC (rev 17953)
+++ pkg/trunk/motion_planning/planning_models/include/planning_models/kinematic_state_params.h 2009-06-30 05:22:26 UTC (rev 17954)
@@ -44,9 +44,8 @@
#include <map>
#include <iostream>
-/** Maintaining a kinematic state */
-/** Main namespace */
+/** \brief Main namespace */
namespace planning_models
{
Modified: pkg/trunk/motion_planning/planning_models/include/planning_models/output.h
===================================================================
--- pkg/trunk/motion_planning/planning_models/include/planning_models/output.h 2009-06-30 05:22:08 UTC (rev 17953)
+++ pkg/trunk/motion_planning/planning_models/include/planning_models/output.h 2009-06-30 05:22:26 UTC (rev 17954)
@@ -40,17 +40,23 @@
#include <string>
#include <cstdarg>
-/** Main namespace */
+/** \brief Main namespace */
namespace planning_models
{
- /** Message namespace */
+ /** \brief Message namespace. Code in this namespace is used to
+ forward information/warnings/errors to the user by using
+ output handlers. The library uses an Interface to send such
+ messages. The Interface in turn uses an instance of an
+ OutputHandler to publish this data. By default, data goes to
+ STDOUT and STDERR */
namespace msg
{
- /** The piece of code that desires interaction with an action
- or an output handler should use an instance of this
- class */
+ /** \brief The piece of code that desires interaction with an
+ output handler should use an instance of this
+ class. Multiple instances of this class will use the same
+ OutputHandler */
class Interface
{
public:
@@ -74,7 +80,9 @@
};
- /** Generic class to handle output from a piece of code */
+ /** \brief Generic class to handle output from a piece of
+ code. An instance of an output handler is used by the
+ Interface instances */
class OutputHandler
{
public:
@@ -87,19 +95,20 @@
{
}
- /** Print an error message: "Error: ...." */
+ /** \brief Print an error message: "Error: ...." */
virtual void error(const std::string &text) = 0;
- /** Print an warning message: "Warning: ...." */
+ /** \brief Print an warning message: "Warning: ...." */
virtual void warn(const std::string &text) = 0;
- /** Print some information: "Information: ...." */
+ /** \brief Print some information: "Information: ...." */
virtual void inform(const std::string &text) = 0;
- /** Print a simple message */
+ /** \brief Print a simple message */
virtual void message(const std::string &text) = 0;
};
-
+
+ /** \brief Default output handler: prints to STDOUT and STDERR */
class OutputHandlerSTD : public OutputHandler
{
public:
@@ -108,23 +117,28 @@
{
}
- /** Print an error message: "Error: ...." */
+ /** \brief Print an error message: "Error: ...." */
virtual void error(const std::string &text);
- /** Print an warning message: "Warning: ...." */
+ /** \brief Print an warning message: "Warning: ...." */
virtual void warn(const std::string &text);
- /** Print some information: "Information: ...." */
+ /** \brief Print some information: "Information: ...." */
virtual void inform(const std::string &text);
- /** Print a simple message */
+ /** \brief Print a simple message */
virtual void message(const std::string &text);
};
+ /** \brief Disable all output */
void noOutputHandler(void);
+
+ /** \brief Direct output to this handler */
void useOutputHandler(OutputHandler *oh);
+
+ /** \brief Get the address of the active handler */
OutputHandler* getOutputHandler(void);
}
Added: pkg/trunk/motion_planning/planning_models/mainpage.dox
===================================================================
--- pkg/trunk/motion_planning/planning_models/mainpage.dox (rev 0)
+++ pkg/trunk/motion_planning/planning_models/mainpage.dox 2009-06-30 05:22:26 UTC (rev 17954)
@@ -0,0 +1,32 @@
+/**
+\mainpage
+\htmlinclude manifest.html
+
+\b planning_models is used for describing a kinematic robot model loaded from URDF. Visual geometry is ignored (only collision geometry is considered). This package allows performing forward kinematics for various groups of joints, for potentially multiple robots. The states for different groups of joints can be easily extractes using the KinematicModel class. The StateParams class allows easy updating of various state values by using the joint names specified in URDF.
+
+<!--
+In addition to providing an overview of your package,
+this is the section where the specification and design/architecture
+should be detailed. While the original specification may be done on the
+wiki, it should be transferred here once your package starts to take shape.
+You can then link to this documentation page from the Wiki.
+-->
+
+
+\section codeapi Code API
+- see the KinematicModel class
+- see the StateParams class
+
+<!--
+Provide links to specific auto-generated API documentation within your
+package that is of particular interest to a reader. Doxygen will
+document pretty much every part of your code, so do your best here to
+point the reader to the actual API.
+
+If your codebase is fairly large or has different sets of APIs, you
+should use the doxygen 'group' tag to keep these APIs together. For
+example, the roscpp documentation has 'libros' group.
+-->
+
+
+*/
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <is...@us...> - 2009-07-01 04:09:12
|
Revision: 18070
http://personalrobots.svn.sourceforge.net/personalrobots/?rev=18070&view=rev
Author: isucan
Date: 2009-07-01 04:08:49 +0000 (Wed, 01 Jul 2009)
Log Message:
-----------
functions to allow state perturbation
Modified Paths:
--------------
pkg/trunk/motion_planning/planning_models/include/planning_models/kinematic_state_params.h
pkg/trunk/motion_planning/planning_models/src/kinematic_state_params.cpp
Modified: pkg/trunk/motion_planning/planning_models/include/planning_models/kinematic_state_params.h
===================================================================
--- pkg/trunk/motion_planning/planning_models/include/planning_models/kinematic_state_params.h 2009-07-01 03:26:49 UTC (rev 18069)
+++ pkg/trunk/motion_planning/planning_models/include/planning_models/kinematic_state_params.h 2009-07-01 04:08:49 UTC (rev 18070)
@@ -69,6 +69,12 @@
/** \brief Construct a random state */
void randomState(void);
+ /** \brief Perturb state. Each dimension is perturbed by a factor of its range */
+ void perturbState(double factor);
+
+ /** \brief Update parameters so that they are within the specified bounds */
+ void enforceBounds(void);
+
/** \brief Mark all values as unseen */
void reset(void);
Modified: pkg/trunk/motion_planning/planning_models/src/kinematic_state_params.cpp
===================================================================
--- pkg/trunk/motion_planning/planning_models/src/kinematic_state_params.cpp 2009-07-01 03:26:49 UTC (rev 18069)
+++ pkg/trunk/motion_planning/planning_models/src/kinematic_state_params.cpp 2009-07-01 04:08:49 UTC (rev 18070)
@@ -113,6 +113,25 @@
}
}
+void planning_models::StateParams::perturbState(double factor)
+{
+ for (unsigned int i = 0 ; i < m_mi.stateDimension ; ++i)
+ m_params[i] += factor * (m_mi.stateBounds[2 * i + 1] - m_mi.stateBounds[2 * i]) * (2.0 * ((double)rand() / (RAND_MAX + 1.0)) - 1.0);
+ enforceBounds();
+}
+
+void planning_models::StateParams::enforceBounds(void)
+{
+ for (unsigned int i = 0 ; i < m_mi.stateDimension ; ++i)
+ {
+ if (m_params[i] > m_mi.stateBounds[2 * i + 1])
+ m_params[i] = m_mi.stateBounds[2 * i + 1];
+ else
+ if (m_params[i] < m_mi.stateBounds[2 * i])
+ m_params[i] = m_mi.stateBounds[2 * i];
+ }
+}
+
void planning_models::StateParams::reset(void)
{
for (unsigned int i = 0 ; i < m_mi.stateDimension ; ++i)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <is...@us...> - 2009-07-17 20:23:12
|
Revision: 19132
http://personalrobots.svn.sourceforge.net/personalrobots/?rev=19132&view=rev
Author: isucan
Date: 2009-07-17 20:23:10 +0000 (Fri, 17 Jul 2009)
Log Message:
-----------
cloning for kinematic models works
Modified Paths:
--------------
pkg/trunk/motion_planning/planning_models/src/kinematic.cpp
pkg/trunk/motion_planning/planning_models/test/test_kinematic.cpp
Modified: pkg/trunk/motion_planning/planning_models/src/kinematic.cpp
===================================================================
--- pkg/trunk/motion_planning/planning_models/src/kinematic.cpp 2009-07-17 20:15:00 UTC (rev 19131)
+++ pkg/trunk/motion_planning/planning_models/src/kinematic.cpp 2009-07-17 20:23:10 UTC (rev 19132)
@@ -547,17 +547,23 @@
// for each group, keep track of the indices from the robot state that correspond to it
for (unsigned int i = 0 ; i < joint->inGroup.size() ; ++i)
if (joint->inGroup[i])
+ {
for (unsigned int j = 0 ; j < joint->usedParams ; ++j)
robot->groupStateIndexList[i].push_back(j + robot->stateDimension);
-
- // check if the current link has parents in this group
- // if it does not, it is a root link, so we keep track of it
- for (unsigned int k = 0 ; k < urdfLink->groups.size() ; ++k)
- if (urdfLink->groups[k]->isRoot(urdfLink))
- {
- std::string gname = urdfLink->groups[k]->name;
- if (m_groupsMap.find(gname) != m_groupsMap.end())
- robot->groupChainStart[m_groupsMap[gname]].push_back(joint);
+
+ // if we have a parent link, check if that link is in the same group as we are
+ bool found = false;
+ if (parent)
+ {
+ for (unsigned int j = 0 ; j < m_groupContent[m_groups[i]].size() ; ++j)
+ if (parent->name == m_groupContent[m_groups[i]][j])
+ {
+ found = true;
+ break;
+ }
+ }
+ if (!found)
+ robot->groupChainStart[i].push_back(joint);
}
if (m_verbose && joint->usedParams > 0)
@@ -802,6 +808,7 @@
if (newJoint)
{
+ newJoint->name = joint->name;
newJoint->usedParams = joint->usedParams;
newJoint->inGroup = joint->inGroup;
newJoint->varTrans = joint->varTrans;
@@ -855,8 +862,7 @@
km->m_built = m_built;
km->m_verbose = m_verbose;
km->m_name = m_name;
- km->m_mi = m_mi;
-
+
for (unsigned int i = 0 ; i < m_robots.size() ; ++i)
{
Robot *r = new Robot(km);
Modified: pkg/trunk/motion_planning/planning_models/test/test_kinematic.cpp
===================================================================
--- pkg/trunk/motion_planning/planning_models/test/test_kinematic.cpp 2009-07-17 20:15:00 UTC (rev 19131)
+++ pkg/trunk/motion_planning/planning_models/test/test_kinematic.cpp 2009-07-17 20:23:10 UTC (rev 19132)
@@ -126,61 +126,8 @@
" <elem key=\"my_key\" value=\"my_key_val\"/>"
" </map>"
"</link>"
- "<group name=\"base\" flags=\"planning\">"
- "base_link"
- "</group>"
"</robot>";
- static const std::string MODEL1_PARSED =
- "\n"
- "List of root links in robot 'one_robot' (1) :\n"
- " Link [base_link]:\n"
- " - parent link: world\n"
- " - rpy: (0, 0, 1)\n"
- " - xyz: (0.1, 0, 0)\n"
- " Joint [base_link_joint]:\n"
- " - type: 4\n"
- " - axis: (0, 0, 0)\n"
- " - anchor: (0, 0, 0)\n"
- " - limit: (0, 0)\n"
- " - effortLimit: 0\n"
- " - velocityLimit: 0\n"
- " - calibration: \n"
- " Collision [my_collision]:\n"
- " - verbose: No\n"
- " - rpy: (0, 0, -1)\n"
- " - xyz: (-0.1, 0, 0)\n"
- " Geometry [my_collision_geom]:\n"
- " - type: 2\n"
- " - size: (1, 2, 1)\n"
- " Inertial [base_link_inertial]:\n"
- " - mass: 2.81\n"
- " - com: (0, 0.099, 0)\n"
- " - inertia: (0.1, -0.2, 0.5, -0.09, 1, 0.101)\n"
- " Visual [base_link_visual]:\n"
- " - rpy: (0, 0, 0)\n"
- " - xyz: (0, 0, 0)\n"
- " Geometry [base_link_visual_geom]:\n"
- " - type: 2\n"
- " - size: (1, 2, 1)\n"
- " - groups: base ( planning ) \n"
- " - children links: \n"
- " Data flagged as '':\n"
- " []\n"
- " my_key = my_key_val\n"
- "\n"
- "Frames:\n"
- "\n"
- "Groups:\n"
- " Group [base]:\n"
- " - links: base_link \n"
- " - frames: \n"
- " - flags: planning \n"
- "\n"
- "Chains:\n"
- "\n"
- "Data types:\n";
-
static const std::string MODEL1_INFO =
"Number of robots = 1\n"
"Complete model state dimension = 3\n"
@@ -216,10 +163,6 @@
EXPECT_EQ((unsigned int)1, model->getModelInfo().planarJoints.size());
EXPECT_EQ(0, model->getModelInfo().planarJoints[0]);
-
- std::stringstream ssp;
- file->print(ssp);
- EXPECT_EQ(MODEL1_PARSED, ssp.str());
std::stringstream ssi;
model->printModelInfo(ssi);
@@ -339,12 +282,6 @@
" </geometry>"
" </visual>"
"</link>"
- "<group name=\"base\" flags=\"planning\">"
- "base_link "
- "link_a "
- "link_b "
- "link_c "
- "</group>"
"</robot>";
static const std::string MODEL2_INFO =
@@ -671,37 +608,7 @@
" <box size=\"1 2 1\" />"
" </geometry>"
" </visual>"
- "</link>"
- "<group name=\"r1\" flags=\"planning\">"
- "base_link1 "
- "link_a "
- "link_b "
- "link_c "
- "</group>"
- "<group name=\"r2\" flags=\"planning\">"
- "base_link2 "
- "link_d "
- "link_e "
- "link_f "
- "</group>"
- "<group name=\"r1r2\" flags=\"planning\">"
- "base_link1 "
- "link_a "
- "link_b "
- "link_c "
- "base_link2 "
- "link_d "
- "link_e "
- "link_f "
- "</group>"
- "<group name=\"parts\" flags=\"planning\">"
- "base_link1 "
- "link_a "
- "link_b "
- "link_e "
- "link_f "
- "base_link3 "
- "</group>"
+ "</link>"
"</robot>";
static const std::string MODEL3_INFO =
@@ -774,17 +681,20 @@
model->reduceToRobotFrame();
EXPECT_EQ((unsigned int)13, model->getModelInfo().stateDimension);
- // planning_models::KinematicModel *clone = model->clone();
- // delete model;
- // model = clone;
+ planning_models::KinematicModel *clone = model->clone();
+ delete model;
+ model = clone;
std::stringstream ss;
model->printModelInfo(ss);
- printf("%s\n", ss.str().c_str());
double param[8] = { -1, -1, 0, 1.57, 0.0, 5, 5, 0 };
model->computeTransformsGroup(param, model->getGroupID("parts"));
+ clone = model->clone();
+ delete model;
+ model = clone;
+
EXPECT_TRUE(sameStringIgnoringWS(MODEL3_INFO, ss.str()));
EXPECT_NEAR(-1.0, model->getLink("base_link1")->globalTrans.getOrigin().x(), 1e-5);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <is...@us...> - 2009-07-17 22:29:17
|
Revision: 19146
http://personalrobots.svn.sourceforge.net/personalrobots/?rev=19146&view=rev
Author: isucan
Date: 2009-07-17 22:29:08 +0000 (Fri, 17 Jul 2009)
Log Message:
-----------
on the same way....
Modified Paths:
--------------
pkg/trunk/motion_planning/planning_models/include/planning_models/kinematic.h
pkg/trunk/motion_planning/planning_models/src/kinematic.cpp
Modified: pkg/trunk/motion_planning/planning_models/include/planning_models/kinematic.h
===================================================================
--- pkg/trunk/motion_planning/planning_models/include/planning_models/kinematic.h 2009-07-17 22:28:52 UTC (rev 19145)
+++ pkg/trunk/motion_planning/planning_models/include/planning_models/kinematic.h 2009-07-17 22:29:08 UTC (rev 19146)
@@ -452,7 +452,7 @@
}
/** \brief Return a new instance of the same model */
- KinematicModel* clone(void);
+ KinematicModel* clone(void) const;
/** \brief Construct a kinematic model from a string description and a list of planning groups */
void build(const std::string &description, const std::map< std::string, std::vector<std::string> > &groups);
@@ -601,13 +601,13 @@
Joint* createJoint(const robot_desc::URDF::Link* urdfLink);
/** \brief Create a new joint instance (a copy) */
- Joint* copyJoint(const Joint *joint);
+ Joint* copyJoint(const Joint *joint) const;
/** \brief Recursive copy of data after a joint */
- void cloneAfterJoint(Robot *rb, Joint *dest, const Joint *src);
+ void cloneAfterJoint(Robot *rb, Joint *dest, const Joint *src) const;
/** \brief Recursive copy of data after a link */
- void cloneAfterLink(Robot *rb, Link *dest, const Link *src);
+ void cloneAfterLink(Robot *rb, Link *dest, const Link *src) const;
};
Modified: pkg/trunk/motion_planning/planning_models/src/kinematic.cpp
===================================================================
--- pkg/trunk/motion_planning/planning_models/src/kinematic.cpp 2009-07-17 22:28:52 UTC (rev 19145)
+++ pkg/trunk/motion_planning/planning_models/src/kinematic.cpp 2009-07-17 22:29:08 UTC (rev 19146)
@@ -763,7 +763,7 @@
}
}
-planning_models::KinematicModel::Joint* planning_models::KinematicModel::copyJoint(const Joint *joint)
+planning_models::KinematicModel::Joint* planning_models::KinematicModel::copyJoint(const Joint *joint) const
{
Joint *newJoint = NULL;
@@ -817,7 +817,7 @@
return newJoint;
}
-void planning_models::KinematicModel::cloneAfterJoint(Robot *rb, Joint *dest, const Joint *src)
+void planning_models::KinematicModel::cloneAfterJoint(Robot *rb, Joint *dest, const Joint *src) const
{
rb->joints.push_back(dest);
dest->owner = rb;
@@ -829,7 +829,7 @@
}
}
-void planning_models::KinematicModel::cloneAfterLink(Robot *rb, Link *dest, const Link *src)
+void planning_models::KinematicModel::cloneAfterLink(Robot *rb, Link *dest, const Link *src) const
{
rb->links.push_back(dest);
dest->owner = rb;
@@ -856,7 +856,7 @@
}
}
-planning_models::KinematicModel* planning_models::KinematicModel::clone(void)
+planning_models::KinematicModel* planning_models::KinematicModel::clone(void) const
{
KinematicModel *km = new KinematicModel();
km->m_built = m_built;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <is...@us...> - 2009-07-18 01:20:33
|
Revision: 19162
http://personalrobots.svn.sourceforge.net/personalrobots/?rev=19162&view=rev
Author: isucan
Date: 2009-07-18 01:20:31 +0000 (Sat, 18 Jul 2009)
Log Message:
-----------
random and perturbed states for groups
Modified Paths:
--------------
pkg/trunk/motion_planning/planning_models/include/planning_models/kinematic_state_params.h
pkg/trunk/motion_planning/planning_models/src/kinematic_state_params.cpp
Modified: pkg/trunk/motion_planning/planning_models/include/planning_models/kinematic_state_params.h
===================================================================
--- pkg/trunk/motion_planning/planning_models/include/planning_models/kinematic_state_params.h 2009-07-18 01:09:23 UTC (rev 19161)
+++ pkg/trunk/motion_planning/planning_models/include/planning_models/kinematic_state_params.h 2009-07-18 01:20:31 UTC (rev 19162)
@@ -73,8 +73,20 @@
/** \brief Construct a random state */
void randomState(void);
+ /** \brief Construct a random state for a group */
+ void randomStateGroup(const std::string &group);
+
+ /** \brief Construct a random state for a group */
+ void randomStateGroup(int groupID);
+
/** \brief Perturb state. Each dimension is perturbed by a factor of its range */
void perturbState(double factor);
+
+ /** \brief Perturb state of a group. Each dimension is perturbed by a factor of its range */
+ void perturbStateGroup(double factor, const std::string &group);
+
+ /** \brief Perturb state of a group. Each dimension is perturbed by a factor of its range */
+ void perturbStateGroup(double factor, int groupID);
/** \brief Update parameters so that they are within the specified bounds */
void enforceBounds(void);
Modified: pkg/trunk/motion_planning/planning_models/src/kinematic_state_params.cpp
===================================================================
--- pkg/trunk/motion_planning/planning_models/src/kinematic_state_params.cpp 2009-07-18 01:09:23 UTC (rev 19161)
+++ pkg/trunk/motion_planning/planning_models/src/kinematic_state_params.cpp 2009-07-18 01:20:31 UTC (rev 19162)
@@ -104,6 +104,23 @@
}
}
+void planning_models::StateParams::randomStateGroup(const std::string &group)
+{
+ randomStateGroup(m_owner->getGroupID(group));
+}
+
+
+void planning_models::StateParams::randomStateGroup(int groupID)
+{
+ assert(groupID >= 0 && groupID < (int)m_owner->getGroupCount());
+ for (unsigned int i = 0 ; i < m_mi.groupStateIndexList[groupID].size() ; ++i)
+ {
+ unsigned int j = m_mi.groupStateIndexList[groupID][i];
+ m_params[j] = (m_mi.stateBounds[2 * j + 1] - m_mi.stateBounds[2 * j]) * ((double)rand() / (RAND_MAX + 1.0)) + m_mi.stateBounds[2 * j];
+ m_seen[j] = true;
+ }
+}
+
void planning_models::StateParams::randomState(void)
{
for (unsigned int i = 0 ; i < m_mi.stateDimension ; ++i)
@@ -113,6 +130,23 @@
}
}
+void planning_models::StateParams::perturbStateGroup(double factor, const std::string &group)
+{
+ perturbStateGroup(factor, m_owner->getGroupID(group));
+}
+
+
+void planning_models::StateParams::perturbStateGroup(double factor, int groupID)
+{
+ assert(groupID >= 0 && groupID < (int)m_owner->getGroupCount());
+ for (unsigned int i = 0 ; i < m_mi.groupStateIndexList[groupID].size() ; ++i)
+ {
+ unsigned int j = m_mi.groupStateIndexList[groupID][i];
+ m_params[j] += factor * (m_mi.stateBounds[2 * j + 1] - m_mi.stateBounds[2 * j]) * (2.0 * ((double)rand() / (RAND_MAX + 1.0)) - 1.0);
+ m_seen[j] = true;
+ }
+}
+
void planning_models::StateParams::perturbState(double factor)
{
for (unsigned int i = 0 ; i < m_mi.stateDimension ; ++i)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <is...@us...> - 2009-08-04 18:15:22
|
Revision: 20668
http://personalrobots.svn.sourceforge.net/personalrobots/?rev=20668&view=rev
Author: isucan
Date: 2009-08-04 18:15:14 +0000 (Tue, 04 Aug 2009)
Log Message:
-----------
one more helper function
Modified Paths:
--------------
pkg/trunk/motion_planning/planning_models/include/planning_models/kinematic_state_params.h
pkg/trunk/motion_planning/planning_models/src/kinematic_state_params.cpp
Modified: pkg/trunk/motion_planning/planning_models/include/planning_models/kinematic_state_params.h
===================================================================
--- pkg/trunk/motion_planning/planning_models/include/planning_models/kinematic_state_params.h 2009-08-04 18:14:43 UTC (rev 20667)
+++ pkg/trunk/motion_planning/planning_models/include/planning_models/kinematic_state_params.h 2009-08-04 18:15:14 UTC (rev 20668)
@@ -189,6 +189,12 @@
/** \brief Copy the parameters describing a given joint */
void copyParamsJoint(std::vector<double> ¶ms, const std::string &name) const;
+ /** \brief Copy the parameters describing a given set of joints */
+ void copyParamsJoints(double *params, const std::vector<std::string> &names) const;
+
+ /** \brief Copy the parameters describing a given set of joints */
+ void copyParamsJoints(std::vector<double> ¶ms, const std::vector<std::string> &names) const;
+
/** \brief Check if all params for a joint were seen */
bool seenJoint(const std::string &name) const;
Modified: pkg/trunk/motion_planning/planning_models/src/kinematic_state_params.cpp
===================================================================
--- pkg/trunk/motion_planning/planning_models/src/kinematic_state_params.cpp 2009-08-04 18:14:43 UTC (rev 20667)
+++ pkg/trunk/motion_planning/planning_models/src/kinematic_state_params.cpp 2009-08-04 18:15:14 UTC (rev 20668)
@@ -482,6 +482,18 @@
params[i] = m_params[i];
}
+void planning_models::StateParams::copyParamsJoints(std::vector<double> ¶ms, const std::vector<std::string> &names) const
+{
+ params.clear();
+ for (unsigned int j = 0 ; j < names.size() ; ++j)
+ {
+ std::vector<double> p;
+ copyParamsJoint(p, names[j]);
+ for (unsigned int i = 0 ; i < p.size() ; ++i)
+ params.push_back(p[i]);
+ }
+}
+
void planning_models::StateParams::copyParamsGroup(double *params, const std::string &group) const
{
copyParamsGroup(params, m_owner->getGroupID(group));
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <is...@us...> - 2009-08-29 20:57:37
|
Revision: 23339
http://personalrobots.svn.sourceforge.net/personalrobots/?rev=23339&view=rev
Author: isucan
Date: 2009-08-29 20:57:27 +0000 (Sat, 29 Aug 2009)
Log Message:
-----------
began work on new KinematicModel class; still unused for now, but somewhat complete implementation
Modified Paths:
--------------
pkg/trunk/motion_planning/planning_models/CMakeLists.txt
pkg/trunk/motion_planning/planning_models/manifest.xml
Added Paths:
-----------
pkg/trunk/motion_planning/planning_models/include/planning_models/kinematic_model.h
pkg/trunk/motion_planning/planning_models/src/kinematic_model.cpp
Modified: pkg/trunk/motion_planning/planning_models/CMakeLists.txt
===================================================================
--- pkg/trunk/motion_planning/planning_models/CMakeLists.txt 2009-08-29 20:35:20 UTC (rev 23338)
+++ pkg/trunk/motion_planning/planning_models/CMakeLists.txt 2009-08-29 20:57:27 UTC (rev 23339)
@@ -10,6 +10,10 @@
src/output.cpp)
rospack_link_boost(planning_models thread)
+
+rospack_add_library(planning_models2 src/kinematic_model.cpp)
+rospack_link_boost(planning_models2 thread)
+
# Unit tests
rospack_add_gtest(test_kinematic test/test_kinematic.cpp)
target_link_libraries(test_kinematic planning_models)
Added: pkg/trunk/motion_planning/planning_models/include/planning_models/kinematic_model.h
===================================================================
--- pkg/trunk/motion_planning/planning_models/include/planning_models/kinematic_model.h (rev 0)
+++ pkg/trunk/motion_planning/planning_models/include/planning_models/kinematic_model.h 2009-08-29 20:57:27 UTC (rev 23339)
@@ -0,0 +1,428 @@
+/*********************************************************************
+* Software License Agreement (BSD License)
+*
+* Copyright (c) 2008, Willow Garage, Inc.
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+*
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+* * Neither the name of the Willow Garage nor the names of its
+* contributors may be used to endorse or promote products derived
+* from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+* POSSIBILITY OF SUCH DAMAGE.
+*********************************************************************/
+
+/** \author Ioan Sucan */
+
+#ifndef PLANNING_MODELS_KINEMATIC_MODEL_
+#define PLANNING_MODELS_KINEMATIC_MODEL_
+
+#include <geometric_shapes/shapes.h>
+
+#include <urdf/model.h>
+#include <LinearMath/btTransform.h>
+#include <boost/thread/mutex.hpp>
+
+#include <iostream>
+#include <vector>
+#include <string>
+#include <map>
+
+
+/** \brief Main namespace */
+namespace planning_models
+{
+
+ /** \brief Definition of a kinematic model. This class is not thread
+ safe, however multiple instances can be created */
+ class KinematicModel
+ {
+ public:
+ /** \brief Forward definition of a joint */
+ class Joint;
+
+ /** \brief Forward definition of a link */
+ class Link;
+
+ /** \brief Forward definition of an attached body */
+ class AttachedBody;
+
+ /** \brief Forward definition of a group of joints */
+ class JointGroup;
+
+
+ /** \brief A joint from the robot. Contains the transform applied by the joint type */
+ class Joint
+ {
+ public:
+ Joint(KinematicModel *model);
+ virtual ~Joint(void);
+
+ /** \brief Name of the joint */
+ std::string name;
+
+ /** \brief The model that owns this joint */
+ KinematicModel *owner;
+
+ /** \brief The range of indices in the parameter vector that
+ needed to access information about the position of this
+ joint */
+ unsigned int usedParams;
+
+ /** \brief The index where this joint starts readin params in the global state vector */
+ unsigned int stateIndex;
+
+ /** \brief the links that this joint connects */
+ Link *before;
+ Link *after;
+
+ /** \brief the local transform (computed by forward kinematics) */
+ btTransform varTrans;
+
+ /** \brief Update the value of varTrans using the information from params */
+ virtual void updateVariableTransform(const double *params) = 0;
+
+ };
+
+ /** \brief A fixed joint */
+ class FixedJoint : public Joint
+ {
+ public:
+
+ FixedJoint(KinematicModel *owner) : Joint(owner)
+ {
+ }
+
+ /** \brief Update the value of varTrans using the information from params */
+ virtual void updateVariableTransform(const double *params);
+ };
+
+ /** \brief A planar joint */
+ class PlanarJoint : public Joint
+ {
+ public:
+
+ PlanarJoint(KinematicModel *owner) : Joint(owner)
+ {
+ usedParams = 3; // (x, y, theta)
+ }
+
+ /** \brief Update the value of varTrans using the information from params */
+ virtual void updateVariableTransform(const double *params);
+ };
+
+ /** \brief A floating joint */
+ class FloatingJoint : public Joint
+ {
+ public:
+
+ FloatingJoint(KinematicModel *owner) : Joint(owner)
+ {
+ usedParams = 7; // vector: (x, y, z) quaternion: (x, y, z, w)
+ }
+
+ /** \brief Update the value of varTrans using the information from params */
+ virtual void updateVariableTransform(const double *params);
+ };
+
+ /** \brief A prismatic joint */
+ class PrismaticJoint : public Joint
+ {
+ public:
+
+ PrismaticJoint(KinematicModel *owner) : Joint(owner), axis(0.0, 0.0, 0.0), lowLimit(0.0), hiLimit(0.0)
+ {
+ usedParams = 1;
+ }
+
+ btVector3 axis;
+ double lowLimit;
+ double hiLimit;
+
+ /** \brief Update the value of varTrans using the information from params */
+ virtual void updateVariableTransform(const double *params);
+
+ };
+
+ /** \brief A revolute joint */
+ class RevoluteJoint : public Joint
+ {
+ public:
+
+ RevoluteJoint(KinematicModel *owner) : Joint(owner), axis(0.0, 0.0, 0.0),
+ lowLimit(0.0), hiLimit(0.0), continuous(false)
+ {
+ usedParams = 1;
+ }
+
+ btVector3 axis;
+ double lowLimit;
+ double hiLimit;
+ bool continuous;
+
+ /** \brief Update the value of varTrans using the information from params */
+ virtual void updateVariableTransform(const double *params);
+
+ };
+
+ /** \brief A link from the robot. Contains the constant transform applied to the link and its geometry */
+ class Link
+ {
+ public:
+
+ Link(KinematicModel *model);
+ ~Link(void);
+
+ /** \brief Name of the link */
+ std::string name;
+
+ /** \brief The model that owns this link */
+ KinematicModel *owner;
+
+ /** \brief Joint that connects this link to the parent link */
+ Joint *before;
+
+ /** \brief List of descending joints (each connects to a child link) */
+ std::vector<Joint*> after;
+
+ /** \brief The constant transform applied to the link (local) */
+ btTransform constTrans;
+
+ /** \brief The constant transform applied to the collision geometry of the link (local) */
+ btTransform constGeomTrans;
+
+ /** \brief The geometry of the link */
+ shapes::Shape *shape;
+
+ /** \brief Attached bodies */
+ std::vector<AttachedBody*> attachedBodies;
+
+ /** \brief The global transform this link forwards (computed by forward kinematics) */
+ btTransform globalTransFwd;
+
+ /** \brief The global transform for this link (computed by forward kinematics) */
+ btTransform globalTrans;
+
+ /** \brief Recompute globalTrans and globalTransFwd */
+ inline void computeTransform(void);
+
+ };
+
+
+
+ /** \brief Class defining bodies that can be attached to robot
+ links. This is useful when handling objects picked up by
+ the robot. */
+ class AttachedBody
+ {
+ public:
+
+ AttachedBody(Link *link);
+ ~AttachedBody(void);
+
+ /** \brief The link that owns this attached body */
+ Link *owner;
+
+ /** \brief The geometry of the attached body */
+ shapes::Shape *shape;
+
+ /** \brief The constant transform applied to the link (needs to be specified by user) */
+ btTransform attachTrans;
+
+ /** \brief The global transform for this link (computed by forward kinematics) */
+ btTransform globalTrans;
+
+ /** \brief The set of links this body is allowed to touch */
+ std::vector<std::string> touchLinks;
+
+ /** \brief Recompute globalTrans */
+ inline void computeTransform(void);
+ };
+
+
+ class JointGroup
+ {
+ public:
+
+ JointGroup(KinematicModel *model, const std::string& groupName, const std::vector<Joint*> &groupJoints);
+ ~JointGroup(void);
+
+ /** \brief The kinematic model that owns the group */
+ KinematicModel *owner;
+
+ /** \brief Name of group */
+ std::string name;
+
+ /** \brief Names of joints in the order they appear in the group state */
+ std::vector<std::string> jointNames;
+
+ /** \brief Joint instances in the order they appear in the group state */
+ std::vector<Joint*> joints;
+
+ /** \brief Index where each joint starts within the group state */
+ std::vector<unsigned int> jointIndex;
+
+ /** \brief The dimension of the group */
+ unsigned int dimension;
+
+ /** \brief An array containing the index in the global state for each dimension of the state of the group */
+ std::vector<unsigned int> stateIndex;
+
+ /** \brief The list of joints that are roots in this group */
+ std::vector<Joint*> jointRoots;
+
+ /** \brief Perform forward kinematics starting at the roots
+ within a group. Links that are not in the group are also
+ updated, but transforms for joints that are not in the
+ group are not recomputed. */
+ void computeTransforms(const double *params);
+
+ /** \brief Check if a joint is part of this group */
+ bool hasJoint(const std::string &joint) const;
+
+ private:
+
+ std::map<std::string, unsigned int> jointMap_;
+
+ };
+
+
+ /** \brief Construct a kinematic model from a parsed description and a list of planning groups */
+ KinematicModel(const urdf::Model &model, const std::map< std::string, std::vector<std::string> > &groups);
+
+ /** \brief Destructor. Clear all memory. */
+ ~KinematicModel(void);
+
+ /** \brief Return a new instance of the same model */
+ KinematicModel* clone(void) const;
+
+ /** \brief Bring the robot to a default state */
+ void defaultState(void);
+
+ /** \brief General the model name **/
+ const std::string& getName(void) const;
+
+ /** \brief Get a group by its name */
+ const JointGroup* getGroup(const std::string &name) const;
+
+ /** \brief Check if a group exists */
+ bool hasGroup(const std::string &name) const;
+
+ /** \brief Get the array of planning groups */
+ void getGroups(std::vector<const JointGroup*> &groups) const;
+
+ /** \brief Get the group names, in no particular order */
+ void getGroupNames(std::vector<std::string> &groups) const;
+
+ /** \brief Get a link by its name */
+ const Link* getLink(const std::string &link) const;
+
+ /** \brief Check if a link exists */
+ bool hasLink(const std::string &name) const;
+
+ /** \brief Get the array of links, in no particular order */
+ void getLinks(std::vector<const Link*> &links) const;
+
+ /** \brief Get the link names, in no particular order */
+ void getLinkNames(std::vector<std::string> &links) const;
+
+ /** \brief Get a joint by its name */
+ const Joint* getJoint(const std::string &joint) const;
+
+ /** \brief Check if a joint exists */
+ bool hasJoint(const std::string &name) const;
+
+ /** \brief Get the array of joints, in the order they appear
+ in the robot state. */
+ void getJoints(std::vector<const Joint*> &joints) const;
+
+ /** \brief Get the array of joint names, in the order they
+ appear in the robot state. */
+ void getJointNames(std::vector<std::string> &joints) const;
+
+ /** \brief Perform forward kinematics for the entire robot */
+ void computeTransforms(const double *params);
+
+ /** \brief Get the global transform applied to the entire tree of links */
+ const btTransform& getRootTransform(void) const;
+
+ /** \brief Set the global transform applied to the entire tree of links */
+ void setRootTransform(const btTransform &transform);
+
+ /** \brief Get the dimension of the entire model */
+ unsigned int getDimension(void) const;
+
+ /** \brief Provide interface to a lock. Use carefully! */
+ void lock(void);
+
+ /** \brief Provide interface to a lock. Use carefully! */
+ void unlock(void);
+
+ /** \brief Print information about the constructed model */
+ void printModelInfo(std::ostream &out = std::cout) const;
+
+ /** \brief Print the pose of every link */
+ void printLinkPoses(std::ostream &out = std::cout) const;
+
+ private:
+
+ /** \brief The name of the model */
+ std::string modelName_;
+
+ /** \brief A map from group names to their instances */
+ std::map<std::string, JointGroup*> groupMap_;
+
+ /** \brief A map from link names to their instances */
+ std::map<std::string, Link*> linkMap_;
+
+ /** \brief A map from joint names to their instances */
+ std::map<std::string, Joint*> jointMap_;
+
+ /** \brief The list of joints in the model, in the order they appear in the state vector */
+ std::vector<Joint*> jointList_;
+
+ /** \brief The index at which a joint starts reading values in the state vector */
+ std::vector<unsigned int> jointIndex_;
+
+ /** \brief The root joint */
+ Joint *root_;
+
+ /** \brief The dimension of the model */
+ unsigned int dimension_;
+
+ /** \brief Additional transform to be applied to the tree of links */
+ btTransform rootTransform_;
+
+ boost::mutex lock_;
+
+ void buildGroups(const std::map< std::string, std::vector<std::string> > &groups);
+ Joint* buildRecursive(Link *parent, const urdf::Link *link);
+ Joint* constructJoint(const urdf::Joint *urdfJoint);
+ Link* constructLink(const urdf::Link *urdfLink);
+ shapes::Shape* constructShape(const urdf::Geometry *geom);
+
+ };
+
+}
+
+#endif
Modified: pkg/trunk/motion_planning/planning_models/manifest.xml
===================================================================
--- pkg/trunk/motion_planning/planning_models/manifest.xml 2009-08-29 20:35:20 UTC (rev 23338)
+++ pkg/trunk/motion_planning/planning_models/manifest.xml 2009-08-29 20:57:27 UTC (rev 23339)
@@ -1,16 +1,20 @@
<package>
<description brief="A set of robot models">
A set of robot models that can be instantiated from a parsed URDF file.
- See: http://pr.willowgarage.com/wiki/RobotDescriptionFormat
</description>
<author>Ioan Sucan/is...@wi...</author>
<license>BSD</license>
<review status="unreviewed" notes=""/>
- <url>http://pr.willowgarage.com/wiki/RobotDescriptionFormat</url>
+ <url>http://www.ros.org/wiki/urdf</url>
<depend package="wg_robot_description_parser"/>
+
+ <depend package="urdf"/>
+ <depend package="rosconsole" />
<depend package="geometric_shapes"/>
<depend package="bullet"/>
+ <depend package="resource_retriever"/>
+ <depend package="ogre_tools"/>
<export>
<cpp cflags="-I${prefix}/include `rosboost-cfg --cflags`" lflags="-Wl,-rpath,${prefix}/lib -L${prefix}/lib -lplanning_models `rosboost-cfg --lflags thread`"/>
Added: pkg/trunk/motion_planning/planning_models/src/kinematic_model.cpp
===================================================================
--- pkg/trunk/motion_planning/planning_models/src/kinematic_model.cpp (rev 0)
+++ pkg/trunk/motion_planning/planning_models/src/kinematic_model.cpp 2009-08-29 20:57:27 UTC (rev 23339)
@@ -0,0 +1,604 @@
+/*********************************************************************
+* Software License Agreement (BSD License)
+*
+* Copyright (c) 2008, Willow Garage, Inc.
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+*
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+* * Neither the name of the Willow Garage nor the names of its
+* contributors may be used to endorse or promote products derived
+* from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+* POSSIBILITY OF SUCH DAMAGE.
+*********************************************************************/
+
+/** \author Ioan Sucan */
+
+#include <planning_models/kinematic_model.h>
+#include <resource_retriever/retriever.h>
+#include <ogre_tools/stl_loader.h>
+#include <ros/console.h>
+#include <cmath>
+
+/* ------------------------ KinematicModel ------------------------ */
+
+planning_models::KinematicModel::KinematicModel(const urdf::Model &model, const std::map< std::string, std::vector<std::string> > &groups)
+{
+ dimension_ = 0;
+ if (model.getRoot())
+ {
+ root_ = buildRecursive(NULL, model.getRoot().get());
+ buildGroups(groups);
+ }
+ else
+ {
+ root_ = NULL;
+ ROS_WARN("No root found");
+ }
+}
+
+planning_models::KinematicModel::~KinematicModel(void)
+{
+ for (std::map<std::string, JointGroup*>::iterator it = groupMap_.begin() ; it != groupMap_.end() ; ++it)
+ delete it->second;
+ if (root_)
+ delete root_;
+}
+
+const std::string& planning_models::KinematicModel::getName(void) const
+{
+ return modelName_;
+}
+
+unsigned int planning_models::KinematicModel::getDimension(void) const
+{
+ return dimension_;
+}
+
+const btTransform& planning_models::KinematicModel::getRootTransform(void) const
+{
+ return rootTransform_;
+}
+
+void planning_models::KinematicModel::setRootTransform(const btTransform &transform)
+{
+ rootTransform_ = transform;
+}
+
+void planning_models::KinematicModel::lock(void)
+{
+ lock_.lock();
+}
+
+void planning_models::KinematicModel::unlock(void)
+{
+ lock_.unlock();
+}
+
+void planning_models::KinematicModel::buildGroups(const std::map< std::string, std::vector<std::string> > &groups)
+{
+ for (std::map< std::string, std::vector<std::string> >::const_iterator it = groups.begin() ; it != groups.end() ; ++it)
+ {
+ std::vector<Joint*> jointv;
+ for (unsigned int i = 0 ; i < it->second.size() ; ++i)
+ {
+ std::map<std::string, Joint*>::iterator p = jointMap_.find(it->second[i]);
+ if (p == jointMap_.end())
+ {
+ ROS_ERROR("Unknown joint '%s'. Not adding to group '%s'", it->second[i].c_str(), it->first.c_str());
+ jointv.clear();
+ break;
+ }
+ else
+ jointv.push_back(p->second);
+ }
+ if (jointv.empty())
+ ROS_ERROR("Skipping group '%s'", it->first.c_str());
+ else
+ {
+ ROS_DEBUG("Adding group '%s'", it->first.c_str());
+ groupMap_[it->first] = new JointGroup(this, it->first, jointv);
+ }
+ }
+}
+
+planning_models::KinematicModel::Joint* planning_models::KinematicModel::buildRecursive(Link *parent, const urdf::Link *link)
+{
+ Joint *joint = constructJoint(link->parent_joint.get());
+ joint->stateIndex = dimension_;
+ jointMap_[joint->name] = joint;
+ jointList_.push_back(joint);
+ jointIndex_.push_back(dimension_);
+ dimension_ += joint->usedParams;
+ joint->before = parent;
+ joint->after = constructLink(link);
+ linkMap_[joint->after->name] = joint->after;
+ joint->after->before = joint;
+
+ for (unsigned int i = 0 ; link->child_links.size() ; ++i)
+ joint->after->after.push_back(buildRecursive(joint->after, link->child_links[i].get()));
+
+ return joint;
+}
+
+planning_models::KinematicModel::Joint* planning_models::KinematicModel::constructJoint(const urdf::Joint *urdfJoint)
+{
+ planning_models::KinematicModel::Joint *result = NULL;
+
+ ROS_ASSERT(urdfJoint);
+
+ switch (urdfJoint->type)
+ {
+ case urdf::Joint::REVOLUTE:
+ {
+ ROS_ASSERT(urdfJoint->safety);
+ RevoluteJoint *j = new RevoluteJoint(this);
+ j->hiLimit = urdfJoint->safety->soft_upper_limit;
+ j->lowLimit = urdfJoint->safety->soft_lower_limit;
+ j->continuous = false;
+ j->axis.setValue(urdfJoint->axis.x, urdfJoint->axis.y, urdfJoint->axis.z);
+ result = j;
+ }
+ break;
+ case urdf::Joint::CONTINUOUS:
+ {
+ RevoluteJoint *j = new RevoluteJoint(this);
+ j->hiLimit = M_PI;
+ j->lowLimit = -M_PI;
+ j->continuous = true;
+ j->axis.setValue(urdfJoint->axis.x, urdfJoint->axis.y, urdfJoint->axis.z);
+ result = j;
+ }
+ break;
+ case urdf::Joint::PRISMATIC:
+ {
+ ROS_ASSERT(urdfJoint->safety);
+ PrismaticJoint *j = new PrismaticJoint(this);
+ j->hiLimit = urdfJoint->safety->soft_upper_limit;
+ j->lowLimit = urdfJoint->safety->soft_lower_limit;
+ j->axis.setValue(urdfJoint->axis.x, urdfJoint->axis.y, urdfJoint->axis.z);
+ result = j;
+ }
+ break;
+ case urdf::Joint::FLOATING:
+ result = new FloatingJoint(this);
+ break;
+ case urdf::Joint::PLANAR:
+ result = new PlanarJoint(this);
+ break;
+ case urdf::Joint::FIXED:
+ result = new FixedJoint(this);
+ break;
+ default:
+ ROS_ERROR("Unknown joint type: %d", (int)urdfJoint->type);
+ break;
+ }
+
+ if (result)
+ result->name = urdfJoint->name;
+
+ return result;
+}
+
+namespace planning_models
+{
+ static inline btTransform urdfPose2btTransform(const urdf::Pose &pose)
+ {
+ return btTransform(btQuaternion(pose.rotation.x, pose.rotation.y, pose.rotation.z, pose.rotation.w),
+ btVector3(pose.position.x, pose.position.y, pose.position.z));
+ }
+}
+
+planning_models::KinematicModel::Link* planning_models::KinematicModel::constructLink(const urdf::Link *urdfLink)
+{
+ ROS_ASSERT(urdfLink);
+ ROS_ASSERT(urdfLink->collision);
+
+ Link *result = new Link(this);
+ result->name = urdfLink->name;
+
+ result->constGeomTrans = urdfPose2btTransform(urdfLink->collision->origin);
+ result->constTrans = urdfPose2btTransform(urdfLink->parent_joint->parent_to_joint_origin_transform);
+
+ result->shape = constructShape(urdfLink->collision->geometry.get());
+
+ return result;
+}
+
+shapes::Shape* planning_models::KinematicModel::constructShape(const urdf::Geometry *geom)
+{
+ ROS_ASSERT(geom);
+
+ shapes::Shape *result = NULL;
+ switch (geom->type)
+ {
+ case urdf::Geometry::SPHERE:
+ result = new shapes::Sphere(dynamic_cast<const urdf::Sphere*>(geom)->radius);
+ break;
+ case urdf::Geometry::BOX:
+ {
+ urdf::Vector3 dim = dynamic_cast<const urdf::Box*>(geom)->dim;
+ result = new shapes::Box(dim.x, dim.y, dim.z);
+ }
+ case urdf::Geometry::CYLINDER:
+ result = new shapes::Cylinder(dynamic_cast<const urdf::Cylinder*>(geom)->radius,
+ dynamic_cast<const urdf::Cylinder*>(geom)->length);
+ break;
+ case urdf::Geometry::MESH:
+ {
+ const urdf::Mesh *mesh = dynamic_cast<const urdf::Mesh*>(geom);
+ if (!mesh->filename.empty())
+ {
+ resource_retriever::Retriever retriever;
+ resource_retriever::MemoryResource res;
+ bool ok = true;
+
+ try
+ {
+ res = retriever.get(mesh->filename);
+ }
+ catch (resource_retriever::Exception& e)
+ {
+ ROS_ERROR("%s", e.what());
+ ok = false;
+ }
+
+ if (ok)
+ {
+ if (res.size == 0)
+ ROS_WARN("Retrieved empty mesh for resource [%s]", mesh->filename.c_str());
+ else
+ {
+ ogre_tools::STLLoader loader;
+ if (loader.load(res.data.get()))
+ {
+ std::vector<btVector3> triangles;
+ for (unsigned int i = 0 ; i < loader.triangles_.size() ; ++i)
+ {
+ triangles.push_back(btVector3(loader.triangles_[i].vertices_[0].x, loader.triangles_[i].vertices_[0].y, loader.triangles_[i].vertices_[0].z));
+ triangles.push_back(btVector3(loader.triangles_[i].vertices_[1].x, loader.triangles_[i].vertices_[1].y, loader.triangles_[i].vertices_[1].z));
+ triangles.push_back(btVector3(loader.triangles_[i].vertices_[2].x, loader.triangles_[i].vertices_[2].y, loader.triangles_[i].vertices_[2].z));
+ }
+ result = shapes::createMeshFromVertices(triangles);
+ }
+ else
+ ROS_ERROR("Failed to load mesh [%s]", mesh->filename.c_str());
+ }
+ }
+ }
+ else
+ ROS_WARN("Empty mesh filename");
+ }
+
+ break;
+ default:
+ ROS_ERROR("Unknown geometry type: %d", (int)geom->type);
+ break;
+ }
+
+ return result;
+}
+
+void planning_models::KinematicModel::computeTransforms(const double *params)
+{
+ for (unsigned int i = 0 ; i < jointList_.size() ; ++i)
+ jointList_[i]->updateVariableTransform(params + jointIndex_[i]);
+
+ if (root_)
+ {
+ std::queue<Link*> links;
+ links.push(root_->after);
+ while (!links.empty())
+ {
+ Link *link = links.front();
+ links.pop();
+
+ link->computeTransform();
+ for (unsigned int i = 0 ; i < link->after.size() ; ++i)
+ links.push(link->after[i]->after);
+ }
+ }
+}
+
+bool planning_models::KinematicModel::hasJoint(const std::string &name) const
+{
+ return jointMap_.find(name) != jointMap_.end();
+}
+
+bool planning_models::KinematicModel::hasLink(const std::string &name) const
+{
+ return linkMap_.find(name) != linkMap_.end();
+}
+
+bool planning_models::KinematicModel::hasGroup(const std::string &name) const
+{
+ return groupMap_.find(name) != groupMap_.end();
+}
+
+const planning_models::KinematicModel::Joint* planning_models::KinematicModel::getJoint(const std::string &name) const
+{
+ std::map<std::string, Joint*>::const_iterator it = jointMap_.find(name);
+ if (it == jointMap_.end())
+ {
+ ROS_ERROR("Joint '%s' not found", name.c_str());
+ return NULL;
+ }
+ else
+ return it->second;
+}
+
+const planning_models::KinematicModel::Link* planning_models::KinematicModel::getLink(const std::string &name) const
+{
+ std::map<std::string, Link*>::const_iterator it = linkMap_.find(name);
+ if (it == linkMap_.end())
+ {
+ ROS_ERROR("Link '%s' not found", name.c_str());
+ return NULL;
+ }
+ else
+ return it->second;
+}
+
+const planning_models::KinematicModel::JointGroup* planning_models::KinematicModel::getGroup(const std::string &name) const
+{
+ std::map<std::string, JointGroup*>::const_iterator it = groupMap_.find(name);
+ if (it == groupMap_.end())
+ {
+ ROS_ERROR("Joint group '%s' not found", name.c_str());
+ return NULL;
+ }
+ else
+ return it->second;
+}
+
+void planning_models::KinematicModel::getGroups(std::vector<const JointGroup*> &groups) const
+{
+ groups.clear();
+ groups.reserve(groupMap_.size());
+ for (std::map<std::string, JointGroup*>::const_iterator it = groupMap_.begin() ; it != groupMap_.end() ; ++it)
+ groups.push_back(it->second);
+}
+
+void planning_models::KinematicModel::getGroupNames(std::vector<std::string> &groups) const
+{
+ groups.clear();
+ groups.reserve(groupMap_.size());
+ for (std::map<std::string, JointGroup*>::const_iterator it = groupMap_.begin() ; it != groupMap_.end() ; ++it)
+ groups.push_back(it->second->name);
+}
+
+void planning_models::KinematicModel::getLinks(std::vector<const Link*> &links) const
+{
+ links.clear();
+ links.reserve(linkMap_.size());
+ for (std::map<std::string, Link*>::const_iterator it = linkMap_.begin() ; it != linkMap_.end() ; ++it)
+ links.push_back(it->second);
+}
+
+void planning_models::KinematicModel::getLinkNames(std::vector<std::string> &links) const
+{
+ links.clear();
+ links.reserve(linkMap_.size());
+ for (std::map<std::string, Link*>::const_iterator it = linkMap_.begin() ; it != linkMap_.end() ; ++it)
+ links.push_back(it->second...
[truncated message content] |
|
From: <is...@us...> - 2009-08-30 00:28:06
|
Revision: 23340
http://personalrobots.svn.sourceforge.net/personalrobots/?rev=23340&view=rev
Author: isucan
Date: 2009-08-30 00:27:56 +0000 (Sun, 30 Aug 2009)
Log Message:
-----------
a bit more stuff... still far from complete
Modified Paths:
--------------
pkg/trunk/motion_planning/planning_models/CMakeLists.txt
pkg/trunk/motion_planning/planning_models/include/planning_models/kinematic_model.h
pkg/trunk/motion_planning/planning_models/src/kinematic_model.cpp
Added Paths:
-----------
pkg/trunk/motion_planning/planning_models/test/test_kinematic2.cpp
Modified: pkg/trunk/motion_planning/planning_models/CMakeLists.txt
===================================================================
--- pkg/trunk/motion_planning/planning_models/CMakeLists.txt 2009-08-29 20:57:27 UTC (rev 23339)
+++ pkg/trunk/motion_planning/planning_models/CMakeLists.txt 2009-08-30 00:27:56 UTC (rev 23340)
@@ -18,3 +18,7 @@
rospack_add_gtest(test_kinematic test/test_kinematic.cpp)
target_link_libraries(test_kinematic planning_models)
rospack_link_boost(test_kinematic thread)
+
+#rospack_add_gtest(test_kinematic2 test/test_kinematic2.cpp)
+#target_link_libraries(test_kinematic2 planning_models2)
+#rospack_link_boost(test_kinematic2 thread)
Modified: pkg/trunk/motion_planning/planning_models/include/planning_models/kinematic_model.h
===================================================================
--- pkg/trunk/motion_planning/planning_models/include/planning_models/kinematic_model.h 2009-08-29 20:57:27 UTC (rev 23339)
+++ pkg/trunk/motion_planning/planning_models/include/planning_models/kinematic_model.h 2009-08-30 00:27:56 UTC (rev 23340)
@@ -285,6 +285,9 @@
/** \brief The dimension of the group */
unsigned int dimension;
+ /** \brief The bounds for the state corresponding to the group */
+ std::vector<double> stateBounds;
+
/** \brief An array containing the index in the global state for each dimension of the state of the group */
std::vector<unsigned int> stateIndex;
@@ -372,6 +375,11 @@
/** \brief Get the dimension of the entire model */
unsigned int getDimension(void) const;
+ /** \brief Get the state bounds constructed for this
+ model. Component i of the state space has bounds (min,
+ max) at index positions (2*i, 2*i+1)*/
+ const std::vector<double> &getStateBounds(void) const;
+
/** \brief Provide interface to a lock. Use carefully! */
void lock(void);
@@ -407,6 +415,15 @@
/** \brief The root joint */
Joint *root_;
+ /** \brief List of floating joints, maintained for convenience */
+ std::vector<std::string> floatingJoints_;
+
+ /** \brief List of planar joints, maintained for convenience */
+ std::vector<std::string> planarJoints_;
+
+ /** \brief The bounds in the form (min, max) for every component of the state */
+ std::vector<double> stateBounds_;
+
/** \brief The dimension of the model */
unsigned int dimension_;
@@ -417,7 +434,7 @@
void buildGroups(const std::map< std::string, std::vector<std::string> > &groups);
Joint* buildRecursive(Link *parent, const urdf::Link *link);
- Joint* constructJoint(const urdf::Joint *urdfJoint);
+ Joint* constructJoint(const urdf::Joint *urdfJoint, std::vector<double> &bounds);
Link* constructLink(const urdf::Link *urdfLink);
shapes::Shape* constructShape(const urdf::Geometry *geom);
Modified: pkg/trunk/motion_planning/planning_models/src/kinematic_model.cpp
===================================================================
--- pkg/trunk/motion_planning/planning_models/src/kinematic_model.cpp 2009-08-29 20:57:27 UTC (rev 23339)
+++ pkg/trunk/motion_planning/planning_models/src/kinematic_model.cpp 2009-08-30 00:27:56 UTC (rev 23340)
@@ -45,6 +45,8 @@
planning_models::KinematicModel::KinematicModel(const urdf::Model &model, const std::map< std::string, std::vector<std::string> > &groups)
{
dimension_ = 0;
+ modelName_ = model.getName();
+
if (model.getRoot())
{
root_ = buildRecursive(NULL, model.getRoot().get());
@@ -75,6 +77,11 @@
return dimension_;
}
+const std::vector<double> &planning_models::KinematicModel::getStateBounds(void) const
+{
+ return stateBounds_;
+}
+
const btTransform& planning_models::KinematicModel::getRootTransform(void) const
{
return rootTransform_;
@@ -124,7 +131,9 @@
planning_models::KinematicModel::Joint* planning_models::KinematicModel::buildRecursive(Link *parent, const urdf::Link *link)
{
- Joint *joint = constructJoint(link->parent_joint.get());
+ ROS_INFO("%s", link->name.c_str());
+
+ Joint *joint = constructJoint(link->parent_joint.get(), stateBounds_);
joint->stateIndex = dimension_;
jointMap_[joint->name] = joint;
jointList_.push_back(joint);
@@ -135,13 +144,19 @@
linkMap_[joint->after->name] = joint->after;
joint->after->before = joint;
+ if (dynamic_cast<FloatingJoint*>(joint))
+ floatingJoints_.push_back(joint->name);
+ if (dynamic_cast<PlanarJoint*>(joint))
+ planarJoints_.push_back(joint->name);
+
for (unsigned int i = 0 ; link->child_links.size() ; ++i)
joint->after->after.push_back(buildRecursive(joint->after, link->child_links[i].get()));
return joint;
}
-planning_models::KinematicModel::Joint* planning_models::KinematicModel::constructJoint(const urdf::Joint *urdfJoint)
+planning_models::KinematicModel::Joint* planning_models::KinematicModel::constructJoint(const urdf::Joint *urdfJoint,
+ std::vector<double> &bounds)
{
planning_models::KinematicModel::Joint *result = NULL;
@@ -157,6 +172,8 @@
j->lowLimit = urdfJoint->safety->soft_lower_limit;
j->continuous = false;
j->axis.setValue(urdfJoint->axis.x, urdfJoint->axis.y, urdfJoint->axis.z);
+ bounds.push_back(j->lowLimit);
+ bounds.push_back(j->hiLimit);
result = j;
}
break;
@@ -167,6 +184,8 @@
j->lowLimit = -M_PI;
j->continuous = true;
j->axis.setValue(urdfJoint->axis.x, urdfJoint->axis.y, urdfJoint->axis.z);
+ bounds.push_back(j->lowLimit);
+ bounds.push_back(j->hiLimit);
result = j;
}
break;
@@ -177,14 +196,20 @@
j->hiLimit = urdfJoint->safety->soft_upper_limit;
j->lowLimit = urdfJoint->safety->soft_lower_limit;
j->axis.setValue(urdfJoint->axis.x, urdfJoint->axis.y, urdfJoint->axis.z);
+ bounds.push_back(j->lowLimit);
+ bounds.push_back(j->hiLimit);
result = j;
}
break;
case urdf::Joint::FLOATING:
result = new FloatingJoint(this);
+ bounds.insert(bounds.end(), 14, 0.0);
break;
case urdf::Joint::PLANAR:
result = new PlanarJoint(this);
+ bounds.insert(bounds.end(), 4, 0.0);
+ bounds.push_back(-M_PI);
+ bounds.push_back(M_PI);
break;
case urdf::Joint::FIXED:
result = new FixedJoint(this);
@@ -421,12 +446,66 @@
void planning_models::KinematicModel::printModelInfo(std::ostream &out) const
{
+ out << "Complete model state dimension = " << dimension_ << std::endl;
+
+ std::ios_base::fmtflags old_flags = out.flags();
+ out.setf(std::ios::fixed, std::ios::floatfield);
+ std::streamsize old_prec = out.precision();
+ out.precision(5);
+ out << "State bounds: ";
+ for (unsigned int i = 0 ; i < dimension_ ; ++i)
+ out << "[" << stateBounds_[2 * i] << ", " << stateBounds_[2 * i + 1] << "] ";
+ out << std::endl;
+ out.precision(old_prec);
+ out.flags(old_flags);
+
+ out << "Floating joints : ";
+ for (unsigned int i = 0 ; i < floatingJoints_.size() ; ++i)
+ out << floatingJoints_[i] << " ";
+ out << std::endl;
+
+ out << "Planar joints : ";
+ for (unsigned int i = 0 ; i < planarJoints_.size() ; ++i)
+ out << planarJoints_[i] << " ";
+ out << std::endl;
+
+ out << "Available groups: ";
+ std::vector<std::string> l;
+ getGroupNames(l);
+ for (unsigned int i = 0 ; i < l.size() ; ++i)
+ out << l[i] << " ";
+ out << std::endl;
+
+ for (unsigned int i = 0 ; i < l.size() ; ++i)
+ {
+ const JointGroup *g = getGroup(l[i]);
+ out << "Group " << l[i] << " has " << g->jointRoots.size() << " roots: ";
+ for (unsigned int j = 0 ; j < g->jointRoots.size() ; ++j)
+ out << g->jointRoots[j]->name << " ";
+ out << std::endl;
+ out << "The state components for this group are: ";
+ for (unsigned int j = 0 ; j < g->stateIndex.size() ; ++j)
+ out << g->stateIndex[j] << " ";
+ out << std::endl;
+ }
}
void planning_models::KinematicModel::printLinkPoses(std::ostream &out) const
{
+ out << "Link poses:" << std::endl;
+ std::vector<const Link*> links;
+ getLinks(links);
+ for (unsigned int i = 0 ; i < links.size() ; ++i)
+ {
+ out << links[i]->name << std::endl;
+ const btVector3 &v = links[i]->globalTrans.getOrigin();
+ out << " origin: " << v.x() << ", " << v.y() << ", " << v.z() << std::endl;
+ const btQuaternion &q = links[i]->globalTrans.getRotation();
+ out << " quaternion: " << q.x() << ", " << q.y() << ", " << q.z() << ", " << q.w() << std::endl;
+ out << std::endl;
+ }
}
-
+
/* ------------------------ Joint ------------------------ */
planning_models::KinematicModel::Joint::Joint(KinematicModel *model) : owner(model), usedParams(0), stateIndex(0), before(NULL), after(NULL)
@@ -531,6 +610,7 @@
std::vector<const Joint*> allJoints;
owner->getJoints(allJoints);
+ std::vector<double> allBounds = owner->getStateBounds();
for (unsigned int i = 0 ; i < joints.size() ; ++i)
{
@@ -545,7 +625,12 @@
if (allJoints[j]->name == joints[i]->name)
{
for (unsigned int k = 0 ; k < joints[i]->usedParams ; ++k)
- stateIndex.push_back(globalStateIndex + k);
+ {
+ unsigned int si = globalStateIndex + k;
+ stateIndex.push_back(si);
+ stateBounds.push_back(allBounds[2 * si]);
+ stateBounds.push_back(allBounds[2 * si + 1]);
+ }
found = true;
break;
}
Added: pkg/trunk/motion_planning/planning_models/test/test_kinematic2.cpp
===================================================================
--- pkg/trunk/motion_planning/planning_models/test/test_kinematic2.cpp (rev 0)
+++ pkg/trunk/motion_planning/planning_models/test/test_kinematic2.cpp 2009-08-30 00:27:56 UTC (rev 23340)
@@ -0,0 +1,106 @@
+/*********************************************************************
+* Software License Agreement (BSD License)
+*
+* Copyright (c) 2008, Willow Garage, Inc.
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+*
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+* * Neither the name of the Willow Garage nor the names of its
+* contributors may be used to endorse or promote products derived
+* from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+* POSSIBILITY OF SUCH DAMAGE.
+*********************************************************************/
+
+/** \author Ioan Sucan */
+
+#include <planning_models/kinematic_model.h>
+#include <gtest/gtest.h>
+#include <sstream>
+#include <ctype.h>
+
+static bool sameStringIgnoringWS(const std::string &s1, const std::string &s2)
+{
+ unsigned int i1 = 0;
+ unsigned int i2 = 0;
+ while (i1 < s1.size() && isspace(s1[i1])) i1++;
+ while (i2 < s2.size() && isspace(s2[i2])) i2++;
+ while (i1 < s1.size() && i2 < s2.size())
+ {
+ if (i1 < s1.size() && i2 < s2.size())
+ {
+ if (s1[i1] != s2[i2])
+ return false;
+ i1++;
+ i2++;
+ }
+ while (i1 < s1.size() && isspace(s1[i1])) i1++;
+ while (i2 < s2.size() && isspace(s2[i2])) i2++;
+ }
+ return i1 == s1.size() && i2 == s2.size();
+}
+
+TEST(Loading, EmptyRobot)
+{
+ static const std::string MODEL0 =
+ "<?xml version=\"1.0\" ?>"
+ "<robot name=\"myrobot\">"
+ " <joint name=\"base_joint\" type=\"planar\">"
+ " <origin rpy=\"0 0 0\" xyz=\"0 0 0.051\"/>"
+ " <parent link=\"world\"/>"
+ " <child link=\"base_link\"/>"
+ "</joint>"
+ "<link name=\"base_link\">"
+ "</link>"
+ "</robot>";
+
+ urdf::Model urdfModel;
+ urdfModel.initString(MODEL0);
+
+ std::map < std::string, std::vector<std::string> > groups;
+ planning_models::KinematicModel *model = new planning_models::KinematicModel(urdfModel, groups);
+
+ EXPECT_EQ(std::string("myrobot"), model->getName());
+ EXPECT_EQ((unsigned int)0, model->getDimension());
+
+ std::vector<const planning_models::KinematicModel::Link*> links;
+ model->getLinks(links);
+ EXPECT_EQ((unsigned int)0, links.size());
+
+ std::vector<const planning_models::KinematicModel::Joint*> joints;
+ model->getJoints(joints);
+ EXPECT_EQ((unsigned int)0, joints.size());
+
+ std::vector<std::string> pgroups;
+ model->getGroupNames(pgroups);
+ EXPECT_EQ((unsigned int)0, pgroups.size());
+
+ delete model;
+}
+
+
+int main(int argc, char **argv)
+{
+ testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <is...@us...> - 2009-08-30 22:31:23
|
Revision: 23357
http://personalrobots.svn.sourceforge.net/personalrobots/?rev=23357&view=rev
Author: isucan
Date: 2009-08-30 22:31:13 +0000 (Sun, 30 Aug 2009)
Log Message:
-----------
first test that passes
Modified Paths:
--------------
pkg/trunk/motion_planning/planning_models/CMakeLists.txt
pkg/trunk/motion_planning/planning_models/include/planning_models/kinematic_model.h
pkg/trunk/motion_planning/planning_models/src/kinematic_model.cpp
pkg/trunk/motion_planning/planning_models/test/test_kinematic2.cpp
Modified: pkg/trunk/motion_planning/planning_models/CMakeLists.txt
===================================================================
--- pkg/trunk/motion_planning/planning_models/CMakeLists.txt 2009-08-30 22:14:43 UTC (rev 23356)
+++ pkg/trunk/motion_planning/planning_models/CMakeLists.txt 2009-08-30 22:31:13 UTC (rev 23357)
@@ -19,6 +19,6 @@
target_link_libraries(test_kinematic planning_models)
rospack_link_boost(test_kinematic thread)
-#rospack_add_gtest(test_kinematic2 test/test_kinematic2.cpp)
-#target_link_libraries(test_kinematic2 planning_models2)
-#rospack_link_boost(test_kinematic2 thread)
+rospack_add_gtest(test_kinematic2 test/test_kinematic2.cpp)
+target_link_libraries(test_kinematic2 planning_models2)
+rospack_link_boost(test_kinematic2 thread)
Modified: pkg/trunk/motion_planning/planning_models/include/planning_models/kinematic_model.h
===================================================================
--- pkg/trunk/motion_planning/planning_models/include/planning_models/kinematic_model.h 2009-08-30 22:14:43 UTC (rev 23356)
+++ pkg/trunk/motion_planning/planning_models/include/planning_models/kinematic_model.h 2009-08-30 22:31:13 UTC (rev 23357)
@@ -380,6 +380,12 @@
max) at index positions (2*i, 2*i+1)*/
const std::vector<double> &getStateBounds(void) const;
+ /** \brief Return a list of names of joints that are planar */
+ const std::vector<std::string> &getPlanarJoints(void) const;
+
+ /** \brief Return a list of names of joints that are floating */
+ const std::vector<std::string> &getFloatingJoints(void) const;
+
/** \brief Provide interface to a lock. Use carefully! */
void lock(void);
@@ -390,7 +396,7 @@
void printModelInfo(std::ostream &out = std::cout) const;
/** \brief Print the pose of every link */
- void printLinkPoses(std::ostream &out = std::cout) const;
+ void printTransforms(std::ostream &out = std::cout) const;
private:
@@ -437,6 +443,7 @@
Joint* constructJoint(const urdf::Joint *urdfJoint, std::vector<double> &bounds);
Link* constructLink(const urdf::Link *urdfLink);
shapes::Shape* constructShape(const urdf::Geometry *geom);
+ void printTransform(const std::string &st, const btTransform &t, std::ostream &out = std::cout) const;
};
Modified: pkg/trunk/motion_planning/planning_models/src/kinematic_model.cpp
===================================================================
--- pkg/trunk/motion_planning/planning_models/src/kinematic_model.cpp 2009-08-30 22:14:43 UTC (rev 23356)
+++ pkg/trunk/motion_planning/planning_models/src/kinematic_model.cpp 2009-08-30 22:31:13 UTC (rev 23357)
@@ -46,16 +46,35 @@
{
dimension_ = 0;
modelName_ = model.getName();
+ rootTransform_.setIdentity();
if (model.getRoot())
{
- root_ = buildRecursive(NULL, model.getRoot().get());
- buildGroups(groups);
+ const urdf::Link *root = model.getRoot().get();
+
+ if (root->name == "world")
+ {
+ if (root->child_links.empty())
+ {
+ root = NULL;
+ ROS_ERROR("No links connected to the world");
+ }
+ else
+ root = root->child_links[0].get();
+ if (root->child_links.size() > 1)
+ ROS_WARN("More than one link connected to the world. Only considering the first one");
+ }
+
+ if (root)
+ {
+ root_ = buildRecursive(NULL, root);
+ buildGroups(groups);
+ }
}
else
{
root_ = NULL;
- ROS_WARN("No root found");
+ ROS_WARN("No root link found");
}
}
@@ -92,6 +111,16 @@
rootTransform_ = transform;
}
+const std::vector<std::string> &planning_models::KinematicModel::getFloatingJoints(void) const
+{
+ return floatingJoints_;
+}
+
+const std::vector<std::string> &planning_models::KinematicModel::getPlanarJoints(void) const
+{
+ return planarJoints_;
+}
+
void planning_models::KinematicModel::lock(void)
{
lock_.lock();
@@ -102,6 +131,22 @@
lock_.unlock();
}
+void planning_models::KinematicModel::defaultState(void)
+{
+ if (dimension_ <= 0)
+ return;
+
+ double params[dimension_];
+ for (unsigned int i = 0 ; i < dimension_ ; ++i)
+ {
+ if (stateBounds_[2 * i] <= 0.0 && stateBounds_[2 * i + 1] >= 0.0)
+ params[i] = 0.0;
+ else
+ params[i] = (stateBounds_[2 * i] + stateBounds_[2 * i + 1]) / 2.0;
+ }
+ computeTransforms(params);
+}
+
void planning_models::KinematicModel::buildGroups(const std::map< std::string, std::vector<std::string> > &groups)
{
for (std::map< std::string, std::vector<std::string> >::const_iterator it = groups.begin() ; it != groups.end() ; ++it)
@@ -141,6 +186,8 @@
dimension_ += joint->usedParams;
joint->before = parent;
joint->after = constructLink(link);
+ if (parent == NULL)
+ joint->after->constTrans.setIdentity();
linkMap_[joint->after->name] = joint->after;
joint->after->before = joint;
@@ -265,6 +312,7 @@
urdf::Vector3 dim = dynamic_cast<const urdf::Box*>(geom)->dim;
result = new shapes::Box(dim.x, dim.y, dim.z);
}
+ break;
case urdf::Geometry::CYLINDER:
result = new shapes::Cylinder(dynamic_cast<const urdf::Cylinder*>(geom)->radius,
dynamic_cast<const urdf::Cylinder*>(geom)->length);
@@ -490,19 +538,32 @@
}
}
-void planning_models::KinematicModel::printLinkPoses(std::ostream &out) const
+void planning_models::KinematicModel::printTransform(const std::string &st, const btTransform &t, std::ostream &out) const
{
+ out << st << std::endl;
+ const btVector3 &v = t.getOrigin();
+ out << " origin: " << v.x() << ", " << v.y() << ", " << v.z() << std::endl;
+ const btQuaternion &q = t.getRotation();
+ out << " quaternion: " << q.x() << ", " << q.y() << ", " << q.z() << ", " << q.w() << std::endl;
+}
+
+void planning_models::KinematicModel::printTransforms(std::ostream &out) const
+{
+ out << "Joint transforms:" << std::endl;
+ std::vector<const Joint*> joints;
+ getJoints(joints);
+ for (unsigned int i = 0 ; i < joints.size() ; ++i)
+ {
+ printTransform(joints[i]->name, joints[i]->varTrans);
+ out << std::endl;
+ }
out << "Link poses:" << std::endl;
std::vector<const Link*> links;
getLinks(links);
for (unsigned int i = 0 ; i < links.size() ; ++i)
{
- out << links[i]->name << std::endl;
- const btVector3 &v = links[i]->globalTrans.getOrigin();
- out << " origin: " << v.x() << ", " << v.y() << ", " << v.z() << std::endl;
- const btQuaternion &q = links[i]->globalTrans.getRotation();
- out << " quaternion: " << q.x() << ", " << q.y() << ", " << q.z() << ", " << q.w() << std::endl;
- out << std::endl;
+ printTransform(links[i]->name, links[i]->globalTrans);
+ out << std::endl;
}
}
@@ -569,11 +630,11 @@
void planning_models::KinematicModel::Link::computeTransform(void)
-{
+{
globalTransFwd.mult(before->before ? before->before->globalTransFwd : owner->getRootTransform(), constTrans);
globalTransFwd *= before->varTrans;
globalTrans.mult(globalTransFwd, constGeomTrans);
-
+
for (unsigned int i = 0 ; i < attachedBodies.size() ; ++i)
attachedBodies[i]->computeTransform();
}
Modified: pkg/trunk/motion_planning/planning_models/test/test_kinematic2.cpp
===================================================================
--- pkg/trunk/motion_planning/planning_models/test/test_kinematic2.cpp 2009-08-30 22:14:43 UTC (rev 23356)
+++ pkg/trunk/motion_planning/planning_models/test/test_kinematic2.cpp 2009-08-30 22:31:13 UTC (rev 23357)
@@ -60,17 +60,23 @@
return i1 == s1.size() && i2 == s2.size();
}
-TEST(Loading, EmptyRobot)
+TEST(Loading, SimpleRobot)
{
static const std::string MODEL0 =
"<?xml version=\"1.0\" ?>"
"<robot name=\"myrobot\">"
" <joint name=\"base_joint\" type=\"planar\">"
- " <origin rpy=\"0 0 0\" xyz=\"0 0 0.051\"/>"
+ " <origin rpy=\"0 0 0\" xyz=\"0 0 0.0\"/>"
" <parent link=\"world\"/>"
" <child link=\"base_link\"/>"
"</joint>"
"<link name=\"base_link\">"
+ " <collision name=\"base_collision\">"
+ " <origin rpy=\"0 0 0\" xyz=\"0 0 0.165\"/>"
+ " <geometry name=\"base_collision_geom\">"
+ " <box size=\"0.65 0.65 0.23\"/>"
+ "</geometry>"
+ "</collision>"
"</link>"
"</robot>";
@@ -81,15 +87,15 @@
planning_models::KinematicModel *model = new planning_models::KinematicModel(urdfModel, groups);
EXPECT_EQ(std::string("myrobot"), model->getName());
- EXPECT_EQ((unsigned int)0, model->getDimension());
+ EXPECT_EQ((unsigned int)3, model->getDimension());
std::vector<const planning_models::KinematicModel::Link*> links;
model->getLinks(links);
- EXPECT_EQ((unsigned int)0, links.size());
+ EXPECT_EQ((unsigned int)1, links.size());
std::vector<const planning_models::KinematicModel::Joint*> joints;
model->getJoints(joints);
- EXPECT_EQ((unsigned int)0, joints.size());
+ EXPECT_EQ((unsigned int)1, joints.size());
std::vector<std::string> pgroups;
model->getGroupNames(pgroups);
@@ -98,7 +104,84 @@
delete model;
}
+TEST(LoadingAndFK, SimpleRobot)
+{
+ static const std::string MODEL1 =
+ "<?xml version=\"1.0\" ?>"
+ "<robot name=\"one_robot\">"
+ " <joint name=\"base_joint\" type=\"planar\">"
+ " <parent link=\"world\"/>"
+ " <child link=\"base_link\"/>"
+ " <origin rpy=\"1 0 0 \" xyz=\"0 0 0 \"/>"
+ " </joint>"
+ "<link name=\"base_link\">"
+ " <inertial>"
+ " <mass value=\"2.81\"/>"
+ " <origin rpy=\"0 0 0\" xyz=\"0.0 0.099 .0\"/>"
+ " <inertia ixx=\"0.1\" ixy=\"-0.2\" ixz=\"0.5\" iyy=\"-.09\" iyz=\"1\" izz=\"0.101\"/>"
+ " </inertial>"
+ " <collision name=\"my_collision\">"
+ " <origin rpy=\"0 0 -1\" xyz=\"-0.1 0 0\"/>"
+ " <geometry>"
+ " <box size=\"1 2 1\" />"
+ " </geometry>"
+ " </collision>"
+ " <visual>"
+ " <origin rpy=\"0 0 0\" xyz=\"0.0 0 0\"/>"
+ " <geometry>"
+ " <box size=\"1 2 1\" />"
+ " </geometry>"
+ " </visual>"
+ "</link>"
+ "</robot>";
+
+ static const std::string MODEL1_INFO =
+ "Complete model state dimension = 3\n"
+ "State bounds: [0.00000, 0.00000] [0.00000, 0.00000] [-3.14159, 3.14159] \n"
+ "Floating joints : \n"
+ "Planar joints : base_joint \n"
+ "Available groups: base \n"
+ "Group base has 1 roots: base_joint \n"
+ "The state components for this group are: 0 1 2 \n";
+
+ urdf::Model urdfModel;
+ urdfModel.initString(MODEL1);
+
+ std::map < std::string, std::vector<std::string> > groups;
+ groups["base"].push_back("base_joint");
+ planning_models::KinematicModel *model = new planning_models::KinematicModel(urdfModel, groups);
+
+ EXPECT_EQ((unsigned int)3, model->getDimension());
+
+ model->defaultState();
+
+ std::vector<const planning_models::KinematicModel::Joint*> joints;
+ model->getJoints(joints);
+ EXPECT_EQ((unsigned int)1, joints.size());
+ EXPECT_EQ((unsigned int)3, joints[0]->usedParams);
+
+ EXPECT_EQ((unsigned int)1, model->getPlanarJoints().size());
+
+ std::stringstream ssi;
+ model->printModelInfo(ssi);
+ EXPECT_TRUE(sameStringIgnoringWS(MODEL1_INFO, ssi.str()));
+
+
+ double param[3] = { 10, 8, 0 };
+ model->computeTransforms(param);
+
+ EXPECT_NEAR(9.9, model->getLink("base_link")->globalTrans.getOrigin().x(), 1e-5);
+ EXPECT_NEAR(8.0, model->getLink("base_link")->globalTrans.getOrigin().y(), 1e-5);
+ EXPECT_NEAR(0.0, model->getLink("base_link")->globalTrans.getOrigin().z(), 1e-5);
+ EXPECT_NEAR(0.0, model->getLink("base_link")->globalTrans.getRotation().x(), 1e-5);
+ EXPECT_NEAR(0.0, model->getLink("base_link")->globalTrans.getRotation().y(), 1e-5);
+ EXPECT_NEAR(-0.479426, model->getLink("base_link")->globalTrans.getRotation().z(), 1e-5);
+ EXPECT_NEAR(0.877583, model->getLink("base_link")->globalTrans.getRotation().w(), 1e-5);
+
+ delete model;
+}
+
int main(int argc, char **argv)
{
testing::InitGoogleTest(&argc, argv);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <is...@us...> - 2009-08-31 02:58:10
|
Revision: 23359
http://personalrobots.svn.sourceforge.net/personalrobots/?rev=23359&view=rev
Author: isucan
Date: 2009-08-31 02:58:00 +0000 (Mon, 31 Aug 2009)
Log Message:
-----------
began work on state handling
Modified Paths:
--------------
pkg/trunk/motion_planning/planning_models/CMakeLists.txt
pkg/trunk/motion_planning/planning_models/include/planning_models/kinematic_model.h
pkg/trunk/motion_planning/planning_models/src/kinematic_model.cpp
pkg/trunk/motion_planning/planning_models/test/test_kinematic2.cpp
Added Paths:
-----------
pkg/trunk/motion_planning/planning_models/include/planning_models/kinematic_state.h
pkg/trunk/motion_planning/planning_models/src/kinematic_state.cpp
Modified: pkg/trunk/motion_planning/planning_models/CMakeLists.txt
===================================================================
--- pkg/trunk/motion_planning/planning_models/CMakeLists.txt 2009-08-31 00:32:46 UTC (rev 23358)
+++ pkg/trunk/motion_planning/planning_models/CMakeLists.txt 2009-08-31 02:58:00 UTC (rev 23359)
@@ -11,7 +11,8 @@
rospack_link_boost(planning_models thread)
-rospack_add_library(planning_models2 src/kinematic_model.cpp)
+rospack_add_library(planning_models2 src/kinematic_model.cpp
+ src/kinematic_state.cpp)
rospack_link_boost(planning_models2 thread)
# Unit tests
Modified: pkg/trunk/motion_planning/planning_models/include/planning_models/kinematic_model.h
===================================================================
--- pkg/trunk/motion_planning/planning_models/include/planning_models/kinematic_model.h 2009-08-31 00:32:46 UTC (rev 23358)
+++ pkg/trunk/motion_planning/planning_models/include/planning_models/kinematic_model.h 2009-08-31 02:58:00 UTC (rev 23359)
@@ -224,7 +224,7 @@
btTransform globalTrans;
/** \brief Recompute globalTrans and globalTransFwd */
- inline void computeTransform(void);
+ void computeTransform(void);
};
@@ -256,7 +256,7 @@
std::vector<std::string> touchLinks;
/** \brief Recompute globalTrans */
- inline void computeTransform(void);
+ void computeTransform(void);
};
@@ -327,6 +327,9 @@
/** \brief Get a group by its name */
const JointGroup* getGroup(const std::string &name) const;
+
+ /** \brief Get a group by its name */
+ JointGroup* getGroup(const std::string &name);
/** \brief Check if a group exists */
bool hasGroup(const std::string &name) const;
@@ -340,6 +343,9 @@
/** \brief Get a link by its name */
const Link* getLink(const std::string &link) const;
+ /** \brief Get a link by its name */
+ Link* getLink(const std::string &link);
+
/** \brief Check if a link exists */
bool hasLink(const std::string &name) const;
@@ -352,6 +358,9 @@
/** \brief Get a joint by its name */
const Joint* getJoint(const std::string &joint) const;
+ /** \brief Get a joint by its name */
+ Joint* getJoint(const std::string &joint);
+
/** \brief Check if a joint exists */
bool hasJoint(const std::string &name) const;
Added: pkg/trunk/motion_planning/planning_models/include/planning_models/kinematic_state.h
===================================================================
--- pkg/trunk/motion_planning/planning_models/include/planning_models/kinematic_state.h (rev 0)
+++ pkg/trunk/motion_planning/planning_models/include/planning_models/kinematic_state.h 2009-08-31 02:58:00 UTC (rev 23359)
@@ -0,0 +1,221 @@
+/*********************************************************************
+* Software License Agreement (BSD License)
+*
+* Copyright (c) 2008, Willow Garage, Inc.
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+*
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+* * Neither the name of the Willow Garage nor the names of its
+* contributors may be used to endorse or promote products derived
+* from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+* POSSIBILITY OF SUCH DAMAGE.
+*********************************************************************/
+
+/** \author Ioan Sucan */
+
+#ifndef PLANNING_MODELS_KINEMATIC_STATE_
+#define PLANNING_MODELS_KINEMATIC_STATE_
+
+#include "planning_models/kinematic_model.h"
+
+/** \brief Main namespace */
+namespace planning_models
+{
+
+ /** \brief A class that can hold the named parameters of this planning model */
+ class KinematicState
+ {
+ public:
+ KinematicState(const KinematicModel *model);
+ KinematicState(const KinematicState &sp);
+
+ ~KinematicState(void);
+
+ KinematicState &operator=(const KinematicState &rhs);
+
+ bool operator==(const KinematicState &rhs) const;
+
+ /** \brief Construct a default state: each value at 0.0, if
+ within bounds. Otherwise, select middle point. */
+ void defaultState(void);
+
+ /** \brief Construct a random state (within bounds) */
+ void randomState(void);
+
+ /** \brief Construct a random state for a group */
+ void randomStateGroup(const std::string &group);
+
+ /** \brief Construct a random state for a group */
+ void randomStateGroup(const KinematicModel::JointGroup *group);
+
+ /** \brief Perturb state. Each dimension is perturbed by a factor of its range */
+ void perturbState(double factor);
+
+ /** \brief Perturb state of a group. Each dimension is perturbed by a factor of its range */
+ void perturbStateGroup(double factor, const std::string &group);
+
+ /** \brief Perturb state of a group. Each dimension is perturbed by a factor of its range */
+ void perturbStateGroup(double factor, const KinematicModel::JointGroup *group);
+
+ /** \brief Update parameters so that they are within the specified bounds */
+ void enforceBounds(void);
+
+ /** \brief Update parameters so that they are within the specified bounds (for a specific group) */
+ void enforceBoundsGroup(const std::string &group);
+
+ /** \brief Update parameters so that they are within the specified bounds (for a specific group) */
+ void enforceBoundsGroup(const KinematicModel::JointGroup *group);
+
+ /** \brief Mark all values as unseen */
+ void reset(void);
+
+ /** \brief Mark all values in a group as unseen */
+ void resetGroup(const KinematicModel::JointGroup *group);
+
+ /** \brief Mark all values in a group as unseen */
+ void resetGroup(const std::string &group);
+
+ /** \brief Set all the parameters to a given value */
+ void setAll(const double value);
+
+ /** \brief Set all the parameters from a group to a given value */
+ void setAllInGroup(const double value, const std::string &group);
+
+ /** \brief Set all the parameters from a group to a given value */
+ void setAllInGroup(const double value, const KinematicModel::JointGroup *group);
+
+ /** \brief Set the parameters for the complete robot. */
+ bool setParams(const std::vector<double> ¶ms);
+
+ /** \brief Set the parameters for the complete robot. */
+ bool setParams(const double *params);
+
+ /** \brief Set the parameters for a given group. Return true if
+ any change was observed in either of the set
+ values. */
+ bool setParamsGroup(const std::vector<double> ¶ms, const std::string &group);
+
+ /** \brief Set the parameters for a given group. Return true if
+ any change was observed in either of the set
+ values. */
+ bool setParamsGroup(const std::vector<double> ¶ms, const KinematicModel::JointGroup *group);
+
+ /** \brief Set the parameters for a given group. Return true if
+ any change was observed in either of the set
+ values. */
+ bool setParamsGroup(const double *params, const std::string &group);
+
+ /** \brief Set the parameters for a given group. Return true if
+ any change was observed in either of the set
+ values. */
+ bool setParamsGroup(const double *params, const KinematicModel::JointGroup *group);
+
+ /** \brief Given the name of a joint, set the values of the
+ parameters describing the joint. Return true if any
+ change was observed in the set value */
+ bool setParamsJoint(const double *params, const std::string &name);
+
+ /** \brief Given the name of a joint, set the values of the
+ parameters describing the joint. Return true if any
+ change was observed in the set value */
+ bool setParamsJoint(const std::vector<double> ¶ms, const std::string &name);
+
+ /** \brief Given the names of some joints, set the values of the
+ parameters describing the joints. Return true if any
+ change was observed in the set values */
+ bool setParamsJoints(const double *params, const std::vector<std::string> &names);
+
+ /** \brief Given the names of some joints, set the values of the
+ parameters describing the joints. Return true if any
+ change was observed in the set values */
+ bool setParamsJoints(const std::vector<double> ¶ms, const std::vector<std::string> &names);
+
+ /** \brief Given the name of a joint, get the values of the
+ parameters describing the joint. */
+ const double* getParamsJoint(const std::string &name) const;
+
+ /** \brief Return the current value of the params */
+ const double* getParams(void) const;
+
+ /** \brief Copy the parameters for a given group to a destination address */
+ void copyParamsGroup(std::vector<double> ¶ms, const std::string &group) const;
+
+ /** \brief Copy the parameters for a given group to a destination address */
+ void copyParamsGroup(std::vector<double> ¶ms, const KinematicModel::JointGroup *group) const;
+
+ /** \brief Copy the parameters for a given group to a destination address */
+ void copyParamsGroup(double *params, const std::string &group) const;
+
+ /** \brief Copy the parameters for a given group to a destination address */
+ void copyParamsGroup(double *params, const KinematicModel::JointGroup *group) const;
+
+ /** \brief Copy all parameters to a destination address */
+ void copyParams(double *params) const;
+
+ /** \brief Copy all parameters to a destination address */
+ void copyParams(std::vector<double> ¶ms) const;
+
+ /** \brief Copy the parameters describing a given joint */
+ void copyParamsJoint(double *params, const std::string &name) const;
+
+ /** \brief Copy the parameters describing a given joint */
+ void copyParamsJoint(std::vector<double> ¶ms, const std::string &name) const;
+
+ /** \brief Copy the parameters describing a given set of joints */
+ void copyParamsJoints(double *params, const std::vector<std::string> &names) const;
+
+ /** \brief Copy the parameters describing a given set of joints */
+ void copyParamsJoints(std::vector<double> ¶ms, const std::vector<std::string> &names) const;
+
+ /** \brief Check if all params for a joint were seen */
+ bool seenJoint(const std::string &name) const;
+
+ /** \brief Check if all params in a group were seen */
+ bool seenAllGroup(const std::string &group) const;
+
+ /** \brief Check if all params in a group were seen */
+ bool seenAllGroup(const KinematicModel::JointGroup *group) const;
+
+ /** \brief Check if all params were seen */
+ bool seenAll(void) const;
+
+ /** \brief Print the data from the state to screen */
+ void print(std::ostream &out = std::cout) const;
+
+ /** \brief Print the missing joint index values */
+ void missing(std::ostream &out = std::cout);
+
+ protected:
+
+ /** \brief Copy data from another instance of this class */
+ void copyFrom(const KinematicState &sp);
+
+ const KinematicModel *owner_;
+ double *params_;
+ std::vector<bool> seen_;
+ };
+
+}
+
+#endif
Modified: pkg/trunk/motion_planning/planning_models/src/kinematic_model.cpp
===================================================================
--- pkg/trunk/motion_planning/planning_models/src/kinematic_model.cpp 2009-08-31 00:32:46 UTC (rev 23358)
+++ pkg/trunk/motion_planning/planning_models/src/kinematic_model.cpp 2009-08-31 02:58:00 UTC (rev 23359)
@@ -91,7 +91,7 @@
return modelName_;
}
-unsigned int planning_models::KinematicModel::getDimension(void) const
+inline unsigned int planning_models::KinematicModel::getDimension(void) const
{
return dimension_;
}
@@ -101,12 +101,12 @@
return stateBounds_;
}
-const btTransform& planning_models::KinematicModel::getRootTransform(void) const
+inline const btTransform& planning_models::KinematicModel::getRootTransform(void) const
{
return rootTransform_;
}
-void planning_models::KinematicModel::setRootTransform(const btTransform &transform)
+inline void planning_models::KinematicModel::setRootTransform(const btTransform &transform)
{
rootTransform_ = transform;
}
@@ -121,12 +121,12 @@
return planarJoints_;
}
-void planning_models::KinematicModel::lock(void)
+inline void planning_models::KinematicModel::lock(void)
{
lock_.lock();
}
-void planning_models::KinematicModel::unlock(void)
+inline void planning_models::KinematicModel::unlock(void)
{
lock_.unlock();
}
@@ -176,8 +176,6 @@
planning_models::KinematicModel::Joint* planning_models::KinematicModel::buildRecursive(Link *parent, const urdf::Link *link)
{
- ROS_INFO("%s", link->name.c_str());
-
Joint *joint = constructJoint(link->parent_joint.get(), stateBounds_);
joint->stateIndex = dimension_;
jointMap_[joint->name] = joint;
@@ -196,7 +194,7 @@
if (dynamic_cast<PlanarJoint*>(joint))
planarJoints_.push_back(joint->name);
- for (unsigned int i = 0 ; link->child_links.size() ; ++i)
+ for (unsigned int i = 0 ; i < link->child_links.size() ; ++i)
joint->after->after.push_back(buildRecursive(joint->after, link->child_links[i].get()));
return joint;
@@ -420,6 +418,18 @@
return it->second;
}
+planning_models::KinematicModel::Joint* planning_models::KinematicModel::getJoint(const std::string &name)
+{
+ std::map<std::string, Joint*>::iterator it = jointMap_.find(name);
+ if (it == jointMap_.end())
+ {
+ ROS_ERROR("Joint '%s' not found", name.c_str());
+ return NULL;
+ }
+ else
+ return it->second;
+}
+
const planning_models::KinematicModel::Link* planning_models::KinematicModel::getLink(const std::string &name) const
{
std::map<std::string, Link*>::const_iterator it = linkMap_.find(name);
@@ -432,6 +442,18 @@
return it->second;
}
+planning_models::KinematicModel::Link* planning_models::KinematicModel::getLink(const std::string &name)
+{
+ std::map<std::string, Link*>::iterator it = linkMap_.find(name);
+ if (it == linkMap_.end())
+ {
+ ROS_ERROR("Link '%s' not found", name.c_str());
+ return NULL;
+ }
+ else
+ return it->second;
+}
+
const planning_models::KinematicModel::JointGroup* planning_models::KinematicModel::getGroup(const std::string &name) const
{
std::map<std::string, JointGroup*>::const_iterator it = groupMap_.find(name);
@@ -444,6 +466,18 @@
return it->second;
}
+planning_models::KinematicModel::JointGroup* planning_models::KinematicModel::getGroup(const std::string &name)
+{
+ std::map<std::string, JointGroup*>::iterator it = groupMap_.find(name);
+ if (it == groupMap_.end())
+ {
+ ROS_ERROR("Joint group '%s' not found", name.c_str());
+ return NULL;
+ }
+ else
+ return it->second;
+}
+
void planning_models::KinematicModel::getGroups(std::vector<const JointGroup*> &groups) const
{
groups.clear();
@@ -554,7 +588,7 @@
getJoints(joints);
for (unsigned int i = 0 ; i < joints.size() ; ++i)
{
- printTransform(joints[i]->name, joints[i]->varTrans);
+ printTransform(joints[i]->name, joints[i]->varTrans, out);
out << std::endl;
}
out << "Link poses:" << std::endl;
@@ -562,7 +596,7 @@
getLinks(links);
for (unsigned int i = 0 ; i < links.size() ; ++i)
{
- printTransform(links[i]->name, links[i]->globalTrans);
+ printTransform(links[i]->name, links[i]->globalTrans, out);
out << std::endl;
}
}
@@ -629,7 +663,7 @@
}
-void planning_models::KinematicModel::Link::computeTransform(void)
+inline void planning_models::KinematicModel::Link::computeTransform(void)
{
globalTransFwd.mult(before->before ? before->before->globalTransFwd : owner->getRootTransform(), constTrans);
globalTransFwd *= before->varTrans;
@@ -652,7 +686,7 @@
delete shape;
}
-void planning_models::KinematicModel::AttachedBody::computeTransform(void)
+inline void planning_models::KinematicModel::AttachedBody::computeTransform(void)
{
globalTrans = owner->globalTrans * attachTrans;
}
Added: pkg/trunk/motion_planning/planning_models/src/kinematic_state.cpp
===================================================================
--- pkg/trunk/motion_planning/planning_models/src/kinematic_state.cpp (rev 0)
+++ pkg/trunk/motion_planning/planning_models/src/kinematic_state.cpp 2009-08-31 02:58:00 UTC (rev 23359)
@@ -0,0 +1,468 @@
+/*********************************************************************
+* Software License Agreement (BSD License)
+*
+* Copyright (c) 2008, Willow Garage, Inc.
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+*
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+* * Neither the name of the Willow Garage nor the names of its
+* contributors may be used to endorse or promote products derived
+* from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+* POSSIBILITY OF SUCH DAMAGE.
+*********************************************************************/
+
+/** \author Ioan Sucan */
+
+#include <planning_models/kinematic_state.h>
+#include <ros/console.h>
+#include <algorithm>
+#include <sstream>
+#include <cmath>
+#include <cstdlib>
+
+planning_models::KinematicState::KinematicState(const KinematicModel *model) : owner_(model)
+{
+ params_ = model->getDimension() > 0 ? new double[model->getDimension()] : NULL;
+ seen_.resize(model->getDimension(), false);
+ defaultState();
+ reset();
+}
+
+planning_models::KinematicState::KinematicState(const KinematicState &sp) : owner_(sp.owner_), params_(NULL)
+{
+ copyFrom(sp);
+}
+
+planning_models::KinematicState::~KinematicState(void)
+{
+ if (params_)
+ delete[] params_;
+}
+
+planning_models::KinematicState& planning_models::KinematicState::operator=(const KinematicState &rhs)
+{
+ if (this != &rhs)
+ copyFrom(rhs);
+ return *this;
+}
+
+bool planning_models::KinematicState::operator==(const KinematicState &rhs) const
+{
+ const unsigned int dim = owner_->getDimension();
+ if (dim != rhs.owner_->getDimension())
+ return false;
+ for (unsigned int i = 0 ; i < dim ; ++i)
+ if (fabs(params_[i] - rhs.params_[i]) > DBL_MIN)
+ return false;
+ return true;
+}
+
+void planning_models::KinematicState::copyFrom(const KinematicState &sp)
+{
+ owner_ = sp.owner_;
+ if (params_)
+ delete[] params_;
+ const unsigned int dim = owner_->getDimension();
+ params_ = dim > 0 ? new double[dim] : NULL;
+ if (params_)
+ for (unsigned int i = 0 ; i < dim ; ++i)
+ params_[i] = sp.params_[i];
+ seen_ = sp.seen_;
+}
+
+void planning_models::KinematicState::defaultState(void)
+{
+ const unsigned int dim = owner_->getDimension();
+ const std::vector<double> &bounds = owner_->getStateBounds();
+
+ for (unsigned int i = 0 ; i < dim ; ++i)
+ {
+ const unsigned int i2 = i << 1;
+ if (bounds[i2] <= 0.0 && bounds[i2 + 1] >= 0.0)
+ params_[i] = 0.0;
+ else
+ params_[i] = (bounds[i2] + bounds[i2 + 1]) / 2.0;
+ seen_[i] = true;
+ }
+}
+
+void planning_models::KinematicState::randomStateGroup(const std::string &group)
+{
+ randomStateGroup(owner_->getGroup(group));
+}
+
+void planning_models::KinematicState::randomStateGroup(const KinematicModel::JointGroup *group)
+{
+ const std::vector<double> &bounds = owner_->getStateBounds();
+ for (unsigned int i = 0 ; i < group->dimension ; ++i)
+ {
+ const unsigned int j = group->stateIndex[i];
+ const unsigned int j2 = j << 1;
+ params_[j] = (bounds[j2 + 1] - bounds[j2]) * ((double)rand() / (RAND_MAX + 1.0)) + bounds[j2];
+ seen_[j] = true;
+ }
+}
+
+void planning_models::KinematicState::randomState(void)
+{
+ const std::vector<double> &bounds = owner_->getStateBounds();
+ const unsigned int dim = owner_->getDimension();
+ for (unsigned int i = 0 ; i < dim ; ++i)
+ {
+ const unsigned int i2 = i << 1;
+ params_[i] = (bounds[i2 + 1] - bounds[i2]) * ((double)rand() / (RAND_MAX + 1.0)) + bounds[i2];
+ seen_[i] = true;
+ }
+}
+
+void planning_models::KinematicState::perturbStateGroup(double factor, const std::string &group)
+{
+ perturbStateGroup(factor, owner_->getGroup(group));
+}
+
+void planning_models::KinematicState::perturbStateGroup(double factor, const KinematicModel::JointGroup *group)
+{
+ const std::vector<double> &bounds = owner_->getStateBounds();
+ for (unsigned int i = 0 ; i < group->dimension ; ++i)
+ {
+ const unsigned int j = group->stateIndex[i];
+ const unsigned int j2 = j << 1;
+ params_[j] += factor * (bounds[j2 + 1] - bounds[j2]) * (2.0 * ((double)rand() / (RAND_MAX + 1.0)) - 1.0);
+ }
+ enforceBoundsGroup(group);
+}
+
+void planning_models::KinematicState::perturbState(double factor)
+{
+ const std::vector<double> &bounds = owner_->getStateBounds();
+ const unsigned int dim = owner_->getDimension();
+ for (unsigned int i = 0 ; i < dim ; ++i)
+ {
+ const unsigned int i2 = i << 1;
+ params_[i] += factor * (bounds[i2 + 1] - bounds[i2]) * (2.0 * ((double)rand() / (RAND_MAX + 1.0)) - 1.0);
+ }
+ enforceBounds();
+}
+
+void planning_models::KinematicState::enforceBoundsGroup(const std::string &group)
+{
+ enforceBoundsGroup(owner_->getGroup(group));
+}
+
+void planning_models::KinematicState::enforceBoundsGroup(const KinematicModel::JointGroup *group)
+{
+ const std::vector<double> &bounds = owner_->getStateBounds();
+ for (unsigned int i = 0 ; i < group->dimension ; ++i)
+ {
+ const unsigned int j = group->stateIndex[i];
+ const unsigned int j2 = j << 1;
+ if (params_[j] > bounds[j2 + 1])
+ params_[j] = bounds[j2 + 1];
+ else
+ if (params_[j] < bounds[j2])
+ params_[j] = bounds[j2];
+ }
+}
+
+void planning_models::KinematicState::enforceBounds(void)
+{
+ const std::vector<double> &bounds = owner_->getStateBounds();
+ const unsigned int dim = owner_->getDimension();
+ for (unsigned int i = 0 ; i < dim ; ++i)
+ {
+ const unsigned int i2 = i << 1;
+ if (params_[i] > bounds[i2 + 1])
+ params_[i] = bounds[i2 + 1];
+ else
+ if (params_[i] < bounds[i2])
+ params_[i] = bounds[i2];
+ }
+}
+
+void planning_models::KinematicState::reset(void)
+{
+ const unsigned int dim = owner_->getDimension();
+ for (unsigned int i = 0 ; i < dim ; ++i)
+ seen_[i] = false;
+}
+
+void planning_models::KinematicState::resetGroup(const std::string &group)
+{
+ resetGroup(owner_->getGroup(group));
+}
+
+void planning_models::KinematicState::resetGroup(const KinematicModel::JointGroup *group)
+{
+ for (unsigned int i = 0 ; i < group->dimension ; ++i)
+ seen_[group->stateIndex[i]] = false;
+}
+
+bool planning_models::KinematicState::seenAll(void) const
+{
+ const unsigned int dim = owner_->getDimension();
+ for (unsigned int i = 0 ; i < dim ; ++i)
+ if (!seen_[i])
+ return false;
+ return true;
+}
+
+bool planning_models::KinematicState::seenAllGroup(const std::string &group) const
+{
+ return seenAllGroup(owner_->getGroup(group));
+}
+
+bool planning_models::KinematicState::seenAllGroup(const KinematicModel::JointGroup *group) const
+{
+ for (unsigned int i = 0 ; i < group->dimension ; ++i)
+ if (!seen_[group->stateIndex[i]])
+ return false;
+ return true;
+}
+
+bool planning_models::KinematicState::seenJoint(const std::string &name) const
+{
+ const KinematicModel::Joint *joint = owner_->getJoint(name);
+ for (unsigned int i = 0 ; i < joint->usedParams ; ++i)
+ if (!seen_[joint->stateIndex + i])
+ return false;
+ return true;
+}
+
+void planning_models::KinematicState::missing(std::ostream &out)
+{
+ const unsigned int dim = owner_->getDimension();
+ for (unsigned int i = 0 ; i < dim ; ++i)
+ if (!seen_[i])
+ out << i << " ";
+}
+
+const double* planning_models::KinematicState::getParamsJoint(const std::string &name) const
+{
+ const KinematicModel::Joint *joint = owner_->getJoint(name);
+ return params_ + joint->stateIndex;
+}
+
+bool planning_models::KinematicState::setParamsJoints(const double *params, const std::vector<std::string> &names)
+{
+ bool change = false;
+ int u = 0;
+ for (unsigned int i = 0 ; i < names.size() ; ++i)
+ {
+ const KinematicModel::Joint *joint = owner_->getJoint(names[i]);
+ bool ch = setParamsJoint(params + u, names[i]);
+ u += joint->usedParams;
+ change = change || ch;
+ }
+
+ return change;
+}
+
+bool planning_models::KinematicState::setParamsJoints(const std::vector<double> ¶ms, const std::vector<std::string> &names)
+{
+ return setParamsJoints(¶ms[0], names);
+}
+
+bool planning_models::KinematicState::setParamsJoint(const std::vector<double> ¶ms, const std::string &name)
+{
+ return setParamsJoint(¶ms[0], name);
+}
+
+bool planning_models::KinematicState::setParamsJoint(const double *params, const std::string &name)
+{
+ bool result = false;
+ const KinematicModel::Joint *joint = owner_->getJoint(name);
+
+ for (unsigned int i = 0 ; i < joint->usedParams ; ++i)
+ {
+ unsigned int pos_i = joint->stateIndex + i;
+ if (params_[pos_i] != params[i] || !seen_[pos_i])
+ {
+ params_[pos_i] = params[i];
+ seen_[pos_i] = true;
+ result = true;
+ }
+ }
+
+ return result;
+}
+
+bool planning_models::KinematicState::setParams(const std::vector<double> ¶ms)
+{
+ return setParams(¶ms[0]);
+}
+
+bool planning_models::KinematicState::setParams(const double *params)
+{
+ const unsigned int dim = owner_->getDimension();
+ bool result = false;
+ for (unsigned int i = 0 ; i < dim ; ++i)
+ if (params_[i] != params[i] || !seen_[i])
+ {
+ params_[i] = params[i];
+ seen_[i] = true;
+ result = true;
+ }
+ return result;
+}
+
+bool planning_models::KinematicState::setParamsGroup(const std::vector<double> ¶ms, const std::string &group)
+{
+ return setParamsGroup(¶ms[0], owner_->getGroup(group));
+}
+
+bool planning_models::KinematicState::setParamsGroup(const std::vector<double> ¶ms, const KinematicModel::JointGroup *group)
+{
+ return setParamsGroup(¶ms[0], group);
+}
+
+bool planning_models::KinematicState::setParamsGroup(const double *params, const std::string &group)
+{
+ return setParamsGroup(params, owner_->getGroup(group));
+}
+
+bool planning_models::KinematicState::setParamsGroup(const double *params, const KinematicModel::JointGroup *group)
+{
+ bool result = false;
+ for (unsigned int i = 0 ; i < group->dimension ; ++i)
+ {
+ unsigned int j = group->stateIndex[i];
+ if (params_[j] != params[i] || !seen_[j])
+ {
+ params_[j] = params[i];
+ seen_[j] = true;
+ result = true;
+ }
+ }
+ return result;
+}
+
+void planning_models::KinematicState::setAllInGroup(const double value, const std::string &group)
+{
+ setAllInGroup(value, owner_->getGroup(group));
+}
+
+void planning_models::KinematicState::setAllInGroup(const double value, const KinematicModel::JointGroup *group)
+{
+ for (unsigned int i = 0 ; i < group->dimension ; ++i)
+ {
+ unsigned int j = group->stateIndex[i];
+ params_[j] = value;
+ seen_[j] = true;
+ }
+}
+
+void planning_models::KinematicState::setAll(const double value)
+{
+ const unsigned int dim = owner_->getDimension();
+ for (unsigned int i = 0 ; i < dim ; ++i)
+ {
+ params_[i] = value;
+ seen_[i] = true;
+ }
+}
+
+const double* planning_models::KinematicState::getParams(void) const
+{
+ return params_;
+}
+
+void planning_models::KinematicState::copyParamsJoint(double *params, const std::string &name) const
+{
+ cons...
[truncated message content] |
|
From: <is...@us...> - 2009-08-31 03:15:47
|
Revision: 23361
http://personalrobots.svn.sourceforge.net/personalrobots/?rev=23361&view=rev
Author: isucan
Date: 2009-08-31 03:15:39 +0000 (Mon, 31 Aug 2009)
Log Message:
-----------
tests for kinematic state pass
Modified Paths:
--------------
pkg/trunk/motion_planning/planning_models/src/kinematic_model.cpp
pkg/trunk/motion_planning/planning_models/test/test_kinematic2.cpp
Modified: pkg/trunk/motion_planning/planning_models/src/kinematic_model.cpp
===================================================================
--- pkg/trunk/motion_planning/planning_models/src/kinematic_model.cpp 2009-08-31 03:01:50 UTC (rev 23360)
+++ pkg/trunk/motion_planning/planning_models/src/kinematic_model.cpp 2009-08-31 03:15:39 UTC (rev 23361)
@@ -703,9 +703,7 @@
jointIndex.resize(joints.size());
dimension = 0;
- std::vector<const Joint*> allJoints;
- owner->getJoints(allJoints);
- std::vector<double> allBounds = owner->getStateBounds();
+ const std::vector<double> &allBounds = owner->getStateBounds();
for (unsigned int i = 0 ; i < joints.size() ; ++i)
{
@@ -713,24 +711,14 @@
jointIndex[i] = dimension;
dimension += joints[i]->usedParams;
jointMap_[jointNames[i]] = i;
-
- unsigned int globalStateIndex = 0;
- bool found = false;
- for (unsigned int j = 0 ; j < allJoints.size() ; ++j)
- if (allJoints[j]->name == joints[i]->name)
- {
- for (unsigned int k = 0 ; k < joints[i]->usedParams ; ++k)
- {
- unsigned int si = globalStateIndex + k;
- stateIndex.push_back(si);
- stateBounds.push_back(allBounds[2 * si]);
- stateBounds.push_back(allBounds[2 * si + 1]);
- }
- found = true;
- break;
- }
- if (!found)
- ROS_FATAL("Group joint not in kinematic model");
+
+ for (unsigned int k = 0 ; k < joints[i]->usedParams ; ++k)
+ {
+ const unsigned int si = joints[i]->stateIndex + k;
+ stateIndex.push_back(si);
+ stateBounds.push_back(allBounds[2 * si]);
+ stateBounds.push_back(allBounds[2 * si + 1]);
+ }
}
for (unsigned int i = 0 ; i < joints.size() ; ++i)
Modified: pkg/trunk/motion_planning/planning_models/test/test_kinematic2.cpp
===================================================================
--- pkg/trunk/motion_planning/planning_models/test/test_kinematic2.cpp 2009-08-31 03:01:50 UTC (rev 23360)
+++ pkg/trunk/motion_planning/planning_models/test/test_kinematic2.cpp 2009-08-31 03:15:39 UTC (rev 23361)
@@ -35,6 +35,7 @@
/** \author Ioan Sucan */
#include <planning_models/kinematic_model.h>
+#include <planning_models/kinematic_state.h>
#include <gtest/gtest.h>
#include <sstream>
#include <ctype.h>
@@ -289,26 +290,15 @@
" </visual>"
"</link>"
"</robot>";
-
+
static const std::string MODEL2_INFO =
- "Number of robots = 1\n"
"Complete model state dimension = 5\n"
- "State bounds: [0.00000, 0.00000] [0.00000, 0.00000] [-3.14159, 3.14159] [-3.14159, 3.14159] [0.01000, 0.38600] \n"
- "Parameter index:\n"
- "base_link_joint = 0\n"
- "link_a_joint = 3\n"
- "link_c_joint = 4\n"
- "Parameter name:\n"
- "0 = base_link_joint\n"
- "1 = base_link_joint\n"
- "2 = base_link_joint\n"
- "3 = link_a_joint\n"
- "4 = link_c_joint\n"
- "Floating joints at: \n"
- "Planar joints at: 0 base_link_joint \n"
+ "State bounds: [0.00000, 0.00000] [0.00000, 0.00000] [-3.14159, 3.14159] [-3.14159, 3.14159] [0.00000, 0.08900] \n"
+ "Floating joints : \n"
+ "Planar joints : base_joint \n"
"Available groups: base \n"
- "Group base with ID 0 has 1 roots: base_link_joint \n"
- "The state components for this group are: 0 1 2 3 4 base_link_joint base_link_joint base_link_joint link_a_joint link_c_joint \n";
+ "Group base has 1 roots: base_joint \n"
+ "The state components for this group are: 0 1 2 3 4 \n";
urdf::Model urdfModel;
urdfModel.initString(MODEL2);
@@ -329,8 +319,7 @@
std::stringstream ss1;
model->printModelInfo(ss1);
- // EXPECT_TRUE(sameStringIgnoringWS(MODEL2_INFO, ss1.str()));
- ROS_INFO("'%s'", ss1.str().c_str());
+ EXPECT_TRUE(sameStringIgnoringWS(MODEL2_INFO, ss1.str()));
// make sure applying the state works for the entire robot
model->printTransforms(ss1);
@@ -341,7 +330,7 @@
model->printModelInfo(ss2);
model->printTransforms(ss2);
- // EXPECT_EQ(ss1.str(), ss2.str());
+ EXPECT_EQ(ss1.str(), ss2.str());
EXPECT_NEAR(1.0, model->getLink("base_link")->globalTrans.getOrigin().x(), 1e-5);
EXPECT_NEAR(1.0, model->getLink("base_link")->globalTrans.getOrigin().y(), 1e-5);
@@ -375,22 +364,21 @@
EXPECT_NEAR(0.0, model->getLink("link_c")->globalTrans.getRotation().z(), 1e-5);
EXPECT_NEAR(1.0, model->getLink("link_c")->globalTrans.getRotation().w(), 1e-5);
- /*
- planning_models::StateParams *sp = model->newStateParams();
+ planning_models::KinematicState *sp = new planning_models::KinematicState(model);
EXPECT_FALSE(sp->seenAll());
double tmpParam[3];
tmpParam[0] = 0.1;
- sp->setParamsJoint(tmpParam, "link_a_joint");
+ sp->setParamsJoint(tmpParam, "joint_a");
EXPECT_FALSE(sp->seenAll());
- EXPECT_TRUE(sp->seenJoint("link_a_joint"));
+ EXPECT_TRUE(sp->seenJoint("joint_a"));
tmpParam[0] = -1.0;
- sp->setParamsJoint(tmpParam, "link_c_joint");
+ sp->setParamsJoint(tmpParam, "joint_c");
EXPECT_FALSE(sp->seenAll());
tmpParam[0] = 0.5; tmpParam[1] = 0.4; tmpParam[2] = 1.1;
- sp->setParamsJoint(tmpParam, "base_link_joint");
+ sp->setParamsJoint(tmpParam, "base_joint");
EXPECT_TRUE(sp->seenAll());
EXPECT_EQ(0.5, sp->getParams()[0]);
@@ -399,11 +387,10 @@
EXPECT_EQ(0.1, sp->getParams()[3]);
EXPECT_EQ(-1.0, sp->getParams()[4]);
- planning_models::StateParams sp_copy = *sp;
+ planning_models::KinematicState sp_copy = *sp;
EXPECT_TRUE(sp_copy == *sp);
delete sp;
- */
delete model;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <is...@us...> - 2009-09-04 04:16:19
|
Revision: 23814
http://personalrobots.svn.sourceforge.net/personalrobots/?rev=23814&view=rev
Author: isucan
Date: 2009-09-04 04:16:11 +0000 (Fri, 04 Sep 2009)
Log Message:
-----------
removing dependency of planning_models on ogre_tools
Modified Paths:
--------------
pkg/trunk/motion_planning/planning_models/manifest.xml
pkg/trunk/motion_planning/planning_models/src/kinematic_model.cpp
Modified: pkg/trunk/motion_planning/planning_models/manifest.xml
===================================================================
--- pkg/trunk/motion_planning/planning_models/manifest.xml 2009-09-04 04:11:58 UTC (rev 23813)
+++ pkg/trunk/motion_planning/planning_models/manifest.xml 2009-09-04 04:16:11 UTC (rev 23814)
@@ -12,7 +12,6 @@
<depend package="geometric_shapes"/>
<depend package="bullet"/>
<depend package="resource_retriever"/>
- <depend package="ogre_tools"/>
<export>
<cpp cflags="-I${prefix}/include `rosboost-cfg --cflags`" lflags="-Wl,-rpath,${prefix}/lib -L${prefix}/lib -lplanning_models `rosboost-cfg --lflags thread`"/>
Modified: pkg/trunk/motion_planning/planning_models/src/kinematic_model.cpp
===================================================================
--- pkg/trunk/motion_planning/planning_models/src/kinematic_model.cpp 2009-09-04 04:11:58 UTC (rev 23813)
+++ pkg/trunk/motion_planning/planning_models/src/kinematic_model.cpp 2009-09-04 04:16:11 UTC (rev 23814)
@@ -36,7 +36,7 @@
#include <planning_models/kinematic_model.h>
#include <resource_retriever/retriever.h>
-#include <ogre_tools/stl_loader.h>
+#include <queue>
#include <ros/console.h>
#include <cmath>
@@ -363,23 +363,12 @@
if (ok)
{
if (res.size == 0)
- ROS_WARN("Retrieved empty mesh for resource [%s]", mesh->filename.c_str());
+ ROS_WARN("Retrieved empty mesh for resource '%s'", mesh->filename.c_str());
else
{
- ogre_tools::STLLoader loader;
- if (loader.load(res.data.get()))
- {
- std::vector<btVector3> triangles;
- for (unsigned int i = 0 ; i < loader.triangles_.size() ; ++i)
- {
- triangles.push_back(btVector3(loader.triangles_[i].vertices_[0].x, loader.triangles_[i].vertices_[0].y, loader.triangles_[i].vertices_[0].z));
- triangles.push_back(btVector3(loader.triangles_[i].vertices_[1].x, loader.triangles_[i].vertices_[1].y, loader.triangles_[i].vertices_[1].z));
- triangles.push_back(btVector3(loader.triangles_[i].vertices_[2].x, loader.triangles_[i].vertices_[2].y, loader.triangles_[i].vertices_[2].z));
- }
- result = shapes::createMeshFromVertices(triangles);
- }
- else
- ROS_ERROR("Failed to load mesh [%s]", mesh->filename.c_str());
+ result = shapes::createMeshFromBinaryStlData(reinterpret_cast<char*>(res.data.get()), res.size);
+ if (result == NULL)
+ ROS_ERROR("Failed to load mesh '%s'", mesh->filename.c_str());
}
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <is...@us...> - 2009-09-04 16:16:26
|
Revision: 23832
http://personalrobots.svn.sourceforge.net/personalrobots/?rev=23832&view=rev
Author: isucan
Date: 2009-09-04 16:16:14 +0000 (Fri, 04 Sep 2009)
Log Message:
-----------
keeping track of links to be updated
Modified Paths:
--------------
pkg/trunk/motion_planning/planning_models/CMakeLists.txt
pkg/trunk/motion_planning/planning_models/include/planning_models/kinematic_model.h
pkg/trunk/motion_planning/planning_models/src/kinematic_model.cpp
Modified: pkg/trunk/motion_planning/planning_models/CMakeLists.txt
===================================================================
--- pkg/trunk/motion_planning/planning_models/CMakeLists.txt 2009-09-04 15:42:33 UTC (rev 23831)
+++ pkg/trunk/motion_planning/planning_models/CMakeLists.txt 2009-09-04 16:16:14 UTC (rev 23832)
@@ -3,7 +3,7 @@
rospack(planning_models)
rospack_add_boost_directories()
-set(ROS_BUILD_TYPE Debug)
+set(ROS_BUILD_TYPE Release)
rospack_add_library(planning_models src/kinematic_model.cpp
src/kinematic_state.cpp)
Modified: pkg/trunk/motion_planning/planning_models/include/planning_models/kinematic_model.h
===================================================================
--- pkg/trunk/motion_planning/planning_models/include/planning_models/kinematic_model.h 2009-09-04 15:42:33 UTC (rev 23831)
+++ pkg/trunk/motion_planning/planning_models/include/planning_models/kinematic_model.h 2009-09-04 16:16:14 UTC (rev 23832)
@@ -297,6 +297,9 @@
/** \brief The list of joints that are roots in this group */
std::vector<Joint*> jointRoots;
+ /** \brief The list of links that are updated when computeTransforms() is called, in the order they are updated */
+ std::vector<Link*> updatedLinks;
+
/** \brief Perform forward kinematics starting at the roots
within a group. Links that are not in the group are also
updated, but transforms for joints that are not in the
@@ -434,6 +437,9 @@
/** \brief The index at which a joint starts reading values in the state vector */
std::vector<unsigned int> jointIndex_;
+ /** \brief The list of links that are updated when computeTransforms() is called, in the order they are updated */
+ std::vector<Link*> updatedLinks_;
+
/** \brief The root joint */
Joint *root_;
@@ -453,7 +459,9 @@
btTransform rootTransform_;
boost::mutex lock_;
-
+
+
+ void buildConvenientDatastructures(void);
void buildGroups(const std::map< std::string, std::vector<std::string> > &groups);
Joint* buildRecursive(Link *parent, const urdf::Link *link);
Joint* constructJoint(const urdf::Joint *urdfJoint, std::vector<double> &bounds);
Modified: pkg/trunk/motion_planning/planning_models/src/kinematic_model.cpp
===================================================================
--- pkg/trunk/motion_planning/planning_models/src/kinematic_model.cpp 2009-09-04 15:42:33 UTC (rev 23831)
+++ pkg/trunk/motion_planning/planning_models/src/kinematic_model.cpp 2009-09-04 16:16:14 UTC (rev 23832)
@@ -58,6 +58,7 @@
for (unsigned int i = 0 ; i < groups.size() ; ++i)
groupContent[groups[i]->name] = groups[i]->jointNames;
buildGroups(groupContent);
+ buildConvenientDatastructures();
}
else
root_ = NULL;
@@ -95,6 +96,7 @@
{
root_ = buildRecursive(NULL, root);
buildGroups(groups);
+ buildConvenientDatastructures();
}
}
else
@@ -173,6 +175,23 @@
computeTransforms(params);
}
+void planning_models::KinematicModel::buildConvenientDatastructures(void)
+{
+ if (root_)
+ {
+ std::queue<Link*> links;
+ links.push(root_->after);
+ while (!links.empty())
+ {
+ Link *link = links.front();
+ links.pop();
+ updatedLinks_.push_back(link);
+ for (unsigned int i = 0 ; i < link->after.size() ; ++i)
+ links.push(link->after[i]->after);
+ }
+ }
+}
+
void planning_models::KinematicModel::buildGroups(const std::map< std::string, std::vector<std::string> > &groups)
{
for (std::map< std::string, std::vector<std::string> >::const_iterator it = groups.begin() ; it != groups.end() ; ++it)
@@ -387,23 +406,13 @@
void planning_models::KinematicModel::computeTransforms(const double *params)
{
- for (unsigned int i = 0 ; i < jointList_.size() ; ++i)
+ const unsigned int js = jointList_.size();
+ for (unsigned int i = 0 ; i < js ; ++i)
jointList_[i]->updateVariableTransform(params + jointIndex_[i]);
- if (root_)
- {
- std::queue<Link*> links;
- links.push(root_->after);
- while (!links.empty())
- {
- Link *link = links.front();
- links.pop();
-
- link->computeTransform();
- for (unsigned int i = 0 ; i < link->after.size() ; ++i)
- links.push(link->after[i]->after);
- }
- }
+ const unsigned int ls = updatedLinks_.size();
+ for (unsigned int i = 0 ; i < ls ; ++i)
+ updatedLinks_[i]->computeTransform();
}
const planning_models::KinematicModel::Joint* planning_models::KinematicModel::getRoot(void) const
@@ -862,6 +871,21 @@
if (!found)
jointRoots.push_back(joints[i]);
}
+
+ for (unsigned int i = 0 ; i < jointRoots.size() ; ++i)
+ {
+ std::queue<Link*> links;
+ links.push(jointRoots[i]->after);
+
+ while (!links.empty())
+ {
+ Link *link = links.front();
+ links.pop();
+ updatedLinks.push_back(link);
+ for (unsigned int i = 0 ; i < link->after.size() ; ++i)
+ links.push(link->after[i]->after);
+ }
+ }
}
planning_models::KinematicModel::JointGroup::~JointGroup(void)
@@ -887,22 +911,11 @@
void planning_models::KinematicModel::JointGroup::computeTransforms(const double *params)
{
- for (unsigned int i = 0 ; i < joints.size() ; ++i)
+ const unsigned int js = joints.size();
+ for (unsigned int i = 0 ; i < js ; ++i)
joints[i]->updateVariableTransform(params + jointIndex[i]);
- for (unsigned int i = 0 ; i < jointRoots.size() ; ++i)
- {
- std::queue<Link*> links;
- links.push(jointRoots[i]->after);
-
- while (!links.empty())
- {
- Link *link = links.front();
- links.pop();
-
- link->computeTransform();
- for (unsigned int i = 0 ; i < link->after.size() ; ++i)
- links.push(link->after[i]->after);
- }
- }
+ const unsigned int ls = updatedLinks.size();
+ for (unsigned int i = 0 ; i < ls ; ++i)
+ updatedLinks[i]->computeTransform();
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|