multicopterDynamicsSim.cpp
Go to the documentation of this file.
1 
8 #include <iostream>
9 #include <chrono>
10 
30 double thrustCoefficient, double torqueCoefficient,
31 double minMotorSpeed, double maxMotorSpeed,
32 double motorTimeConstant, double motorRotationalInertia,
33 double vehicleMass,
34 const Eigen::Matrix3d & vehicleInertia,
35 const Eigen::Matrix3d & aeroMomentCoefficient,
36 double dragCoefficient,
37 double momentProcessNoiseAutoCorrelation,
38 double forceProcessNoiseAutoCorrelation,
39 const Eigen::Vector3d & gravity
40 )
41 : numCopter_(numCopter)
42 , motorFrame_(numCopter)
43 , motorDirection_(numCopter)
44 , motorRotationalInertia_(numCopter)
45 , thrustCoefficient_(numCopter)
46 , torqueCoefficient_(numCopter)
47 , motorSpeed_(numCopter)
48 , motorTimeConstant_(numCopter)
49 , maxMotorSpeed_(numCopter)
50 , minMotorSpeed_(numCopter)
51 {
52  randomNumberGenerator_.seed(std::chrono::system_clock::now().time_since_epoch().count());
53 
54  for (int indx = 0; indx < numCopter; indx++){
55  motorFrame_.at(indx).setIdentity();
56  thrustCoefficient_.at(indx) = thrustCoefficient;
57  torqueCoefficient_.at(indx) = torqueCoefficient;
58  motorTimeConstant_.at(indx) = motorTimeConstant;
59  motorRotationalInertia_.at(indx) = motorRotationalInertia;
60  maxMotorSpeed_.at(indx) = maxMotorSpeed;
61  minMotorSpeed_.at(indx) = minMotorSpeed;
62  motorDirection_.at(indx) = 1;
63  motorSpeed_.at(indx) = 0.;
64  }
65 
66  vehicleMass_ = vehicleMass;
67  vehicleInertia_ = vehicleInertia;
68  aeroMomentCoefficient_ = aeroMomentCoefficient;
69  dragCoefficient_ = dragCoefficient;
70  momentProcessNoiseAutoCorrelation_ = momentProcessNoiseAutoCorrelation;
71  forceProcessNoiseAutoCorrelation_ = forceProcessNoiseAutoCorrelation;
72 
73  gravity_ = gravity;
74 }
75 
83 : numCopter_(numCopter)
84 , motorFrame_(numCopter)
85 , motorDirection_(numCopter)
86 , motorRotationalInertia_(numCopter)
87 , thrustCoefficient_(numCopter)
88 , torqueCoefficient_(numCopter)
89 , motorSpeed_(numCopter)
90 , motorTimeConstant_(numCopter)
91 , maxMotorSpeed_(numCopter)
92 , minMotorSpeed_(numCopter)
93 {
94  randomNumberGenerator_.seed(std::chrono::system_clock::now().time_since_epoch().count());
95 
96  for (int indx = 0; indx < numCopter; indx++){
97  motorFrame_.at(indx).setIdentity();
98  thrustCoefficient_.at(indx) = 0.;
99  torqueCoefficient_.at(indx) = 0.;
100  motorTimeConstant_.at(indx) = 0.;
101  motorRotationalInertia_.at(indx) = 0.;
102  maxMotorSpeed_.at(indx) = 0.;
103  minMotorSpeed_.at(indx) = 0.;
104  motorDirection_.at(indx) = 1;
105  motorSpeed_.at(indx) = 0.;
106  }
107 
108  // Default is NED, but can be set by changing gravity direction
109  gravity_ << 0.,0.,9.81;
110 }
111 
123  const Eigen::Matrix3d & vehicleInertia,
124  const Eigen::Matrix3d & aeroMomentCoefficient,
125  double dragCoefficient,
126  double momentProcessNoiseAutoCorrelation,
127  double forceProcessNoiseAutoCorrelation){
128  vehicleMass_ = vehicleMass;
129  vehicleInertia_ = vehicleInertia;
130  aeroMomentCoefficient_ = aeroMomentCoefficient;
131  dragCoefficient_ = dragCoefficient;
132  momentProcessNoiseAutoCorrelation_ = momentProcessNoiseAutoCorrelation;
133  forceProcessNoiseAutoCorrelation_ = forceProcessNoiseAutoCorrelation;
134 }
135 
141 void MulticopterDynamicsSim::setGravityVector(const Eigen::Vector3d & gravity){
142  gravity_ = gravity;
143 }
144 
155 void MulticopterDynamicsSim::setMotorFrame(const Eigen::Isometry3d & motorFrame, int motorDirection, int motorIndex){
156  motorFrame_.at(motorIndex) = motorFrame;
157  motorDirection_.at(motorIndex) = motorDirection;
158 }
159 
171 void MulticopterDynamicsSim::setMotorProperties(double thrustCoefficient, double torqueCoefficient, double motorTimeConstant,
172  double minMotorSpeed, double maxMotorSpeed, double rotationalInertia, int motorIndex){
173  thrustCoefficient_.at(motorIndex) = thrustCoefficient;
174  torqueCoefficient_.at(motorIndex) = torqueCoefficient;
175  motorTimeConstant_.at(motorIndex) = motorTimeConstant;
176  maxMotorSpeed_.at(motorIndex) = maxMotorSpeed;
177  minMotorSpeed_.at(motorIndex) = minMotorSpeed;
178  motorRotationalInertia_.at(motorIndex) = rotationalInertia;
179 }
180 
191 void MulticopterDynamicsSim::setMotorProperties(double thrustCoefficient, double torqueCoefficient, double motorTimeConstant,
192  double minMotorSpeed, double maxMotorSpeed, double rotationalInertia){
193  for (int motorIndex = 0; motorIndex < numCopter_; motorIndex++){
194  setMotorProperties(thrustCoefficient, torqueCoefficient, motorTimeConstant,
195  minMotorSpeed, maxMotorSpeed, rotationalInertia, motorIndex);
196  }
197 }
198 
205 void MulticopterDynamicsSim::setMotorSpeed(double motorSpeed, int motorIndex){
206  motorSpeed_.at(motorIndex) = motorSpeed;
207 }
208 
209 
216  for (int motorIndex = 0; motorIndex < numCopter_; motorIndex++){
217  setMotorSpeed(motorSpeed, motorIndex);
218  }
219 }
220 
226  for (int indx = 0; indx < numCopter_; indx++){
227  motorSpeed_.at(indx) = 0.;
228  }
229 }
230 
237 void MulticopterDynamicsSim::setVehiclePosition(const Eigen::Vector3d & position,
238  const Eigen::Quaterniond & attitude){
239  position_ = position;
240  attitude_ = attitude;
241 
242  angularVelocity_.setZero();
243  velocity_.setZero();
244 
246 }
247 
248 void MulticopterDynamicsSim::setVehicleInitialAttitude(const Eigen::Quaterniond & attitude){
249  default_attitude_ = attitude;
250 }
251 
261 void MulticopterDynamicsSim::setVehicleState(const Eigen::Vector3d & position,
262  const Eigen::Vector3d & velocity,
263  const Eigen::Vector3d & angularVelocity,
264  const Eigen::Quaterniond & attitude,
265  const std::vector<double> & motorSpeed){
266  position_ = position;
267  velocity_ = velocity;
268  angularVelocity_ = angularVelocity;
269  attitude_ = attitude;
270  for (int indx = 0; indx < numCopter_; indx++){
271  motorSpeed_.at(indx) = motorSpeed.at(indx);
272  }
273 }
274 
284 void MulticopterDynamicsSim::getVehicleState(Eigen::Vector3d & position,
285  Eigen::Vector3d & velocity,
286  Eigen::Vector3d & angularVelocity,
287  Eigen::Quaterniond & attitude,
288  std::vector<double> & motorSpeed){
289  position = position_;
290  velocity = velocity_;
291  angularVelocity = angularVelocity_;
292  attitude = attitude_;
293  motorSpeed = motorSpeed_;
294 }
295 
302  return position_;
303 }
304 
311  return attitude_;
312 }
313 
320  return velocity_;
321 }
322 
329  return angularVelocity_;
330 }
331 
338  Eigen::Vector3d specificForce = (getThrust(motorSpeed_) +
340  / vehicleMass_;
341 
342  return specificForce;
343 }
344 
345 
353 }
354 
355 
362 Eigen::Vector3d MulticopterDynamicsSim::getThrust(const std::vector<double> & motorSpeed){
363  Eigen::Vector3d thrust = Eigen::Vector3d::Zero();
364  for (int indx = 0; indx < numCopter_; indx++){
365 
366  Eigen::Vector3d motorThrust(0.,0.,fabs(motorSpeed.at(indx))*motorSpeed.at(indx)*thrustCoefficient_.at(indx));
367  thrust += motorFrame_.at(indx).linear()*motorThrust;
368  }
369  return thrust;
370 }
371 
379 Eigen::Vector3d MulticopterDynamicsSim::getControlMoment(const std::vector<double> & motorSpeed, const std::vector<double> & motorAcceleration){
380  Eigen::Vector3d controlMoment = Eigen::Vector3d::Zero();
381 
382  for (int indx = 0; indx < numCopter_; indx++){
383  // Moment due to thrust
384  Eigen::Vector3d motorThrust(0.,0.,fabs(motorSpeed.at(indx))*motorSpeed.at(indx)*thrustCoefficient_.at(indx));
385  controlMoment += motorFrame_.at(indx).translation().cross(motorFrame_.at(indx).linear()*motorThrust);
386 
387  // Moment due to torque
388  Eigen::Vector3d motorTorque(0.,0.,motorDirection_.at(indx)*fabs(motorSpeed.at(indx))*motorSpeed.at(indx)*torqueCoefficient_.at(indx));
389  motorTorque(2) += motorDirection_.at(indx)*motorRotationalInertia_.at(indx)*motorAcceleration.at(indx);
390  controlMoment += motorFrame_.at(indx).linear()*motorTorque;
391  }
392 
393  return controlMoment;
394 }
395 
402 Eigen::Vector3d MulticopterDynamicsSim::getAeroMoment(const Eigen::Vector3d & angularVelocity){
403  return (-angularVelocity.norm()*aeroMomentCoefficient_*angularVelocity);
404 }
405 
412 Eigen::Vector3d MulticopterDynamicsSim::getDragForce(const Eigen::Vector3d & velocity){
413  return (-dragCoefficient_*velocity.norm()*velocity);
414 }
415 
422 void MulticopterDynamicsSim::getIMUMeasurement(Eigen::Vector3d & accOutput, Eigen::Vector3d & gyroOutput){
423  if( position_.z() < 0.1){
424  Eigen::Vector3d zero_force;
425  zero_force.setZero();
426  imu_.getMeasurement(accOutput, gyroOutput, zero_force, angularVelocity_);
427  accOutput = accOutput - attitude_.inverse()*gravity_;
428  }else{
429  imu_.getMeasurement(accOutput, gyroOutput, getVehicleSpecificForce(), angularVelocity_);
430  }
431 }
432 
439 void MulticopterDynamicsSim::proceedState_ExplicitEuler(double dt_secs, const std::vector<double> & motorSpeedCommandIn, bool isCmdPercent){
440  std::vector<double> motorSpeedCommand = motorSpeedCommandIn;
441  if(isCmdPercent)
442  {
443  for (size_t i = 0; i < motorSpeedCommand.size(); i++)
444  {
445  motorSpeedCommand[i] *= maxMotorSpeed_[i];
446  }
447  }
448 
449  std::vector<double> motorSpeedCommandBounded(numCopter_);
450  vectorBoundOp(motorSpeedCommand,motorSpeedCommandBounded,minMotorSpeed_,maxMotorSpeed_);
451 
452  std::vector<double> motorSpeed(motorSpeed_);
453  Eigen::Vector3d position = position_;
454  Eigen::Vector3d velocity = velocity_;
455  Eigen::Vector3d angularVelocity = angularVelocity_;
456  Eigen::Quaterniond attitude = attitude_;
457 
458  stochForce_ /= sqrt(dt_secs);
459  Eigen::Vector3d stochMoment;
463 
464  std::vector<double> motorSpeedDer(numCopter_);
465  getMotorSpeedDerivative(motorSpeedDer,motorSpeed,motorSpeedCommandBounded);
466  Eigen::Vector3d positionDer = velocity;
467  Eigen::Vector3d velocityDer = getVelocityDerivative(attitude,stochForce_,velocity,motorSpeed);
468  Eigen::Vector4d attitudeDer = getAttitudeDerivative(attitude,angularVelocity);
469  Eigen::Vector3d angularVelocityDer = getAngularVelocityDerivative(motorSpeed,motorSpeedDer,angularVelocity,stochMoment);
470 
471  vectorAffineOp(motorSpeed,motorSpeedDer,motorSpeed_,dt_secs);
473  position_ = position + positionDer*dt_secs;
474  velocity_ = velocity + velocityDer*dt_secs;
475  angularVelocity_ = angularVelocity + angularVelocityDer*dt_secs;
476  attitude_.coeffs() = attitude.coeffs() + attitudeDer*dt_secs;
477 
478  attitude_.normalize();
479 
480  if( position_.z() < 0){
481  position_[2] = 0.00;
482  velocity_ << 0.0, 0.0, 0.0;
483  angularVelocity_ << 0.0, 0.0, 0.0;
485  }
486 
490 
491  imu_.proceedBiasDynamics(dt_secs);
492 }
493 
500 void MulticopterDynamicsSim::proceedState_RK4(double dt_secs, const std::vector<double> & motorSpeedCommandIn, bool isCmdPercent){
501  std::vector<double> motorSpeedCommand = motorSpeedCommandIn;
502 
503  if(isCmdPercent)
504  {
505  for (size_t i = 0; i < motorSpeedCommand.size(); i++)
506  {
507  motorSpeedCommand[i] *= maxMotorSpeed_[i];
508  }
509  }
510  std::vector<double> motorSpeedCommandBounded(numCopter_);
511  vectorBoundOp(motorSpeedCommand,motorSpeedCommandBounded,minMotorSpeed_,maxMotorSpeed_);
512 
513  std::vector<double> motorSpeed(motorSpeed_);
514  Eigen::Vector3d position = position_;
515  Eigen::Vector3d velocity = velocity_;
516  Eigen::Vector3d angularVelocity = angularVelocity_;
517  Eigen::Quaterniond attitude = attitude_;
518 
519  stochForce_ /= sqrt(dt_secs);
520 
521  Eigen::Vector3d stochMoment;
525 
526  // k1
527  std::vector<double> motorSpeedDer(numCopter_);
528  getMotorSpeedDerivative(motorSpeedDer,motorSpeed_,motorSpeedCommandBounded);
529  Eigen::Vector3d positionDer = dt_secs*velocity_;
530  Eigen::Vector3d velocityDer = dt_secs*getVelocityDerivative(attitude_,stochForce_,velocity_,motorSpeed_);
531  Eigen::Vector4d attitudeDer = dt_secs*getAttitudeDerivative(attitude_,angularVelocity_);
532  Eigen::Vector3d angularVelocityDer = dt_secs*getAngularVelocityDerivative(motorSpeed_,motorSpeedDer,angularVelocity_,stochMoment);
533  vectorScalarProd(motorSpeedDer,motorSpeedDer,dt_secs);
534 
535  // x + 1/6*(k1)
536  vectorAffineOp(motorSpeed,motorSpeedDer,motorSpeed,(1./6.));
537  position += (1./6.)*positionDer;
538  velocity += (1./6.)*velocityDer;
539  attitude.coeffs() += (1./6.)*attitudeDer;
540  attitude.normalize();
541  angularVelocity += (1./6.)*angularVelocityDer;
542 
543  // k2
544  std::vector<double> motorSpeedIntermediate(numCopter_);
545  Eigen::Quaterniond attitudeIntermediate;
546 
547  vectorAffineOp(motorSpeed_,motorSpeedDer,motorSpeedIntermediate,0.5); // x + 0.5*(k1)
548  vectorBoundOp(motorSpeedIntermediate,motorSpeedIntermediate,minMotorSpeed_,maxMotorSpeed_);
549  attitudeIntermediate.coeffs() = attitude_.coeffs() + attitudeDer*0.5;
550  attitudeIntermediate.normalize();
551 
552  getMotorSpeedDerivative(motorSpeedDer, motorSpeedIntermediate, motorSpeedCommandBounded);
553  positionDer = dt_secs*(velocity_ + 0.5*velocityDer);
554  velocityDer = dt_secs*getVelocityDerivative(attitudeIntermediate,stochForce_,(velocity_ + 0.5*velocityDer), motorSpeedIntermediate);
555  attitudeDer = dt_secs*getAttitudeDerivative(attitudeIntermediate,(angularVelocity_ + 0.5*angularVelocityDer));
556  angularVelocityDer = dt_secs*getAngularVelocityDerivative(motorSpeedIntermediate,motorSpeedDer,(angularVelocity_ + 0.5*angularVelocityDer),stochMoment);
557  vectorScalarProd(motorSpeedDer, motorSpeedDer, dt_secs);
558 
559  // x + 1/6*(k1 + 2*k2)
560  vectorAffineOp(motorSpeed,motorSpeedDer,motorSpeed,(1./3.));
561  position += (1./3.)*positionDer;
562  velocity += (1./3.)*velocityDer;
563  attitude.coeffs() += (1./3.)*attitudeDer;
564  attitude.normalize();
565  angularVelocity += (1./3.)*angularVelocityDer;
566 
567  // k3
568  vectorAffineOp(motorSpeed_,motorSpeedDer,motorSpeedIntermediate,0.5);
569  vectorBoundOp(motorSpeedIntermediate,motorSpeedIntermediate,minMotorSpeed_,maxMotorSpeed_);
570  attitudeIntermediate.coeffs() = attitude_.coeffs() + attitudeDer*0.5;
571  attitudeIntermediate.normalize();
572 
573  getMotorSpeedDerivative(motorSpeedDer, motorSpeedIntermediate, motorSpeedCommandBounded);
574  positionDer = dt_secs*(velocity_ + 0.5*velocityDer);
575  velocityDer = dt_secs*getVelocityDerivative(attitudeIntermediate,stochForce_,(velocity_ + 0.5*velocityDer), motorSpeedIntermediate);
576  attitudeDer = dt_secs*getAttitudeDerivative(attitudeIntermediate,(angularVelocity_ + 0.5*angularVelocityDer));
577  angularVelocityDer = dt_secs*getAngularVelocityDerivative(motorSpeedIntermediate,motorSpeedDer,(angularVelocity_ + 0.5*angularVelocityDer),stochMoment);
578  vectorScalarProd(motorSpeedDer, motorSpeedDer, dt_secs);
579 
580  // x + 1/6*(k1 + 2*k2 + 2*k3)
581  vectorAffineOp(motorSpeed,motorSpeedDer,motorSpeed,(1./3.));
582  position += (1./3.)*positionDer;
583  velocity += (1./3.)*velocityDer;
584  attitude.coeffs() += (1./3.)*attitudeDer;
585  attitude.normalize();
586  angularVelocity += (1./3.)*angularVelocityDer;
587 
588  // k4
589  vectorAffineOp(motorSpeed_,motorSpeedDer,motorSpeedIntermediate,1.);
590  vectorBoundOp(motorSpeedIntermediate,motorSpeedIntermediate,minMotorSpeed_,maxMotorSpeed_);
591  attitudeIntermediate.coeffs() = attitude_.coeffs() + attitudeDer;
592  attitudeIntermediate.normalize();
593 
594  getMotorSpeedDerivative(motorSpeedDer, motorSpeedIntermediate, motorSpeedCommandBounded);
595  positionDer = dt_secs*(velocity_ + velocityDer);
596  velocityDer = dt_secs*getVelocityDerivative(attitudeIntermediate,stochForce_,(velocity_ + velocityDer), motorSpeedIntermediate);
597  attitudeDer = dt_secs*getAttitudeDerivative(attitudeIntermediate,(angularVelocity_ + angularVelocityDer));
598  angularVelocityDer = dt_secs*getAngularVelocityDerivative(motorSpeedIntermediate,motorSpeedDer,(angularVelocity_ + angularVelocityDer),stochMoment);
599  vectorScalarProd(motorSpeedDer, motorSpeedDer, dt_secs);
600 
601  // x + 1/6*(k1 + 2*k2 + 2*k3 + k4)
602  vectorAffineOp(motorSpeed,motorSpeedDer,motorSpeed_,(1./6.));
604  position_ = position + positionDer*(1./6.);
605  velocity_ = velocity + velocityDer*(1./6.);
606  attitude_.coeffs() = attitude.coeffs() + attitudeDer*(1./6.);
607  attitude_.normalize();
608  angularVelocity_ = angularVelocity + angularVelocityDer*(1./6.);
609 
613 
614  imu_.proceedBiasDynamics(dt_secs);
615 }
616 
625 void MulticopterDynamicsSim::vectorAffineOp(const std::vector<double> & vec1, const std::vector<double> & vec2,
626  std::vector<double> & vec3, double val){
627  std::transform(vec1.begin(), vec1.end(), vec2.begin(), vec3.begin(), [val](const double & vec1val, const double & vec2val)->double{return (vec1val + val*vec2val);});
628 }
629 
638 void MulticopterDynamicsSim::vectorBoundOp(const std::vector<double> & vec1, std::vector<double> & vec2,
639  const std::vector<double> & minvec, const std::vector<double> & maxvec){
640  std::transform(vec1.begin(), vec1.end(), maxvec.begin(), vec2.begin(), [](const double & vec1val, const double & maxvalue)->double{return fmin(vec1val,maxvalue);});
641  std::transform(vec2.begin(), vec2.end(), minvec.begin(), vec2.begin(), [](const double & vec2val, const double & minvalue)->double{return fmax(vec2val,minvalue);});
642 }
643 
651 void MulticopterDynamicsSim::vectorScalarProd(const std::vector<double> & vec1, std::vector<double> & vec2, double val){
652  std::transform(vec1.begin(), vec1.end(), vec2.begin(), [val](const double & vec1val){return vec1val*val;});
653 }
654 
662 void MulticopterDynamicsSim::getMotorSpeedDerivative(std::vector<double> & motorSpeedDer,
663  const std::vector<double> & motorSpeed,
664  const std::vector<double> & motorSpeedCommand){
665  for (int indx = 0; indx < numCopter_; indx++){
666  motorSpeedDer.at(indx) = (motorSpeedCommand.at(indx) - motorSpeed.at(indx))/motorTimeConstant_.at(indx);
667  }
668 }
669 
679 Eigen::Vector3d MulticopterDynamicsSim::getVelocityDerivative(const Eigen::Quaterniond & attitude, const Eigen::Vector3d & stochForce,
680  const Eigen::Vector3d & velocity, const std::vector<double> & motorSpeed){
681  return (gravity_ + (attitude*getThrust(motorSpeed) + getDragForce(velocity) + stochForce)/vehicleMass_);
682 }
683 
691 Eigen::Vector4d MulticopterDynamicsSim::getAttitudeDerivative(const Eigen::Quaterniond & attitude, const Eigen::Vector3d & angularVelocity){
692  Eigen::Quaterniond angularVelocityQuad;
693  angularVelocityQuad.w() = 0;
694  angularVelocityQuad.vec() = angularVelocity;
695 
696  return (0.5*(attitude*angularVelocityQuad).coeffs());
697 }
698 
708 Eigen::Vector3d MulticopterDynamicsSim::getAngularVelocityDerivative(const std::vector<double> & motorSpeed,
709  const std::vector<double>& motorAcceleration, const Eigen::Vector3d & angularVelocity, const Eigen::Vector3d & stochMoment){
710 
711  Eigen::Vector3d angularMomentum = vehicleInertia_*angularVelocity;
712 
713  for (int indx = 0; indx < numCopter_; indx++){
714  Eigen::Vector3d motorAngularMomentum = Eigen::Vector3d::Zero();
715 
716  motorAngularMomentum(2) = -1*motorDirection_.at(indx)*motorRotationalInertia_.at(indx)*motorSpeed.at(indx);
717 
718  angularMomentum += motorFrame_.at(indx).linear()*motorAngularMomentum;
719  }
720 
721  return (vehicleInertia_.inverse()*(getControlMoment(motorSpeed,motorAcceleration) + getAeroMoment(angularVelocity) + stochMoment
722  - angularVelocity.cross(angularMomentum)));
723 }
void setMotorProperties(double thrustCoefficient, double torqueCoefficient, double motorTimeConstant, double minMotorSpeed, double maxMotorSpeed, double rotationalInertia, int motorIndex)
Set properties for individual motor.
std::vector< Eigen::Isometry3d > motorFrame_
std::vector< double > minMotorSpeed_
std::default_random_engine randomNumberGenerator_
void setVehicleInitialAttitude(const Eigen::Quaterniond &attitude)
void proceedState_ExplicitEuler(double dt_secs, const std::vector< double > &motorSpeedCommand, bool isCmdPercent=false)
Proceed vehicle dynamics using Explicit Euler integration.
void setMotorFrame(const Eigen::Isometry3d &motorFrame, int motorDirection, int motorIndex)
Set orientation and position for individual motor.
void getMotorSpeedDerivative(std::vector< double > &motorSpeedDer, const std::vector< double > &motorSpeed, const std::vector< double > &motorSpeedCommand)
Get motor acceleration.
void setVehicleProperties(double vehicleMass, const Eigen::Matrix3d &vehicleInertia, const Eigen::Matrix3d &aeroMomentCoefficient, double dragCoefficient, double momentProcessNoiseAutoCorrelation, double forceProcessNoiseAutoCorrelation)
Set vehicle properties.
Eigen::Vector3d getVehicleVelocity(void)
Get vehicle velocity.
std::normal_distribution< double > standardNormalDistribution_
void vectorBoundOp(const std::vector< double > &vec1, std::vector< double > &vec2, const std::vector< double > &minvec, const std::vector< double > &maxvec)
Element-wise vector bound operation: vec2 = max(minvalue, min(maxvalue, vec1))
void setMotorSpeed(double motorSpeed, int motorIndex)
Set motor speed for individual motor.
Eigen::Vector3d getVehicleAngularVelocity(void)
Get vehicle angular velocity.
Eigen::Vector3d getThrust(const std::vector< double > &motorSpeed)
Get thrust in vehicle-fixed reference frame.
std::vector< double > motorTimeConstant_
Eigen::Vector3d getAngularVelocityDerivative(const std::vector< double > &motorSpeed, const std::vector< double > &motorAcceleration, const Eigen::Vector3d &angularVelocity, const Eigen::Vector3d &stochMoment)
Get vehicle angular acceleration in vehicle-fixed reference frame.
Eigen::Vector3d getControlMoment(const std::vector< double > &motorSpeed, const std::vector< double > &motorAcceleration)
Get control moment in vehicle-fixed reference frame.
void vectorAffineOp(const std::vector< double > &vec1, const std::vector< double > &vec2, std::vector< double > &vec3, double val)
Element-wise affine vector calculus: vec3 = vec1 + val*vec2.
Eigen::Vector4d getAttitudeDerivative(const Eigen::Quaterniond &attitude, const Eigen::Vector3d &angularVelocity)
Get attitude quaternion time-derivative.
std::vector< double > motorRotationalInertia_
Eigen::Quaterniond default_attitude_
std::vector< int > motorDirection_
void proceedBiasDynamics(double dt_secs)
Proceed accelerometer and gyroscope bias dynamics.
Eigen::Quaterniond getVehicleAttitude(void)
Get vehicle attitude.
std::vector< double > thrustCoefficient_
std::vector< double > motorSpeed_
Multicopter dynamics simulator class header file.
void setVehiclePosition(const Eigen::Vector3d &position, const Eigen::Quaterniond &attitude)
Set vehicle position and attitude.
Eigen::Vector3d getVehicleSpecificForce(void)
Get total specific force acting on vehicle, excluding gravity force.
void getIMUMeasurement(Eigen::Vector3d &accOutput, Eigen::Vector3d &gyroOutput)
Get IMU measurement.
void vectorScalarProd(const std::vector< double > &vec1, std::vector< double > &vec2, double val)
Vector-scalar product: vec2 = val*vec1.
void resetMotorSpeeds(void)
Set motor speed to zero for all motors.
MulticopterDynamicsSim(int numCopter, double thrustCoefficient, double torqueCoefficient, double minMotorSpeed, double maxMotorSpeed, double motorTimeConstant, double motorRotationalInertia, double vehicleMass, const Eigen::Matrix3d &vehicleInertia, const Eigen::Matrix3d &aeroMomentCoefficient, double dragCoefficient, double momentProcessNoiseAutoCorrelation, double forceProcessNoiseAutoCorrelation, const Eigen::Vector3d &gravity)
Construct a new Multicopter Dynamics Sim object.
void proceedState_RK4(double dt_secs, const std::vector< double > &motorSpeedCommand, bool isCmdPercent=false)
Proceed vehicle dynamics using 4th order Runge-Kutta integration.
Eigen::Vector3d getVehiclePosition(void)
Get vehicle position.
Eigen::Vector3d getAeroMoment(const Eigen::Vector3d &angularVelocity)
Get aerodynamic moment in vehicle-fixed reference frame.
std::vector< double > torqueCoefficient_
inertialMeasurementSim imu_
Eigen::Vector3d getVelocityDerivative(const Eigen::Quaterniond &attitude, const Eigen::Vector3d &stochForce, const Eigen::Vector3d &velocity, const std::vector< double > &motorSpeed)
Get vehicle accelertion in world-fixed reference frame.
double time_since_epoch()
Eigen::Vector3d getDragForce(const Eigen::Vector3d &velocity)
Get drag force in world-fixed reference frame.
void getVehicleState(Eigen::Vector3d &position, Eigen::Vector3d &velocity, Eigen::Vector3d &angularVelocity, Eigen::Quaterniond &attitude, std::vector< double > &motorSpeed)
Get vehicle state.
Eigen::Vector3d getTotalForce(void)
Get total force acting on vehicle, including gravity force.
std::vector< double > maxMotorSpeed_
void setGravityVector(const Eigen::Vector3d &gravity)
Set orientation of world-fixed reference frame using gravity vector.
void getMeasurement(Eigen::Vector3d &accOutput, Eigen::Vector3d &gyroOutput, const Eigen::Vector3d specificForce, const Eigen::Vector3d angularVelocity)
Get IMU measurement.
void setVehicleState(const Eigen::Vector3d &position, const Eigen::Vector3d &velocity, const Eigen::Vector3d &angularVelocity, const Eigen::Quaterniond &attitude, const std::vector< double > &motorSpeed)
Set vehicle state.


inno_vtol_dynamics
Author(s): Roman Fedorenko, Dmitry Ponomarev, Ezra Tal, Winter Guerra
autogenerated on Sat Jul 1 2023 02:13:44