NASA Astrobee Robot Software  0.19.1
Flight software for the Astrobee robots operating inside the International Space Station.
pmc_sim.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_PMC_SIM_H_
20 #define PMC_PMC_SIM_H_
21 
22 #include <Eigen/Dense>
23 
24 namespace pmc {
25 
26 class PID {
27  public:
28  void Initialize(float Kp, float Ki, float Kd, float out_max, float out_min);
29  float Run(float x);
30 
31  private:
32  float kp, ki, kd, omax, omin;
33  float last;
34  float integral;
35 };
36 
37 class Blower {
38  public:
39  explicit Blower(bool is_pmc1);
40  void Step(int impeller_cmd, Eigen::Matrix<float, 6, 1> & servo_cmd, Eigen::Vector3f & omega, float voltage);
41  Eigen::Vector3f Force() {return force_B_;}
42  Eigen::Vector3f Torque() {return torque_B_;}
43  float ImpellerCurrent() {return impeller_current_;}
44  Eigen::Matrix<float, 6, 1> NozzlesTheta() {return nozzles_theta_;}
45  Eigen::Matrix<float, 6, 1> ServoCurrent() {return servo_current_;}
46  float MotorSpeed() {return last_speed_;}
47 
48  private:
49  void ServoModel(const Eigen::Matrix<float, 6, 1> & servo_cmd, Eigen::Matrix<float, 6, 1> & nozzle_theta,
50  Eigen::Matrix<float, 6, 1> & nozzle_area);
51  void ImpellerModel(int speed_cmd, float voltage, float* motor_current, float* motor_torque);
52  Eigen::Matrix<float, 6, 1> Aerodynamics(const Eigen::Matrix<float, 6, 1> & nozzle_area);
53  void BlowerBodyDynamics(const Eigen::Vector3f & omega_body, Eigen::Matrix<float, 6, 1> & nozzle_thrusts,
54  float motor_torque);
55 
56  Eigen::Matrix<float, 6, 1> prev_omega_, servo_thetas_, backlash_theta_, discharge_coeff_;
57  Eigen::Matrix<float, 6, 3> nozzle_offsets_, nozzle_orientations_;
58  Eigen::Vector3f center_of_mass_, impeller_orientation_;
59  PID servo_pids_[6], speed_pid_;
60  float prev_speed_rate_;
61  float zero_thrust_area_;
62  // outputs
63  Eigen::Vector3f force_B_, torque_B_;
64  Eigen::Matrix<float, 6, 1> nozzles_theta_, servo_current_;
65  float impeller_speed_, last_speed_;
66  float impeller_current_;
67 };
68 
69 class PMCSim {
70  public:
71  PMCSim();
72  virtual void Step();
73  virtual void SetAngularVelocity(float x, float y, float z);
74  virtual void SetBatteryVoltage(float voltage);
75 
76  void SetImpellerCmd(int blower, unsigned char cmd) {impeller_cmd_[blower] = cmd;}
77  unsigned char ImpellerCmd(int blower) {return impeller_cmd_[blower];}
78  void SetServoCmd(int blower, int index, float value) {servo_cmd_[blower][index] = value;}
79  float MotorSpeed(int blower) {return (blower == 0) ? b1.MotorSpeed() : b2.MotorSpeed();}
80  Eigen::Vector3f Force() {return b1.Force() + b2.Force();}
81  Eigen::Vector3f Torque() {return b1.Torque() + b2.Torque();}
82 
83  private:
84  Blower b1, b2;
85  Eigen::Vector3f omega_;
86  float voltage_;
87  unsigned char impeller_cmd_[2];
88  Eigen::Matrix<float, 6, 1> servo_cmd_[2];
89 };
90 
91 } // end namespace pmc
92 
93 #endif // PMC_PMC_SIM_H_
pmc::PMCSim::SetServoCmd
void SetServoCmd(int blower, int index, float value)
Definition: pmc_sim.h:78
pmc::PID::Initialize
void Initialize(float Kp, float Ki, float Kd, float out_max, float out_min)
Definition: pmc_sim.cc:25
pmc::Blower::Blower
Blower(bool is_pmc1)
Definition: pmc_sim.cc:46
pmc::PID::Run
float Run(float x)
Definition: pmc_sim.cc:34
pmc::Blower::NozzlesTheta
Eigen::Matrix< float, 6, 1 > NozzlesTheta()
Definition: pmc_sim.h:44
pmc::PMCSim::PMCSim
PMCSim()
Definition: pmc_sim.cc:166
pmc::PMCSim::SetAngularVelocity
virtual void SetAngularVelocity(float x, float y, float z)
Definition: pmc_sim.cc:178
pmc::PMCSim::Torque
Eigen::Vector3f Torque()
Definition: pmc_sim.h:81
pmc::Blower::Force
Eigen::Vector3f Force()
Definition: pmc_sim.h:41
pmc::Blower::ImpellerCurrent
float ImpellerCurrent()
Definition: pmc_sim.h:43
pmc::PMCSim::SetImpellerCmd
void SetImpellerCmd(int blower, unsigned char cmd)
Definition: pmc_sim.h:76
pmc::PMCSim::Step
virtual void Step()
Definition: pmc_sim.cc:173
pmc::Blower::MotorSpeed
float MotorSpeed()
Definition: pmc_sim.h:46
pmc::PMCSim::SetBatteryVoltage
virtual void SetBatteryVoltage(float voltage)
Definition: pmc_sim.cc:182
pmc::PMCSim::ImpellerCmd
unsigned char ImpellerCmd(int blower)
Definition: pmc_sim.h:77
pmc::PID
Definition: pmc_sim.h:26
pmc::PMCSim::Force
Eigen::Vector3f Force()
Definition: pmc_sim.h:80
pmc::Blower::ServoCurrent
Eigen::Matrix< float, 6, 1 > ServoCurrent()
Definition: pmc_sim.h:45
pmc::Blower::Torque
Eigen::Vector3f Torque()
Definition: pmc_sim.h:42
pmc
Definition: fam.h:24
pmc::PMCSim
Definition: pmc_sim.h:69
pmc::Blower
Definition: pmc_sim.h:37
pmc::PMCSim::MotorSpeed
float MotorSpeed(int blower)
Definition: pmc_sim.h:79
pmc::Blower::Step
void Step(int impeller_cmd, Eigen::Matrix< float, 6, 1 > &servo_cmd, Eigen::Vector3f &omega, float voltage)
Definition: pmc_sim.cc:140