Graphics.NewbieCubeDriveWithLiveSimData - lordmundi/wikidoctest GitHub Wiki

Newbie Cube Drive with Live Sim Data

« Cube Playback With Trick Data | NewbieIndex | Drive Cube Using Trick-Doug Var Server Interface »

This method works, but is usually not preferred. In this method, DOUG comm is actually compiled into a sim, which isn't always the best way to approach things. There's a couple other ways to get sim data to doug, Check out the Sim data Dialog and Variable Server methods — djordan April 06, 2010, at 04:13 PM

Goal

Drive cube with real-time Trick simulation data.

In A Nutshell

  1. Add Doug Comm To Sim
  2. Drive Node Through Doug Comm

Edit And Add Code

| cube.h | || | Trick 7:

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

 #ifndef _cube_h_
 #define _cube_h_

 #include "d_comm.h"

 typedef struct {

        double xyz[3] ;  /* M xyz pos */
        double pyr[3] ;  /* r pitch, yaw, roll */
        int    node_id ; /* — Doug node id */ 

 } 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 */
        int    node_id ; /* — Doug node id */ 

 } CUBE;

 #endif |

| % vi ${TRICK_MODELS}/cube/includes/cube.h Add: int node_id ; /* — Doug node id */ |

| cube_init.c | || | Trick 7:

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


 int cube_init( XYZPYR* T )
 {
         DCF_InitProc(); 
         DCF_Comm(); 
         T&rarr;node_id = DCF_GetNodeID("CUBE"); 
         return 0 ;
 }

Trick 10:

/********************* TRICK HEADER ****************
 PURPOSE:                     (Test cube)
 LIBRARY DEPENDENCY:          ((cube_init.o))
 ****************************************************/
 #include <math.h>
 #include "../include/cube.h"
 #include "d_comm.h" 

 int cube_init( CUBE *C )
 {
         DCF_InitProc(); 
         DCF_Comm(); 
         C&rarr;node_id = DCF_GetNodeID("CUBE"); 
         return (0) ;
 } |

| % vi ${TRICK_MODELS}/cube/src/cube_init.c ; # New file to init doug comm |

| cube.c | || | Trick 7:

/********************** TRICK HEADER *****************
 PURPOSE:                     (Test cube)
 REFERENCES:                  (none)
 ASSUMPTIONS AND LIMITATIONS: (Autocreated by trick_ui)
 CLASS:                       (scheduled)
 LIBRARY DEPENDENCY:          ((cube.o) 
                               (libd_comm_tc.a) (libdsp.a) (dl.a)) 
 PROGRAMMERS:                 ((keith) (Wed Mar 14 2007))
 ******************************************************/
 #include <math.h>
 #include "../include/cube.h"
 #include "d_comm.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 ;
                }
        }

       /* Drive Graphics */ 
       DCM_SetRPYRD( T&rarr;node_id,  T&rarr;pyr ); 
       DCF_Comm(); 

        return 0 ;
 }                                                                                                                                                                                                                               |

| % vi ${TRICK_MODELS}/models/cube/src/cube.c Tell Trick To Link In Doug Libs: LIBRARY DEPENDENCY: ((cube.o) (libd_comm_tc.a) (libdsp.a) (dl.a))
Add To Code Body: DCM_SetRPYRD( T→node_id, T→pyr ); DCF_Comm(); And don't forget to add the #include so we know how those functions are defined: #include "d_comm.h"

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;
      }
   }

       /* DOUG Comm */ 
       DCM_SetRPYRD( C&rarr;node_id,  C&rarr;pyr ); 
       DCF_Comm(); 

   return 0 ;
 } |

| % vi ${TRICK_MODELS}/models/cube/src/cube_spin.c Tell Trick To Link In Doug Libs: LIBRARY DEPENDENCY: ((cube.o) (libd_comm_tc.a) (libdsp.a) (dl.a))
Add To Code Body: DCM_SetRPYRD( C→node_id, C→pyr ); DCF_Comm(); And don't forget to add the #include so we know how those functions are defined: #include "d_comm.h" |

| 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) ;

         (initialization) cube: cube_init( 
               Inout   XYZPYR *T = &qbert.newbiecube ) ; 

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

| % vi ${TRICK_USER_HOME}/SIM_cube/S_define Add: (initialization) cube: cube_init( Inout XYZPYR *T = &qbert.newbiecube ) ;

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() {
         ("initialization") cube_init( &cube );
         ("default_data") cube_default_data( &cube );
         (0.01, "scheduled") cube_spin( &cube );
      }
 };

 CubeSimObject xyzpyr; |

| % vi ${TRICK_USER_HOME}/SIM_cube/S_define Add: ("initialization") cube_init( &cube ); |

Add Doug Paths For Build

| ${HOME}/.Trick_user_cshrc | || | Note for the setenv lines below, you will need to expand the ${} values to your specific configuration. Also be aware that if you are on a 64-bit machine, you should point your TRICK_USER_LINK_LIBS to {DOUG_HOME}/lib_Linux_FC3_x86_64. It's important to note here, that DOUG plugins must be 32-bit, because DOUG is 32-bit. However, communication with DOUG can be accomplished on either bit depth through DOUG comm (in this tutorial section) or via tcl scripts.

# Add
 setenv TRICK_CFLAGS "-g -Wall -I${TRICK_MODELS} -I${DOUG_HOME}/src.dist/includes"
 setenv TRICK_USER_LINK_LIBS "-L${DOUG_HOME}/lib_Linux_FC3" |

| % vi ${HOME}/.Trick_user_cshrc Add: -I${DOUG_HOME}/src.dist/includes To: TRICK_CFLAGS Why: Trick needs to be able to find d_comm.h which is refereneced in cube.h

   Add: -L${DOUG_HOME}/lib_Linux_FC3{HOST_CPU_TYPE}    # check your machine!
    To: ${TRICK_USER_LINK_LIBS}
   Why: Trick needs to find lib dependencies set in comment header of cube.c                                                                                                                                                                                                                                                          |

Note you could also just set these two env variables in your shell manually, instead of changing your .Trick_user_cshrc

| input | || | #include "S_default.dat" #include "Modified_data/cube.dr" //stop = 60.0; // stop after 60 seconds sys.exec.sim_com.monitor_on = Yes ; sys.exec.in.rt_software_frame = 1e-2; //realtime software frame time | | % vi ${TRICK_USER_HOME}/SIM_cube/RUN_test/input % Comment out the time limit, and turn the Sim control panel on % and set the software frame around the value of the fastest job

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 % Comment out the time limit |

Build Sim

% cd ${TRICK_USER_HOME}/SIM_cube
 % CP
   You should see a link line like this:
         cc -g -Wall -I/users/vetter/models -I/users/vetter/doug/src/includes 
             -DTRICK_VER=05 -I/users/vetter/05.11.7/trick_source -I../include -o S_main_Linux_3.4_234.exe 
             lib_Linux_3.4_234/S_source.o lib_Linux_3.4_234/S_checksums.o
             /users/vetter/05.11.7/lib_Linux_3.4_234/master.o lib/o0.o lib/o1.o lib/i0.o
             -L/users/vetter/doug/lib_Linux_FC3 -ld_comm_tc -ldl -ldsp
             -L/users/vetter/doug/lib_Linux_FC3 -ld_comm_tc -ldl -ldsp
             /users/vetter/05.11.7/lib_Linux_3.4_234/libtrick.a -lm -lrt
         Generating S_sie.resource&hellip;
         ./S_main_Linux_3.4_234.exe sie

         === Simulation make complete ===

Multicast environment, you gotta have it

Before we run, you need to make sure the shell you are planning to run the sim in will have an appropriate environment for multicast communication. Otherwise, it can't find doug! We are working on a way to make this more seamless, but for now you can set these environment vars manually:

% setenv  MC_TAG   "cev_comm_${USER}"
 % setenv  MC_PORT  "12349"
 % setenv  MC_GROUP "225.0.0.48"
 % setenv  TCP_PORT "8000"
 % setenv  UDS_NODE "/tmp/cev_comm_${USER}"
 % setenv  SERVER_PORT "${TCP_PORT}"

Run: Manager and Client, living together in harmony…

Here's the deal. We're about to introduce something we haven't talked about in this tutorial yet — run_manager and run_client. For a rambling more in-depth explanation, see this link. All you need to know here is the manager is the server, and the client is the client, and the sim we just wrote sends data to the manager. Client is the one where we actually get the 3D doug stuff.

# Bring up Manager, make sure your $USERDATA is set correctly!
 % cd ${DOUG_HOME}
 % ./run_manager -display CUBE

 # Get a new terminal, make sure your $USERDATA is set correctly, seriously dude.
 # Bring up client, show fps too, why not right?
 % cd ${DOUG_HOME}
 % ./run_client -fps

 # Bring up the old trick simulation you made.
 % cd ${TRICK_USER_HOME}/SIM_cube
 % ./S_main*exe RUN_test/input

« Cube Playback With Trick Data | NewbieIndex | Drive Cube Using Trick-Doug Var Server Interface »

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