A.Elgogary Posted May 8, 2016 Report Share Posted May 8, 2016 I was using systemc ams 2.3.1 with systemc ams 2.0 beta, i was using State Space model TDF with my controller but i noticed that the result is a function of sampling time , i mean to let SS yield a correct output, sampling time should be 1s, otherwise the output is divided by the sampling time for example if sampling time is 10ms than the result will be divided by 1000 and so on. i created a small example to show what i got, and i need to understand is this behavior correct ? and why ? or it is a bug ? if you changed set_timestep(1, SC_MS); and simmulation time to 2 ms you will see the difference, also i compare to matlab state space model and the one with one sec is the correct. Output with 1s Sampling time Y SS Systemc 0 0 Y Matrix 170 230 Y SS Systemc 170 230 Y Matrix 170 230 Result with 1ms Y SS Systemc 0 0 Y Matrix 170 230 Y SS Systemc 0.17 0.23 Y Matrix 170 230 /* * State-Space.cpp * * Created on: Mar 14, 2016 * Author: elgogary */ #include "systemc.h" #include "systemc-ams.h" #include <Eigen/Dense> using Eigen::MatrixXd; SCA_TDF_MODULE( StateSpace ) { sca_tdf::sca_out< double> q; void initialize() { a(0, 0) = 0; a(0, 1) = 0; a(1, 0) = 0; a(1, 1) = 0; b(0, 0) = 5; b(0, 1) = 6; b(1, 0) = 7; b(1, 1) = 8; c(0, 0) = 1; c(0, 1) = 0; c(1, 0) = 0; c(1, 1) = 1; d(0, 0) = 0; d(0, 1) = 0; d(0, 0) = 0; d(0, 1) = 0; s(0) = 0; s(1) = 0; } void set_attributes() { set_timestep(1, SC_SEC); } void processing() { sca_util::sca_vector<double> x; x(0) = 10; x(1) = 20; //sca_core::sca_time timestep; sca_util::sca_vector<double> y = q_ss(a, b, c, d, s, x ); cout << "Y SS Systemc" << y <<endl; MatrixXd B(2,2); MatrixXd inp(2,1); inp(0,0) = 10; inp(1,0) = 20; B(0, 0) = 5; B(0, 1) = 6; B(1, 0) = 7; B(1, 1) = 8; cout << "Y Matrix" <<endl<< B*inp<<endl; } SCA_CTOR( StateSpace ) : q("q"), a(2,2), b(2,2), c(2,2), d(2,2) { } private: sca_tdf::sca_ss q_ss; // state-space equation sca_util::sca_matrix<double> a, b, c, d; // state-space matrices sca_util::sca_vector<double> s; // state vector }; #include "State-Space.cpp" SC_MODULE( Crane ) { StateSpace * StateSpace0; sca_tdf::sca_signal<double> q; SC_CTOR( Crane ) { StateSpace0 = new StateSpace("StateSpace0"); StateSpace0->q(q); } ~Crane() { delete StateSpace0; } }; Crane * Crane0 = NULL; int sc_main(int argc, char* argv[]) { Crane0 = new Crane("Crane0"); sc_start(2, SC_SEC); return (0); } Quote Link to comment Share on other sites More sharing options...
karsten Posted May 11, 2016 Report Share Posted May 11, 2016 the result is independent from the timestep as long as the timestep is at least smaller than half of the time constant of the equations. I checked your model - the required timestep seems to be smaller around 1ms with 10ms timestep after 1sec simulation time Y SS Systemc 338.3 457.7 after 1 sec simulation I get the result: 339.83 459.77 If I change the timestep to 0.1 ms I get after 1sec simulation the result: Y SS Systemc 339.983 459.977 with 0.01ms after 1sec simulation time: Y SS Systemc 339.998 459.998 Hopefully, this answers your question Best regards Karsten Quote Link to comment Share on other sites More sharing options...
A.Elgogary Posted May 17, 2016 Author Report Share Posted May 17, 2016 i partially understand you but why it is yielding different results than Matlab? my be because the timestep larger than half of the time constant of the equations but is there is a way to edit it ? without changing the controller timestep which is 10ms ? Quote Link to comment Share on other sites More sharing options...
Martin Barnasconi Posted June 10, 2016 Report Share Posted June 10, 2016 In your State-space function you did not explicitly specify the time step. In such case, the State-space function will take the module time step. It could be that this module time step is too coarse for your analog State-space equation. In that case, you should specify a more fine-grained timestep as argument for the State-space function. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.