/* 
 * MBDyn (C) is a multibody analysis code. 
 * http://www.mbdyn.org
 *
 * Copyright (C) 1996-2017
 *
 * Pierangelo Masarati	<masarati@aero.polimi.it>
 * Paolo Mantegazza	<mantegazza@aero.polimi.it>
 *
 * Dipartimento di Ingegneria Aerospaziale - Politecnico di Milano
 * via La Masa, 34 - 20156 Milano, Italy
 * http://www.aero.polimi.it
 *
 * Changing this copyright notice is forbidden.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation (version 2 of the License).
 * 
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
/*
 * Author: Tommaso Solcia <tommaso.solcia@mail.polimi.it>
 */

/*
 * This file models an inverse pendulum, controlled by Simulink
 * by means of a simple PD controller.
 *
 * Part of the ScicosInterface test suite.
 */

begin: data;
	integrator: multistep;
end: data;

set: real tf = 2;
set: real dt = 1.e-3;

begin: multistep;
	initial time: 0.;
	final time: tf;
	time step: dt;

	tolerance: 1.e-6;
	max iterations: 10;

	method: ms, .6;
end: multistep;

begin: control data;
	# default output: none;
	structural nodes: 1;
	parameter nodes: 2;
	rigid bodies: 1;
	joints: 1;
	output elements: 1;
	gravity;
	forces: 1;
        file drivers: 1;
end: control data;

reference: 1,
	reference, global, null,
	reference, global, eye,
	reference, global, null,
	reference, global, 0., 0., 0.;
reference: 2,
	reference, 1, null,
	reference, 1, eye,
	reference, 1, null,
	reference, 1, 0.,0.,0.;

begin: nodes;
	structural: 1, dynamic,
		reference, 2, 0.,0.,1.,
		reference, 2, eye,
		reference, 2, null,
		reference, 2, null;
	parameter: 1, /* bound to */ element;
	parameter: 2, /* bound to */ element;
end: nodes;

begin: drivers;
        file: 1, stream,
        	stream drive name, "MBXOUT",
        	create, yes,
		# path, "/tmp/mbdyn.pendulum.in.sock",
		port, 9011,
                no signal,
		1;
end: drivers;

begin: elements;
	body: 1, 1,
		1.,
		null,
		diag, 1.,1.,1.;
	joint: 1, revolute pin,
		1, reference, 1, null,
		hinge, reference, 1, 1, 1.,0.,0., 3, 0.,1.,0.,
		reference, 1, null,
		hinge, reference, 1, 1, 1.,0.,0., 3, 0.,1.,0.;
	# bind joint 1 revolute angle ("rz") to parameter node 1 
	bind: 1, joint, 1, string, "rz";
	# bind joint 1 revolute angular velocity ("wz") to parameter node 2 
	bind: 1, joint, 2, string, "wz";
	gravity: 0.,0.,-1., 9.81;

	stream output: 1,
		stream name, "MBXINN",
		create, yes,
		# path, "../tmp/mbdyn.out.pendulum.sock",
		port, 9012,
                send first,
		values, 2,
			nodedof, 1, parameter,	# revolute angle
                        nodedof, 2, parameter;	# revolute angular velocity

	force: 1, follower,
		1,			# applied to structural node 1
			position, null,	# arm
			-1.,0.,0.,	# direction
		file,
			1,		# read input from file 1
			1;		# use channel 1
end: elements;


