def posvelatt(self, jd):
     jdsec = jd * common.secofday
     pos, vel =self.orbit.posvelatt(jdsec)
     
     # sunpos, sunvel at jd
     spos, svel = common.SPKposvel(10, jd)
     return pos + spos, vel + svel
 def fix_state(self, jd, ppos, pvel):
     self.jd = jd
     self.sunpos, self.sunvel = common.SPKposvel(10, self.jd)
     jdsec = self.jd * common.secofday
     self.ppos = ppos
     self.pvel = pvel
     pos = self.ppos - self.sunpos
     vel = self.pvel - self.sunvel
     self.orbit.setOrbCart(jdsec, pos, vel)
     return
    def redrawTargetFromSSVG(self):
        status = self.savedstatus
        target_pos, target_vel = g.mytarget.posvel(status[0])
        sun_pos, sun_vel = common.SPKposvel(10, status[0])

        # adjust center of image
        xlim = g.ax.get_xlim3d()
        hw = (xlim[1] - xlim[0]) * 0.5
        if self.ui.tobarycenter.isChecked():
            cent = [0.0, 0.0, 0.0]
        elif self.ui.toprobe.isChecked():
            cent = status[1:4]
        else:
            cent = target_pos
        g.ax.set_xlim3d(cent[0]-hw, cent[0]+hw)
        g.ax.set_ylim3d(cent[1]-hw, cent[1]+hw)
        g.ax.set_zlim3d(cent[2]-hw, cent[2]+hw)

        # Planets
        remove_planets()
        if self.ui.showplanets.isChecked():
            replot_planets(status[0])
        
        # Kepler Orbit of target
        xs, ys, zs, ts = g.mytarget.points(status[0], g.ndata)
        g.target_Kepler = [xs, ys, zs]
        erase_TKepler()
        if self.ui.check_TKepler.isChecked():
            draw_TKepler()

        # Target mark
        if self.artist_of_target is not None:
            self.artist_of_target.remove()
            self.artist_of_target = None
        self.artist_of_target = g.ax.scatter(*target_pos, s=50, c='g',
                                             depthshade=False, marker='+')
        
        # display relative position and velocity
        rel_pos = target_pos - status[1:4]
        rel_pos = common.eclv2lv(rel_pos, status[1:4], 
                                 status[4:], sun_pos, sun_vel)
        trange, tphi, telv = common.rect2polar(rel_pos)
        rel_vel = target_vel - status[4:]
        rel_vel = common.eclv2lv(rel_vel, status[1:4], 
                                 status[4:], sun_pos, sun_vel)
        relabsvel, tvphi, tvelv = common.rect2polar(rel_vel)
        losvel = np.dot(rel_vel, rel_pos) / trange
        self.ui.RPTrange.setText('{:.3f}'.format(trange / 1000.0))
        self.ui.RPTphi.setText('{:.2f}'.format(tphi))
        self.ui.RPTelv.setText('{:.2f}'.format(telv))
        self.ui.RVTvel.setText('{:.3f}'.format(relabsvel))
        self.ui.RVTphi.setText('{:.2f}'.format(tvphi))
        self.ui.RVTelv.setText('{:.2f}'.format(tvelv))
        self.ui.LoSVvel.setText('{:.3f}'.format(losvel))
Exemplo n.º 4
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)
Exemplo n.º 5
0
 def points(self, jd, ndata):
     sunpos, sunvel = common.SPKposvel(10, jd)
     tpos, tvel = self.posvel(jd)
     tpos -= sunpos
     tvel -= sunvel
     orbit = TwoBodyOrbit(self.name, 'Sun', common.solarmu)
     orbit.setOrbCart(0.0, tpos, tvel)
     xs, ys, zs, ts = orbit.points(ndata)
     xs += sunpos[0]
     ys += sunpos[1]
     zs += sunpos[2]
     ts /= common.secofday
     return xs, ys, zs, ts
 def fta(self, jd, tepos):
     # compute fixed time arrival guidance
     # jd : date of arrival
     # tepos position of target at jd (barycenter origin)
     dsec = (jd - self.jd) * common.secofday
     ipos = self.ppos - self.sunpos
     
     # sun position at end
     esunpos, esunvel = common.SPKposvel(10, jd)
     
     tpos = tepos - esunpos
     ivel, tvel = lambert(ipos, tpos, dsec, common.solarmu, ccw=True)
     iprobe_vel = self.pvel - self.sunvel
     delta_v = ivel - iprobe_vel
     
     localdv = common.eclv2lv(delta_v, self.ppos, self.pvel, self.sunpos, 
                              self.sunvel)
     return common.rect2polar(localdv)
Exemplo n.º 7
0
def replot_planets(jd):
    markx = []
    marky = []
    markz = []
    names = []
    id_of_target = g.mytarget.getID()
    id_of_Moon = 301
    id_of_Pluto = 9

    for iplanet in g.i_planetnames:
        planet_id = common.planets_id[iplanet[1]]
        if planet_id[0] == id_of_target: continue
        if planet_id[0] == id_of_Pluto: continue
        pos, vel = common.SPKposvel(planet_id[0], jd)
        markx.append(pos[0])
        marky.append(pos[1])
        markz.append(pos[2])
        if planet_id[0] == id_of_Moon:
            names.append('')
        else:
            names.append(iplanet[0])

    g.artist_mark_of_planets = g.ax.scatter(markx,
                                            marky,
                                            markz,
                                            marker='+',
                                            s=20,
                                            c='c',
                                            depthshade=False)
    g.artist_name_of_planets = []
    for i in range(len(names)):
        g.artist_name_of_planets.append(
            g.ax.text(markx[i],
                      marky[i],
                      markz[i],
                      ' ' + names[i],
                      color='c',
                      fontsize=9))
    def ftavel(self, jd, tepos):
        # compute fixed time arrival guidance
        # jd : date of arrival
        # tepos position of target at jd (barycenter origin)
        dsec = (jd - self.jd) * common.secofday
        ipos = self.ppos - self.sunpos
        
        # sun position and velocity at end
        esunpos, esunvel = common.SPKposvel(10, jd)
        
        tpos = tepos - esunpos
        ivel, tvel = lambert(ipos, tpos, dsec, common.solarmu, ccw=True)
        iprobe_vel = self.pvel - self.sunvel
        delta_v = ivel - iprobe_vel
        localdv = common.eclv2lv(delta_v, self.ppos, self.pvel, self.sunpos, 
                                 self.sunvel)
        dv, phi, elv = common.rect2polar(localdv)
        
        bc_ivel = ivel + self.sunvel
        bc_tvel = tvel + esunvel

        # returns intial velocity and terminal velocity (SSB origin)
        return dv, phi, elv, bc_ivel, bc_tvel
Exemplo n.º 9
0
    def draworbit(self):
        self.clearSysMes()
        self.ui.finishbutton.setEnabled(False)        
        
        # erase positions and orbit
        if self.artist_PCpos is not None:
            self.artist_PCpos.remove()
            self.artist_PCpos = None
        if self.artist_PEpos is not None:
            self.artist_PEpos.remove()
            self.artist_PEpos = None
        if self.artist_TCpos is not None:
            self.artist_TCpos.remove()
            self.artist_TCpos = None
        if self.artist_Porbit is not None:
            self.artist_Porbit[0].remove()
            self.artist_Porbit = None

        # Check time
        tsjd, tejd = g.mytarget.getsejd()
        if self.itcurrent < tsjd or self.itcurrent >= tejd:
            self.dispSysMes(self.sysMes01)
            return
        if self.ttcurrent < tsjd or self.ttcurrent >= tejd:
            self.dispSysMes(self.sysMes02)
            return

        ppos, pvel = self.orgorbposvel(self.itcurrent)
        
        if self.artist_sol is not None:
            self.artist_sol.remove()
            self.artist_sol = None
        
        # FTA
        ttpos, ttvel = g.mytarget.posvel(self.ttcurrent)
        self.predorbit.fix_state(self.itcurrent, ppos, pvel)
        if self.itcurrent + common.minft >= self.ttcurrent:
            self.dispSysMes(self.sysMes03)
            return
        try:
            dv, phi, elv, ivel, tvel = self.predorbit.ftavel(self.ttcurrent, 
                                                             ttpos)
        except ValueError:
            self.dispSysMes(self.sysMes03)
            return

        self.predorbit.fix_state(self.itcurrent, ppos, ivel)
        
        # Draw
        targetpos, targetvel = g.mytarget.posvel(self.itcurrent)
        self.artist_PCpos = g.ax.scatter(*ppos, s=40, c='r',depthshade=False, 
                                         marker='x')
        self.artist_TCpos = g.ax.scatter(*targetpos, s=50, c='g',
                                         depthshade=False, marker='+')
        self.artist_PEpos = g.ax.scatter(*ttpos, s=40, c='b',depthshade=False, 
                                         marker='x')
        sunpos, sunvel = common.SPKposvel(10, self.itcurrent)
        self.artist_sol = g.ax.scatter(*sunpos, s=50, c='#FFAF00',depthshade=False, 
                                       marker='o')
        if self.ui.check_Ppred.isChecked():
            x, y, z, t = self.predorbit.points(g.ndata_s)
            self.artist_Porbit = g.ax.plot(x, y, z,color='c', lw=0.75)

        if g.fig is not None: plt.draw()
        self.ui.finishbutton.setEnabled(True)
        
        # Print
        idv = ivel - pvel
        idvabs = np.sqrt(np.dot(idv, idv))
        if self.statIDVmin is None:
            self.statIDVmin = idvabs
        elif idvabs < self.statIDVmin:
            self.statIDVmin = idvabs
        if self.statIDVmax is None:
            self.statIDVmax = idvabs
        elif idvabs > self.statIDVmax:
            self.statIDVmax = idvabs
        self.ui.initialDV_cur.setText('{:.3f}'.format(idvabs))
        self.ui.initialDV_min.setText('{:.3f}'.format(self.statIDVmin))
#        self.ui.initialDV_max.setText('{:.3f}'.format(self.statIDVmax))
        
        self.ui.idv_phi.setText('{:.2f}'.format(phi))
        self.ui.idv_elv.setText('{:.2f}'.format(elv))
        
        self.result_it = self.itcurrent
        self.result_dv = round(dv, 3)
        self.result_phi = round(phi, 2)
        self.result_elv = round(elv, 2)
        self.result_tt = self.ttcurrent
        
        trv = ttvel - tvel
        trvabs = np.sqrt(np.dot(trv, trv))
        if self.statTRVmin is None:
            self.statTRVmin = trvabs
        elif trvabs < self.statTRVmin:
            self.statTRVmin = trvabs
        if self.statTRVmax is None:
            self.statTRVmax = trvabs
        elif trvabs > self.statTRVmax:
            self.statTRVmax = trvabs
        self.ui.terminalRV_cur.setText('{:.3f}'.format(trvabs))
        self.ui.terminalRV_min.setText('{:.3f}'.format(self.statTRVmin))
#        self.ui.terminalRV_max.setText('{:.3f}'.format(self.statTRVmax))
        
        tdv = idvabs + trvabs
        if self.statTDVmin is None:
            self.statTDVmin = tdv
        elif tdv < self.statTDVmin:
            self.statTDVmin = tdv
        if self.statTDVmax is None:
            self.statTDVmax = tdv
        elif tdv > self.statTDVmax:
            self.statTDVmax = tdv
        self.ui.totalDV_cur.setText('{:.3f}'.format(tdv))
        self.ui.totalDV_min.setText('{:.3f}'.format(self.statTDVmin))
    def drawman(self):
        record = g.myprobe.trj_record[self.man_index]
        mantype = record[0]['type']
        self.c_maninfo = record[0]
        self.c_mantype = mantype
        self.mantext = '   ' + str(self.man_index + 1) + ' ' + mantype
        status = np.zeros(7)
        self.ui.sysMessage.appendPlainText(self.sysMes02.format(self.c_mantype, self.man_index+1))
        self.ui.sysMessage.centerCursor()
        if mantype == 'FLYTO':
            status[0] = record[1][0]
            status[1] = record[2][0]
            status[2] = record[3][0]
            status[3] = record[4][0]
            status[4] = record[5][0]
            status[5] = record[6][0]
            status[6] = record[7][0]
            ssacc = record[8][0]
            self.last_trj = record[1:]
            if self.fromNextman:
                self.c_index = len(self.last_trj[0]) - 1
                self.ui.fastbackward.setEnabled(True)
                self.ui.backward.setEnabled(True)
                self.ui.forward.setEnabled(False)
                self.ui.fastforward.setEnabled(False)
            else:
                self.c_index = 0
                self.ui.fastbackward.setEnabled(False)
                self.ui.backward.setEnabled(False)
                self.ui.forward.setEnabled(True)
                self.ui.fastforward.setEnabled(True)
            self.ui.timescale.setEnabled(True)
            self.ui.label_2.setEnabled(True)
            if self.c_maninfo['epon']:
                self.mantext = self.mantext + ' EP(' + \
                                self.c_maninfo['epmode'] + ')'
            if self.c_maninfo['sson']:
                self.mantext = self.mantext + ' SS(' + \
                                self.c_maninfo['ssmode'] + ')'
        else:
            status = record[1]
            self.ui.fastbackward.setEnabled(False)
            self.ui.backward.setEnabled(False)
            self.ui.forward.setEnabled(False)
            self.ui.fastforward.setEnabled(False)
            self.ui.timescale.setEnabled(False)
            self.ui.label_2.setEnabled(False)

        self.savedstatus = np.copy(status)        
        
        if mantype == 'START':
            self.ui.starttime.setText(common.jd2isot(record[1][0]))
            self.start_time = status[0]
        target_pos, target_vel = g.mytarget.posvel(status[0])

        erase_Ptrj()
        if self.ui.check_Ptrj.isChecked():
            draw_Ptrj()

        # Kepler Orbit of target
        xs, ys, zs, ts = g.mytarget.points(status[0], g.ndata)
        g.target_Kepler = [xs, ys, zs]
        erase_TKepler()
        if self.ui.check_TKepler.isChecked():
            draw_TKepler()

        self.mainwindow.ui.manplans.selectRow(self.man_index)
        if mantype == 'FLYTO':
            self.drawFLYTO()
            return
        
        # adjust center of image
        xlim = g.ax.get_xlim3d()
        hw = (xlim[1] - xlim[0]) * 0.5
        if self.ui.tobarycenter.isChecked():
            cent = [0.0, 0.0, 0.0]
        elif self.ui.toprobe.isChecked():
            cent = status[1:4]
        else:
            cent = target_pos
        g.ax.set_xlim3d(cent[0]-hw, cent[0]+hw)
        g.ax.set_ylim3d(cent[1]-hw, cent[1]+hw)
        g.ax.set_zlim3d(cent[2]-hw, cent[2]+hw)

        # Kepler Orbit of probe        
        erase_PKepler()
        if self.ui.check_PKepler.isChecked():
            self.tbpred.fix_state(status[0], status[1:4], status[4:])
            x, y, z, t = self.tbpred.points(g.ndata)
            g.probe_Kepler = [x, y, z]
            if self.ui.check_PKepler.isChecked():
                draw_PKepler()
        
        # Planets
        remove_planets()
        if self.ui.showplanets.isChecked():
            replot_planets(status[0])

        # Probe mark
        if self.artist_of_probe is not None:
            self.artist_of_probe.remove()
            self.artist_of_probe = None
        self.artist_of_probe = g.ax.scatter(*status[1:4], s=40, c='r',
                                            depthshade=False, marker='x')
        
        # Maneuver Type
        if self.artist_of_type is not None:
            self.artist_of_type.remove()
            self.artist_of_type = None
        if self.ui.showmantype.isChecked():
            self.artist_of_type = g.ax.text(*status[1:4], self.mantext, 
                                            color='r', fontsize=10)
        
        # Target mark
        if self.artist_of_target is not None:
            self.artist_of_target.remove()
            self.artist_of_target = None
        self.artist_of_target = g.ax.scatter(*target_pos, s=50, c='g',
                                             depthshade=False, marker='+')
        
        # Sun mark
        if self.artist_of_sun is not None:
            self.artist_of_sun.remove()
            self.artist_of_sun = None
        sun_pos, sun_vel = common.SPKposvel(10, status[0])
        self.artist_of_sun = g.ax.scatter(*sun_pos, s=50, c='#FFAF00',
                                          depthshade=False, marker='o')
        
        # time
        remove_time()
        replot_time(status[0], self.timecap_real)
        
        if g.fig is not None: plt.draw()
        
        # display relative position and velocity, and time
        rel_pos = target_pos - status[1:4]
        rel_pos = common.eclv2lv(rel_pos, status[1:4], status[4:], sun_pos, 
                                 sun_vel)
        trange, tphi, telv = common.rect2polar(rel_pos)
        rel_vel = target_vel - status[4:]
        rel_vel = common.eclv2lv(rel_vel, status[1:4], status[4:], sun_pos, 
                                 sun_vel)
        relabsvel, tvphi, tvelv = common.rect2polar(rel_vel)
        losvel = np.dot(rel_vel, rel_pos) / trange
        self.ui.RPTrange.setText('{:.3f}'.format(trange / 1000.0))
        self.ui.RPTphi.setText('{:.2f}'.format(tphi))
        self.ui.RPTelv.setText('{:.2f}'.format(telv))
        self.ui.RVTvel.setText('{:.3f}'.format(relabsvel))
        self.ui.RVTphi.setText('{:.2f}'.format(tvphi))
        self.ui.RVTelv.setText('{:.2f}'.format(tvelv))
        self.ui.LoSVvel.setText('{:.3f}'.format(losvel))
        delta_jd = status[0] - self.start_time
        self.ui.currenttime.setText(common.jd2isot(status[0]))
        self.ui.delta_t_edit.setText('{:.8f}'.format(delta_jd))
    def drawFLYTO(self):
        c_time = self.last_trj[0][self.c_index]
        delta_jd = c_time - self.start_time
        self.ui.currenttime.setText(common.jd2isot(c_time))
        self.ui.delta_t_edit.setText('{:.8f}'.format(delta_jd))
        
        ppos = np.zeros(3)
        pvel = np.zeros(3)

        ppos[0] = self.last_trj[1][self.c_index]
        ppos[1] = self.last_trj[2][self.c_index]
        ppos[2] = self.last_trj[3][self.c_index]
        pvel[0] = self.last_trj[4][self.c_index]
        pvel[1] = self.last_trj[5][self.c_index]
        pvel[2] = self.last_trj[6][self.c_index]
        ssacc = self.last_trj[7][self.c_index]
        
        self.savedstatus[0] = np.copy(c_time)
        self.savedstatus[1:4] = np.copy(ppos)
        self.savedstatus[4:7] = np.copy(pvel)

        erase_PKepler()
        if self.ui.check_PKepler.isChecked():
            self.tbpred.fix_state(c_time, ppos, pvel)
            x, y, z, t = self.tbpred.points(g.ndata_s)
            g.probe_Kepler = [x, y, z]
            draw_PKepler()

        target_pos, target_vel = g.mytarget.posvel(c_time)
        sun_pos, sun_vel = common.SPKposvel(10, c_time)        

        xlim = g.ax.get_xlim3d()
        hw = (xlim[1] - xlim[0]) * 0.5
        if self.ui.tobarycenter.isChecked():
            cent = [0.0, 0.0, 0.0]
        elif self.ui.toprobe.isChecked():
            cent = ppos
        else:
            cent = target_pos
        
        g.ax.set_xlim3d(cent[0]-hw, cent[0]+hw)
        g.ax.set_ylim3d(cent[1]-hw, cent[1]+hw)
        g.ax.set_zlim3d(cent[2]-hw, cent[2]+hw)

        # redraw planets
        remove_planets()
        if self.ui.showplanets.isChecked():
            replot_planets(c_time)

        if self.artist_of_probe is not None:
            self.artist_of_probe.remove()
            self.artist_of_probe = None
        self.artist_of_probe = g.ax.scatter(*ppos, s=40, c='r',
                                            depthshade=False, marker='x')
        if self.artist_of_target is not None:
            self.artist_of_target.remove()
            self.artist_of_target = None

        # Maneuver Type
        if self.artist_of_type is not None:
            self.artist_of_type.remove()
            self.artist_of_type = None
        if self.ui.showmantype.isChecked():
            acctext = ''
            if self.c_maninfo['sson']:
                acctext = ' SSacc={:.3f}'.format(ssacc)
            if self.c_index == 0:
                self.artist_of_type = g.ax.text(*ppos, self.mantext+acctext+
                    ' (start)', color='r', fontsize=10)
            elif self.c_index + 1 == len(self.last_trj[0]):
                self.artist_of_type = g.ax.text(*ppos, self.mantext+acctext+
                    ' (end)', color='r', fontsize=10)
            else:
                self.artist_of_type = g.ax.text(*ppos, self.mantext+acctext, 
                    color='r', fontsize=10)

        self.artist_of_target = g.ax.scatter(*target_pos, s=50, c='g',
                                             depthshade=False, marker='+')
        if self.artist_of_sun is not None:
            self.artist_of_sun.remove()
            self.artist_of_sun = None
        self.artist_of_sun = g.ax.scatter(*sun_pos, s=50, c='#FFAF00',
                                          depthshade=False, marker='o')

        remove_time()
        replot_time(c_time, self.timecap_real)
        
        if g.fig is not None: plt.draw()
        
        # display relative position and velocity
        rel_pos = target_pos - ppos
        rel_pos = common.eclv2lv(rel_pos, ppos, pvel, sun_pos, sun_vel)
        trange, tphi, telv = common.rect2polar(rel_pos)
        rel_vel = target_vel - pvel
        rel_vel = common.eclv2lv(rel_vel, ppos, pvel, sun_pos, sun_vel)
        relabsvel, tvphi, tvelv = common.rect2polar(rel_vel)
        losvel = np.dot(rel_vel, rel_pos) / trange
        self.ui.RPTrange.setText('{:.3f}'.format(trange / 1000.0))
        self.ui.RPTphi.setText('{:.2f}'.format(tphi))
        self.ui.RPTelv.setText('{:.2f}'.format(telv))
        self.ui.RVTvel.setText('{:.3f}'.format(relabsvel))
        self.ui.RVTphi.setText('{:.2f}'.format(tvphi))
        self.ui.RVTelv.setText('{:.2f}'.format(tvelv))
        self.ui.LoSVvel.setText('{:.3f}'.format(losvel))
Exemplo n.º 12
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'])
Exemplo n.º 13
0
 def posvel(self, jd):
     pos, vel = common.SPKposvel(self.SPKID, jd)
     sunpos, sunvel = common.SPKposvel(10, jd)
     pos = (pos - sunpos) * self.factor + sunpos
     vel = (vel - sunvel) * self.factor + sunvel
     return pos, vel
Exemplo n.º 14
0
    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()