void pebble_edge_t::get_plan(sim::plan_t& computed_plan, util::undirected_vertex_index_t source)
 {
     if( source == v_source )
         get_plan(computed_plan, p_source);
     else
     {
         get_plan(computed_plan, p_target);
     }
 }
void ext_model::update( double time )
{
    view::update(time);

    double const fms_calc_step = cfg().model_params.msys_step;
    if(pilot_impl_)
    {
        double dt = last_time_ ? time - *last_time_ : 0.;

#if 0
        if (!cg::eq_zero(dt))
        {
            geo_base_3 prev_pos = pilot_impl_->state().dyn_state.pos;
            if (dt > 0)
            {
                size_t steps = cg::floor(dt / fms_calc_step + fms_calc_step * .1);
                fms::pilot_simulation_ptr pilot_sim(pilot_impl_);
                for (size_t i = 0; i < steps; ++i)
                {
                    pilot_sim->update(fms_calc_step);
                }
            }

            point_3 offset = prev_pos(pilot_impl_->state().dyn_state.pos);

            double course = pilot_impl_->state().dyn_state.course;
            double roll = pilot_impl_->roll();

            cpr orien(course, polar_point_3(offset).pitch, roll);
            
            set_state(state_t(pilot_impl_->state(), orien.pitch, orien.roll, state_.version + 1), false);

            if (pilot_impl_->instrument() && pilot_impl_->instrument_ended())
            {
                fms::plan_t plan;
                if (get_plan().size() > 1)
                {
                    auto tmp_plan = fms::plan_t(get_plan().begin()+1, get_plan().end());
                    std::swap(plan, tmp_plan);
                }
                else if (pilot_impl_->instrument()->kind() == fms::INSTRUMENT_APPROACH && pilot_impl_->state().dyn_state.cfg != fms::CFG_GD)
                {
                    plan.push_back(fms::create_direction_instrument(boost::none, get_instruments_env())) ;
                }

                set_plan(plan);
            }
        }
#endif

    }

    last_time_ = time;
}
void ext_model::init_fms()
{
    if (!fsettings() || !get_meteo_proxy())
        return ;

    fms::pilot_state_t fmsst = get_state();

    ada::data_t const& fsetttings = *fsettings();
    fms::aircraft_data_t adata(fsetttings, payload_ * fsetttings.max_payload_mass);

    pilot_impl_ = fms::create_aircraft_pilot(get_meteo_proxy(), fmsst, adata);      

    fms::pilot_control_ptr(pilot_impl_)->set_instrument(!get_plan().empty() ? get_plan().front() : fms::instrument_ptr());
}
Exemplo n.º 4
0
/**
 * Converts the contents of input_buff from the frequency domain
 * to the time domain, omitting the 1/N factor.
 *
 * input_buff: input in half complex array format.
 * output_buff: output of real values (because the IFFT of a 
 *              halfcomplex (eg symmetric) sequency is purely real.
 * 
 * Since this function uses FFTW to compute the inverse FFT,
 * the result is not scaled by the 1/N factor that it should be.
 * In our implementation, the impulse response of the filter
 * is prescaled scaled by 1/N so we get the correct answer.
 *
 * Note that this function trashes the values in input_buff.
 **/
void convert_from_freq(void* thisptr, float* input_buff, float* output_buff, int size) 
{
  struct rfftw_plan_list *plan;

  /* Start off by finding the plan pair, or creating one. */
  plan = get_plan(size);

  /* Run the backward FFT (destroys the contents of input_buff) */
  // reverse is specified by the plan. Then comes input followed by output.
  
  rfftw_one(plan->ctor_plan, (fftw_real *)input_buff, (fftw_real *)output_buff);
  
  /** and we are done. Return value is the input_buffer parameter. **/
}
Exemplo n.º 5
0
/**
 * Create plan.
 * @param j_plan
 * @return
 */
bool create_plan(const struct ast_json* j_plan)
{
	int ret;
	char* uuid;
	struct ast_json* j_tmp;
	char* tmp;

	if(j_plan == NULL) {
		return false;
	}

	j_tmp = ast_json_deep_copy(j_plan);
	uuid = gen_uuid();
	ast_json_object_set(j_tmp, "uuid", ast_json_string_create(uuid));

	tmp = get_utc_timestamp();
	ast_json_object_set(j_tmp, "tm_create", ast_json_string_create(tmp));
	ast_free(tmp);

	ast_log(LOG_NOTICE, "Create plan. uuid[%s], name[%s]\n",
			ast_json_string_get(ast_json_object_get(j_tmp, "uuid")),
			ast_json_string_get(ast_json_object_get(j_tmp, "name"))? : "<unknown>"
			);
	ret = db_insert("plan", j_tmp);
	AST_JSON_UNREF(j_tmp);
	if(ret == false) {
		ast_free(uuid);
		return false;
	}
	ast_log(LOG_VERBOSE, "Finished insert.\n");

	// send ami event
	j_tmp = get_plan(uuid);
	ast_log(LOG_VERBOSE, "Check plan info. uuid[%s]\n",
			ast_json_string_get(ast_json_object_get(j_tmp, "uuid"))
			);
	ast_free(uuid);
	if(j_tmp == NULL) {
		ast_log(LOG_ERROR, "Could not get created plan info.");
		return false;
	}
	send_manager_evt_out_plan_create(j_tmp);
	AST_JSON_UNREF(j_tmp);

	return true;
}
Exemplo n.º 6
0
/**
 * Replaces the contents of input_buff with the value of its FFT.
 * input_buff: input (real format)/output (halfcomplex format)
 *
 * Since buff is a assumed completly real, the corresponding complex
 * valued FFT(input_buff) is stored in the "half complex array" format of
 * fftw (see http://www.fftw.org/doc/fftw_2.html#SEC5)
 **/
void convert_to_freq(void* thisptr, float* input_buff, int size) 
{
  struct rfftw_plan_list *plan;
  int i;

  /* Start off by finding the plan pair, or creating one. */
  plan = get_plan(size);

  /* Run the forward FFT on the input buffer, saving the result
     into the plan's buffer. */
  rfftw_one(plan->rtoc_plan, (fftw_real *)input_buff, (fftw_real *)plan->buff);

  /* copy the values from the plan buffer (eg the output) into the 
   * input buffer (return value is passed via input). **/
  for (i=0; i<size; i++) {
    input_buff[i] = plan->buff[i];
  }

  /** and we are done. Return value is the input_buffer parameter. **/
}
void ext_model::on_plan_changed()
{
    view::on_plan_changed();

    fms::pilot_control_ptr(pilot_impl_)->set_instrument(!get_plan().empty() ? get_plan().front() : fms::instrument_ptr());
}
Exemplo n.º 8
0
/**
 * Update plan
 * @param j_plan
 * @return
 */
bool update_plan(const struct ast_json* j_plan)
{
	char* tmp;
	const char* tmp_const;
	char* sql;
	struct ast_json* j_tmp;
	int ret;
	char* uuid;

	if(j_plan == NULL) {
		return false;
	}

	j_tmp = ast_json_deep_copy(j_plan);
	if(j_tmp == NULL) {
		return false;
	}

	tmp_const = ast_json_string_get(ast_json_object_get(j_tmp, "uuid"));
	if(tmp_const == NULL) {
		ast_log(LOG_WARNING, "Could not get uuid.\n");
		AST_JSON_UNREF(j_tmp);
		return false;
	}
	uuid = ast_strdup(tmp_const);

	tmp = get_utc_timestamp();
	ast_json_object_set(j_tmp, "tm_update", ast_json_string_create(tmp));
	ast_free(tmp);

	tmp = db_get_update_str(j_tmp);
	if(tmp == NULL) {
		ast_log(LOG_WARNING, "Could not get update str.\n");
		AST_JSON_UNREF(j_tmp);
		ast_free(uuid);
		return false;
	}
	AST_JSON_UNREF(j_tmp);

	ast_asprintf(&sql, "update plan set %s where in_use=%d and uuid=\"%s\";", tmp, E_DL_USE_OK, uuid);
	ast_free(tmp);

	ret = db_exec(sql);
	ast_free(sql);
	if(ret == false) {
		ast_log(LOG_WARNING, "Could not update plan info. uuid[%s]\n", uuid);
		ast_free(uuid);
		return false;
	}

	j_tmp = get_plan(uuid);
	ast_free(uuid);
	if(j_tmp == NULL) {
		ast_log(LOG_WARNING, "Could not get updated plan info.\n");
		return false;
	}
	send_manager_evt_out_plan_update(j_tmp);
	AST_JSON_UNREF(j_tmp);

	return true;
}