code:new_target_type
Differences
This shows you the differences between two versions of the page.
Next revision | |||
— | code:new_target_type [2009/01/26 22:39] – created pkubanek | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== How to add a new target type ====== | ||
+ | |||
+ | RTS2 targets used for scheduling are represented by subclass of Target class. | ||
+ | If you would like to introduce a new target type, you must: | ||
+ | |||
+ | - introduce its type identifier among types listed in //types// table. This table contains character identifiing type and short type description. | ||
+ | |||
+ | - add its description to src/ | ||
+ | |||
+ | - create table which will hold target extended parameters. This table must include reference to tar_id from targets as primary key. | ||
+ | |||
+ | - create its class as subclass of Target class in src/utils directory. You might choose to create a new file with this subclass, or add its definition to existing file. It is recommended to start a new file. You must add this file to src/ | ||
+ | |||
+ | - in subclass load method, you can add any additional select statements which will load from database additional fields. For an example, look to rts2targetgrb.ec for ::load method implementation. You can of course use any ECPG statements. Please consult ECPG documentation for details. | ||
+ | |||
+ | - add this target type to //Target *createTarget (int _tar_id, struct ln_lnlat_posn *_obs)// in // | ||
+ | |||
+ | There is an example. Lets suppose we would like to add target for observing | ||
+ | earth low orbit satelites. This target will have seven extra parameters - six | ||
+ | for description of the orbit, seventh for date of orbit update. We start with | ||
+ | adding type to types table, using pgsql console: | ||
+ | |||
+ | <code sql> | ||
+ | stars=# insert into types values (' | ||
+ | INSERT 0 1 | ||
+ | stars=# | ||
+ | </ | ||
+ | |||
+ | Then add type define to // | ||
+ | |||
+ | <code c++> | ||
+ | // master plan target | ||
+ | #define TYPE_PLAN | ||
+ | |||
+ | // target type for | ||
+ | #define TYPE_ORBIT | ||
+ | </ | ||
+ | |||
+ | Now add table //orbits// for additional parameters: | ||
+ | |||
+ | <code sql> | ||
+ | stars=# insert into types values (' | ||
+ | INSERT 0 1 | ||
+ | stars=# | ||
+ | </ | ||
+ | |||
+ | Then add type define to // | ||
+ | |||
+ | <code c++> | ||
+ | // master plan target | ||
+ | #define TYPE_PLAN | ||
+ | |||
+ | // target type for | ||
+ | #define TYPE_ORBIT | ||
+ | </ | ||
+ | |||
+ | Now add table //orbits// for additional parameters: | ||
+ | |||
+ | <code sql> | ||
+ | stars=# create table orbits (tar_id integer references targets (tar_id), p1 float8 not null, p2 float8 not null, p3 float8 not null, p4 float8 not null, p5 float8 not null, p6 float8 not null, p7 timestamp not null); | ||
+ | </ | ||
+ | |||
+ | Now we will create in // | ||
+ | rts2targetorbit.cpp and add them to Makefile.am in this directory: | ||
+ | |||
+ | <code makefile> | ||
+ | |||
+ | inst_HEADERS = sqlerror.h rts2devicedb.h target.h rts2appdb.h rts2sqlcolumn.h rts2obs.h rts2obsset.h \ | ||
+ | ..... | ||
+ | rts2imgsetstat.h rts2targetell.h rts2user.h rts2userset.h account.h accountset.h rts2targetorbit.h | ||
+ | |||
+ | EXTRA_DIST = sqlerror.ec rts2devicedb.ec target.ec sub_targets.ec rts2appdb.ec airmasscale.ec rts2sqlcolumn.ec rts2obs.ec \ | ||
+ | ..... | ||
+ | rts2user.ec rts2userset.ec account.ec accountset.ec rts2targetorbit.ec | ||
+ | |||
+ | CLEANFILES = sqlerror.cpp rts2devicedb.cpp target.cpp sub_targets.cpp rts2appdb.cpp airmasscale.cpp rts2sqlcolumn.cpp rts2obs.cpp \ | ||
+ | ..... | ||
+ | rts2user.cpp rts2userset.cpp account.cpp accountset.cpp rts2targetorbit.cpp | ||
+ | |||
+ | nodist_librts2blockdb_a_SOURCES = sqlerror.cpp rts2devicedb.cpp target.cpp sub_targets.cpp rts2appdb.cpp rts2sqlcolumn.cpp rts2obs.cpp \ | ||
+ | ..... | ||
+ | rts2imgsetstat.cpp rts2targetell.cpp rts2user.cpp rts2userset.cpp account.cpp accountset.cpp rts2targetorbit.cpp | ||
+ | |||
+ | </ | ||
+ | |||
+ | After you are done, you can fill rts2targetorbit.h and rts2targetorbit.cpp file.There is rts2targetorbit.h: | ||
+ | |||
+ | <code c++> | ||
+ | #include " | ||
+ | |||
+ | class Rts2TargetOrbit { | ||
+ | private: | ||
+ | double p1; | ||
+ | double p2; | ||
+ | double p3; | ||
+ | double p4; | ||
+ | double p5; | ||
+ | double p6; | ||
+ | time_t p7; | ||
+ | public: | ||
+ | Rts2TargetOrbit (int _tar_id, struct ln_lnlat_posn *_obs); | ||
+ | Rts2TargetOrbit (); | ||
+ | |||
+ | virtual int getRST (struct ln_rts_time *rst, double jd, double horizon); | ||
+ | virtual int load (); | ||
+ | }; | ||
+ | </ | ||
+ | |||
+ | and there is rts2targetorbit.cpp: | ||
+ | |||
+ | <code c++> | ||
+ | #include " | ||
+ | |||
+ | Rts2TargetOrbit (int _tar_id, struct ln_lnlat_posn *_obs) | ||
+ | :Target (_tar_id, _obs) | ||
+ | { | ||
+ | p1 = p2 = p3 = p4 = p5 = p6 = nan (" | ||
+ | p7 = 0; | ||
+ | } | ||
+ | |||
+ | int | ||
+ | Rts2TargetOrbit:: | ||
+ | { | ||
+ | |||
+ | } | ||
+ | |||
+ | int | ||
+ | Rts2TargetOrbit:: | ||
+ | { | ||
+ | EXEC SQL BEGIN DECLARE SECTION; | ||
+ | double d_p1; | ||
+ | double d_p2; | ||
+ | double d_p3; | ||
+ | double d_p4; | ||
+ | double d_p5; | ||
+ | double d_p6; | ||
+ | int d_p7; | ||
+ | int d_tar_id = getTargetID (); | ||
+ | EXEC SQL END DECLARE SECTION; | ||
+ | |||
+ | EXEC SQL SELECT | ||
+ | p1, | ||
+ | p2, | ||
+ | p3, | ||
+ | p4, | ||
+ | p5, | ||
+ | p6, | ||
+ | EXTRACT (EPOCH FROM p7) | ||
+ | INTO | ||
+ | :d_p1, | ||
+ | :d_p2, | ||
+ | :d_p3, | ||
+ | :d_p4, | ||
+ | :d_p5, | ||
+ | :d_p6, | ||
+ | :d_p7 | ||
+ | FROM | ||
+ | orbits | ||
+ | WHERE | ||
+ | tar_id = :d_tar_id; | ||
+ | |||
+ | if (sqlca.sqlcode) | ||
+ | { | ||
+ | logMsgDb (" | ||
+ | return -1; | ||
+ | } | ||
+ | p1 = d_p1; | ||
+ | p2 = d_p2; | ||
+ | p3 = d_p3; | ||
+ | p4 = d_p4; | ||
+ | p5 = d_p5; | ||
+ | p6 = d_p6; | ||
+ | p7 = d_p7; | ||
+ | |||
+ | return Target:: | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | And finally add new target type to createTarget method: | ||
+ | |||
+ | <code c++> | ||
+ | Target *createTarget (int _tar_id, struct ln_lnlat_posn *_obs) | ||
+ | { | ||
+ | EXEC SQL BEGIN DECLARE SECTION; | ||
+ | int db_tar_id = _tar_id; | ||
+ | char db_type_id; | ||
+ | EXEC SQL END DECLARE SECTION; | ||
+ | ..... | ||
+ | case TYPE_PLANET: | ||
+ | retTarget = new TargetPlanet (_tar_id, _obs); | ||
+ | break; | ||
+ | case TYPE_ORBIT: | ||
+ | retTarget = new Rts2TargetOrbit (_tar_id, _obs); | ||
+ | default: | ||
+ | retTarget = new ConstTarget (_tar_id, _obs); | ||
+ | break; | ||
+ | ..... | ||
+ | } | ||
+ | </ | ||
code/new_target_type.txt · Last modified: 2009/01/26 00:00 (external edit)