collada exporter using soft limits if they exist (thanks to Kei Okada)
This commit is contained in:
parent
48bf8cff23
commit
c463e9e6e0
|
@ -63,7 +63,7 @@
|
|||
#include <assimp/IOStream.h>
|
||||
#include <assimp/IOSystem.h>
|
||||
|
||||
#define FOREACH(it, v) for(typeof((v).begin()) it = (v).begin(); it != (v).end(); (it)++)
|
||||
#define FOREACH(it, v) for(typeof((v).begin())it = (v).begin(); it != (v).end(); (it)++)
|
||||
#define FOREACHC FOREACH
|
||||
|
||||
using namespace std;
|
||||
|
@ -77,10 +77,12 @@ public:
|
|||
ResourceIOStream(const resource_retriever::MemoryResource& res)
|
||||
: res_(res)
|
||||
, pos_(res.data.get())
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
~ResourceIOStream()
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
size_t Read(void* buffer, size_t size, size_t count)
|
||||
{
|
||||
|
@ -96,7 +98,9 @@ public:
|
|||
return to_read;
|
||||
}
|
||||
|
||||
size_t Write( const void* buffer, size_t size, size_t count) { ROS_BREAK(); return 0; }
|
||||
size_t Write( const void* buffer, size_t size, size_t count) {
|
||||
ROS_BREAK(); return 0;
|
||||
}
|
||||
|
||||
aiReturn Seek( size_t offset, aiOrigin origin)
|
||||
{
|
||||
|
@ -135,7 +139,8 @@ public:
|
|||
return res_.size;
|
||||
}
|
||||
|
||||
void Flush() {}
|
||||
void Flush() {
|
||||
}
|
||||
|
||||
private:
|
||||
resource_retriever::MemoryResource res_;
|
||||
|
@ -195,14 +200,16 @@ public:
|
|||
return new ResourceIOStream(res);
|
||||
}
|
||||
|
||||
void Close(Assimp::IOStream* stream) { delete stream; }
|
||||
void Close(Assimp::IOStream* stream) {
|
||||
delete stream;
|
||||
}
|
||||
|
||||
private:
|
||||
mutable resource_retriever::Retriever retriever_;
|
||||
};
|
||||
|
||||
/** \brief Implements writing urdf::Model objects to a COLLADA DOM.
|
||||
*/
|
||||
*/
|
||||
class ColladaWriter : public daeErrorHandler
|
||||
{
|
||||
private:
|
||||
|
@ -229,7 +236,8 @@ private:
|
|||
struct axis_output
|
||||
{
|
||||
//axis_output(const string& sid, KinBody::JointConstPtr pjoint, int iaxis) : sid(sid), pjoint(pjoint), iaxis(iaxis) {}
|
||||
axis_output() : iaxis(0) {}
|
||||
axis_output() : iaxis(0) {
|
||||
}
|
||||
string sid, nodesid;
|
||||
boost::shared_ptr<const urdf::Joint> pjoint;
|
||||
int iaxis;
|
||||
|
@ -242,7 +250,8 @@ private:
|
|||
|
||||
struct axis_sids
|
||||
{
|
||||
axis_sids(const string& axissid, const string& valuesid, const string& jointnodesid) : axissid(axissid), valuesid(valuesid), jointnodesid(jointnodesid) {}
|
||||
axis_sids(const string& axissid, const string& valuesid, const string& jointnodesid) : axissid(axissid), valuesid(valuesid), jointnodesid(jointnodesid) {
|
||||
}
|
||||
string axissid, valuesid, jointnodesid;
|
||||
};
|
||||
|
||||
|
@ -270,7 +279,8 @@ public:
|
|||
_collada->setDatabase(NULL);
|
||||
_importer.SetIOHandler(new ResourceIOSystem());
|
||||
}
|
||||
virtual ~ColladaWriter() {}
|
||||
virtual ~ColladaWriter() {
|
||||
}
|
||||
|
||||
boost::shared_ptr<DAE> convert()
|
||||
{
|
||||
|
@ -350,8 +360,12 @@ public:
|
|||
}
|
||||
|
||||
protected:
|
||||
virtual void handleError(daeString msg) { throw ColladaUrdfException(msg); }
|
||||
virtual void handleWarning(daeString msg) { std::cerr << "COLLADA DOM warning: " << msg << std::endl; }
|
||||
virtual void handleError(daeString msg) {
|
||||
throw ColladaUrdfException(msg);
|
||||
}
|
||||
virtual void handleWarning(daeString msg) {
|
||||
std::cerr << "COLLADA DOM warning: " << msg << std::endl;
|
||||
}
|
||||
|
||||
void _CreateScene()
|
||||
{
|
||||
|
@ -440,6 +454,10 @@ protected:
|
|||
flower = pjoint->limits->lower;
|
||||
fupper = pjoint->limits->upper;
|
||||
}
|
||||
if( !!pjoint->safety ) {
|
||||
flower = pjoint->safety->soft_lower_limit;
|
||||
fupper = pjoint->safety->soft_upper_limit;
|
||||
}
|
||||
if( flower == fupper ) {
|
||||
bactive = false;
|
||||
}
|
||||
|
@ -544,11 +562,14 @@ protected:
|
|||
if( !!it->pjoint->limits ) {
|
||||
flower = it->pjoint->limits->lower;
|
||||
fupper = it->pjoint->limits->upper;
|
||||
}
|
||||
if( !!it->pjoint->safety ) {
|
||||
flower = it->pjoint->safety->soft_lower_limit;
|
||||
fupper = it->pjoint->safety->soft_upper_limit;
|
||||
}
|
||||
if( flower > 0 || fupper < 0 ) {
|
||||
value = 0.5*(flower+fupper);
|
||||
}
|
||||
}
|
||||
|
||||
domKinematics_newparamRef pvalueparam = daeSafeCast<domKinematics_newparam>(_ikmout->ikm->add(COLLADA_ELEMENT_NEWPARAM));
|
||||
pvalueparam->setSid((sid+string("_value")).c_str());
|
||||
daeSafeCast<domKinematics_newparam::domFloat>(pvalueparam->add(COLLADA_ELEMENT_FLOAT))->setValue(value);
|
||||
|
@ -601,11 +622,15 @@ protected:
|
|||
boost::shared_ptr<urdf::Joint> pjoint = itjoint->second;
|
||||
int index = _mapjointindices[itjoint->second];
|
||||
domJointRef pdomjoint = daeSafeCast<domJoint>(ktec->add(COLLADA_ELEMENT_JOINT));
|
||||
string jointid = _ComputeId(pjoint->name);//str(boost::format("joint%d")%index);
|
||||
string jointid = _ComputeId(pjoint->name); //str(boost::format("joint%d")%index);
|
||||
pdomjoint->setSid(jointid.c_str() );
|
||||
pdomjoint->setName(pjoint->name.c_str());
|
||||
domAxis_constraintRef axis;
|
||||
if( !!pjoint->limits ) {
|
||||
if( !!pjoint->safety ) {
|
||||
lmin=pjoint->safety->soft_lower_limit;
|
||||
lmax=pjoint->safety->soft_upper_limit;
|
||||
}
|
||||
else if( !!pjoint->limits ) {
|
||||
lmin=pjoint->limits->lower;
|
||||
lmax=pjoint->limits->upper;
|
||||
}
|
||||
|
@ -932,7 +957,7 @@ protected:
|
|||
|
||||
void _loadMesh(std::string const& filename, domGeometryRef pdomgeom, const urdf::Vector3& scale)
|
||||
{
|
||||
const aiScene* scene = _importer.ReadFile(filename, aiProcess_SortByPType|aiProcess_Triangulate);//|aiProcess_GenNormals|aiProcess_GenUVCoords|aiProcess_FlipUVs);
|
||||
const aiScene* scene = _importer.ReadFile(filename, aiProcess_SortByPType|aiProcess_Triangulate); //|aiProcess_GenNormals|aiProcess_GenUVCoords|aiProcess_FlipUVs);
|
||||
if( !scene ) {
|
||||
ROS_WARN("failed to load resource %s",filename.c_str());
|
||||
return;
|
||||
|
@ -1271,7 +1296,7 @@ private:
|
|||
domLibrary_materialsRef _materialsLib;
|
||||
domLibrary_effectsRef _effectsLib;
|
||||
domLibrary_geometriesRef _geometriesLib;
|
||||
domTechniqueRef _sensorsLib;///< custom sensors library
|
||||
domTechniqueRef _sensorsLib; ///< custom sensors library
|
||||
SCENE _scene;
|
||||
|
||||
boost::shared_ptr<instance_kinematics_model_output> _ikmout;
|
||||
|
|
Loading…
Reference in New Issue