40、伪距计算函数实现

\qquad 下面是HD-GR GNSS导航软件的伪距计算函数实现代码,入口函数calculate_pseudorange(…)

// main_pseudorange.c -- Process measurements into pseudoranges.

/* 
 * Copyright (C) 2005 Andrew Greenberg
 * Distributed under the GNU GENERAL PUBLIC LICENSE (GPL) Version 2 (June 1991).
 * See the "COPYING" file distributed with this software for more information.
 */

/* Namuru GPS receiver project
 * Original : pseudorange.c
 * Modes    : removed includes to gp4020 HW
 * version  : V1.0
 * date     : 21st/Dec/2006
 */

/* 
 * HD-GR GNSS receiver project
 * Modes    : Inherited the code of pseudorange.c in the Namuru GPS receiver  
 *            project V1.0 and made necessary adjustments to adapt to the new  
 *            RTOS and functions.
 * version  : V1.0
 * date     : xx/xx/2015
 */

#include <io.h>
#include <stdio.h>
#include <math.h>
#include  <stdlib.h>
#include "includes.h"
#include "system.h"
#include "altera_avalon_pio_regs.h"
#include "alt_types.h"
#include "sys/alt_irq.h"
#include "main_pseudorange.h"
#include "main_measure.h"
#include "main_position.h"

/******************************************************************************
 * Globals
 ******************************************************************************/

pseudorange_t g_pr[2];
unsigned short g_pr_idx = 0;
pseudorange_t *g_ppr_cur = &g_pr[0];
pseudorange_t *m_ppr_pos = 0;

/******************************************************************************
 * Calculate them pseudoranges.
 ******************************************************************************/
void gps_calculate_pseudorange( unsigned short ch)
{
    // sat_time
	g_ppr_cur->chan_pr[ch].sat_time =
    		m_raw_meas.chan_meas[ch].meas_bit_time*0.02 + GPS_CODE_TIME *
    		( m_raw_meas.chan_meas[ch].epoch_codes +
    		 ( 1/(double)GPS_MAX_CODE_PHASE) *
    		 ( m_raw_meas.chan_meas[ch].code_phase +
    		   m_raw_meas.chan_meas[ch].code_dco_phase / (double)GPS_CODE_DCO_LENGTH)
    		 );

	// range
	g_ppr_cur->chan_pr[ch].range = (g_ppr_cur->pr_time.seconds - g_ppr_cur->chan_pr[ch].sat_time) * SPEED_OF_LIGHT;

	// Record the following information for debugging
	g_ppr_cur->chan_pr[ch].prn = m_raw_meas.chan_meas[ch].prn;
	g_ppr_cur->chan_pr[ch].power = m_raw_meas.chan_meas[ch].power;
}

/******************************************************************************
 * Calculate them pseudoranges.
 ******************************************************************************/
void b1i_calculate_pseudorange( unsigned short ch)
{
    // sat_time
	g_ppr_cur->chan_pr[ch].sat_time =
    		m_raw_meas.chan_meas[ch].meas_bit_time*0.02 + B1I_CODE_TIME *
    		(m_raw_meas.chan_meas[ch].epoch_codes +
    		 (1/(double)B1I_MAX_CODE_PHASE) *
    		 (m_raw_meas.chan_meas[ch].code_phase +
    		  m_raw_meas.chan_meas[ch].code_dco_phase / (double)B1I_CODE_DCO_LENGTH)
    		);

	// range
	g_ppr_cur->chan_pr[ch].range = (g_ppr_cur->pr_time.seconds - g_ppr_cur->chan_pr[ch].sat_time) * SPEED_OF_LIGHT;

	// Record the following information for debugging
	g_ppr_cur->chan_pr[ch].prn = m_raw_meas.chan_meas[ch].prn;
	g_ppr_cur->chan_pr[ch].power = m_raw_meas.chan_meas[ch].power;
}

/******************************************************************************
 * Wake up on valid measurements and produce pseudoranges. Flag the navigation
 * thread if we have four or more valid pseudoranges
 ******************************************************************************/
void calculate_pseudorange(OS_FLAGS measurements_ready)
{
	unsigned short ch;
	unsigned short pr_count;

	// led_turnon(LED3);

	// Copy over the measurement time so we know when the rho's were computed.
	g_ppr_cur->pr_time = m_raw_meas.meas_time;
	g_ppr_cur->pr_tic = m_raw_meas.meas_tic;

	// OK we're awake: for each measurement that we get, (Which we assume
	// is valid, since it wouldn't get up to this thread if it weren't!),
	// produce a pseudorange. Clear it to zero if it's not valid.
	pr_count = 0;
	if (m_sys_posconst & POS_CONSTELL_GPS) {
		for (ch = 0; ch < GPS_MAX_CHANNELS; ch++) {
			if (measurements_ready & (1 << ch)) {
				gps_calculate_pseudorange( ch);
				g_ppr_cur->chan_pr[ch].valid = 1;
				pr_count++;
			}
			else {
				g_ppr_cur->chan_pr[ch].valid = 0;
			}
		}
	}

	if (m_sys_posconst & POS_CONSTELL_BDS) {
		for (ch = GPS_MAX_CHANNELS; ch < TOT_MAX_CHANNELS; ch++) {
			if (measurements_ready & (1 << ch)) {
				b1i_calculate_pseudorange( ch);
				g_ppr_cur->chan_pr[ch].valid = 1;
				pr_count++;
			}
			else {
				g_ppr_cur->chan_pr[ch].valid = 0;
			}
		}
	}

	// If we have any satellites, send them to the position thread. But
	// note that the position thread is going to take a BZILLION years to
	// process it all. Because we want to keep producing psuedoranges while
	// the position thread runs, we copy over the g_ppr_cur's so the position
	// thread can use a private copy.
	if  (pr_count > 0) {
#ifdef GNSS_ENABLE_MUTEX
		OSMutexPend(m_PrCbsMutex, 0, &err);
#endif
		if (m_ppr_pos == 0) {
			m_ppr_pos = g_ppr_cur;
			g_pr_idx = (g_pr_idx+1) & 1;
			g_ppr_cur = &g_pr[g_pr_idx];
#ifdef GNSS_ENABLE_MUTEX
			OSMutexPost(m_PrCbsMutex);
#endif
			// Run the position thread which will clear m_ppr_pos when it's done.
			OSSemPost(m_SemPosi);
        }
#ifdef GNSS_ENABLE_MUTEX
		OSMutexPost(m_PrCbsMutex);
#endif
    }
	// led_turnoff(LED3);
}


  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
### 回答1: 在进行单历元伪距定位的过程中,我们可以利用MATLAB来实现。下面是一种可能的实现方式。 首先,我们需要获取卫星的伪距观测数据和卫星的位置信息。可以通过GNSS接收机来获取伪距观测数据,卫星的位置信息可以通过星历数据获得。在MATLAB中,可以利用内置的函数来读取和处理这些数据。 接下来,我们需要计算接收机的位置。这可以通过解算伪距观测数据来实现。一个常用的方法是使用最小二乘法,通过最小化观测伪距计算伪距之间的差异来估计接收机的位置。MATLAB提供了相应的函数实现最小二乘法。 在计算接收机的位置之后,我们可以使用该位置和卫星的位置来计算接收机和卫星之间的距离。可以使用欧几里得距离公式来计算两点之间的距离。MATLAB提供了相应的函数实现这一计算。 最后,我们可以将计算的距离与卫星的位置信息进行多边定位。通过多边定位,我们可以进一步提高定位精度。在MATLAB中,可以使用三角定位等方法来实现多边定位。 总结起来,MATLAB可以通过读取和处理伪距观测数据和卫星位置信息,以及利用最小二乘法和距离计算公式,实现单历元伪距定位。通过多边定位,我们可以进一步提高定位精度。 ### 回答2: MATLAB可以通过编写适当的代码实现单历元伪距定位。以下是基本的步骤: 1. 获取卫星的位置和伪距值:首先,需要获取卫星的位置信息,可以通过卫星导航系统(例如GPS)提供的数据或者仿真数据获得。同时,还需要获取接收器接收到的单历元(一个瞬间)的伪距值。 2. 准备接收器的位置:将接收器的位置信息作为输入,例如经纬度坐标或笛卡尔坐标。 3. 计算真实距离:根据卫星位置和接收器位置,可以计算出接收器到每个卫星的真实距离。 4. 添加误差模型:真实距离存在一些误差,例如大气延迟、多径效应等。在伪距定位中,这些误差被称为伪距误差。为了更好地估计接收器的位置,需要将这些误差添加到真实距离上。 5. 求解位置:使用伪距值和经过误差修正的真实距离,可以通过最小二乘法或其他定位算法求解接收器的位置。这一步通常需要迭代计算来优化位置解算。 6. 结果分析和可视化:最后,可以对定位结果进行分析和可视化。使用MATLAB的绘图函数可以将接收器的位置在地图上显示出来,或者与真实位置进行对比。 MATLAB提供了许多有用的函数和工具箱,用于处理信号处理、矩阵运算、优化算法等任务,这些都是实现单历元伪距定位所需的。通过编写适当的代码,将以上步骤整合起来,就可以实现单历元伪距定位。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值