Comments (5)
Wouldn't original functions(with void param) still make the calculations?
How would the function know what to update?
from trick.
Well, I have managed to find a workaround that works for my case but I don't know if it is the best practice.
I have added wrappers functions to the models folder which I use it in S_define file.
- Here is my directory tree :
├── models
│ ├── WRAPPERS
│ │ ├── include
│ │ │ ├── CANNON_WRAPPER.h
│ │ └── src
│ │ ├── CANNON_WRAPPER.c
│ └── cannon
│ ├── include
│ │ ├── rtw_continuous.h
│ │ ├── rtw_solver.h
│ │ ├── rtwtypes.h
│ │ └── CANNON.h
│ └── src
│ ├── CANNON.c
│ └── CANNON_data.c
├── Modified_data
│ └── realtime.py
├── RUN_test
│ └── input.py
├── S_define
└── S_overrides.mk
- Here is my S_define ;
class cannonSimObject: public Trick::SimObject {
Ext_CANON CANNON_A;
public:
cannonSimObject(){
("initialization") cannon_initialize_wrapper(&CANNON_A);
(0.01, "scheduled") cannon_step_wrapper(&CANNON_A);
}
}
cannonSimObject cannonSO;
- And this is my CANNON_WRAPPER.c ;
#include "../include/CANNON_WRAPPER.h";
#include "../../cannon/include/CANNON.h"
void cannon_initialize_wrapper(Ext_CANON* cannon_a){
*cannon_a = CANNON_A ; /*CANNON_A which is already declared in CANNON.c and CANNON.h*/
cannon_initialize();
}
void cannon_step_wrapper(Ext_CANON* cannon_a){
*cannon_a = CANNON_A ; /*CANNON_A which is already declared in CANNON.c and CANNON.h*/
cannon_step();
}
What I am doing here is that passing the value of CANNON_A from model source file to the one from S_define. This solved my issue but my question still keeping on. I wonder if trick has another way around?
from trick.
First off we don’t know anything about “Embedded Coder auto generated code.” That’s apparently a Simulink / Mathworks thing.
However, from what I can see, you're trying to update an external object (namely "Ext_CANON CANNON_A") from within a Trick sim object. I can show you how I would do that by way of a little example sim (below). Hope this helps.
S_define
/************************************************************
PURPOSE:
()
LIBRARY DEPENDENCIES:
((cannon/src/cannon.c))
*************************************************************/
#include "sim_objects/default_trick_sys.sm"
##include "cannon/include/cannon.h"
class CannonSimObject : public Trick::SimObject {
public:
CannonSimObject() {
("initialization") cannon_initialize( &CANNON_B) ;
(0.1, "scheduled") cannon_step( &CANNON_B) ;
}
};
CannonSimObject cannonSO;
cannon.h
(put this in ./models/cannon/include/ )
/*************************************************************************
PURPOSE: (Example)
LIBRARY DEPENDENCIES:
((cannon/src/cannon.o))
**************************************************************************/
#ifndef _cannon_hh_
#define _cannon_hh_
typedef struct cannon {
double pos[2] ;
} Ext_CANON;
#ifdef __cplusplus
extern "C" {
#endif
int cannon_initialize(Ext_CANON* cannon);
int cannon_step(Ext_CANON* cannon);
#ifdef __cplusplus
}
#endif
extern Ext_CANON CANNON_A; // This is a "promise" that the objects are out there.
extern Ext_CANON CANNON_B;
#endif
cannon.c
(put this in ./models/cannon/src/ )
/********************************* TRICK HEADER *******************************
PURPOSE: ( EXAMPLE )
LIBRARY DEPENDENCY:
((cannon.o))
*******************************************************************************/
#include "../include/cannon.h"
#include <math.h>
#include <stdio.h>
Ext_CANON CANNON_A = {0.1, 0.2}; // Here is where the objects are actually instanciated.
Ext_CANON CANNON_B = {0.3, 0.4};
int cannon_initialize(Ext_CANON* cannon) {
printf("INIT: pos = < %g, %g >\n", cannon->pos[0], cannon->pos[1]);
return (0);
}
int cannon_step(Ext_CANON* cannon) {
printf("STEP: pos = < %g, %g >\n", cannon->pos[0], cannon->pos[1]);
return(0);
}
realtime.py
(put this in ./Modified_data/ )
trick.real_time_enable()
trick.exec_set_software_frame(0.1)
trick.itimer_enable()
input.py
(put this in ./RUN_test/ )
exec(open("Modified_data/realtime.py").read())
trick.stop(5);
S_overrides.mk
(Same dir as S_define)
TRICK_CFLAGS += -Imodels
TRICK_CXXFLAGS += -Imodels
from trick.
I really don't think the wrapper functions are necessary.
from trick.
Well, I thought about your answer already however, I avoid changes in source files because it is auto generated. Probably the best option to handle such a problem finding a way to create trick friendly source code. Wrappers might keep my works generic. Thank you.
I got a question about your answer. You didn't declare &CANNON_B
in the S_define so it is reading from the cannon.h but why did you change the functions if the &CANNON_B
is accesible from the S_define? Wouldn't original functions(with void param) still make the calculations?
I mean this :
/************************************************************
PURPOSE:
()
LIBRARY DEPENDENCIES:
((cannon/src/cannon.c))
*************************************************************/
#include "sim_objects/default_trick_sys.sm"
##include "cannon/include/cannon.h"
class CannonSimObject : public Trick::SimObject {
public:
CannonSimObject() {
("initialization") cannon_initialize( /* &CANNON_B*/ ) ;
(0.1, "scheduled") cannon_step( /* &CANNON_B*/ ) ;
}
};
CannonSimObject cannonSO;
from trick.
Related Issues (20)
- Apparent race condition in checkpointing data recording groups
- Testing every OS with every version of python is too time consuming
- GitHub GUI Reports not defined or enabled for macOS and More Linux
- Simulation works but Trick View not updated in Viewing Real-Time Data with Trick View (TV) Tutorial HOT 4
- Parser for variable server binary format messages
- Improve timing that variable server sends out information HOT 5
- Why "Nested struct not currently supported (ignored)." HOT 2
- QUESTION: Is multiple sim models usage possible? HOT 3
- Cannot find trick.tlc file used in MATLAB tutorial HOT 1
- Unnecessary warnings displayed if time_tic_value is large
- Empty PYTHON_MODULE() statement silently kills the sim
- Add option to terminate a sim on a Python error in Trick events HOT 1
- var_byteswap mode doesn't work
- Add a warning when trying to data record unsupported types HOT 1
- QUESTION: How to order simulation jobs according to the simObject we created? HOT 3
- variable server and arrays HOT 3
- EXC_BAD_ACCESS (code=EXC_I386_GPFLT) in trick_error_report() when terminating during init on Darwin
- Make ICG compatible with clang/llvm 15 HOT 2
- Investigate possible concurrency issue in memory manger clear_all_vars
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from trick.