Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 #ifndef CONTROLLER_H
00033 #define CONTROLLER_H
00034 
00035 #include "motoPlus.h"
00036 #include "ParameterExtraction.h"  
00037 #include "joint_data.h"
00038 #include "robot_status.h"
00039 
00040 namespace motoman
00041 {
00042 namespace controller
00043 {
00044 
00045 
00046 typedef enum
00047 {
00048   GP_GETNUMBEROFAXES        = 0x01,
00049   GP_GETPULSETORAD          = 0x02,
00050   GP_GETFBPULSECORRECTION   = 0x04,
00051   GP_GETQTYOFALLOWEDTASKS   = 0x08,
00052   GP_GETINTERPOLATIONPERIOD = 0x10,
00053   GP_GETMAXINCPERIPCYCLE    = 0x20,
00054   GP_GETGOVFORINCMOTION     = 0x40,
00055 } param_func_t;
00056 
00060 struct ctrl_grp_param_t
00061 {
00062   int initialized;
00063   int num_axes;
00064   float pulses_per_rad[MAX_PULSE_AXES];
00065   FB_AXIS_CORRECTION pulse_correction[MAX_PULSE_AXES];
00066   int max_incr_per_cycle[MAX_PULSE_AXES];
00067   float incr_motion_limit;
00068   
00069   ctrl_grp_param_t() : initialized(0) {}  
00070 };
00071 
00075 struct sys_param_t
00076 {
00077   int initialized;
00078   TASK_QTY_INFO tasks;
00079   UINT16 interp_period;
00080   
00081   sys_param_t() : initialized(0) {}  
00082 };
00083 
00084 
00088 #define MP_DRAM_DEV_DOS "MPRAM1:"  //This macro is supposed to be defined in motoPlus.h
00089 
00096 
00108 class Controller
00109 {
00110 public:
00111 
00116  Controller();
00117  
00122  ~Controller();
00123  
00131  static bool initParameters(int ctrl_grp=0);
00132  
00141 static int getInteger(int index);
00142 
00143 
00151 static void setInteger(int index, int value);
00152 
00162 static bool setJointPositionVar(int index, industrial::joint_data::JointData ros_joints);
00163 
00172  void setDigitalOut(int bit_offset, bool value);
00173  
00182  void waitDigitalIn(int bit_offset, bool wait_value);
00183  
00192  static bool getActJointPos(float* pos);
00193   
00194   
00202  bool getStatus(industrial::robot_status::RobotStatus & status);
00203  
00210 bool isMotionEnabled(void) {return motionEnabled;};
00211 
00218 bool isJobStarted(void) {return jobStarted;};
00219   
00225 void enableMotion(void);
00226 
00232 void disableMotion(void);
00233 
00239 void startMotionJob(char* job_name);
00240         
00245 void stopMotionJob(char* job_name);
00246 
00252 void delayTicks(int ticks) { mpTaskDelay(ticks);};
00253 
00263  bool writeJob(char* path, char* job);
00264  
00275  bool loadJob(char* path, char * job);
00276  
00283  double getVelocityLimit()
00284     {return (double) this->getInteger(VELOCITY_LIMIT_INDEX);};
00285 
00286 
00295   static bool getNumRobotAxes(int ctrl_grp, int* numAxes);
00296   static bool getNumRobotAxes(int* numAxes) { return getNumRobotAxes(active_ctrl_grp_, numAxes); }
00297 
00308  static bool getPulsesPerRadian(int ctrl_grp, float* pulses_per_radian);
00309  static bool getPulsesPerRadian(float* pulses_per_radian) { return getPulsesPerRadian(active_ctrl_grp_, pulses_per_radian); }
00310 
00321  static bool getFBPulseCorrection(int ctrl_grp, FB_AXIS_CORRECTION* pulse_correction);
00322  static bool getFBPulseCorrection(FB_AXIS_CORRECTION* pulse_correction) { return getFBPulseCorrection(active_ctrl_grp_, pulse_correction); }
00323  
00333  static bool getNumTasks(int* num_normal_tasks, int* num_highPrio_tasks, int* num_out_files);
00334 
00343  static bool getInterpPeriod(UINT16* interp_period);
00344 
00354  static bool getMaxIncrPerCycle(int ctrl_grp, int* max_incr);
00355  static bool getMaxIncrPerCycle(int* max_incr) { return getMaxIncrPerCycle(active_ctrl_grp_, max_incr); }
00356 
00366  static bool getIncrMotionLimit(int ctrl_grp, float* limit);
00367  static bool getIncrMotionLimit(float* limit) { return getIncrMotionLimit(active_ctrl_grp_, limit); }
00368 
00369  static int getCtrlGroup() { return active_ctrl_grp_; }
00370  static void setCtrlGroup(int ctrl_grp) { active_ctrl_grp_ = ctrl_grp; }
00371 
00372 protected:
00373 
00377 static const int VELOCITY_LIMIT_INDEX = 94;
00378                 
00382  static const int MP_ERROR = -1;
00383  
00389  static const int MP_OK = 0;
00390 
00394  static const int VAR_POLL_DELAY_ = 10; 
00395  static const int UNIV_IN_DATA_START_ = 10;
00396  static const int UNIV_OUT_DATA_START_ = 10010;
00397  static const int UNIV_IO_DATA_SIZE_ = 2048;
00398  
00399  
00400 MP_SERVO_POWER_SEND_DATA servo_power_data;
00401 MP_STD_RSP_DATA servo_power_error;
00402 
00403 
00404 MP_START_JOB_SEND_DATA job_start_data;
00405 MP_DELETE_JOB_SEND_DATA job_delete_data;
00406 MP_STD_RSP_DATA job_error;
00407 
00408 
00409 
00410 MP_HOLD_SEND_DATA hold_data;
00411 MP_STD_RSP_DATA hold_error;
00412  
00413 
00414 
00418 bool motionEnabled;
00419  
00423 bool jobStarted;
00424 
00432  industrial::robot_status::TriState getInMotionStatus();
00433  
00434 static int active_ctrl_grp_;
00435  
00436 static bool is_valid_ctrl_grp(int ctrl_grp);
00437 static bool is_bit_set(int i, param_func_t type) { return (i & type); }
00438 static void set_bit(int* i, param_func_t type) { *i |= type; }
00439 };
00440 
00441 
00442 
00443 } 
00444 } 
00445 
00446 #endif //CONTROLLER_H