[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [21866] branches/itasc: iTaSC: add 2 control parameters: feedback and max velocity.
Benoit Bolsee
benoit.bolsee at online.be
Fri Jul 24 22:29:04 CEST 2009
Revision: 21866
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21866
Author: ben2610
Date: 2009-07-24 22:29:04 +0200 (Fri, 24 Jul 2009)
Log Message:
-----------
iTaSC: add 2 control parameters: feedback and max velocity. Feedback controls how quicly the solver reacts to errors on target. The reaction time is approximately 1/feedback. Max velocity defined how fast the armature joints can rotate, expressing is rad/s.
Modified Paths:
--------------
branches/itasc/intern/itasc/Armature.cpp
branches/itasc/intern/itasc/Armature.hpp
branches/itasc/intern/itasc/ControlledObject.hpp
branches/itasc/release/ui/buttons_data_bone.py
branches/itasc/source/blender/blenkernel/intern/action.c
branches/itasc/source/blender/ikplugin/intern/itasc_plugin.cpp
branches/itasc/source/blender/makesdna/DNA_action_types.h
branches/itasc/source/blender/makesrna/intern/rna_pose.c
Modified: branches/itasc/intern/itasc/Armature.cpp
===================================================================
--- branches/itasc/intern/itasc/Armature.cpp 2009-07-24 20:01:08 UTC (rev 21865)
+++ branches/itasc/intern/itasc/Armature.cpp 2009-07-24 20:29:04 UTC (rev 21866)
@@ -68,9 +68,8 @@
// create a single channel for all the constraints
if (m_nconstraint) {
m_yCCh = m_cache->addChannel(this, "y", m_nconstraint*constraintCacheSize*sizeof(double));
+ m_buf = new double[m_nconstraint*constraintCacheSize];
}
- if (m_nconstraint)
- m_buf = new double[m_nconstraint*constraintCacheSize];
// store the initial cache position at timestamp 0
pushQ(0);
pushConstraints(0);
@@ -132,11 +131,15 @@
if (item && m_yCTs != timestamp) {
for (unsigned int i=0; i<m_nconstraint; i++) {
JointConstraint_struct* pConstraint = m_constraints[i];
- pConstraint->values.feedback = *item++;
- pConstraint->values.tolerance = *item++;
- pConstraint->value.yd = *item++;
- pConstraint->value.yddot = *item++;
- pConstraint->values.alpha = *item++;
+ if (pConstraint->function != JointLimitCallback) {
+ pConstraint->values.feedback = *item++;
+ pConstraint->values.tolerance = *item++;
+ pConstraint->value.yd = *item++;
+ pConstraint->value.yddot = *item++;
+ pConstraint->values.alpha = *item++;
+ } else {
+ item += constraintCacheSize;
+ }
}
m_yCTs = timestamp;
}
@@ -468,7 +471,16 @@
bool Armature::setControlParameter(unsigned int constraintId, unsigned int valueId, ConstraintAction action, double value, double timestep)
{
- if (constraintId < m_nconstraint) {
+ unsigned int lastid;
+ if (constraintId == CONSTRAINT_ID_ALL) {
+ constraintId = 0;
+ lastid = m_nconstraint;
+ } else if (constraintId < m_nconstraint) {
+ lastid = constraintId+1;
+ } else {
+ return false;
+ }
+ for ( ; constraintId<lastid; ++constraintId) {
JointConstraint_struct* pConstraint = m_constraints[constraintId];
if (valueId == ID_JOINT) {
switch (action) {
@@ -492,10 +504,9 @@
}
if (m_finalized)
m_Wy(constraintId) = pConstraint->values.alpha/(pConstraint->values.tolerance*pConstraint->values.feedback);
- return true;
}
}
- return false;
+ return true;
}
double Armature::getMaxTimestep(double& timestep)
Modified: branches/itasc/intern/itasc/Armature.hpp
===================================================================
--- branches/itasc/intern/itasc/Armature.hpp 2009-07-24 20:01:08 UTC (rev 21865)
+++ branches/itasc/intern/itasc/Armature.hpp 2009-07-24 20:29:04 UTC (rev 21866)
@@ -38,7 +38,7 @@
virtual void updateKinematics(const Timestamp& timestamp);
virtual void pushCache(const Timestamp& timestamp);
virtual void updateControlOutput(const Timestamp& timestamp);
- virtual bool setControlParameter(unsigned int constraintId, unsigned int valueId, ConstraintAction action, double value, double timestep);
+ virtual bool setControlParameter(unsigned int constraintId, unsigned int valueId, ConstraintAction action, double value, double timestep=0.0);
virtual void initCache(Cache *_cache);
virtual double getMaxTimestep(double& timestep);
Modified: branches/itasc/intern/itasc/ControlledObject.hpp
===================================================================
--- branches/itasc/intern/itasc/ControlledObject.hpp 2009-07-24 20:01:08 UTC (rev 21865)
+++ branches/itasc/intern/itasc/ControlledObject.hpp 2009-07-24 20:29:04 UTC (rev 21866)
@@ -17,6 +17,8 @@
namespace iTaSC {
+#define CONSTRAINT_ID_ALL ((unsigned int)-1)
+
class ControlledObject : public Object {
protected:
e_scalar m_maxDeltaQ;
Modified: branches/itasc/release/ui/buttons_data_bone.py
===================================================================
--- branches/itasc/release/ui/buttons_data_bone.py 2009-07-24 20:01:08 UTC (rev 21865)
+++ branches/itasc/release/ui/buttons_data_bone.py 2009-07-24 20:29:04 UTC (rev 21866)
@@ -265,6 +265,11 @@
row.itemR(itasc, "max_step")
else:
row.itemR(itasc, "num_step")
+
+ row = layout.row()
+ row.itemR(itasc, "feedback")
+ row.itemR(itasc, "max_velocity")
+
bpy.types.register(BONE_PT_context_bone)
bpy.types.register(BONE_PT_transform)
Modified: branches/itasc/source/blender/blenkernel/intern/action.c
===================================================================
--- branches/itasc/source/blender/blenkernel/intern/action.c 2009-07-24 20:01:08 UTC (rev 21865)
+++ branches/itasc/source/blender/blenkernel/intern/action.c 2009-07-24 20:29:04 UTC (rev 21866)
@@ -534,6 +534,8 @@
itasc->numstep = 4;
itasc->precision = 0.005f;
itasc->flag = ITASC_AUTO_STEP|ITASC_INITIAL_REITERATION;
+ itasc->feedback = 20.f;
+ itasc->maxvel = 50.f;
}
}
void init_pose_ikparam(bPose *pose)
Modified: branches/itasc/source/blender/ikplugin/intern/itasc_plugin.cpp
===================================================================
--- branches/itasc/source/blender/ikplugin/intern/itasc_plugin.cpp 2009-07-24 20:01:08 UTC (rev 21865)
+++ branches/itasc/source/blender/ikplugin/intern/itasc_plugin.cpp 2009-07-24 20:29:04 UTC (rev 21866)
@@ -450,14 +450,21 @@
IK_Target* iktarget =(IK_Target*)_param;
bKinematicConstraint *condata = (bKinematicConstraint *)iktarget->blenderConstraint->data;
iTaSC::ConstraintValues* values = _values;
+ bItasc* ikparam = (bItasc*) iktarget->owner->pose->ikparam;
+ // we need default parameters
+ if (!ikparam)
+ ikparam = &DefIKParam;
+
if (iktarget->controlType & iTaSC::CopyPose::CTL_POSITION) {
values->alpha = (iktarget->blenderConstraint->flag & CONSTRAINT_OFF) ? 0.0 : condata->weight;
- values->action = iTaSC::ACT_ALPHA;
+ values->feedback = ikparam->feedback;
+ values->action = iTaSC::ACT_ALPHA|iTaSC::ACT_FEEDBACK;
values++;
}
if (iktarget->controlType & iTaSC::CopyPose::CTL_ROTATION) {
values->alpha = (iktarget->blenderConstraint->flag & CONSTRAINT_OFF) ? 0.0 : condata->orientweight;
- values->action = iTaSC::ACT_ALPHA;
+ values->feedback = ikparam->feedback;
+ values->action = iTaSC::ACT_ALPHA|iTaSC::ACT_FEEDBACK;
values++;
}
return true;
@@ -952,6 +959,9 @@
if (i == 0)
// all constraint disabled
return;
+ // update parameters
+ ikscene->solver->setQmax(ikparam->maxvel);
+ // compute timestep
double timestamp = ctime * frtime + 2147483.648;
double timestep = frtime;
bool reiterate = (ikparam->flag & ITASC_REITERATION) ? true : false;
@@ -1134,9 +1144,11 @@
if (pose->ikdata && pose->ikparam) {
IK_Data* ikdata = (IK_Data*)pose->ikdata;
bItasc* ikparam = (bItasc*)pose->ikparam;
- for (IK_Scene* scene = ikdata->first; scene; scene = scene->next) {
- scene->scene->setParam(iTaSC::Scene::MIN_TIMESTEP, ikparam->minstep);
- scene->scene->setParam(iTaSC::Scene::MAX_TIMESTEP, ikparam->maxstep);
+ for (IK_Scene* ikscene = ikdata->first; ikscene; ikscene = ikscene->next) {
+ ikscene->scene->setParam(iTaSC::Scene::MIN_TIMESTEP, ikparam->minstep);
+ ikscene->scene->setParam(iTaSC::Scene::MAX_TIMESTEP, ikparam->maxstep);
+ ikscene->solver->setQmax(ikparam->maxvel);
+ ikscene->armature->setControlParameter(CONSTRAINT_ID_ALL, iTaSC::Armature::ID_JOINT, iTaSC::ACT_FEEDBACK, ikparam->feedback);
}
}
}
Modified: branches/itasc/source/blender/makesdna/DNA_action_types.h
===================================================================
--- branches/itasc/source/blender/makesdna/DNA_action_types.h 2009-07-24 20:01:08 UTC (rev 21865)
+++ branches/itasc/source/blender/makesdna/DNA_action_types.h 2009-07-24 20:29:04 UTC (rev 21866)
@@ -220,6 +220,8 @@
float minstep;
float maxstep;
int flag;
+ float feedback;
+ float maxvel;
} bItasc;
/* bItasc->flag */
Modified: branches/itasc/source/blender/makesrna/intern/rna_pose.c
===================================================================
--- branches/itasc/source/blender/makesrna/intern/rna_pose.c 2009-07-24 20:01:08 UTC (rev 21865)
+++ branches/itasc/source/blender/makesrna/intern/rna_pose.c 2009-07-24 20:29:04 UTC (rev 21866)
@@ -231,6 +231,14 @@
itasc->minstep = 0.001f;
if (itasc->maxstep < itasc->minstep)
itasc->maxstep = itasc->minstep;
+ if (itasc->feedback < 0.01f)
+ itasc->feedback = 0.01f;
+ if (itasc->feedback > 100.f)
+ itasc->feedback = 100.f;
+ if (itasc->maxvel < 0.01f)
+ itasc->maxvel = 0.01f;
+ if (itasc->maxvel > 100.f)
+ itasc->maxvel = 100.f;
BIK_update_param(ob->pose);
DAG_object_flush_update(CTX_data_scene(C), ob, OB_RECALC_DATA);
@@ -659,6 +667,18 @@
RNA_def_property_range(prop, 0.0f,1.0f);
RNA_def_property_ui_text(prop, "Max step", "Higher bound for timestep in second in case of automatic substeps.");
RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Itasc_update");
+
+ prop= RNA_def_property(srna, "feedback", PROP_FLOAT, PROP_NONE);
+ RNA_def_property_float_sdna(prop, NULL, "feedback");
+ RNA_def_property_range(prop, 0.0f,50.0f);
+ RNA_def_property_ui_text(prop, "Feedback", "Feedback coefficient for error correction. Average response time=1/feedback. Default=20.");
+ RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Itasc_update");
+
+ prop= RNA_def_property(srna, "max_velocity", PROP_FLOAT, PROP_NONE);
+ RNA_def_property_float_sdna(prop, NULL, "maxvel");
+ RNA_def_property_range(prop, 0.0f,100.0f);
+ RNA_def_property_ui_text(prop, "Max vel", "Maximum joint velocity in rad/s. Default=50.");
+ RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Itasc_update");
}
static void rna_def_pose_ikparam(BlenderRNA *brna)
More information about the Bf-blender-cvs
mailing list