/*
 * Simulation initialization
 */
Loop_inputs* init_simulation()
{
	// -- Variables declaration -- //
	
	int i;
	int model_state_size;

    double *ystart;

	MBSdataStruct *MBSdata   = NULL;
	LocalDataStruct *lds     = NULL;
	Loop_inputs *loop_inputs = NULL;

	#if defined(JNI) & defined (REAL_TIME)
	JNI_struct* jni_struct = NULL;
	#endif

	#ifdef WRITE_FILES
	Write_files *write_files;
	#endif

	#ifdef YARP
    void* RobotranYarp_interface = NULL;
    #endif

	struct timeval seed_time;

	// -- Seed for random -- //

	gettimeofday(&seed_time, NULL);
	srand(seed_time.tv_usec * seed_time.tv_sec);
    
    // -- Variables initialization -- //

    MBSdata = loadMBSdata_xml(MBS_FILE);

	if(MBSdata == NULL)
	{
        printf("error while loading MBSdata \n");
	}
	#ifdef PRINT_REPORT
	else
	{
        printf("MBSdata successfully loaded \n");
	}
	#endif

    // LocalDataStruct initialization

    #if !defined ACCELRED
    lds = initLocalDataStruct(MBSdata);
    #else
    lds = NULL;
    #endif

	if(lds == NULL)
	{
	    printf("error while initializing LocalDataStruct\n");
	}
	#ifdef PRINT_REPORT
	else
	{
	    printf("LocalDataStruct successfully initialized\n");
	}
	#endif

	// Yarp Initialization
	#ifdef YARP
    RobotranYarp_interface = yarp_init();
    if(RobotranYarp_interface == NULL)
    {
        printf("******************\nSomething went wrong during YARP initialization... what to do here?\n******************\n");
    }
    #endif

	// Model initialization
	if(user_initialization(MBSdata, lds))
	{
	    printf("error in user_initialization\n");
	}
	#ifdef PRINT_REPORT
	else
	{
	    printf("Model successfully initialized\n");
	}
	#endif

	// Integrator parameters initialization
	model_state_size = 2*MBSdata->nqu + MBSdata->Nux;

	#ifdef PRINT_REPORT
	printf("model_state_size: %d\n", model_state_size);
	#endif

	ystart = dvector(1,model_state_size);

	#ifdef WRITE_FILES
	write_files = init_write_files(NB_SIMU_STEPS, MBSdata->njoint);
	#endif

    // Simulation state initialization
	for(i=1; i<=MBSdata->nqu; i++)
	{
		ystart[i]              = MBSdata->q[MBSdata->qu[i]];
		ystart[i+MBSdata->nqu] = MBSdata->qd[MBSdata->qu[i]];
	}

	for(i=1; i<=MBSdata->Nux; i++)
	{
	    ystart[i+2*MBSdata->nqu] = MBSdata->ux[i];
	}

	// JNI visualization
	#if defined(JNI) & defined (REAL_TIME)
	jni_struct = init_jni(MBSdata);
	#endif

    // initialize the inputs of the simulation loop
    loop_inputs = (Loop_inputs*) malloc(sizeof(Loop_inputs));

    // absolute initial time of the simulation
    time_get(&(loop_inputs->init_t_sec), &(loop_inputs->init_t_usec));

    loop_inputs->nvar    = model_state_size;
    loop_inputs->nstep   = NB_SIMU_STEPS;
    loop_inputs->x1      = TSIM_INIT;
    loop_inputs->x2      = TSIM_END;
    loop_inputs->ystart  = ystart;
    loop_inputs->lds     = lds;
    loop_inputs->MBSdata = MBSdata;

    #ifdef WRITE_FILES
    loop_inputs->write_files = write_files;
    #endif

    // Real-time constraiints
    #ifdef REAL_TIME
    loop_inputs->real_time = init_real_time(loop_inputs->init_t_sec, loop_inputs->init_t_usec);
    #endif

    // SDL window
    #if defined(SDL) & defined (REAL_TIME)	
	loop_inputs->screen_sdl = configure_screen_sdl(loop_inputs->init_t_sec, loop_inputs->init_t_usec);
	#endif

	#if defined(JNI) & defined (REAL_TIME)
    loop_inputs->jni_struct = jni_struct;
    update_jni(loop_inputs->jni_struct, MBSdata, loop_inputs->real_time, MBSdata->q+1);
    #endif

    #ifdef YARP
    loop_inputs->RobotranYarp_interface = RobotranYarp_interface;
    #endif

    // Running model integration
    #ifdef PRINT_REPORT
    printf("Running integration of the model...\n");
    #endif

    return loop_inputs;
} 
Example #2
0
/*
 * Main function used to plot save vectors
 */
int main(int argc, char const *argv[])
{
	// variables declaration
	int i, j;
	int nb_curves;
	int size_vector, cur_size_vector;
	int init_t_sec, init_t_usec;

	double last_tsim;
	double cur_value, cur_min, cur_max;
	double y_min_init, y_max_init;

	char *generic_vec_file;
	char **vec_names;
	char t_file[PATH_MAX_LENGTH];
	char cur_vec_file[PATH_MAX_LENGTH];

	double *vec_t;
	double **vec_out;
	double *y_tab_min, *y_tab_max;

	Screen_sdl *screen_sdl;
	Simu_real_time *real_time;

	// vectors to plot
	vec_names = get_vec_names(&nb_curves);

	// vectors initialization
	generic_vec_file = CUR_PROJECT_ABS_PATH"/vectors";

	sprintf (t_file, "%s/vectors/%s", CUR_PROJECT_ABS_PATH, vec_names[0]);	

	vec_t = read_vector(t_file, &size_vector);

	vec_out = (double**) malloc (nb_curves*sizeof(double*));

	for (i=0; i<nb_curves; i++)
	{
		sprintf (cur_vec_file, "%s/%s", generic_vec_file, vec_names[i+1]);

		vec_out[i] = read_vector(cur_vec_file, &cur_size_vector);

		if (cur_size_vector != size_vector)
		{
			printf("Problem: all vectors do not have the same size !\n");
			printf("Time vector size: %d\n", size_vector);
			printf("Vector %s size: %d\n", cur_vec_file, cur_size_vector);
			exit(1);
		}
	}

	// max and min tabulars
	y_tab_min = (double*) malloc(nb_curves*sizeof(double));
	y_tab_max = (double*) malloc(nb_curves*sizeof(double));

	// compute minimal and maximal values
	cur_value  = vec_out[0][0];
	y_min_init = cur_value;
	y_max_init = cur_value;

	for (i=0; i<nb_curves; i++)
	{
		cur_value = vec_out[i][0];
		cur_min   = cur_value;
		cur_max   = cur_value;

		for (j=1; j<size_vector; j++)
		{
			cur_value = vec_out[i][j];

			if (cur_value < cur_min)
			{
				cur_min = cur_value;
			}

			if (cur_value > cur_max)
			{
				cur_max = cur_value;
			}
		}

		y_tab_min[i] = cur_min;
		y_tab_max[i] = cur_max;

		if (cur_min < y_min_init)
		{
			y_min_init = cur_min;
		}

		if (cur_max > y_max_init)
		{
			y_max_init = cur_max;
		}
	}

	// absolute time before starting loop
	time_get(&init_t_sec, &init_t_usec);

	// real time structure initialization
	real_time = init_real_time(init_t_sec, init_t_usec);

	// init screen SDL
	screen_sdl = configure_screen_sdl_plot_save(init_t_sec, init_t_usec, y_min_init, y_max_init, size_vector, nb_curves);

	// fill screen SDL
	for (i=0; i<nb_curves; i++)
	{
		for (j=1; j<size_vector; j++)
		{
			screen_sdl->y_vectors[i][j] = vec_out[i][j];
		}
	}

	for (i=0; i<size_vector; i++)
	{
		screen_sdl->tsim_vec[i] = vec_t[i];
	}

	for (i=0; i<nb_curves; i++)
	{
		screen_sdl->y_tab_min[i] = y_tab_min[i];
		screen_sdl->y_tab_max[i] = y_tab_max[i];
	}

	// special values
	real_time->simu_break  = 1;
	screen_sdl->index_simu = size_vector-1;
	last_tsim              = vec_t[size_vector-1];

	// plot main loop
	break_gestion_plot_save(screen_sdl, real_time, init_t_sec, init_t_usec, last_tsim);

	// release memory
	for (i=0; i<nb_curves; i++)
	{
		free(vec_out[i]);
	}

	free(vec_out);
	free(vec_t);
	free(y_tab_min);
	free(y_tab_max);
	
	free_screen_sdl(screen_sdl);
	free_simu_real_time(real_time);
	free_char_tab(vec_names);

	return 0;
}
Example #3
0
void init_soar_agent(agent* thisAgent) {

  /* JC ADDED: initialize the rhs function linked list */
  thisAgent->rhs_functions = NIL;

   /* --- initialize everything --- */
  init_symbol_tables(thisAgent);
  create_predefined_symbols(thisAgent);
  init_production_utilities(thisAgent);
  init_built_in_rhs_functions (thisAgent);
  init_rete (thisAgent);
  init_lexer (thisAgent);
  init_firer (thisAgent);
  init_decider (thisAgent);
  init_soar_io (thisAgent);
  init_chunker (thisAgent);
  init_tracing (thisAgent);
  init_explain(thisAgent);  /* AGR 564 */
  select_init(thisAgent);
  predict_init(thisAgent);

  init_memory_pool( thisAgent, &( thisAgent->gds_pool ), sizeof( goal_dependency_set ), "gds" );

  init_memory_pool( thisAgent, &( thisAgent->rl_info_pool ), sizeof( rl_data ), "rl_id_data" );
  init_memory_pool( thisAgent, &( thisAgent->rl_et_pool ), sizeof( rl_et_map ), "rl_et" );
  init_memory_pool( thisAgent, &( thisAgent->rl_rule_pool ), sizeof( rl_rule_list ), "rl_rules" );

  init_memory_pool( thisAgent, &( thisAgent->wma_decay_element_pool ), sizeof( wma_decay_element ), "wma_decay" );
  init_memory_pool( thisAgent, &( thisAgent->wma_decay_set_pool ), sizeof( wma_decay_set ), "wma_decay_set" );
  init_memory_pool( thisAgent, &( thisAgent->wma_wme_oset_pool ), sizeof( wma_pooled_wme_set ), "wma_oset" );
  init_memory_pool( thisAgent, &( thisAgent->wma_slot_refs_pool ), sizeof( wma_sym_reference_map ), "wma_slot_ref" );

  init_memory_pool( thisAgent, &( thisAgent->epmem_wmes_pool ), sizeof( epmem_wme_stack ), "epmem_wmes" );
  init_memory_pool( thisAgent, &( thisAgent->epmem_info_pool ), sizeof( epmem_data ), "epmem_id_data" );
  init_memory_pool( thisAgent, &( thisAgent->smem_wmes_pool ), sizeof( smem_wme_stack ), "smem_wmes" );
  init_memory_pool( thisAgent, &( thisAgent->smem_info_pool ), sizeof( smem_data ), "smem_id_data" );

  init_memory_pool( thisAgent, &( thisAgent->epmem_literal_pool ), sizeof( epmem_literal), "epmem_literals" );
  init_memory_pool( thisAgent, &( thisAgent->epmem_pedge_pool ), sizeof( epmem_pedge ), "epmem_pedges" );
  init_memory_pool( thisAgent, &( thisAgent->epmem_uedge_pool ), sizeof( epmem_uedge ), "epmem_uedges" );
  init_memory_pool( thisAgent, &( thisAgent->epmem_interval_pool ), sizeof( epmem_interval ), "epmem_intervals" );

  thisAgent->epmem_params->exclusions->set_value( "epmem" );
  thisAgent->epmem_params->exclusions->set_value( "smem" );

  thisAgent->smem_params->base_incremental_threshes->set_string( "10" );

#ifdef REAL_TIME_BEHAVIOR
  /* RMJ */
  init_real_time(thisAgent);
#endif


  /* --- add default object trace formats --- */
  add_trace_format (thisAgent, FALSE, FOR_ANYTHING_TF, NIL,
                    "%id %ifdef[(%v[name])]");
  add_trace_format (thisAgent, FALSE, FOR_STATES_TF, NIL,
                    "%id %ifdef[(%v[attribute] %v[impasse])]");
  { Symbol *evaluate_object_sym;
    evaluate_object_sym = make_sym_constant (thisAgent, "evaluate-object");
    add_trace_format (thisAgent, FALSE, FOR_OPERATORS_TF, evaluate_object_sym,
                      "%id (evaluate-object %o[object])");
    symbol_remove_ref (thisAgent, evaluate_object_sym);
  }
  /* --- add default stack trace formats --- */
  add_trace_format (thisAgent, TRUE, FOR_STATES_TF, NIL,
                    "%right[6,%dc]: %rsd[   ]==>S: %cs");
  add_trace_format (thisAgent, TRUE, FOR_OPERATORS_TF, NIL,
                    "%right[6,%dc]: %rsd[   ]   O: %co");

  reset_statistics (thisAgent);

  /* RDF: For gSKI */
  init_agent_memory(thisAgent);
  /* END */

}