[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [20252] trunk/blender/source: BGE #18665: Servo control and relative motion

Benoit Bolsee benoit.bolsee at online.be
Mon May 18 10:22:52 CEST 2009


Revision: 20252
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=20252
Author:   ben2610
Date:     2009-05-18 10:22:51 +0200 (Mon, 18 May 2009)

Log Message:
-----------
BGE #18665: Servo control and relative motion

Servo control motion actuator did not work as expected when the object
is moving on a moving platform. 

This patch introduces a new Ref field in the servo motion actuator
to set a reference object for the velocity calculation.
You can set the object during the game using the actuator "reference"
attribute; use an object name or an object reference.

The servo controller takes into account the angular velocity of the
reference object to compute the relative local velocity.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/sca.c
    trunk/blender/source/blender/blenloader/intern/readfile.c
    trunk/blender/source/blender/makesdna/DNA_actuator_types.h
    trunk/blender/source/blender/src/buttons_logic.c
    trunk/blender/source/gameengine/Converter/KX_ConvertActuators.cpp
    trunk/blender/source/gameengine/Ketsji/KX_ObjectActuator.cpp
    trunk/blender/source/gameengine/Ketsji/KX_ObjectActuator.h

Modified: trunk/blender/source/blender/blenkernel/intern/sca.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/sca.c	2009-05-18 07:53:13 UTC (rev 20251)
+++ trunk/blender/source/blender/blenkernel/intern/sca.c	2009-05-18 08:22:51 UTC (rev 20252)
@@ -579,6 +579,10 @@
 				bCameraActuator *ca= act->data;
 				ID_NEW(ca->ob);
 			}
+			else if(act->type==ACT_OBJECT) {
+				bObjectActuator *oa= act->data;
+				ID_NEW(oa->reference);
+			}
 			else if(act->type==ACT_SCENE) {
 				bSceneActuator *sca= act->data;
 				ID_NEW(sca->camera);
@@ -606,6 +610,7 @@
 	bMessageSensor *ms;
 	bActuator *act;
 	bCameraActuator *ca;
+	bObjectActuator *oa;
 	bSceneActuator *sa;
 	bEditObjectActuator *eoa;
 	bPropertyActuator *pa;
@@ -628,6 +633,10 @@
 			ca= act->data;
 			if(ca->ob==ob) ca->ob= NULL;
 			break;
+		case ACT_OBJECT:
+			oa= act->data;
+			if(oa->reference==ob) oa->reference= NULL;
+			break;
 		case ACT_PROPERTY:
 			pa= act->data;
 			if(pa->ob==ob) pa->ob= NULL;

Modified: trunk/blender/source/blender/blenloader/intern/readfile.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/readfile.c	2009-05-18 07:53:13 UTC (rev 20251)
+++ trunk/blender/source/blender/blenloader/intern/readfile.c	2009-05-18 08:22:51 UTC (rev 20252)
@@ -3077,6 +3077,10 @@
 					bAddObjectActuator *eoa= act->data;
 					if(eoa) eoa->ob= newlibadr(fd, ob->id.lib, eoa->ob);
 				}
+				else if(act->type==ACT_OBJECT) {
+					bObjectActuator *oa= act->data;
+					oa->reference= newlibadr(fd, ob->id.lib, oa->reference);
+				}
 				else if(act->type==ACT_EDIT_OBJECT) {
 					bEditObjectActuator *eoa= act->data;
 					if(eoa==NULL) {
@@ -3087,6 +3091,15 @@
 						eoa->me= newlibadr(fd, ob->id.lib, eoa->me);
 					}
 				}
+				else if(act->type==ACT_OBJECT) {
+					bObjectActuator *oa= act->data;
+					if(oa==NULL) {
+						init_actuator(act);
+					}
+					else {
+						oa->reference= newlibadr(fd, ob->id.lib, oa->reference);
+					}
+				}
 				else if(act->type==ACT_SCENE) {
 					bSceneActuator *sa= act->data;
 					sa->camera= newlibadr(fd, ob->id.lib, sa->camera);
@@ -8862,6 +8875,10 @@
 				expand_doit(fd, mainvar, eoa->me);
 			}
 		}
+		else if(act->type==ACT_OBJECT) {
+			bObjectActuator *oa= act->data;
+			expand_doit(fd, mainvar, oa->reference);
+		}
 		else if(act->type==ACT_SCENE) {
 			bSceneActuator *sa= act->data;
 			expand_doit(fd, mainvar, sa->camera);

Modified: trunk/blender/source/blender/makesdna/DNA_actuator_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_actuator_types.h	2009-05-18 07:53:13 UTC (rev 20251)
+++ trunk/blender/source/blender/makesdna/DNA_actuator_types.h	2009-05-18 08:22:51 UTC (rev 20252)
@@ -107,6 +107,7 @@
 	float loc[3], rot[3];
 	float dloc[3], drot[3];
 	float linearvelocity[3], angularvelocity[3];
+	struct Object *reference;
 } bObjectActuator;
 
 typedef struct bIpoActuator {

Modified: trunk/blender/source/blender/src/buttons_logic.c
===================================================================
--- trunk/blender/source/blender/src/buttons_logic.c	2009-05-18 07:53:13 UTC (rev 20251)
+++ trunk/blender/source/blender/src/buttons_logic.c	2009-05-18 08:22:51 UTC (rev 20252)
@@ -1830,42 +1830,44 @@
 				}				
 			} else if (oa->type == ACT_OBJECT_SERVO)
 			{
-				ysize= 172;
+				ysize= 195;
 				
 				glRects(xco, yco-ysize, xco+width, yco);
 				uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
 				
-				uiDefBut(block, LABEL, 0, "linV",	xco, yco-45, 45, 19, NULL, 0, 0, 0, 0, "Sets the target linear velocity, it will be achieve by automatic application of force. Null velocity is a valid target");
-				uiDefButF(block, NUM, 0, "",		xco+45, yco-45, wval, 19, oa->linearvelocity, -10000.0, 10000.0, 10, 0, "");
-				uiDefButF(block, NUM, 0, "",		xco+45+wval, yco-45, wval, 19, oa->linearvelocity+1, -10000.0, 10000.0, 10, 0, "");
-				uiDefButF(block, NUM, 0, "",		xco+45+2*wval, yco-45, wval, 19, oa->linearvelocity+2, -10000.0, 10000.0, 10, 0, "");
-				uiDefButBitS(block, TOG, ACT_LIN_VEL_LOCAL, 0, "L",		xco+45+3*wval, yco-45, 15, 19, &oa->flag, 0.0, 0.0, 0, 0, "Velocity is defined in local coordinates");
+				uiDefBut(block, LABEL, 0, "Ref",	xco, yco-45, 45, 19, NULL, 0, 0, 0, 0, "");
+				uiDefIDPoinBut(block, test_obpoin_but, ID_OB, 1, "OB:",		xco+45, yco-45, wval*3, 19, &(oa->reference), "Reference object for velocity calculation, leave empty for world reference");
+				uiDefBut(block, LABEL, 0, "linV",	xco, yco-68, 45, 19, NULL, 0, 0, 0, 0, "Sets the target relative linear velocity, it will be achieve by automatic application of force. Null velocity is a valid target");
+				uiDefButF(block, NUM, 0, "",		xco+45, yco-68, wval, 19, oa->linearvelocity, -10000.0, 10000.0, 10, 0, "");
+				uiDefButF(block, NUM, 0, "",		xco+45+wval, yco-68, wval, 19, oa->linearvelocity+1, -10000.0, 10000.0, 10, 0, "");
+				uiDefButF(block, NUM, 0, "",		xco+45+2*wval, yco-68, wval, 19, oa->linearvelocity+2, -10000.0, 10000.0, 10, 0, "");
+				uiDefButBitS(block, TOG, ACT_LIN_VEL_LOCAL, 0, "L",		xco+45+3*wval, yco-68, 15, 19, &oa->flag, 0.0, 0.0, 0, 0, "Velocity is defined in local coordinates");
 
-				uiDefBut(block, LABEL, 0, "Limit",	xco, yco-68, 45, 19, NULL, 0, 0, 0, 0, "Select if the force need to be limited along certain axis (local or global depending on LinV Local flag)");
-				uiDefButBitS(block, TOG, ACT_SERVO_LIMIT_X, B_REDR, "X",		xco+45, yco-68, wval, 19, &oa->flag, 0.0, 0.0, 0, 0, "Set limit to force along the X axis");
-				uiDefButBitS(block, TOG, ACT_SERVO_LIMIT_Y, B_REDR, "Y",		xco+45+wval, yco-68, wval, 19, &oa->flag, 0.0, 0.0, 0, 0, "Set limit to force along the Y axis");
-				uiDefButBitS(block, TOG, ACT_SERVO_LIMIT_Z, B_REDR, "Z",		xco+45+2*wval, yco-68, wval, 19, &oa->flag, 0.0, 0.0, 0, 0, "Set limit to force along the Z axis");
-				uiDefBut(block, LABEL, 0, "Max",	xco, yco-87, 45, 19, NULL, 0, 0, 0, 0, "Set the upper limit for force");
-				uiDefBut(block, LABEL, 0, "Min",	xco, yco-106, 45, 19, NULL, 0, 0, 0, 0, "Set the lower limit for force");
+				uiDefBut(block, LABEL, 0, "Limit",	xco, yco-91, 45, 19, NULL, 0, 0, 0, 0, "Select if the force need to be limited along certain axis (local or global depending on LinV Local flag)");
+				uiDefButBitS(block, TOG, ACT_SERVO_LIMIT_X, B_REDR, "X",		xco+45, yco-91, wval, 19, &oa->flag, 0.0, 0.0, 0, 0, "Set limit to force along the X axis");
+				uiDefButBitS(block, TOG, ACT_SERVO_LIMIT_Y, B_REDR, "Y",		xco+45+wval, yco-91, wval, 19, &oa->flag, 0.0, 0.0, 0, 0, "Set limit to force along the Y axis");
+				uiDefButBitS(block, TOG, ACT_SERVO_LIMIT_Z, B_REDR, "Z",		xco+45+2*wval, yco-91, wval, 19, &oa->flag, 0.0, 0.0, 0, 0, "Set limit to force along the Z axis");
+				uiDefBut(block, LABEL, 0, "Max",	xco, yco-110, 45, 19, NULL, 0, 0, 0, 0, "Set the upper limit for force");
+				uiDefBut(block, LABEL, 0, "Min",	xco, yco-129, 45, 19, NULL, 0, 0, 0, 0, "Set the lower limit for force");
 				if (oa->flag & ACT_SERVO_LIMIT_X) {
-					uiDefButF(block, NUM, 0, "",		xco+45, yco-87, wval, 19, oa->dloc, -10000.0, 10000.0, 10, 0, "");
-					uiDefButF(block, NUM, 0, "",		xco+45, yco-106, wval, 19, oa->drot, -10000.0, 10000.0, 10, 0, "");
+					uiDefButF(block, NUM, 0, "",		xco+45, yco-110, wval, 19, oa->dloc, -10000.0, 10000.0, 10, 0, "");
+					uiDefButF(block, NUM, 0, "",		xco+45, yco-129, wval, 19, oa->drot, -10000.0, 10000.0, 10, 0, "");
 				}
 				if (oa->flag & ACT_SERVO_LIMIT_Y) {
-					uiDefButF(block, NUM, 0, "",		xco+45+wval, yco-87, wval, 19, oa->dloc+1, -10000.0, 10000.0, 10, 0, "");
-					uiDefButF(block, NUM, 0, "",		xco+45+wval, yco-106, wval, 19, oa->drot+1, -10000.0, 10000.0, 10, 0, "");
+					uiDefButF(block, NUM, 0, "",		xco+45+wval, yco-110, wval, 19, oa->dloc+1, -10000.0, 10000.0, 10, 0, "");
+					uiDefButF(block, NUM, 0, "",		xco+45+wval, yco-129, wval, 19, oa->drot+1, -10000.0, 10000.0, 10, 0, "");
 				}
 				if (oa->flag & ACT_SERVO_LIMIT_Z) {
-					uiDefButF(block, NUM, 0, "",		xco+45+2*wval, yco-87, wval, 19, oa->dloc+2, -10000.0, 10000.0, 10, 0, "");
-					uiDefButF(block, NUM, 0, "",		xco+45+2*wval, yco-106, wval, 19, oa->drot+2, -10000.0, 10000.0, 10, 0, "");
+					uiDefButF(block, NUM, 0, "",		xco+45+2*wval, yco-110, wval, 19, oa->dloc+2, -10000.0, 10000.0, 10, 0, "");
+					uiDefButF(block, NUM, 0, "",		xco+45+2*wval, yco-129, wval, 19, oa->drot+2, -10000.0, 10000.0, 10, 0, "");
 				}
-				uiDefBut(block, LABEL, 0, "Servo",	xco, yco-129, 45, 19, NULL, 0, 0, 0, 0, "Coefficients of the PID servo controller");
-				uiDefButF(block, NUMSLI, B_REDR, "P: ",		xco+45, yco-129, wval*3, 19, oa->forcerot, 0.00, 200.0, 100, 0, "Proportional coefficient, typical value is 60x Integral coefficient");
-				uiDefBut(block, LABEL, 0, "Slow",	xco, yco-148, 45, 19, NULL, 0, 0, 0, 0, "Low value of I coefficient correspond to slow response");
-				but = uiDefButF(block, NUMSLI, B_REDR, " I : ",		xco+45, yco-148, wval*3, 19, oa->forcerot+1, 0.0, 3.0, 1, 0, "Integral coefficient, low value (0.01) for slow response, high value (0.5) for fast response");
+				uiDefBut(block, LABEL, 0, "Servo",	xco, yco-152, 45, 19, NULL, 0, 0, 0, 0, "Coefficients of the PID servo controller");
+				uiDefButF(block, NUMSLI, B_REDR, "P: ",		xco+45, yco-152, wval*3, 19, oa->forcerot, 0.00, 200.0, 100, 0, "Proportional coefficient, typical value is 60x Integral coefficient");
+				uiDefBut(block, LABEL, 0, "Slow",	xco, yco-152, 45, 19, NULL, 0, 0, 0, 0, "Low value of I coefficient correspond to slow response");
+				but = uiDefButF(block, NUMSLI, B_REDR, " I : ",		xco+45, yco-171, wval*3, 19, oa->forcerot+1, 0.0, 3.0, 1, 0, "Integral coefficient, low value (0.01) for slow response, high value (0.5) for fast response");
 				uiButSetFunc(but, update_object_actuator_PID, oa, NULL);
-				uiDefBut(block, LABEL, 0, "Fast",	xco+45+3*wval, yco-148, 45, 19, NULL, 0, 0, 0, 0, "High value of I coefficient correspond to fast response");
-				uiDefButF(block, NUMSLI, B_REDR, "D: ",		xco+45, yco-167, wval*3, 19, oa->forcerot+2, -100.0, 100.0, 100, 0, "Derivate coefficient, not required, high values can cause instability");

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list