Improve organization of Cannon sim files. Ref #338

This commit is contained in:
John M. Penn 2016-11-01 18:16:26 -05:00
parent 664797e391
commit 8ad462cd1c
20 changed files with 77 additions and 252 deletions

View File

@ -3,16 +3,14 @@ PURPOSE:
(This S_define works with the RUN_analytic input file)
LIBRARY DEPENDENCIES:
(
(cannon/gravity/src/cannon_default_data.c)
(cannon/gravity/src/cannon_init.c)
(cannon/gravity/src/cannon_analytic.c)
(cannon/gravity/src/cannon_default_data.c)
)
*************************************************************/
#include "sim_objects/default_trick_sys.sm"
##include "cannon/gravity/include/cannon.h"
##include "cannon/gravity/include/cannon_analytic_proto.h"
##include "cannon/gravity/include/cannon_analytic.h"
class CannonSimObject : public Trick::SimObject {
@ -20,11 +18,8 @@ class CannonSimObject : public Trick::SimObject {
CANNON cannon;
CannonSimObject() {
("default_data") cannon_default_data( &cannon ) ;
("initialization") cannon_init( &cannon ) ;
(0.01, "scheduled") cannon_analytic( &cannon ) ;
}
} ;

View File

@ -13,7 +13,7 @@ LIBRARY DEPENDENCIES:
#include "sim_objects/default_trick_sys.sm"
##include "cannon/gravity/include/cannon.h"
##include "cannon/gravity/include/cannon_eulercromer_proto.h"
##include "cannon/gravity/include/cannon_eulercromer.h"
class CannonSimObject : public Trick::SimObject {

View File

@ -12,9 +12,7 @@ LIBRARY DEPENDENCIES:
*************************************************************/
#include "sim_objects/default_trick_sys.sm"
##include "cannon/gravity/include/cannon.h"
##include "cannon/gravity/include/cannon_contact_proto.h"
##include "cannon/gravity/include/cannon_numeric.h"
class CannonSimObject : public Trick::SimObject {

View File

@ -1,38 +1,38 @@
/*************************************************************************
PURPOSE: (Cannonball Structure)
PURPOSE: (Represent the state and initial conditions of a cannonball)
**************************************************************************/
#ifndef CANNON_H
#define CANNON_H
#include <stdio.h>
#include "sim_services/Integrator/include/regula_falsi.h"
#include "trick_utils/comm/include/tc.h"
#include "trick_utils/comm/include/tc_proto.h"
typedef struct {
double pos0[2] ; /* *i m Init position of cannonball */
double vel0[2] ; /* *i m Init velocity of cannonball */
double acc0[2] ; /* *i m Init acceleration of cannonball */
double vel0[2] ; /* *i m Init velocity of cannonball */
double pos0[2] ; /* *i m Init position of cannonball */
double init_speed ; /* *i m/s Init barrel speed */
double init_angle ; /* *i rad Angle of cannon */
double pos[2] ; /* m xy-position */
double vel[2] ; /* m/s xy-velocity */
double acc[2] ; /* m/s2 xy-acceleration */
double acc[2] ; /* m/s2 xy-acceleration */
double vel[2] ; /* m/s xy-velocity */
double pos[2] ; /* m xy-position */
double time;
double timeRate;
double time; /* s Model time */
double timeRate; /* -- Model time per Sim time. */
/* =1.0 when cannon ball in flight. =0.0 otherwise. */
int impact ; /* -- Has impact occured? */
double impactTime; /* s Time of Impact */
/* Impact */
REGULA_FALSI rf ; /* -- Dynamic event params for impact */
int impact ; /* -- Has impact occured? */
double impactTime;
/* Communication Connection */
TCDevice connection ; /* -- Socket connection for sending position */
} CANNON ;
#endif

View File

@ -0,0 +1,17 @@
/*************************************************************************
PURPOSE: ( Cannon Analytic Model )
**************************************************************************/
#ifndef CANNON_ANALYTIC_H
#define CANNON_ANALYTIC_H
#include "cannon_common.h"
#ifdef __cplusplus
extern "C" {
#endif
int cannon_analytic(CANNON*) ;
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,27 +0,0 @@
/*************************************************************************
PURPOSE: (Cannonball Prototypes)
**************************************************************************/
#ifndef CANNON_COMM_PROTO_H
#define CANNON_COMM_PROTO_H
#include <stdio.h>
#include "cannon.h"
#ifdef __cplusplus
extern "C" {
#endif
int cannon_deriv_impact(CANNON*) ;
int cannon_integ(CANNON*) ;
double cannon_impact(CANNON*) ;
int cannon_init(CANNON*) ;
int cannon_default_data(CANNON*) ;
int cannon_init_comm(CANNON*) ;
int cannon_send_position(CANNON*) ;
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,21 +1,16 @@
/*************************************************************************
PURPOSE: (Cannonball Prototypes)
PURPOSE: ( Cannon Analytic Model )
**************************************************************************/
#ifndef CANNON_COMMON_H
#define CANNON_COMMON_H
#ifndef CANNON_ANALYTIC_PROTO_H
#define CANNON_ANALYTIC_PROTO_H
#include <stdio.h>
#include "cannon.h"
#ifdef __cplusplus
extern "C" {
#endif
int cannon_analytic(CANNON*) ;
int cannon_init(CANNON*) ;
int cannon_default_data(CANNON*) ;
int cannon_init(CANNON*) ;
#ifdef __cplusplus
}
#endif

View File

@ -1,25 +0,0 @@
/*************************************************************************
PURPOSE: (Cannonball Prototypes)
**************************************************************************/
#ifndef CANNON_CONTACT_PROTO_H
#define CANNON_CONTACT_PROTO_H
#include <stdio.h>
#include "cannon.h"
#ifdef __cplusplus
extern "C" {
#endif
int cannon_integ(CANNON*) ;
double cannon_impact(CANNON*) ;
double cannon_deriv(CANNON*) ;
int cannon_init(CANNON*) ;
int cannon_default_data(CANNON*) ;
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,22 +1,18 @@
/*************************************************************************
PURPOSE: (Cannonball Prototypes)
PURPOSE: ( Cannonball EulerCromer Model )
**************************************************************************/
#ifndef CANNON_EULERCROMER_PROTO_H
#define CANNON_EULERCROMER_PROTO_H
#include <stdio.h>
#include "cannon.h"
#ifndef CANNON_EULERCROMER_H
#define CANNON_EULERCROMER_H
#include "cannon_common.h"
#ifdef __cplusplus
extern "C" {
#endif
int cannon_ec_integ(CANNON*) ;
int cannon_deriv(CANNON*) ;
int cannon_init(CANNON*) ;
int cannon_default_data(CANNON*) ;
int cannon_ec_integ(CANNON*) ;
#ifdef __cplusplus
}
#endif

View File

@ -1,22 +1,19 @@
/*************************************************************************
PURPOSE: (Cannonball Prototypes)
PURPOSE: ( Cannonball Numeric Model )
**************************************************************************/
#ifndef CANNON_INTEG_PROTO_H
#define CANNON_INTEG_PROTO_H
#include <stdio.h>
#include "cannon.h"
#ifndef CANNON_NUMERIC_H
#define CANNON_NUMERIC_H
#include "cannon_common.h"
#ifdef __cplusplus
extern "C" {
#endif
int cannon_integ(CANNON*) ;
int cannon_deriv(CANNON*) ;
int cannon_init(CANNON*) ;
int cannon_default_data(CANNON*) ;
double cannon_impact(CANNON*) ;
#ifdef __cplusplus
}
#endif

View File

@ -4,24 +4,25 @@ PURPOSE: ( Analytical Cannon )
#include <stdio.h>
#include <math.h>
#include "../include/cannon.h"
#include "../include/cannon_analytic_proto.h"
int cannon_analytic( CANNON* C )
{
C->acc[0] = 0.00;
C->acc[1] = -9.81 ;
C->vel[0] = C->vel0[0] + C->acc0[0] * C->time ;
C->vel[1] = C->vel0[1] + C->acc0[1] * C->time ;
C->pos[0] = C->pos0[0] + (C->vel0[0] + (0.5) * C->acc0[0] * C->time) * C->time ;
C->pos[1] = C->pos0[1] + (C->vel0[1] + (0.5) * C->acc0[1] * C->time) * C->time ;
C->vel[0] = C->vel0[0] + C->acc[0] * C->time ;
C->vel[1] = C->vel0[1] + C->acc[1] * C->time ;
C->pos[0] = C->pos0[0] + (C->vel0[0] + (0.5) * C->acc[0] * C->time) * C->time ;
C->pos[1] = C->pos0[1] + (C->vel0[1] + (0.5) * C->acc[1] * C->time) * C->time ;
if (C->pos[1] < 0.0) {
C->impact = 1;
C->impactTime = (- C->vel0[1] - sqrt( C->vel0[1] * C->vel0[1] - 2 * C->pos0[1]))/C->acc[1];
C->pos[0] = C->impactTime * C->vel0[0];
C->pos[1] = 0.0;
C->vel[0] = 0.0;
C->vel[1] = 0.0;
fprintf(stderr, "\n\nIMPACT: ModelTime = %.9f, pos = %.9f\n\n", C->impactTime, C->pos[0] ) ;
if ( !C->impact ) {
C->impact = 1;
fprintf(stderr, "\n\nIMPACT: ModelTime = %.9f, pos = %.9f\n\n", C->impactTime, C->pos[0] ) ;
}
}
/*

View File

@ -5,20 +5,19 @@ LIBRARY_DEPENDENCY: ((cannon_default_data.o))
/* Model Include files */
#include "../include/cannon.h"
#include "../include/cannon_integ_proto.h"
#include "sim_services/include/Flag.h"
/* Entry Point */
int cannon_default_data( CANNON* C )
{
const double PI = 3.141592 ;
int cannon_default_data( CANNON* C ) {
C->pos0[0] = 0.0 ;
C->pos0[1] = 0.0 ;
C->acc0[0] = 0.0 ;
C->acc0[1] = -9.81 ;
const double PI = 3.1415926535;
C->acc[0] = 0.0;
C->acc[1] = -9.81;
C->init_angle = PI/6 ;
C->init_speed = 50.0 ;
C->pos0[0] = 0.0 ;
C->pos0[1] = 0.0 ;
C->impactTime = 0.0 ;
C->time = 0.0 ;
@ -38,7 +37,7 @@ int cannon_default_data( CANNON* C )
C->rf.error_tol = 1.0e-9 ;
C->rf.mode = Decreasing ;
C->impact = No ;
C->impact = 0 ;
return(0) ;
}

View File

@ -2,7 +2,6 @@
PURPOSE: ( Try Trick integration )
*****************************************************************************/
#include "../include/cannon.h"
#include "../include/cannon_integ_proto.h"
int cannon_deriv( CANNON* C ) {

View File

@ -1,15 +1,11 @@
/*****************************************************************************
PURPOSE: ( Try Trick integration )
PURPOSE: ( Integration Job for Euler-Cromer Example )
*****************************************************************************/
#include <stdio.h>
#include "sim_services/Integrator/include/integrator_c_intf.h"
#include "../include/cannon.h"
#include "../include/cannon_eulercromer_proto.h"
int cannon_ec_integ(
CANNON* C )
{
int cannon_ec_integ( CANNON* C ) {
int ipass;

View File

@ -1,13 +1,12 @@
/*****************************************************************************
PURPOSE: ( Contact )
PURPOSE: ( Dynamic Event to determine cannonball impact time. )
*****************************************************************************/
#include <stdio.h>
#include "../include/cannon.h"
#include "../include/cannon_contact_proto.h"
#include "sim_services/Integrator/include/integrator_c_intf.h"
double cannon_impact( CANNON* C )
{
double cannon_impact( CANNON* C ) {
double tgo ;
double now ;

View File

@ -1,26 +1,18 @@
/*****************************************************************************
PURPOSE: (Initialize the cannonball)
*****************************************************************************/
#include <stdio.h>
#include <math.h>
#include "../include/cannon.h"
#include "../include/cannon_integ_proto.h"
#include "../include/cannon_common.h"
int cannon_init( CANNON* C) {
C->pos[0] = C->pos0[0] ;
C->pos[1] = C->pos0[1] ;
C->vel0[0] = C->init_speed*cos(C->init_angle);
C->vel0[1] = C->init_speed*sin(C->init_angle);
C->vel[0] = C->vel0[0] ;
C->vel[1] = C->vel0[1] ;
C->acc[0] = C->acc0[0] ;
C->acc[1] = C->acc0[1] ;
C->impactTime = 1.0;
C->impactTime = 0.0;
C->impact = 0.0;
return 0 ;

View File

@ -1,44 +0,0 @@
/*****************************************************************************
PURPOSE: (Initialize communications with a server)
*****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include "../include/cannon.h"
#include "sim_services/include/release.h"
int cannon_init_comm(
CANNON* C )
{
int ret, num_attempts ;
/* Launch server */
system("tc_server &");
/* Initialize client's connection to server */
C->connection.port = 9000 ;
C->connection.hostname = (char*) malloc( 16 ) ;
strcpy( C->connection.hostname, "localhost");
/* Shutup status messages */
tc_error( &C->connection, 0 ) ;
/* Client connect to server : try for 5 seconds */
num_attempts = 0 ;
while ( 1 ) {
ret = tc_connect( &C->connection ) ;
if ( ret == TC_SUCCESS ) {
break ;
} else {
num_attempts++ ;
if ( num_attempts == 500000 ) {
fprintf(stderr, "Couldn't connect to "
"server...\n");
exit(-1);
}
RELEASE_1(); /* Pause a microsecond */
}
}
return 0 ;
}

View File

@ -1,44 +0,0 @@
/*****************************************************************************
PURPOSE: (Initialize communications with a server)
*****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include "../include/cannon.h"
#include "sim_services/include/release.h"
int cannon_init_graphics(
CANNON* C )
{
int ret, num_attempts ;
/* Launch graphics server */
system("cd $HOME/trick_models/cannon/graphics ; cannon &");
/* Initialize clien't connection to server */
C->connection.port = 9000 ;
C->connection.hostname = (char*) malloc( 16 ) ;
strcpy( C->connection.hostname, "localhost");
/* Shutup status messages */
tc_error( &C->connection, 0 ) ;
/* Client connect to server : try for 5 seconds */
num_attempts = 0 ;
while ( 1 ) {
ret = tc_connect( &C->connection ) ;
if ( ret == TC_SUCCESS ) {
break ;
} else {
num_attempts++ ;
if ( num_attempts == 500000 ) {
fprintf(stderr, "Couldn't connect to "
"server...\n");
exit(-1);
}
RELEASE_1(); /* Pause a microsecond */
}
}
return 0 ;
}

View File

@ -1,15 +1,10 @@
/*****************************************************************************
PURPOSE: ( Try Trick integration )
PURPOSE: ( Integration Job for SIM_cannon_numeric )
*****************************************************************************/
#include <stdio.h>
#include "sim_services/Integrator/include/integrator_c_intf.h"
#include "../include/cannon.h"
#include "../include/cannon_integ_proto.h"
#include "sim_services/Integrator/include/integrator_c_intf.h"
int cannon_integ(
CANNON* C )
{
int cannon_integ( CANNON* C ) {
int ipass;

View File

@ -1,14 +0,0 @@
/*****************************************************************************
PURPOSE: (Send position to server)
*****************************************************************************/
#include "../include/cannon.h"
int cannon_send_position(
CANNON* C )
{
tc_write( &C->connection, (char *) &C->pos[0], sizeof(double)) ;
tc_write( &C->connection, (char *) &C->pos[1], sizeof(double)) ;
return 0 ;
}