DUECA/DUSIME
Loading...
Searching...
No Matches
PulsedBody.cxx
/* ------------------------------------------------------------------ */
/* item : PulsedBody.cxx
made by : Rene' van Paassen
date : 060502
category : body file
description :
changes : 060502 first version
language : C++
copyright : (c) 2016 TUDelft-AE-C&S
copyright : (c) 2022 René van Paassen
license : EUPL-1.2
*/
#define PulsedBody_cxx
#include "PulsedBody.hxx"
#include <iostream>
using namespace std;
// create a RigidBody, with mass and inertia. Request one additional
// state for the engine.
RigidBody(100.0, 5.0, 6.0, 9.0, 0.0, 0.0, 0.0, 1),
// time constant of the engine, 1.2 s
tau_e(1.2),
// time step
dt(dt),
// force vector is initially zero, 3 elements.
force(Vector::Zero(3)),
// same for the point on the body
fpoint(Vector::Zero(3)),
// vector for the gravitational pull
gravity(Vector::Zero(3)),
// workspace integration, 13 states for body, 1 for me
workspace(14)
{
// modify point where forces are applied, index 2 is z-coordinate
// there is a slight offset in x coordinate
fpoint[2] = -1.0;
fpoint[0] = 1e-8;
// in z-direction
gravity[2] = 9.810665;
// with this, construction of the PulsedBody is complete.
}
{
// nothing to delete
}
void PulsedBody::derivative(VectorE& xd, double dt_offset)
{
// we added one state, engine thrust. The engine thrust is state
// variable x[13]. Calculate the derivative, using the time
// constant, assume we have a constant setpoint of 1330 N for the thrust:
xd[13] = (1330.0 - x[13]) / tau_e;
// now, all other motions are calculated by the RigidBody parent.
// use this to clear all forces from the previous step
// apply the thrust to the body
force.setZero(); // for clarity, all elements of force vector
// are zeroed here.
force[2] = -x[13]; // force in z direction = thruster state
applyBodyForce(force, fpoint); // apply force on the body
addInertialGravity(gravity); // add gravity field
// if we now call derivative from the RigidBody parent, the
// remaining 13 states (0 -- 12) are calculated. Expressly call the
// parent method, otherwise we end up calling ourselves!
// at this point, the derivative of the state vector has been put in
// xd. Return to the calling function, most likely the integration
// routine.
return;
}
{
// use Runge-kutta integration on myself
// just to prove that we did something
cout << X() << endl;
// after a call to output, things like Psi, theta and phi should be
// calculated
output();
cout << "psi=" << psi() << " theta=" << theta() << " phi=" << phi()
<< " V=" << V() << " alpha=" << alpha() << " beta=" << beta() << endl;
// specific forces. Note that it is really inefficient (especially
// for a real-time program) to be creating and removing vector sp
// for each step.
Vector sp(6);
specific(sp);
cout << sp << endl;
}
int main()
{
// main function
PulsedBody pb(0.1);
for (int ii = 1000; ii--; ) {
pb.step();
}
return 0;
}
This is an example, using the RigidBody class as basis for implementation of equations of motion.
Definition PulsedBody.hxx:30
Vector force
For efficiency, auxiliary variable that represents a force vector.
Definition PulsedBody.hxx:44
RungeKuttaWorkspace workspace
Workspace for the RungeKutta integration.
Definition PulsedBody.hxx:54
PulsedBody(double dt)
Constructor.
Vector fpoint
Auxiliary variable, vector giving the point where the force is applied.
Definition PulsedBody.hxx:48
~PulsedBody()
Destructor.
double tau_e
Time constant simulating the "engine" dynamics.
Definition PulsedBody.hxx:34
Vector gravity
Auxiliary variable, vector giving gravity.
Definition PulsedBody.hxx:51
void derivative(VectorE &xd, double dt_offset)
Function needed for integration.
double dt
Size of time steps.
Definition PulsedBody.hxx:37
void step()
Function that does an integration step.
Rigid body dynamics function, calculates derivative of a rigid body, given sum of moments and forces ...
Definition RigidBody.hxx:108
void zeroForces()
Initialize sum of forces on the body to zero.
const double theta() const
Get euler angle theta.
Definition RigidBody.hxx:315
const double psi() const
Get euler angle psi.
Definition RigidBody.hxx:317
void specific(Vector &sp)
Calculate specific forces and moments, forces stored in elements 0, 1, and 2, moments in elements 3,...
const double beta() const
Obtain beta.
Definition RigidBody.hxx:307
const double phi() const
Get euler angle phi.
Definition RigidBody.hxx:313
const Vector & X() const
Obtain the state, 13 elements.
Definition RigidBody.hxx:298
const double V() const
Obtain speed.
Definition RigidBody.hxx:301
const double alpha() const
Obtain alpha.
Definition RigidBody.hxx:304
void derivative(VectorE &xd, double unused=0.0)
Obtain and calculate the derivative, given sum of forces and moments and the gravitational field acti...
void addInertialGravity(const Vector &g)
Add a gravitational field; 3 element vector, gravitation expressed in the inertial system.
void output()
Calculate auxiliary outputs, V, , , , and .
Vector x
State vector.
Definition RigidBody.hxx:114
void applyBodyForce(const Vector3 &Fb, const Vector3 &point)
Apply a force expressed in body coordinates.
Eigen::Map< Eigen::VectorXd > VectorE
a vector that takes external storage
Definition integrate_euler.hxx:29
void integrate_rungekutta(MOD &model, RungeKuttaWorkspace &ws, double dt)
This function applies one Runge Kutta integration step to the state given in the kinematics argument.
Definition integrate_rungekutta.hxx:88
print the IncoRole to a stream
Definition SimStateRequest.hxx:185