NASA Astrobee Robot Software  Astrobee Version:
Flight software for the Astrobee robots operating inside the International Space Station.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
shared.h
Go to the documentation of this file.
1 /* Copyright (c) 2017, United States Government, as represented by the
2  * Administrator of the National Aeronautics and Space Administration.
3  *
4  * All rights reserved.
5  *
6  * The Astrobee platform is licensed under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with the
8  * License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15  * License for the specific language governing permissions and limitations
16  * under the License.
17  */
18 
19 #ifndef PMC_SHARED_H_
20 #define PMC_SHARED_H_
21 
22 #include <Eigen/Dense>
23 #include <limits>
24 
25 namespace pmc {
26 
27 // constants
28 class PMCConstants {
29  public:
30  static constexpr float DT = 1.0 / 62.5;
31  static constexpr float units_inches_to_meters = 0.0254;
32  static const Eigen::Matrix<float, 6, 1> discharge_coeff1, discharge_coeff2;
33  // [m] Position vector of the nozzle locations in the body frame
34  static const Eigen::Matrix<float, 6, 3> nozzle_offsets1, nozzle_offsets2;
35  // [unit vec] PM1: Pointing Direction of each nozzle
36  static const Eigen::Matrix<float, 6, 3> nozzle_orientations1, nozzle_orientations2;
37  // [m^2] If air is leaking from the plenum, the
38  // '0 thrust' position (all nozzles closed) will have an effective open area
39  static const Eigen::Vector3f impeller_orientation1, impeller_orientation2;
40  static const Eigen::Matrix<float, 6, 1> nozzle_widths; // [m]
41  static constexpr float zero_thrust_area[2] = {0.0044667, 0.0042273};
42  // [rad] THEORETICAL max angle that a nozzle can open to
43  static constexpr float abp_nozzle_max_open_angle = 79.91 * M_PI / 180.0;
44  // [rad] Min angle that the nozzle can close to
45  static constexpr float abp_nozzle_min_open_angle = 15.68 * M_PI / 180.0;
46  static constexpr float abp_nozzle_flap_length = 0.5353 * units_inches_to_meters; // [m]
47  static constexpr float abp_nozzle_intake_height = 0.5154 * units_inches_to_meters; // [m]
48  static constexpr float abp_nozzle_gear_ratio = 0.5;
49  // bpm_servo_peak_torque*bpm_servo_motor_gear_ratio/(bpm_servo_peak_curr); [Nm/A] Servo motor torque constant
50  static constexpr float servo_motor_k = 0.2893 * 0.01 / 1.5;
51  // bpm_servo_max_voltage/bpm_servo_peak_curr; %[ohm] Servo internal resistance
52  static constexpr float servo_motor_r = 6.0 / 1.5;
53  // bpm_imp_noload_curr*bpm_imp_motor_torque_k/bpm_imp_noload_speed ; %[Nm*s] Viscous Friction
54  static constexpr float servo_motor_friction = 3e-7;
55  // %[kg*m^2] (Tuned in analysis_servo_motor_test.m) Servo gearbox inertia.
56  static constexpr float servo_motor_gearbox_inertia = .000000025;
57  static constexpr float servo_motor_gear_ratio = 1.0 / 100.0;
58  // dc_motor_model
59  static constexpr float imp_motor_speed_k = 374*2*M_PI/60; // [(rad/s)/V] Impeller Speed constant
60  static constexpr float imp_motor_r = 1.2; // %[ohm] Impeller Motor internal resistance
61  static constexpr float imp_motor_torque_k = 0.0255; // [Nm/A] Impeller Torque constant
62  // noload_curr * torque_k / noload_speed [Nm*s] Viscous Friction
63  static constexpr float imp_motor_friction_coeff = 0.144 * imp_motor_torque_k / (4380*2*M_PI/60.0);
64  static constexpr float backlash_half_width = 1.0 * M_PI / 180.0 / 2;
65  static constexpr float impeller_speed2pwm = 0.792095; // [CNT/(rad/sec)] Converts impeller speeds into PWM values
66  static constexpr float impeller_diameter = 5.5 * units_inches_to_meters; // [m]
67  static constexpr float air_density =
68  1.2; // [kg/m^3] Air density inside of the ISS (some places in code this was 1.225?)
69  static constexpr float impeller_inertia = 0.001;
70  // generated in bpm_blower_propulsion_module_prep.m
71  static const float AREA_LOOKUP_INPUT[];
72  static const float CDP_LOOKUP_OUTPUT[];
73  static const int AREA_LOOKUP_TABLE_SIZE;
74 };
75 
76 float Lookup(int table_size, const float lookup[], const float breakpoints[], float value);
77 
78 template <class MatT>
79 Eigen::Matrix<typename MatT::Scalar, MatT::ColsAtCompileTime, MatT::RowsAtCompileTime> pseudoInverse(
80  const MatT& mat, typename MatT::Scalar tolerance = typename MatT::Scalar{std::numeric_limits<double>::epsilon()}) {
81  typedef typename MatT::Scalar Scalar;
82  auto svd = mat.jacobiSvd(Eigen::ComputeFullU | Eigen::ComputeFullV);
83  const auto& singularValues = svd.singularValues();
84  Eigen::Matrix<Scalar, MatT::ColsAtCompileTime, MatT::RowsAtCompileTime> singularValuesInv(mat.cols(), mat.rows());
85  singularValuesInv.setZero();
86  for (unsigned int i = 0; i < singularValues.size(); ++i) {
87  if (singularValues(i) > tolerance) {
88  singularValuesInv(i, i) = Scalar {1} / singularValues(i);
89  } else {
90  singularValuesInv(i, i) = Scalar {0};
91  }
92  }
93  return svd.matrixV() * singularValuesInv * svd.matrixU().adjoint();
94 }
95 
96 } // end namespace pmc
97 
98 #endif // PMC_SHARED_H_
pmc::PMCConstants::discharge_coeff1
static const Eigen::Matrix< float, 6, 1 > discharge_coeff1
Definition: shared.h:32
pmc::PMCConstants::AREA_LOOKUP_TABLE_SIZE
static const int AREA_LOOKUP_TABLE_SIZE
Definition: shared.h:73
pmc::PMCConstants::abp_nozzle_flap_length
static constexpr float abp_nozzle_flap_length
Definition: shared.h:46
pmc::PMCConstants::imp_motor_torque_k
static constexpr float imp_motor_torque_k
Definition: shared.h:61
pmc::PMCConstants::abp_nozzle_intake_height
static constexpr float abp_nozzle_intake_height
Definition: shared.h:47
pmc::PMCConstants::AREA_LOOKUP_INPUT
static const float AREA_LOOKUP_INPUT[]
Definition: shared.h:71
pmc::PMCConstants::servo_motor_k
static constexpr float servo_motor_k
Definition: shared.h:50
pmc::pseudoInverse
Eigen::Matrix< typename MatT::Scalar, MatT::ColsAtCompileTime, MatT::RowsAtCompileTime > pseudoInverse(const MatT &mat, typename MatT::Scalar tolerance=typename MatT::Scalar{std::numeric_limits< double >::epsilon()})
Definition: shared.h:79
pmc::PMCConstants::impeller_orientation1
static const Eigen::Vector3f impeller_orientation1
Definition: shared.h:39
pmc::PMCConstants::nozzle_orientations2
static const Eigen::Matrix< float, 6, 3 > nozzle_orientations2
Definition: shared.h:36
pmc::PMCConstants::impeller_inertia
static constexpr float impeller_inertia
Definition: shared.h:69
pmc::PMCConstants::abp_nozzle_gear_ratio
static constexpr float abp_nozzle_gear_ratio
Definition: shared.h:48
pmc::PMCConstants::nozzle_orientations1
static const Eigen::Matrix< float, 6, 3 > nozzle_orientations1
Definition: shared.h:36
pmc::PMCConstants::servo_motor_friction
static constexpr float servo_motor_friction
Definition: shared.h:54
pmc::PMCConstants::DT
static constexpr float DT
Definition: shared.h:30
pmc::PMCConstants::imp_motor_speed_k
static constexpr float imp_motor_speed_k
Definition: shared.h:59
pmc::PMCConstants
Definition: shared.h:28
pmc::Lookup
float Lookup(int table_size, const float lookup[], const float breakpoints[], float value)
Definition: shared.cc:216
pmc::PMCConstants::backlash_half_width
static constexpr float backlash_half_width
Definition: shared.h:64
pmc::PMCConstants::abp_nozzle_min_open_angle
static constexpr float abp_nozzle_min_open_angle
Definition: shared.h:45
pmc::PMCConstants::CDP_LOOKUP_OUTPUT
static const float CDP_LOOKUP_OUTPUT[]
Definition: shared.h:72
pmc::PMCConstants::impeller_orientation2
static const Eigen::Vector3f impeller_orientation2
Definition: shared.h:39
pmc::PMCConstants::impeller_diameter
static constexpr float impeller_diameter
Definition: shared.h:66
pmc::PMCConstants::air_density
static constexpr float air_density
Definition: shared.h:67
pmc::PMCConstants::servo_motor_gearbox_inertia
static constexpr float servo_motor_gearbox_inertia
Definition: shared.h:56
pmc::PMCConstants::abp_nozzle_max_open_angle
static constexpr float abp_nozzle_max_open_angle
Definition: shared.h:43
pmc::PMCConstants::imp_motor_r
static constexpr float imp_motor_r
Definition: shared.h:60
pmc::PMCConstants::units_inches_to_meters
static constexpr float units_inches_to_meters
Definition: shared.h:31
pmc::PMCConstants::servo_motor_gear_ratio
static constexpr float servo_motor_gear_ratio
Definition: shared.h:57
pmc::PMCConstants::nozzle_offsets2
static const Eigen::Matrix< float, 6, 3 > nozzle_offsets2
Definition: shared.h:34
pmc::PMCConstants::zero_thrust_area
static constexpr float zero_thrust_area[2]
Definition: shared.h:41
pmc::PMCConstants::discharge_coeff2
static const Eigen::Matrix< float, 6, 1 > discharge_coeff2
Definition: shared.h:32
pmc::PMCConstants::servo_motor_r
static constexpr float servo_motor_r
Definition: shared.h:52
pmc::PMCConstants::impeller_speed2pwm
static constexpr float impeller_speed2pwm
Definition: shared.h:65
pmc::PMCConstants::nozzle_widths
static const Eigen::Matrix< float, 6, 1 > nozzle_widths
Definition: shared.h:40
pmc
Definition: fam.h:24
pmc::PMCConstants::imp_motor_friction_coeff
static constexpr float imp_motor_friction_coeff
Definition: shared.h:63
pmc::PMCConstants::nozzle_offsets1
static const Eigen::Matrix< float, 6, 3 > nozzle_offsets1
Definition: shared.h:34