示例#1
0
 def pseudostart(self, jd, dv, phi, elv):
     elv = math.radians(elv)
     phi = math.radians(phi)
     ldv = np.array([
         dv * np.cos(elv) * np.cos(phi), 
         dv * np.cos(elv) * np.sin(phi), 
         dv * np.sin(elv)
         ])
     bpos, bvel = self.spacebase.posvel(jd)
     sunpos, sunvel = common.SPKposvel(10, jd)
     return bpos, bvel + common.ldv2ecldv(ldv, bpos, bvel, sunpos, sunvel)
 def _epacc(self, td, y, kernel):
     # comupte acceleration of Electric Propulsion System
     acc = np.array([
         self._epdv * np.cos(self._epelv) * np.cos(self._epphi),
         self._epdv * np.cos(self._epelv) * np.sin(self._epphi),
         self._epdv * np.sin(self._epelv)
     ])
     pos = y[0:3]
     vel = y[3:6]
     sunpos, sunvel = kernel[0, 10].compute_and_differentiate(td)
     sunpos = common.eqn2ecl(sunpos) * 1000.0
     sunvel = common.eqn2ecl(sunvel) * 1000.0 / common.secofday
     return common.ldv2ecldv(acc, pos, vel, sunpos, sunvel)
 def set_pred_dv(self, dv, phi, elv):
     relv = math.radians(elv)
     rphi = math.radians(phi)
     ldv = np.array([
         dv * np.cos(relv) * np.cos(rphi),
         dv * np.cos(relv) * np.sin(rphi),
         dv * np.sin(relv)
         ])
     self.pred_vel = self.pvel + \
         common.ldv2ecldv(ldv, self.ppos, self.pvel, \
         self.sunpos, self.sunvel)
     jdsec = self.jd * common.secofday
     pos = self.ppos - self.sunpos
     vel = self.pred_vel - self.sunvel
     self.orbit.setOrbCart(jdsec, pos, vel)
     return
示例#4
0
    def exec_man(self, man, target, pbar=None, plabel=None, ptext=''):
        if man['type'] != 'START' and not self.onflight:
            return False, self.errormes06.format(man['type'])
        if man['type'] == 'START' and self.onflight:
            return False, self.errormes07.format(man['type'])

        cman = man.copy()
        cman['epon'] = False
        cman['epdvpd'] = 0.0
        cman['epmode'] = 'L'
        cman['sson'] = False
        cman['ssmode'] = 'L'
        status = np.zeros(7)
        tsjd, tejd = target.getsejd()

        if man['type'] == 'START':
            self.jd = man['time']
            if self.jd < tsjd or self.jd >= tejd:
                return False, self.errormes05
            self.pos, self.vel = self.pseudostart(self.jd, dv=man['dv'], 
                                            elv=man['elv'], phi=man['phi'])
            self.orbit.setCurrentCart(self.jd*common.secofday, self.pos, 
                                      self.vel)
            self.onflight = True
            status[0] = self.jd
            status[1:4] = self.pos.copy()
            status[4:] = self.vel.copy()
            self.get_epssstatus(cman)
            self.trj_record.append([cman, status])
            return True, ''
        elif man['type'] == 'CP':
            dv = man['dv']
            elv = math.radians(man['elv'])
            phi = math.radians(man['phi'])
            ldv = np.array([                    \
                dv * np.cos(elv) * np.cos(phi), \
                dv * np.cos(elv) * np.sin(phi), \
                dv * np.sin(elv)                \
                ])
            sunpos, sunvel = common.SPKposvel(10, self.jd)
            self.vel += common.ldv2ecldv(ldv, self.pos, self.vel, sunpos, 
                                         sunvel)
            self.orbit.setCurrentCart(self.jd*common.secofday, self.pos, 
                                      self.vel)
            status[0] = self.jd
            status[1:4] = self.pos.copy()
            status[4:] = self.vel.copy()
            self.get_epssstatus(cman)
            self.trj_record.append([cman, status])
            self.accumdv['CP'] += dv
            return True, ''
        elif man['type'] == 'EP_ON':
            dv = man['dvpd'] / common.secofday
            phi = math.radians(man['phi'])
            elv = math.radians(man['elv'])
            self.orbit.set_epstatus(True, dv, phi, elv, man['tvmode'],
                                    common.SPKkernel)
            status[0] = self.jd
            status[1:4] = self.pos.copy()
            status[4:] = self.vel.copy()
            self.get_epssstatus(cman)
            self.trj_record.append([cman, status])
            return True, ''
        elif man['type'] == 'EP_OFF':
            self.orbit.set_epstatus(False, 0.0, 0.0, 0.0)
            status[0] = self.jd
            status[1:4] = self.pos.copy()
            status[4:] = self.vel.copy()
            self.get_epssstatus(cman)
            self.trj_record.append([cman, status])
            return True, ''
        elif man['type'] == 'SS_ON':
            area = man['area']
            theta = math.radians(man['theta'])
            elv = math.radians(man['elv'])
            self.orbit.set_ssstatus(True, area, theta, elv, man['tvmode'],
                                    common.SPKkernel)
            status[0] = self.jd
            status[1:4] = self.pos.copy()
            status[4:] = self.vel.copy()
            self.get_epssstatus(cman)
            self.trj_record.append([cman, status])
            return True, ''
        elif man['type'] == 'SS_OFF':
            self.orbit.set_ssstatus(False, 0.0, 0.0, 0.0)
            status[0] = self.jd
            status[1:4] = self.pos.copy()
            status[4:] = self.vel.copy()
            self.get_epssstatus(cman)
            self.trj_record.append([cman, status])
            return True, ''
        elif man['type'] == 'FLYTO':
            jdto = man['time']
            if jdto < self.jd:
                return False, self.errormes01
            if jdto >= tejd:
                return False, self.errormes02

            duration = jdto - self.jd
            if pbar is not None:
                pbar.setVisible(True)
                pbar.setValue(0)
                plabel.setText(ptext)
            inter = man['inter'] * common.secofday
            secto = jdto * common.secofday
            pt, px, py, pz, pxd, pyd, pzd, ssdvpd, runerror = self.orbit.trj(
                secto, inter, common.SPKkernel, common.planets_grav, 
                common.planets_mu, common.integ_abs_tol, common.integ_rel_tol, 
                pbar)
            if pbar is not None:
                pbar.setVisible(False)
                plabel.setText('')
            if runerror: 
                lastsuccess = 0.0
                length = len(pt)
                for i in range(length):
                    if pt[i] < 1.0: break
                    lastsuccess = pt[i]
                lastsuccess = lastsuccess / common.secofday
                return False, self.errormes04.format(common.jd2isot(lastsuccess))
            pt = pt / common.secofday
            self.get_epssstatus(cman)
            self.trj_record.append([cman, pt, px, py, pz, pxd, pyd, pzd, 
                                    ssdvpd])
            self.jd = pt[-1]
            self.pos = np.array([px[-1], py[-1], pz[-1]])
            self.vel = np.array([pxd[-1], pyd[-1], pzd[-1]])
            self.orbit.setCurrentCart(self.jd*common.secofday, self.pos, 
                                      self.vel)
            if cman['epon']:
                self.accumdv['EP'] += duration * cman['epdvpd']
            if cman['sson']:
                ssdv = man['inter'] * ssdvpd[0]
                for i in range(1, len(pt)):
                    ssdv += (pt[i] -pt[i-1]) * ssdvpd[i]
                self.accumdv['SS'] += ssdv
            return True, ''
        else:
            return False, self.errormes03.format(man['type'])
    def computefta(self):
        norm = lambda x: x / np.sqrt(np.dot(x, x))
        if g.showorbitcontrol is None:
            QMessageBox.information(self, self.mbTtl07, self.mbMes07,
                                    QMessageBox.Ok)
            return

        ftadialog = FTAsettingDialog(self)
        ans = ftadialog.exec_()
        if ans == QDialog.Rejected:
            return

        jd = g.fta_parameters[0]
        tpos, tvel = g.mytarget.posvel(jd)
        sunpos, sunvel = common.SPKposvel(10, jd)

        if g.fta_parameters[1] == 'OL':
            sr = g.fta_parameters[2][1]
            sphi = g.fta_parameters[2][2]
            selv = g.fta_parameters[2][3]
            vect = common.polar2rect(sr, sphi, selv)
            delta_pos = common.ldv2ecldv(vect, tpos, tvel, sunpos, sunvel)
            tepos = tpos + delta_pos
            try:
                dv, phi, elv = g.showorbitcontrol.tbpred.fta(jd, tepos)
            except ValueError:
                QMessageBox.information(self, self.mbTtl07, self.mbMes08,
                                        QMessageBox.Ok)
                return

            dv = round(dv, 3)
            phi = round(phi, 2)
            elv = round(elv, 2)

            mes = self.mbMes09.format(str(dv), str(phi), str(elv))
            ans = QMessageBox.question(self, self.mbTtl09, mes,
                                       QMessageBox.Ok | QMessageBox.Cancel,
                                       QMessageBox.Cancel)
            if ans == QMessageBox.Ok:
                self.editman['dv'] = dv
                self.editman['phi'] = phi
                self.editman['elv'] = elv
                self.dispman()
                self.dispSysMes(self.sysMes02)
                self.showorbit()

                if g.options['log']:
                    logstring = []
                    logstring.append('apply FTA result: ' + nowtimestr() +
                                     '\n')
                    logstring.append('    target: ' + g.mytarget.name + '\n')
                    logstring.append('    time to arrival: ' +
                                     str(g.fta_parameters[2][0]) + '\n')
                    logstring.append('    Type of Precise Targeting: ' +
                                     'OL coordinates or Center' + '\n')
                    logstring.append('    offset distance: ' +
                                     str(g.fta_parameters[2][1] / 1000.0) +
                                     '\n')
                    logstring.append('    phi: ' +
                                     str(g.fta_parameters[2][2]) + '\n')
                    logstring.append('    elv: ' +
                                     str(g.fta_parameters[2][3]) + '\n')
                    logstring.append('    result dv: ' + str(dv) + '\n')
                    logstring.append('    result phi: ' + str(phi) + '\n')
                    logstring.append('    result elv: ' + str(elv) + '\n')
                    g.logfile.writelines(logstring)
                    g.logfile.flush()

        elif g.fta_parameters[1] == 'BP':
            # compute terminal velocity at Target
            tepos = tpos + np.zeros(3)
            try:
                dv, phi, elv, bc_ivel, bc_tvel              \
                    = g.showorbitcontrol.tbpred.ftavel(jd, tepos)
            except ValueError:
                QMessageBox.information(self, self.mbTtl07, self.mbMes08,
                                        QMessageBox.Ok)
                return

            # compute B-Plane Unit Vectors
            uSvec = norm(bc_tvel - tvel)
            ss_tpos = tpos - sunpos
            ss_tvel = tvel - sunvel
            hvec = np.cross(ss_tpos, ss_tvel)
            uTvec = norm(np.cross(uSvec, hvec))
            uRvec = norm(np.cross(uSvec, uTvec))

            # get Precise Targeting Parameters
            sr = g.fta_parameters[2][1]
            sbeta = g.fta_parameters[2][2]
            rbeta = math.radians(sbeta)

            # compute delta_pos
            delta_pos = sr * (np.cos(rbeta) * uTvec + np.sin(rbeta) * uRvec)

            # FTA computing
            tepos = tpos + delta_pos
            try:
                dv, phi, elv = g.showorbitcontrol.tbpred.fta(jd, tepos)
            except ValueError:
                QMessageBox.information(self, self.mbTtl07, self.mbMes08,
                                        QMessageBox.Ok)
                return

            dv = round(dv, 3)
            phi = round(phi, 2)
            elv = round(elv, 2)

            mes = self.mbMes09.format(str(dv), str(phi), str(elv))
            ans = QMessageBox.question(self, self.mbTtl09, mes,
                                       QMessageBox.Ok | QMessageBox.Cancel,
                                       QMessageBox.Cancel)
            if ans == QMessageBox.Ok:
                self.editman['dv'] = dv
                self.editman['phi'] = phi
                self.editman['elv'] = elv
                self.dispman()
                self.dispSysMes(self.sysMes02)
                self.showorbit()

                if g.options['log']:
                    logstring = []
                    logstring.append('apply FTA result: ' + nowtimestr() +
                                     '\n')
                    logstring.append('    target: ' + g.mytarget.name + '\n')
                    logstring.append('    time to arrival: ' +
                                     str(g.fta_parameters[2][0]) + '\n')
                    logstring.append('    Type of Precise Targeting: ' +
                                     'BP (B-plane coordinates)' + '\n')
                    logstring.append('    offset distance: ' +
                                     str(g.fta_parameters[2][1] / 1000.0) +
                                     '\n')
                    logstring.append('    beta: ' +
                                     str(g.fta_parameters[2][2]) + '\n')
                    logstring.append('    result dv: ' + str(dv) + '\n')
                    logstring.append('    result phi: ' + str(phi) + '\n')
                    logstring.append('    result elv: ' + str(elv) + '\n')
                    g.logfile.writelines(logstring)
                    g.logfile.flush()