Graphics.NewbieCubeTrickSim - lordmundi/wikidoctest GitHub Wiki

Newbie Cube Trick Sim

« Respin Cube Using Tcl | NewbieIndex | Cube Playback With Trick Data »

Disclaimer

I assume you know Trick. If you don't Trick, and how to do some minor setup like pointing your TRICK_CFLAGS to the right area, just skip the Trick sections.

Goal

Model a cube using Trick. Log cube data. We'll hook up Doug to the sim later.

Create The Sim Source

| S_define | || | Trick 7:

sim_object {
        sim_services/include: EXECUTIVE exec (sim_services/include/executive.d);
        sim_services/input_processor:
                input_processor( Inout INPUT_PROCESSOR * IP = &sys.exec.ip ) ;
 } sys ;

 #define FREQ 0.01
 sim_object {

          cube: XYZPYR newbiecube  (cube/include/cube_default_data.d) ;


         (FREQ, scheduled) cube: cube(
                 Inout   XYZPYR *T = &qbert.newbiecube ) ;
 } qbert ;

Trick 10:

/**************** TRICK HEADER ******************************
 PURPOSE:                     (S_define)
 LIBRARY_DEPENDENCY:          ((cube/src/cube_spin.c)
                               (cube/src/cube_default_data.c
 *************************************************************/

 #include "sim_objects/default_trick_sys.sm"

 ##include "cube/include/cube.h"
 ##include "cube/include/cube_proto.h"

 class CubeSimObject : public Trick::SimObject {

   public:
      CUBE cube;
      CubeSimObject() {
         ("default_data") cube_default_data( &cube );
         (0.01, "scheduled") cube_spin( &cube );
      }
 };

 CubeSimObject xyzpyr; |

| % cd ${TRICK_USER_HOME} % mkdir -p SIM_cube/RUN_test % vi SIM_cube/S_define Add code to S_define from above |

| cube.h | || | Trick 7:

/**************** TRICK HEADER *************************
 PURPOSE:                     (Test cube)
 REFERENCES:                  (None)
 ASSUMPTIONS AND LIMITATIONS: (Autocreated by trick_ui)
 PROGRAMMERS:                 ((keith) (Wed Mar 14 2007))
 ********************************************************/

 #ifndef _cube_h_
 #define _cube_h_

 typedef struct {

        double xyz[3] ;  /* M xyz pos */
        double pyr[3] ;  /* r pitch, yaw, roll */

 } XYZPYR ;

 #endif

Trick 10:

/**************** TRICK HEADER *************************
 PURPOSE:                     (Test cube)
 ********************************************************/

 #ifndef _cube_h_
 #define _cube_h_

 typedef struct {

        double xyz[3] ;  /* M xyz pos */
        double pyr[3] ;  /* r pitch, yaw, roll */

 } CUBE;

 #endif |

| Make a models area, we'll call it ${TRICK_MODELS} I like ~/trick_models/, put that in your ${TRICK_CFLAGS} env variable

% mkdir -p ${TRICK_MODELS}/cube/include
 % mkdir -p ${TRICK_MODELS}/cube/src
 % vi ${TRICK_MODELS}/cube/include/cube.h ; # source is above                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |

| cube_proto.h | || | Trick 10:

/**************** TRICK HEADER *************************
 PURPOSE:                     (CUBE PROTOTYPES HEADER)
 ********************************************************/

 #include "cube.h"

 #ifdef __cplusplus
 extern "C"
 #endif

 int cube_init( CUBE* );
 int cube_default_data( CUBE* );
 int cube_spin( CUBE* );

 #ifdef __cplusplus

 #endif |

| % vi ${TRICK_MODELS}/cube/include/cube_proto.h ; |

| cube.c | || | Trick 7:

/*********************************** TRICK HEADER **********
 PURPOSE:                     (Test cube)
 REFERENCES:                  (none)
 ASSUMPTIONS AND LIMITATIONS: (Autocreated by trick_ui)
 CLASS:                       (scheduled)
 LIBRARY DEPENDENCY:          (cube.o)
 PROGRAMMERS:                 ((keith) (Wed Mar 14 2007))
 ************************************************************/
 #include <stdio.h>
 #include <math.h>
 #include "../include/cube.h"

 #define ONE_DEGREE (M_PI/180.0)
 #define TWO_PI (2*M_PI)

 int cube( XYZPYR* T )
 {
        int ii ;

        for ( ii = 0 ; ii < 3 ; ii++ ) {
                T&rarr;pyr[ii] += ONE_DEGREE ;
                if ( T&rarr;pyr[ii] > TWO_PI ) {
                        T&rarr;pyr[ii] = 0.0 ;
                }
        }

        return 0 ;
 } |

| % cd ${TRICK_MODELS}/cube/src/ % vi cube.c ; # source is above

Trick 10: cube_spin.c

/*********************************** TRICK HEADER **********
 PURPOSE:            (Test cube)
 LIBRARY DEPENDENCY: ((cube_spin.o)
                     (libd_comm_tc.a)
                     (libdsp.a)
                     (dl.a))
 ************************************************************/
 #include "../include/cube.h"
 #include "d_comm.h"

 int cube_spin ( CUBE* C ) {

   int ii;

   const double PI = 3.141592;
   double one_degree = PI/180.0;
   double two_pi = 2*PI;

   for ( ii = 0; ii < 3; ii++ ) {

      C&rarr;pyr[ii] += one_degree;

      if ( C&rarr;pyr[ii] > two_pi ) {
         C&rarr;pyr[ii] = 0.0;
      }
   }

   return 0 ;
 }                                                                         |

| % cd ${TRICK_MODELS}/cube/src/ % vi cube_spin.c ; # source is above |

| cube_default_data.d | || | Trick 7:

XYZPYR.xyz[0] = 0.0, 0.0, 0.0 ;
 XYZPYR.pyr[0] = 0.0, 0.0, 0.0 ;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |

| % cd ${TRICK_MODELS}/cube/include % vi cube_default_data.d ; # source is above

Trick 10: cube_default_data.c

/*********************************** TRICK HEADER **********
 PURPOSE:            (Cube default data values)
 LIBRARY DEPENDENCY: ((cube_default_data.o)
                      (cube_init.0))
 ************************************************************/
 #include "../include/cube.h"

 int cube_default_data( CUBE *C ) {
    C&rarr;xyz[0] = 0.0, 0.0, 0.0;
    C&rarr;pyr[0] = 0.0, 0.0, 0.0;

    return (0);
 } |

| % cd ${TRICK_MODELS}/cube/src % vi cube_default_data.c ; # source is above |

| cube.dr | || | Trick 7:

#ifndef DR_GROUP_ID
    #define DR_GROUP_ID sys.exec.record.num_group
 #endif

 sys.exec.record.group = alloc( DR_GROUP_ID + 1 ) ;

 sys.exec.record.group[DR_GROUP_ID].name = "cube" ;
 sys.exec.record.group[DR_GROUP_ID].cycle = 0.1 ;
 sys.exec.record.group[DR_GROUP_ID].record = Yes ;
 sys.exec.record.group[DR_GROUP_ID].single_prec_only = No ;
 sys.exec.record.group[DR_GROUP_ID].freq = DR_Always ;
 sys.exec.record.group[DR_GROUP_ID].format = DR_Binary ;
 sys.exec.record.group[DR_GROUP_ID].buffering = DR_No_Buffer ;
 sys.exec.record.group[DR_GROUP_ID].ref[0] =
        "qbert.newbiecube.pyr[0]" ,
        "qbert.newbiecube.pyr[1]" ,
        "qbert.newbiecube.pyr[2]" ;

 DR_GROUP_ID ++ ;

Trick 10:

global DR_GROUP_ID global drg try:

if DR_GROUP_ID >= 0:
        DR_GROUP_ID += 1

except NameError:

DR_GROUP_ID = 0
    drg = []

drg.append(trick.DRAscii("cube")) drg[DR_GROUP_ID].set_freq(trick.DR_Always) drg[DR_GROUP_ID].set_cycle(0.01) drg[DR_GROUP_ID].set_single_prec_only(False) drg[DR_GROUP_ID].add_variable("xyzpyr.cube.pyr[0]") drg[DR_GROUP_ID].add_variable("xyzpyr.cube.pyr1") drg[DR_GROUP_ID].add_variable("xyzpyr.cube.pyr2") trick.add_data_record_group(drg[DR_GROUP_ID], trick.DR_Buffer) drg[DR_GROUP_ID].enable() | | % cd ${TRICK_USER_HOME}/SIM_cube/Modified_data % vi cube.dr ; # code above, this tells trick to log pitch, yaw, roll |

Make a barebones input file

| input | || | Trick 7:

#include "S_default.dat"
 #include "Modified_data/cube.dr"
 sys.exec.sim_com.monitor_on = Yes ;    // Turn on the control panel
 sys.exec.in.rt_software_frame = 1e-2;  // Make it realtime-ish

 stop = 60.0;   // stop after 60 seconds





% vi ${TRICK_USER_HOME}/SIM_cube/RUN_test/input
 % Add the lines above to it

Trick 10:

execfile("Modified_data/cube.dr")
trick.sim_control_panel_set_enabled(True)
trick.exec_set_software_frame(1e-2)
trick.stop(60) | | % vi ${TRICK_USER_HOME}/SIM_cube/RUN_test/input.py % Add the lines above to it |

Build & Run The Sim

% cd ${TRICK_USER_HOME}/SIM_cube
 % CP
 % ./S_main*exe RUN_test/input

« Respin Cube Using Tcl | NewbieIndex | Cube Playback With Trick Data »

⚠️ **GitHub.com Fallback** ⚠️