Commits

Martin Felis committed a34981f Merge

merged default->dev

Comments (0)

Files changed (14)

 Recent Changes
 ==============
 
+   * 29 January 2013: added code for api_version_checking
    * 11 January 2013: removed Eigen3 sources and relying on an already installed Eigen3 library. Optionally RBDL can be used with the included but slower SimpleMath library.
-   * 18 June 2012: added support of \ref luamodel_introduction
-   * 01 June 2012: added support of \ref joint_models_fixed
+   * 18 June 2012: added support of luamodel_introduction
+   * 01 June 2012: added support of joint_models_fixed
    * 14 May 2012: fixed Body constructor as reported by Maxime Reis
    * 04 April 2012: added benchmark tool for CRBA
-   * 01 March 2012: added multi degree of freedom \ref joint_models
-   * 06 Februry 2012: restructured constraint handling using \ref RigidBodyDynamics::ConstraintSet
-   * 24 January 2012: implemented compact and fast representation of \ref RigidBodyDynamics::Math::SpatialTransform 
+   * 01 March 2012: added multi degree of freedom joint_models
+   * 06 Februry 2012: restructured constraint handling using RigidBodyDynamics::ConstraintSet
+   * 24 January 2012: implemented compact and fast representation of RigidBodyDynamics::Math::SpatialTransform 
 
 Documentation
 =============

addons/benchmark/benchmark.cc

 	cout << "Human dofs = " << model->dof_count << endl;
 	delete model;
 
-	RigidBodyDynamics::rbdl_print_version();
+	rbdl_print_version();
 	cout << endl;
 
 	if (benchmark_run_fd_aba) {

addons/luamodel/CMakeLists.txt

 	lua-5.2.1/src/lzio.c	
 	)
 
+# Options
 SET ( LUAMODEL_SOURCES 
 	luamodel.cc
 	luatables.cc
 ADD_LIBRARY ( rbdl_luamodel SHARED ${LUA_SOURCES} ${LUAMODEL_SOURCES} )
 
 IF (BUILD_STATIC)
-	ADD_LIBRARY ( rbdl_luamodel-static STATIC ${LUA_SOURCES} ${LUAMODEL_SOURCES} )
+	ADD_LIBRARY ( rbdl_luamodel-static STATIC ${LUAMODEL_SOURCES} )
 	SET_TARGET_PROPERTIES ( rbdl_luamodel-static PROPERTIES PREFIX "lib")
 	SET_TARGET_PROPERTIES ( rbdl_luamodel-static PROPERTIES OUTPUT_NAME "rbdl_luamodel")
 
 
 TARGET_LINK_LIBRARIES (rbdl_luamodel_util
 	rbdl_luamodel
+	rbdl
 	)
 
 # Installing

addons/luamodel/luamodel.cc

 
 #include "luatables.h"
 
+extern "C"
+{
+   #include <lua.h>
+   #include <lauxlib.h>
+   #include <lualib.h>
+}
+
 using namespace std;
 
 static void bail(lua_State *L, const char *msg){
 		double mass = 0.;
 		Vector3d com (0., 0., 0.);
 		Matrix3d inertia (Matrix3d::Zero(3,3));
+		inertia(0,0) = 1.;
+		inertia(1,1) = 1.;
+		inertia(2,2) = 1.;
 
 		if (ltIsExisting (L, (path + ".body.mass").c_str()) ) {
 			mass = ltGetDouble (L, (path + ".body.mass").c_str());
 					verbose
 					)) {
 			cerr << "Error reading frame " << frame_names[i] << "." << endl;
+
+			lua_close (L);
+
 			return false;
 		}
 
 			cout << "  body id    : " << body_id << endl;
 	}
 
+	lua_close (L);
+
 	return true;
 }
 

addons/luamodel/luatables.cc

 		}
 
 		if (lua_isnil(L, -1)) {
-			cout << "Error: could not find table '" << path_str;
-			if (path.size() == 0 && index > 0)
-				cout << "[" << index << "]";
-			cout << "'." << endl;
-			
 			// clean up the stack
 			lua_pop (L, lua_gettop(L) - stack_top);
 			return false;

addons/luamodel/luatables.h

 #include <vector>
 #include <string>
 
-extern "C"
-{
-   #include <lua.h>
-   #include <lauxlib.h>
-   #include <lualib.h>
-}
+// forward declaration so we do not need to #include lua.h
+struct lua_State;
 
 bool ltOpenFile (lua_State **L, const char *filename);
 void ltClose (lua_State **L);
  *
  * \section recent_changes Recent Changes :
  * <ul>
+ * <li> 29. January 2013: added code for \ref api_version_checking</li>
  * <li> 11. January 2013: removed Eigen3 sources and relying on an already installed Eigen3 library. Optionally RBDL can be used with the included but slower SimpleMath library.</li>
  * <li> 18. June 2012: added support of \ref luamodel_introduction</li>
  * <li> 01. June 2012: added support of \ref joint_models_fixed</li>

examples/luamodel/example_luamodel.cc

 using namespace RigidBodyDynamics::Math;
 
 int main (int argc, char* argv[]) {
+	rbdl_check_api_version (RBDL_API_VERSION);
+
 	Model* model = NULL;
 
 	model = new Model();

examples/simple/example.cc

 using namespace RigidBodyDynamics::Math;
 
 int main (int argc, char* argv[]) {
+	rbdl_check_api_version (RBDL_API_VERSION);
+
 	Model* model = NULL;
 
 	unsigned int body_a_id, body_b_id, body_c_id;

include/rbdl/rbdl.h

 
 #include "rbdl/Contacts.h"
 
-namespace RigidBodyDynamics {
-	/** Prints version information to standard output */
-	void rbdl_print_version();
-}
+/** \defgroup api_version_checking API Version Checking
+ * @{
+ *
+ * This documentation was created for API version 1.0.0.
+ */
+
+/** Returns the API version at compile time of the library. */
+int rbdl_get_api_version();
+
+/** Ensures whether the RBDL library we are linking against is compatible
+ * with the the version we have from rbdl.h.
+ *
+ * To perform the check run:
+ * \code
+ *   rbdl_check_api_version(API_VERSION);
+ * \endcode
+ *
+ * This function will abort if compatibility is not met or warn if you run
+ * a version that might not be entirely compatible.
+ *
+ * In most cases you want to specify a specific version to ensure you are
+ * using a compatible version. To do so replace API_VERSION by a
+ * value of the form 0xAABBCC where AA is the major, BB the minor, and CC
+ * the patch version in hex-format, e.g:
+ *
+ * \code
+ *   rbdl_check_api_version(0x020A0C);
+ * \endcode
+ * 
+ * Would abort if the API major version is not 2 (= 0x02), warn if the
+ * linked minor version is not 10 (= 0x0A). The patch version 12 (= 0x12)
+ * does not have an influence on compatibility.
+ */
+void rbdl_check_api_version(int version);
+
+/** Prints version information to standard output */
+void rbdl_print_version();
 
 #endif /* _RBDL_H */

include/rbdl/rbdl_config.h.cmake

 #ifndef _RBDLCONFIG_H
 #define _RBDLCONFIG_H
 
+#define RBDL_API_VERSION 0x020000
+
 #cmakedefine RBDL_USE_SIMPLE_MATH
 #cmakedefine RBDL_ENABLE_LOGGING
 #cmakedefine RBDL_BUILD_REVISION "@RBDL_BUILD_REVISION@"
 	// exception if we calculate it for the root body
 	assert (joint_id > 0);
 
-	// Calculate the spatial joint velocity
-	v_J = model.S.at(joint_id);
-
 	// Set the joint axis
 	S = model.mJoints[joint_id].mJointAxes[0];
 

src/rbdl_version.cc

 #include <rbdl/rbdl_config.h>
 
 #include <iostream>
+#include <sstream>
 #include <string>
+#include <cstdlib>
 
-namespace RigidBodyDynamics {
+int rbdl_get_api_version() {
+	static int compile_version = RBDL_API_VERSION;
+	return compile_version;
+}
+
+void rbdl_check_api_version(int version) {
+	int compile_version = rbdl_get_api_version();
+
+	int compile_major = (compile_version & 0xff0000) >> 16;
+	int compile_minor = (compile_version & 0x00ff00) >> 8;
+	int compile_patch = (compile_version & 0x0000ff);
+
+	std::ostringstream compile_version_string("");
+	compile_version_string << compile_major << "." << compile_minor << "." << compile_patch;
+
+	int version_major = (version & 0xff0000) >> 16;
+	int version_minor = (version & 0x00ff00) >> 8;
+	int version_patch = (version & 0x0000ff);
+
+	std::ostringstream link_version_string ("");
+	link_version_string << version_major << "." << version_minor << "." << version_patch;
+
+	if (version_major != compile_major) {
+		std::cerr << "Error: trying to link against an incompatible RBDL library." << std::endl;
+		std::cerr << "The library version is: " << compile_version_string.str() << " but rbdl_config.h is version " << link_version_string.str() << std::endl;
+		abort();
+	} else if (version_minor != compile_minor) {
+		std::cout << "Warning: RBDL library is of version " << compile_version_string.str() << " but rbdl_config.h is from version " << link_version_string.str() << std::endl;
+	}
+}
 
 void rbdl_print_version() {
-	std::cout << "RigidBodyDynamicsLibrary version:" << std::endl
-		<< "  revision     : " << RBDL_BUILD_REVISION
+	int compile_version = rbdl_get_api_version();
+
+	int compile_major = (compile_version & 0xff0000) >> 16;
+	int compile_minor = (compile_version & 0x00ff00) >> 8;
+	int compile_patch = (compile_version & 0x0000ff);
+
+	std::ostringstream compile_version_string("");
+	compile_version_string << compile_major << "." << compile_minor << "." << compile_patch;
+
+	std::cout << "RBDL version:" << std::endl
+		<< "  API version  : " << compile_version_string.str() << std::endl;
+
+	if (std::string("unknown") != RBDL_BUILD_REVISION) {
+		std::cout << "  revision     : " << RBDL_BUILD_REVISION 
 		<< " (branch: " << RBDL_BUILD_BRANCH << ")" << std::endl
-		<< "  build type   : " << RBDL_BUILD_TYPE << std::endl
+		<< "  build type   : " << RBDL_BUILD_TYPE << std::endl;
+	}
+
 #ifdef RBDL_ENABLE_LOGGING
-		<< "  logging      : on (warning: reduces performance!)" << std::endl
+	std::cout << "  logging      : on (warning: reduces performance!)" << std::endl;
 #else
-		<< "  logging      : off" << std::endl
+	std::cout << "  logging      : off" << std::endl;
 #endif
 #ifdef RBDL_USE_SIMPLE_MATH
-		<< "  simplemath   : on (warning: reduces performance!)" << std::endl
+	std::cout << "  simplemath   : on (warning: reduces performance!)" << std::endl;
 #else
-		<< "  simplemath   : off" << std::endl
+	std::cout << "  simplemath   : off" << std::endl;
 #endif
+
 #ifdef BUILD_ADDON_LUAMODEL
-		<< "  luamodel     : on" << std::endl;
+	std::cout << "  luamodel     : on" << std::endl;
 #else
-	  << "  luamodel     : off" << std::endl;
+	std::cout << "  luamodel     : off" << std::endl;
 #endif
-		;
 
 	std::string build_revision (RBDL_BUILD_REVISION);
 	if (build_revision == "unknown") {
 		std::cout << std::endl << "Version information incomplete: to enable version information re-build" << std::endl << "library from valid repository and enable RBDL_STORE_VERSION." << std::endl;
 	}
 }
-
-}
 
 int main (int argc, char *argv[])
 {
+	rbdl_check_api_version (RBDL_API_VERSION);
+
 	if (argc > 1) {
 		std::string arg (argv[1]);
 	
 		if (arg == "-v" || arg == "--version")
-			RigidBodyDynamics::rbdl_print_version();
+			rbdl_print_version();
 	}
 
 	return UnitTest::RunAllTests ();