Commit 0d5286c5 authored by ga83nob's avatar ga83nob
Browse files

minor modifications

parent c41516bc
......@@ -60,6 +60,7 @@ auto radius_post = [](state_type &r, input_type &u) -> void {
};
ode_solver(growth_bound_ode,r,u);
*/
u[0]=u[0];
r[0]=0;
r[1]=0;
};
......
......@@ -14,7 +14,7 @@
#include "SENSE.hh"
/* state-space / input-space dimensions */
#define ssDIM 3
#define ssDIM 4
#define isDIM 1
/* NCS Delay bounds */
......
......@@ -61,6 +61,7 @@ auto sys_post = [](state_type &s, input_type &u) -> void {
/* computation of the growth bound (the result is stored in r) */
auto radius_post = [](state_type &r, input_type &u) -> void {
u[0]=u[0];
r[0] = 0.1;
r[1] = 0.4;
r[2] = 0.6;
......
......@@ -38,6 +38,7 @@ auto sys_post = [](state_type &x, input_type &u) -> void {
/* the ode describing the vehicle */
auto rhs =[](state_type& xx, const state_type &x, input_type &u) {
xx[0] = -x[1] -1.5*x[0]*x[0] -0.5*x[0]*x[0]*x[0];
xx[1] = (1/omega_squared)*(x[0] - u[0]);
};
......@@ -60,6 +61,7 @@ auto sys_growth_bound = [](state_type &r, input_type &u) {
eLtau[1][0] = tau*((eLtau_1-eLtau_2)/(std::sqrt(eLtau_3)));
eLtau[1][1] = tau*((eLtau_1*std::sqrt(eLtau_3) + eLtau_2*std::sqrt(eLtau_3)+a*(eLtau_1+eLtau_2))/(2.0*std::sqrt(eLtau_3)));
u[0]=u[0];
r[0] = r[0]*eLtau[0][0] + r[1]*eLtau[0][1];
r[1] = r[0]*eLtau[1][0] + r[1]*eLtau[1][1];
};
......
......@@ -43,6 +43,8 @@ auto robot_post = [](state_type &x, input_type &u) -> void {
/* the ode describing the robot */
auto rhs =[](state_type& xx, const state_type &x, input_type &u) -> void {
double x0=x[0];
x0=x0-1;
xx[0] = u[0];
xx[1] = u[1];
};
......@@ -51,6 +53,7 @@ auto robot_post = [](state_type &x, input_type &u) -> void {
/* computation of the growth bound (the result is stored in r) */
auto radius_post = [](state_type &r, input_type &u) -> void {
u[0]=u[0];
r[0] = 0;
r[1] = 0;
};
......
......@@ -182,5 +182,6 @@ void sys_post(state_type &x, input_type &u)
/* computation of the growth bound (the result is stored in r) */
void r_post (state_type &r, input_type &u)
{
u[0]=u[0];
r[0] = 0;
}
......@@ -18,20 +18,16 @@ CUDDINC = -I$(CUDDPATH)/include
CUDDLIBS = -lcudd
CUDDLPATH = -L$(CUDDPATH)/lib
TARGET1 = tworobots_ncs
TARGET2 = tworobots_ncs_sim
TARGET = tworobots_ncs
all: $(TARGET1) $(TARGET2)
all: $(TARGET)
%.o:%.cc
$(CC) -c $(CXXFLAGS) $(CUDDINC) $(NCSACTINC) $< -o $@
$(TARGET1): $(TARGET1).o
$(CC) $(CXXFLAGS) -o $(TARGET1) $(TARGET1).o $(CUDDLPATH) $(CUDDLIBS)
$(TARGET2): $(TARGET2).o
$(CC) $(CXXFLAGS) -o $(TARGET2) $(TARGET2).o $(CUDDLPATH) $(CUDDLIBS)
$(TARGET): $(TARGET).o
$(CC) $(CXXFLAGS) -o $(TARGET) $(TARGET).o $(CUDDLPATH) $(CUDDLIBS)
clean:
rm ./$(TARGET1) ./$(TARGET1).o ./$(TARGET2) ./$(TARGET2).o
rm ./$(TARGET) ./$(TARGET).o
......@@ -12,7 +12,7 @@ Warning::ncsTransitionRelation:: Your bddVars exceeds the bound of (size_t). You
NCS relation intialized !
Expanding transition relation ...
The size of the new expanded relation is: 8.74785e+12
NCS relation expanded in 36.9255 seconds !
NCS relation expanded in 21.5168 seconds !
Computing recurrence controllers ...
Loading targets !
a target loaded !
......@@ -211,8 +211,8 @@ sub-inner started!
sub-inner started!
sub-inner started!
sub-inner started!
Elapsed time is 81077.8 seconds.
Controllers computed in 81077.8 seconds !
Elapsed time is 89812.5 seconds.
Controllers computed in 89812.5 seconds !
Synthesized controller-1 is saved to the file: tworobots_contr1.nbdd
Synthesized controller-2 is saved to the file: tworobots_contr2.nbdd
Synthesized controller-3 is saved to the file: tworobots_contr3.nbdd
......
Symbolic set saved to file: tworobots_obst_matlab.bdd
Symbolic set saved to file: tworobots_ss.bdd
Symbolic set saved to file: tworobots_obst.bdd
Unfiorm grid details:
First grid point: 0 0 0 0
Last grid point: 15 15 15 15
Grid node distance (eta)in each dimension: 1 1 1 1
Number of grid points in each dimension: 16 16 16 16
Number of grid points in domain: 65536
Number of elements in the symbolic set: 43056
Number of binary variables: 16
Bdd variable indices (=IDs) in dim 1: 0 1 2 3
Bdd variable indices (=IDs) in dim 2: 4 5 6 7
Bdd variable indices (=IDs) in dim 3: 8 9 10 11
Bdd variable indices (=IDs) in dim 4: 12 13 14 15
h= -0 , 15 , -0 , 15 , 2 , 3 , 12 , 13
Symbolic set saved to file: tworobots_ts1.bdd
Symbolic set saved to file: tworobots_ts2.bdd
Symbolic set saved to file: tworobots_ts3.bdd
Symbolic set saved to file: tworobots_ts4.bdd
Symbolic set saved to file: tworobots_ts.bdd
Symbolic set saved to file: tworobots_ts13.bdd
Symbolic set saved to file: tworobots_ts14.bdd
Symbolic set saved to file: tworobots_ts23.bdd
Symbolic set saved to file: tworobots_ts24.bdd
Symbolic set saved to file: robot_is.bdd
Input space details:
First grid point: -1 -1 -1 -1
Grid node distance (eta)in each dimension: 1 1 1 1
Number of grid points in each dimension: 3 3 3 3
Number of grid points in domain: 81
Number of elements in the symbolic set: 81
0.........10.........20.........30.........40.........50.........60.........70.........80.........90.........100
Elapsed time is 43.1406 seconds.
Symbolic set saved to file: tworobots_rel.bdd
Number of elements in the transition relation: 2.26438e+06
Iterations inner1: 20
Iterations inner2: 20
Iterations inner3: 20
Iterations inner4: 20
Iterations inner1: 20
Iterations inner2: 20
Iterations inner3: 20
Iterations inner4: 20
Iterations outer: 3
Elapsed time is 16.8064 seconds.
Symbolic set saved to file: tworobots_cont1.bdd
Symbolic set saved to file: tworobots_cont2.bdd
Symbolic set saved to file: tworobots_cont3.bdd
Symbolic set saved to file: tworobots_cont4.bdd
......@@ -15,7 +15,7 @@
% are created
%
function tworobots
function robot
clear set
close all
......
/*
* robot_ncs.cc
*
* created on: 31.08.2015
* author: m.khaled
*/
#include <array>
#include <iostream>
#include "../../../interface/common/fifosim.hh"
/* state-space / input-space dimensions and sampling period*/
#define ssDIM 4
#define isDIM 4
/* NCS Delay bounds */
#define NSCMAX 2
#define NCAMAX 2
/* files needed for simulation */
#define FILE_BDD_TS1 "scots-files/tworobots_ts1.bdd"
#define FILE_BDD_TS2 "scots-files/tworobots_ts2.bdd"
#define FILE_BDD_TS3 "scots-files/tworobots_ts3.bdd"
#define FILE_BDD_TS4 "scots-files/tworobots_ts4.bdd"
#define FILE_NBDD_REL "robot_rel.nbdd"
#define FILE_NBDD_CONTR1 "tworobots_contr1.nbdd"
#define FILE_NBDD_CONTR2 "tworobots_contr2.nbdd"
#define FILE_NBDD_CONTR3 "tworobots_contr3.nbdd"
#define FILE_NBDD_CONTR4 "tworobots_contr4.nbdd"
const double tau = 1.0;
/* robot simulation class */
class RobotPlant : public Plant{
public:
RobotPlant(){}
~RobotPlant(){}
void
initOde(double tau){
odeTau = tau;
base_initialize(ssDIM, isDIM);
}
void
oderhs(vector<double>& xnew, vector<double> x, vector<double> u){
x[0]=0;
xnew[0] = u[0];
xnew[1] = u[1];
xnew[2] = u[2];
xnew[3] = u[3];
}
};
int direction_to_mode(int robot1_dir, int robot2_dir){
int m;
if(robot1_dir == 1 && robot2_dir == 3)
m=1;
else if(robot1_dir == 1 && robot2_dir == 4)
m=2;
else if(robot1_dir == 2 && robot2_dir == 3)
m=3;
else if(robot1_dir == 2 && robot2_dir == 4)
m=4;
else
m=0;
return m;
}
#define SIM_LOOPS 100
int main() {
vector<double> u0(isDIM);
vector<double> x0(ssDIM);
x0[0]=7;
x0[1]=15;
x0[2]=15;
x0[3]=7;
u0[0]=1;
u0[1]=0;
u0[2]=0;
u0[3]=1;
Cudd cuddManager;
RobotPlant robot;
robot.initOde(tau);
ncsFIFOEstimator T(NSCMAX, NCAMAX, u0 ,tau , &robot);
FIFOChannel channel_SC(NSCMAX);
FIFOChannel channel_CA(NCAMAX, u0);
vector<string> conts = {FILE_NBDD_CONTR1, FILE_NBDD_CONTR2, FILE_NBDD_CONTR3, FILE_NBDD_CONTR4};
vector<string> targets={FILE_BDD_TS1, FILE_BDD_TS2, FILE_BDD_TS3, FILE_BDD_TS4};
cout << "Loading the controllers ... " << endl;
ncsFIFOController controller(cuddManager, conts, targets, NSCMAX);
vector<double> x = x0;
vector<double> xc;
vector<double> u;
vector<double> uc=u0;
int robot1_to = 1;
int robot2_to = 3;
// The simulation loop
cout << "Simulating ... " << endl;
for(size_t i=0; i<SIM_LOOPS; i++){
// The plant
u = channel_CA.get();
x = robot.Compute(x, u);
// The SC channel
channel_SC.put(x);
xc = channel_SC.get();
if(x[0] >= 2 && x[0] <= 4 && x[1] >= 2 && x[1] <= 4)
robot1_to = 2;
else if(x[0] >= 12 && x[0] <= 14 && x[1] >= 12 && x[1] <= 14)
robot1_to = 1;
if(x[2] >= 2 && x[2] <= 4 && x[3] >= 12 && x[3] <= 14)
robot2_to = 4;
else if(x[2] >= 12 && x[2] <= 14 && x[3] >= 2 && x[3] <= 4)
robot2_to = 3;
// The controller
if(xc.size() > 0){
T.Refresh(xc, uc);
uc = controller.getInputs(T, direction_to_mode(robot1_to, robot2_to))[0];
}else{
uc = u0;
}
cout << "LOOP #" << setw(3) << i+1 << "\t|\t";
cout << "X:" << setw(2) << (int)x[0] << "," << setw(2) << (int)x[1] << "," << setw(2) << (int)x[2] << "," << setw(2) << (int)x[3] << "\t\t";
cout << "U:" << setw(2) << (int)uc[0] << "," << setw(2) << (int)uc[1] << "," << setw(2) << (int)uc[2] << "," << setw(2) << (int)uc[3] << endl;
// The SC channel
channel_CA.put(uc);
}
cout << "Simulation Completed !!" << endl;
return 1;
}
......@@ -37,7 +37,7 @@ Nscmax = 2;
Ncamax = 2;
% the NCS state reconstructor
StateReconstructor = FIFOStateReconstructor(Nscmax, Ncamax, u0', @robot_ode, tau);
StateReconstructor = FIFOStateReconstructor(Nscmax, Ncamax, u0, @robot_ode, tau);
disp('loading the controllers NBD files ... ');
contr1=ncsFIFOController('tworobots_contr1.nbdd');
......@@ -90,8 +90,8 @@ drawnow
buffer_sc = cell(ssDim,Nscmax);
buffer_ca = cell(isDim,Ncamax);
for k=1:length(buffer_ca)
buffer_ca(:,k)=num2cell(u0);
for k=1:size(buffer_ca,2)
buffer_ca(:,k)=num2cell(u0');
end
for t=1:SIM_STEPS
......@@ -101,8 +101,8 @@ buffer_ca = cell(isDim,Ncamax);
% are we ready to construct the xBig ?
if(isempty(buffer_sc{end, end}))
StateReconstructor.pushQ(u0);
u = u0;
StateReconstructor.pushQ(u0);
u = u0';
else
StateReconstructor.pushState([buffer_sc{1,end} buffer_sc{2,end} buffer_sc{3,end} buffer_sc{4,end}], ...
[buffer_ca{1,1} buffer_ca{2,1} buffer_ca{3,1} buffer_ca{4,1}]);
......@@ -176,7 +176,7 @@ buffer_ca = cell(isDim,Ncamax);
% selecting one u from the offered inputs
%u_selected = u(:,ceil(rand*size(u,2)));
u_selected = u(1,:)';
u_selected = u(:,1);
u_at_sys = cell2mat(buffer_ca(:, end))';
% NCS: filling ca channel
......
......@@ -21,10 +21,7 @@
#define NCAMAX 2
#define FILE_BDD_REL "scots-files/vehicle_rel.bdd"
#define FILE_BDD_TS "scots-files/vehicle_ts.bdd"
#define FILE_NBDD_REL "vehicle_rel.nbdd"
#define FILE_NBDD_CONTR "vehicle_contr.nbdd"
int main() {
Cudd cuddManager;
......@@ -40,12 +37,5 @@ int main() {
ncsState13.WriteToFile(FILE_NBDD_REL);
cout << "New expanded transition relation is saved to the file: " << FILE_NBDD_REL << endl;
cout << "Computing a reach controller ... " << endl;
ncsController ncsContr = ncsState13.ComputeReachController(FILE_BDD_TS);
cout << "Controller computed in " << ncsContr.getControllerComputeTile() << " seconds !" << endl;
ncsContr.WriteToFile(FILE_NBDD_CONTR);
cout << "Synthesized controller is saved to the file: " << FILE_NBDD_CONTR << endl;
return 1;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment