00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef NODE_HH
00018 #define NODE_HH
00019
00020 #include "rcs_defs.hh"
00021
00022 #ifdef EXTERN_C_STD_HEADERS
00023 extern "C"
00024 {
00025 #endif
00026
00027 #ifdef VXWORKS
00028 #include <semLib.h>
00029 #endif
00030
00031 #ifdef EXTERN_C_STD_HEADERS
00032 }
00033 #endif
00034
00035
00036 #include "rcs_defs.hh"
00037 #include "cms.hh"
00038 #include "nml.hh"
00039 #include "nmlmsg.hh"
00040 #include "cmd_msg.hh"
00041 #include "stat_msg.hh"
00042 #include "wm_msg.hh"
00043 #include "timer.hh"
00044 #include "linklist.hh"
00045
00046
00047 #ifdef VXWORKS
00048 #ifdef NULL
00049 #undef NULL
00050 #endif
00051 #define NULL (0)
00052 #endif
00053
00054
00055 #define NODE_USE_GENERIC_COMMANDS 0x00000001
00056 #define NODE_WAIT_FOR_COMMANDS_TO_BE_READ 0x00000002
00057 #define NODE_CHECK_TIMES 0x00000008
00058 #define NODE_EXECUTE_NEW_COMMANDS_ONLY 0x00000010
00059 #define NODE_RESET_STATE_ON_NEW_COMMAND 0x00000020
00060 #define NODE_USE_STAT_BUFFER 0x00000040
00061 #define NODE_USE_WM_BUFFER 0x00000080
00062 #define NODE_SEND_EXECUTING_ON_NEW_COMMAND 0x00000100
00063 #define NODE_SAVE_LAST_COMMAND 0x00000200
00064
00065 extern long default_node_config_flags;
00066
00067
00068
00069
00070 enum NODE_STATUS_TYPE
00071 { NODE_INIT,
00072 NODE_WAITING,
00073 NODE_EXECUTING,
00074 NODE_DONE,
00075 NODE_ERROR
00076 };
00077
00078
00079
00080 enum OPER_MODE_TYPE
00081 { AUTO, TELEOP, HYBRID };
00082 enum NODE_SECTION
00083 {
00084 NODE_GET_COMMAND_MESSAGE,
00085 NODE_GET_SUBORDINATES_STATUS,
00086 NODE_GET_OI_REQUESTS,
00087 NODE_READ_WORLD_MODEL_IN,
00088 NODE_READ_SENSORS,
00089 NODE_PROCESS_OI_REQUESTS,
00090 NODE_SENSORY_PROCESSOR,
00091 NODE_WORLD_MODELER,
00092 NODE_COMMAND_INDEPENDANT_PLANNER,
00093 NODE_HANDLE_GENERIC_COMMANDS,
00094 NODE_EXECUTE_COMMAND,
00095 NODE_OUTPUT_TO_ACTUATORS,
00096 NODE_SEND_OI_REPLIES,
00097 NODE_WRITE_WORLD_MODEL_OUT,
00098 NODE_SEND_SUBORDINATES_COMMANDS,
00099 NODE_SEND_STATUS_MESSAGE
00100 };
00101
00102 #define RCS_COMMAND_SUFFIX "_cmd"
00103 #define RCS_COMMAND_SUFFIX_LENGTH 4
00104 #define RCS_STATUS_SUFFIX "_stat"
00105 #define RCS_STATUS_SUFFIX_LENGTH 5
00106 #define RCS_WM_SUFFIX "_wm"
00107 #define RCS_WM_SUFFIX_LENGTH 3
00108
00109
00110
00111 class RCS_EXPORT NODE_LINK;
00112
00113 enum RCS_COMMAND_SOURCE_TYPE
00114 {
00115 RCS_SUPERIOR_NODE,
00116 RCS_OPERATOR_INTERFACE,
00117 };
00118
00119 class RCS_EXPORT NODE
00120 {
00121 RCS_CMD_CHANNEL *cmd_in;
00122 RCS_STAT_CHANNEL *status_up;
00123 RCS_WM_CHANNEL *wm_out;
00124 RCS_COMMAND_SOURCE_TYPE command_source;
00125
00126 RCS_LINKED_LIST *sub_list;
00127 RCS_LINKED_LIST *wm_in_list;
00128 RCS_GENERIC_STATUS *generic_status;
00129 RCS_CMD_MSG *startup_cmd;
00130
00131 friend class RCS_EXPORT NODE_LINK;
00132 friend class RCS_OI;
00133 friend class CMD_OI;
00134 public:
00135 long state;
00136 long last_state;
00137 long last_state_of_last_command;
00138 long error_code;
00139 long cycle_count;
00140 NML_FORMAT_PTR format_ptr;
00141 char *config_file;
00142 NODE_SECTION current_section;
00143 NODE_STATUS_TYPE node_status;
00144 OPER_MODE_TYPE oper_mode;
00145 int num_of_subord;
00146 int all_subordinates_done;
00147 int valid;
00148 RCS_CMD_MSG *cmd_in_msg;
00149 RCS_CMD_MSG *last_cmd_in_msg;
00150 RCS_STAT_MSG *status_up_msg;
00151 RCS_WM_MSG *wm_out_msg;
00152 NMLmsg *oper_in_msg;
00153 int status_up_new;
00154 int cmd_in_new;
00155 int oper_in_new;
00156 int wm_out_new;
00157 NMLTYPE cmd_in_type;
00158 NMLTYPE last_cmd_in_type;
00159 NMLTYPE status_up_type;
00160 NMLTYPE oper_in_type;
00161 NMLTYPE wm_type;
00162 int cmd_in_type_new;
00163
00164 RCS_TIMER *cycle_timer;
00165 int cycle_timer_created;
00166 double cycle_time;
00167 double start_time;
00168 double finish_time;
00169
00170
00171 double last_cycle_time;
00172 double min_cycle_time;
00173 double max_cycle_time;
00174
00175 double last_process_time;
00176 double min_process_time;
00177 double max_process_time;
00178
00179
00180
00181 char *name;
00182 int name_length;
00183 long config_flags;
00184 int abort_flag;
00185
00186
00187 NODE (NML_FORMAT_PTR, char *n, char *file, RCS_CMD_MSG * _startup_cmd = NULL);
00188 virtual ~ NODE ();
00189 int initialize_node_variables ();
00190 int initialize_command_buffer ();
00191 int initialize_status_buffer ();
00192 int initialize_world_model_buffer ();
00193
00194
00195
00196 void send_status (NODE_STATUS_TYPE, RCS_STAT_MSG * new_msg = NULL);
00197
00198 void check_timer (RCS_TIMER *);
00199 void wait_for_timer (RCS_TIMER *);
00200 void run (double time);
00201 void run (RCS_TIMER * timer = NULL);
00202 void task (double time);
00203 void task (RCS_TIMER * timer = NULL);
00204 virtual void error_handler ();
00205 virtual void initialize_state_variables ();
00206
00207 virtual int cyclic_read ();
00208 virtual int cyclic_process ();
00209 virtual int cyclic_write ();
00210
00211 virtual int get_command_message ();
00212 virtual int get_subordinates_status ();
00213 virtual int get_oi_requests ();
00214 virtual int read_world_model_in ();
00215 virtual int read_sensors ();
00216 virtual int process_oi_requests ();
00217 virtual int sensory_processor ();
00218 virtual int world_modeler ();
00219 virtual int command_independant_planner ();
00220 virtual int handle_generic_commands ();
00221 virtual void send_command_to_all (RCS_CMD_MSG *);
00222 virtual int execute_command ();
00223 virtual void init ();
00224 virtual void halt ();
00225 virtual int output_to_actuators ();
00226 virtual int send_oi_replies ();
00227 virtual int write_world_model_out ();
00228 virtual int send_subordinates_commands ();
00229 virtual int send_status_message ();
00230
00231 virtual void check_if_valid ();
00232
00233 };
00234
00235
00236 #endif