Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/ode joint factory #128

Open
wants to merge 24 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
edc6b2f
introduce storage manager interface
May 5, 2022
111c55a
Merge branch 'develop' of https://github.com/rock-simulation/mars int…
annaborn May 19, 2022
99ddadd
ODEBox is working. Code not clean.
0Nel Aug 2, 2022
e3114b2
Use ODEObjectFactory
haider8645 Aug 11, 2022
9e3ff41
Add ODEObjectFactory files
haider8645 Aug 11, 2022
5b96bdf
Add ODE object subclasses
haider8645 Aug 12, 2022
2067eb8
Move subclass specific members to the respective subclass
haider8645 Aug 12, 2022
26f5a22
Rename physics object interface classes
haider8645 Aug 12, 2022
c616362
Add and update license information
haider8645 Aug 12, 2022
b8c693a
Add CoreODEObjects and use singelton for the concrete factory
haider8645 Aug 15, 2022
493bfd6
Cleanup debug comments
haider8645 Aug 15, 2022
162b946
Cleanup of unnecessary comments & code
haider8645 Aug 15, 2022
0dcdf71
Replace JointPhysics by subclasses and a factory
haider8645 Aug 15, 2022
85fdcf7
Add parameter to check if the joint was successfully created and clea…
haider8645 Aug 15, 2022
fb7f74f
Check if the ODEObject is created or not and remove JointsMapper
haider8645 Aug 15, 2022
9698a7e
Cleanup comments
haider8645 Aug 15, 2022
084f170
Remove a return used during debugging
haider8645 Aug 17, 2022
b26e7af
Split CoreODEObjects & CoreODEJoints into separate files
haider8645 Dec 30, 2022
12cae6e
Merge pull request #1 from haider8645/split_classes
haider8645 Dec 30, 2022
a13ae6f
Merge branch 'develop' into feature/ode_joint_factory
haider8645 Dec 30, 2022
243a9b4
Handle primtive node types via object factory and string node type
haider8645 Dec 30, 2022
39b5a31
Handle primtive joint types via joint factory and string joint type
haider8645 Dec 30, 2022
9f22b35
Replace enum NodeType with string nodeType
haider8645 Dec 30, 2022
850940f
Bug Fix: Convert enum joint type to string
haider8645 Dec 31, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 15 additions & 19 deletions graphics/src/wrapper/OSGNodeStruct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,51 +82,47 @@ namespace mars {
}
if (filename.compare("PRIMITIVE") == 0) {
Vector vizSize = node.ext;
switch(NodeData::typeFromString(origname.c_str())) {
case mars::interfaces::NODE_TYPE_BOX: {
if (origname == "box") {
drawObject_ = new CubeDrawObject(g);
break;
}
case mars::interfaces::NODE_TYPE_SPHERE: {
else if (origname == "sphere"){
vizSize.x() *= 2;
vizSize.y() = vizSize.z() = vizSize.x();
drawObject_ = new SphereDrawObject(g);
break;
}
case mars::interfaces::NODE_TYPE_REFERENCE: {
else if (origname == "reference"){
#warning add here an coordinate system item
//For now until we have an real coordinate system
drawObject_ = new SphereDrawObject(g);
break;
}
case mars::interfaces::NODE_TYPE_MESH:
case mars::interfaces::NODE_TYPE_CYLINDER:
else if (origname == "mesh"){

}
else if (origname == "cylinder"){
vizSize.x() *= 2;
vizSize.z() = vizSize.y();
vizSize.y() = vizSize.x();
drawObject_ = new CylinderDrawObject(g, 1, 1);
break;
case mars::interfaces::NODE_TYPE_CAPSULE: {
}
else if (origname == "capsule"){
vizSize.x() *= 2;
vizSize.z() = vizSize.y();
vizSize.y() = vizSize.x();
drawObject_ = new CapsuleDrawObject(g);
break;
}
case mars::interfaces::NODE_TYPE_PLANE: {
else if (origname == "plane"){
drawObject_ = new PlaneDrawObject(g, vizSize);
break;
}
case mars::interfaces::NODE_TYPE_EMPTY: {
else if (origname == "empty"){
drawObject_ = new EmptyDrawObject(g);
break;
}
default:
fprintf(stderr,"Cannot find primitive type: %i(%s), at %s:%i\n",
NodeData::typeFromString(origname.c_str()),
else {
fprintf(stderr,"Cannot find primitive type: %s(%s), at %s:%i\n",
node.nodeType.c_str(),
origname.c_str(), __FILE__, __LINE__);
throw std::runtime_error("unknown primitive type");
}

if(map.find("maxNumLights") != map.end()) {
drawObject_->setMaxNumLights(map["maxNumLights"]);
}
Expand Down
20 changes: 10 additions & 10 deletions interfaces/src/NodeData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ namespace mars {
namespace interfaces {

using namespace mars::utils;

//access these strings only via toString(const NodeType&) and typeFromString(const std::string&).
//synchronize this list with the enum NodeType in MARSDefs.h
static const char* sTypeNames[NUMBER_OF_NODE_TYPES] = {
Expand Down Expand Up @@ -149,9 +149,11 @@ namespace mars {

{ // handle node type
if((it = config->find("physicmode")) != config->end()) {
std::string typeName = (std::string)it->second;
nodeType = trim(config->get("physicmode", nodeType));
try {
physicMode = typeFromString(trim(typeName));
//Here we can check whether the node factory has this node type or not
//If not then load it dynamically (if available)
//else just throw an exception
} catch(...) {
//throw SceneParseException("invalid physicmode for node", -1);
LOG_ERROR("could not get type for node: %s", name.c_str());
Expand All @@ -163,7 +165,7 @@ namespace mars {

if(filename == "PRIMITIVE") {
if(origName.empty()) {
origName = toString(physicMode);
origName = nodeType;
}
/* this is a valid case
else if(origName != toString(physicMode)) {
Expand Down Expand Up @@ -308,17 +310,15 @@ namespace mars {
SET_VALUE("noPhysical", noPhysical, writeDefaults);
SET_VALUE("movable", movable, writeDefaults);

if(writeDefaults || physicMode != defaultNode.physicMode) {
if(writeDefaults || nodeType != defaultNode.nodeType) {
if(noPhysical) {
try {
std::string tmp = toString(physicMode);
(*config)["physicmode"] = tmp;
(*config)["physicmode"] = nodeType;
} catch (...) {
}
}
else {
std::string tmp = toString(physicMode);
(*config)["physicmode"] = tmp;
else {;
(*config)["physicmode"] = nodeType;
}
}

Expand Down
31 changes: 12 additions & 19 deletions interfaces/src/NodeData.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ namespace mars {
groupID = 0;
index = 0;
filename = "PRIMITIVE";
physicMode = NODE_TYPE_UNDEFINED;
nodeType = "";
pos.setZero();
pivot.setZero();
rot.setIdentity();
Expand Down Expand Up @@ -133,14 +133,14 @@ namespace mars {
* @param extents extents of the object
* @param mass the mass of the object
*/
void initPrimitive( NodeType type, const utils::Vector& extents, sReal mass )
void initPrimitive(const std::string type, const utils::Vector& extents, sReal mass )
{
physicMode = type;
nodeType = type;
ext = extents;
this->mass = mass;
filename = "PRIMITIVE";

origName = toString(type);
origName = type;
}

bool fromConfigMap(configmaps::ConfigMap *config, std::string filenamePrefix,
Expand Down Expand Up @@ -189,18 +189,11 @@ namespace mars {
unsigned long index;

/**
* This value holds the physical representation of a node. Valid values are:
* - NODE_TYPE_MESH
* - NODE_TYPE_BOX
* - NODE_TYPE_SPHERE
* - NODE_TYPE_CAPSULE
* - NODE_TYPE_CYLINDER
* - NODE_TYPE_PLANE
* - NODE_TYPE_TERRAIN
* .
* \verbatim Default value: NODE_TYPE_UNDEFINED \endverbatim
* @brief The node type name as string
*
*/
NodeType physicMode;

std::string nodeType;

/**
* The position of the node.
Expand Down Expand Up @@ -249,7 +242,7 @@ namespace mars {

/**
* The size of the node. The ext vector is interpreted depending of the
* physicMode of the node:
* type of the node:
* - mesh: ext defines the bounding box of the mesh
* - box: ext defines the size in x, y, and z
* - sphere: ext.x defines the radius
Expand All @@ -266,7 +259,7 @@ namespace mars {
/**
* The mesh struct stores the poly information for a physical representation
* of a mesh. This struct is automatically derived from the visual node
* by the simulation if the physicMode is set to NODE_TYPE_MESH.
* by the simulation if the type is set to mesh.
* \verbatim Default value: see snmesh \endverbatim \sa snmesh
*/
snmesh mesh;
Expand Down Expand Up @@ -307,7 +300,7 @@ namespace mars {


/**
* If the physicMode is set to NODE_TYPE_TERRAIN, this pointer stores
* If the node type is set to terrain, this pointer stores
* all information to create a physical representation of a height map.
* \verbatim Default value: 0 \endverbatim \sa terrainStruct
*/
Expand Down Expand Up @@ -355,7 +348,7 @@ namespace mars {
contact_params c_params;

/**
* Generally the inertia of the physical body is calculated by the physicMode
* Generally the inertia of the physical body is calculated by the node type
* and the mass of a node. In case of a mesh the inertia is calculated for
* a box with the size given by NodeData::extent. If this boolean is set to
* \c true, the inertia array (NodeData::inertia) is used instead.
Expand Down
3 changes: 3 additions & 0 deletions interfaces/src/sim/ControlCenter.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ namespace mars {

namespace interfaces {
class ControlCenter;
class StorageManagerInterface;
class NodeManagerInterface;
class JointManagerInterface;
class MotorManagerInterface;
Expand All @@ -84,6 +85,7 @@ namespace mars {
ControlCenter(){
sim = NULL;
cfg = NULL;
storage = NULL;
nodes = NULL;
joints = NULL;
motors = NULL;
Expand All @@ -95,6 +97,7 @@ namespace mars {
}

cfg_manager::CFGManagerInterface *cfg;
StorageManagerInterface *storage;
NodeManagerInterface *nodes;
JointManagerInterface *joints;
MotorManagerInterface *motors;
Expand Down
2 changes: 1 addition & 1 deletion interfaces/src/sim/NodeManagerInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ namespace mars {



virtual NodeId createPrimitiveNode(const std::string &name, NodeType type,
virtual NodeId createPrimitiveNode(const std::string &name, const std::string &type,
bool movable=false,
const utils::Vector &pos=utils::Vector::Zero(),
const utils::Vector &extension=utils::Vector::Identity(),
Expand Down
54 changes: 54 additions & 0 deletions interfaces/src/sim/StorageManagerInterface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright 2011, 2012, DFKI GmbH Robotics Innovation Center
*
* This file is part of the MARS simulation framework.
*
* MARS is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation, either version 3
* of the License, or (at your option) any later version.
*
* MARS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with MARS. If not, see <http://www.gnu.org/licenses/>.
*
*/

/**
* \file StorageManagerInterface.h
* \author \n
* \brief
*
* \version
* \date
*/

#ifndef STORAGE_MANAGER_INTERFACE_H
#define STORAGE_MANAGER_INTERFACE_H

#ifdef _PRINT_HEADER_
#warning "StorageManagerInterface.h"
#endif


namespace mars {
namespace interfaces {

/**
* \author \n
* \brief
*
*/
class StorageManagerInterface {
public:

};

} // end of namespace interfaces
} // end of namespace mars

#endif // STORAGE_MANAGER_INTERFACE_H
10 changes: 5 additions & 5 deletions plugins/obstacle_generator/src/ObstacleGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ namespace mars {
Vector boxsize(field_length, field_width, 1.0);
Vector boxorientation(0, -params["incline_angle"], 0);
NodeData box("incline", boxposition, eulerToQuaternion(boxorientation));
box.initPrimitive(NODE_TYPE_BOX, boxsize, 1.0);
box.initPrimitive("box", boxsize, 1.0);
box.material.texturename = textures["ground"];
if (textures["ground_bump"] != "") {
box.material.bumpmap = textures["ground_bump"];
Expand All @@ -181,7 +181,7 @@ namespace mars {
box.material.tex_scale = field_width/2.0;
control->nodes->addNode(&box, false);
oldNodeIDs.push_back(box.index);
// control->nodes->createPrimitiveNode("incline", NODE_TYPE_BOX,
// control->nodes->createPrimitiveNode("incline", "box",
// false, boxposition, boxsize, 1.0, eulerToQuaternion(boxorientation), false));
platform_length = 2.0 + params["field_distance"];
platform_x_position = -1.0 + 0.5 * params["field_distance"];
Expand All @@ -195,7 +195,7 @@ namespace mars {
Vector platformposition(platform_x_position, 0.0, -0.5 + params["ground_level"]);
Vector platformorientation(0.0, 0.0, 0.0);
NodeData platform("platform", platformposition, eulerToQuaternion(platformorientation));
platform.initPrimitive(NODE_TYPE_BOX, platformsize, 1.0);
platform.initPrimitive("box", platformsize, 1.0);
platform.material.texturename = textures["ground"];
if (textures["ground_bump"] != "") {
platform.material.bumpmap = textures["ground_bump"];
Expand Down Expand Up @@ -315,10 +315,10 @@ namespace mars {
}
NodeData obstacle(name, position, orientation);
if (bool_params["use_boxes"]) {
obstacle.initPrimitive(NODE_TYPE_BOX, size, 1.0);
obstacle.initPrimitive("box", size, 1.0);
}
else {
obstacle.initPrimitive(NODE_TYPE_CAPSULE, size, 1.0);
obstacle.initPrimitive("capsule", size, 1.0);
}
obstacle.material.texturename = textures["obstacle"];
obstacle.material.diffuseFront = Color(1.0, 1.0, 1.0, 1.0);
Expand Down
Loading