Graphics.NewbieCubeTrickToDougVarServerInterface - lordmundi/wikidoctest GitHub Wiki
« Drive Cube With Live Sim Data | NewbieIndex | Looking Back On The Doug-Trick Interface »
This article is now out of date. The new simdata plugin has an easier way to do this now!!! — frankie May 19, 2010, at 03:47 PM
Frankie says this article is out of date, but what I think he means is there's easier ways to have EDGE talk to a sim, see this link. — djordan April 7, 2011, at 10:47 AM
Connect the Trick simulation to Doug via the variable server interface.
| spincube_varserver.tcl | || | source "$env(DOUG_HOME)/gui/interface_libraries/trick_comm_library.tcl"
proc spincube_init { } {
global spin
set spin(socket) [set_siminfo localhost 7000 generic 0.01 spincube_connect_cb spincube_receive_data_cb [list qbert.newbiecube.pyr\[0\] qbert.newbiecube.pyr\[1\] qbert.newbiecube.pyr\[2\]]]
if { [catch { open_connection $spin(socket) } results] != 0 } {
puts "ERROR: spincube_trick.tcl: Could't connect to sim."
puts " ${results}"
}
}
proc spincube_connect_cb { } {
global spin
request_data $spin(socket)
}
proc spincube_receive_data_cb { trickdata } {
set ldata [split $trickdata \t]
set pitch [lindex $ldata 0]
set yaw [lindex $ldata 1]
set roll [lindex $ldata 2]
# Convert to degrees
set r2d [expr 180.0/3.14159265]
set pitch [expr $pitch*$r2d]
set yaw [expr $yaw*$r2d]
set roll [expr $roll*$r2d]
doug.node CUBE set -pitch $pitch -roll $roll -yaw $yaw
}
proc spincube { } {
spincube_init
}
spincube |
| % vi ${USERDATA}/gui/spincube_varserver.tcl Add code above |
| cube-varserver.cfg | || | DOUG { GUI { spincube_trick "${USERDATA}/gui/spincube_varserver.tcl" } } | | % cd ${USERDATA} % vi user.cfg ; # Add above lines in appropriate blocks, like we always do! |
| 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) (libdl.a))
PROGRAMMERS: ((keith) (Wed Mar 20 2007))
*********************************************************/
#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→pyr[ii] += ONE_DEGREE ;
if ( T→pyr[ii] > TWO_PI ) {
T→pyr[ii] = 0.0 ;
}
}
/* Drive Graphics */
/*
* DCM_SetRPYRD( T→node_id, T→pyr );
* DCF_Comm();
*/
return 0 ;
} |
| % cd ${TRICK_MODELS}/models/cube/src % vi cube.c ; # Comment out comm code
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→pyr[ii] += one_degree;
if ( C→pyr[ii] > two_pi ) {
C→pyr[ii] = 0.0;
}
}
/* DOUG Comm */
/*
* DCM_SetRPYRD( C→node_id, C→pyr );
* DCF_Comm();
*/
return 0 ;
} |
| % cd ${TRICK_MODELS}/models/cube/src % vi cube_spin.c ; # Comment out comm code |
| 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 ;
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; |
| % cd ${TRICK_USER_HOME}/SIM_cube % vi S_define ; # Comment out init job % CP ; # Rebuild sim. Sim is now Dougless. |
The sim is standalone, no comm to Doug. The tcl gui will connect to Trick's variable server and grab values for pitch, yaw and roll, and then drive the cube.
% cd ${DOUG_HOME}
% ./run_graphics ; # Cube pops up
% cd ${TRICK_USER_HOME}/SIM_cube
% ./S_main*exe RUN_test/input & ; # Cube inits to PYR=0,0,0
The cube should spin.
« Drive Cube With Live Sim Data | NewbieIndex | Looking Back On The Doug-Trick Interface »