Code covered by the BSD License  

Highlights from
Biohydrodynamics Toolbox

image thumbnail
from Biohydrodynamics Toolbox by Alexandre Munnier
Tool to simulate easily the motion of moving solids or swimming robots in a potential fluid flow.

The controls M-file
The controls M-file
Biohydrodynamics Toolbox    

controls M-File


The time-evolving angles of articulated bodies' joints are assigned by the user as functions of time. This is done by means of the controls M-File.

Generating a pattern of controls M-File

A pattern of controls M-File can be automatically generated, on user's request, while running the function bht_data_compile by adding the option 'ControlsFilename'. The exact syntax is 
bht_data_compile(...,'ControlsFilename',filename). 
Open next the M-File filename.m and complete the fields as you wish.

DAT-File and related pattern of controls M-File

The pattern obtained by running the function bht_data_compile depends on the data given in the DAT-File. Consider for instance the following sketch of a DAT-File which contains the descriptions of two articulated bodies:
...
fish =
  { ...

     link = {  label = number1
               ... }

     link = {  label = number2
               father = number1
               ... }

     link = {  label = number3
               father = number2
               ... }
  }


fish =
  { ...

     link = {  label = number1
               mfilename = ...
               ... }

     link = {  label = number2
               father = number1
               ... }

     link = {  label = number3
               father = number1
               ... }
  }
The first articulated body is composed of three links in line and the the second one has also three links but two of them, labeled number2 and number3, are connected to the same solid, labeled number1. The statement: 
 bht_data_compile(...,'ControlsFilename',filename)
will produce the following pattern of controls M-File (whose filename will be 'filename.m' ) :
function [c,dc,dttc] = filename(t,cont_parameters)
% ======================================================
% preallocating output variables
c = zeros(4,1);
dc = zeros(4,1);
dttc = zeros(4,1);
% ======================================================
% Warning: non zero controls velocities (dc) at the

% time t = 0 may produce strong fish's drift.

% ======================================================
%

% ====================================================== %                     fish 1
% ======================================================

%            joint              control number

% ______________________________________________________

%       number1-number2               1

%       number2-number3               2

% ======================================================

c(1) =
dc(1) =
dttc(1) =
% ======================================================
c(2) =
dc(2) =
dttc(2) =
% ====================================================== %                     fish 2
% ======================================================

%            joint              control number
%______________________________________________________
%       number1-number2               3

%       number1-number3               4

% ======================================================

c(3) =
dc(3) =
dttc(3) =
% ======================================================
c(4) =
dc(4) =
dttc(4) =
% ======================================================
% Use the fonction BHT_CONTROLS_CHECK to check the formula
 
The variables c(1), c(2),c(3) and c(4) are the angles (in radians) of the hinges connecting the links whose labels are given in the comments tables.  The angles are measured as in the picture below (the left hand side ellipse-shaped solid is the father of the right hand side one).
Images/two_articulated_solids_angle.jpg
A zero angle means that both centers of the attached frames together with the hinge are aligned. You must enter for each c(k) a function of time like, for example:
c(1) = pi/4*sin(t)
The first and  second derivative with respect to the time must also be given. It would be, going on with the example above:
dc(1) = pi/4*cos(t)
dttc(1) = -pi/4*sin(t) 
BhT is not able to detect an error in these formula. 
Note: any error at this level will deeply impact the motion of the body.
However, you can check your formula with the function bht_controls_check
In addition, all of the derivatives dc have to be equal to 0 at the time t = 0.  Any other values will cause bodies' motion to start with a strong drift.

Introducing further parameters

In the controls M-File displayed above,  there is an extra input variable, namely cont_parameters. This variable allows you to introduce parameters you can modify without having to rewrite all of the formula. Consider the following example:
c(1) = cont_parameters(1,1)*sin(t-cont_parameters(1,2))
c(2) = cont_parameters(2,1)*cos(t-cont_parameters(2,2))
The input variable cont_parameter is a matrix having the size you whish. You can then specify the values of the parameters when running the function bht_traject_compute by adding the option 'ControlsParameters' as follows:
[...] = bht_traject_compute(...,'ControlsParameters',cont_parameters)

See also

Writing a DAT-File
bht_traject_compute
bht_controls_check
2008 - A. Munnier and B. Pincon (Insitut Elie Cartan and INRIA Lorraine, Projet CORIDA, Nancy, France).       

Contact us at files@mathworks.com