controller.h
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  * Copyright (c) 2011, Southwest Research Institute
00005  * All rights reserved.
00006  *
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted provided that the following conditions are met:
00009  *
00010  *      * Redistributions of source code must retain the above copyright
00011  *      notice, this list of conditions and the following disclaimer.
00012  *      * Redistributions in binary form must reproduce the above copyright
00013  *      notice, this list of conditions and the following disclaimer in the
00014  *      documentation and/or other materials provided with the distribution.
00015  *      * Neither the name of the Southwest Research Institute, nor the names
00016  *      of its contributors may be used to endorse or promote products derived
00017  *      from this software without specific prior written permission.
00018  *
00019  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00020  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00021  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00022  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00023  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00024  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00025  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00026  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00027  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00028  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00029  * POSSIBILITY OF SUCH DAMAGE.
00030  */
00031 
00032 #ifndef CONTROLLER_H
00033 #define CONTROLLER_H
00034 
00035 #include "motoPlus.h"
00036 #include "ParameterExtraction.h"  // new motoPlus library
00037 #include "joint_data.h"
00038 #include "robot_status.h"
00039 
00040 namespace motoman
00041 {
00042 namespace controller
00043 {
00044 
00045 // bitmask used to track which parameters have been initialized
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) {}  // default constructor to guarantee un-initialized at creation
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) {}  // default constructor to guarantee un-initialized at creation
00082 };
00083 
00084 
00088 #define MP_DRAM_DEV_DOS "MPRAM1:"  //This macro is supposed to be defined in motoPlus.h
00089 
00096 //* Controller
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; //ms
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  // Servo power variables
00400 MP_SERVO_POWER_SEND_DATA servo_power_data;
00401 MP_STD_RSP_DATA servo_power_error;
00402 
00403 // Job variables
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 // Hold variables
00410 MP_HOLD_SEND_DATA hold_data;
00411 MP_STD_RSP_DATA hold_error;
00412  
00413 //TODO: motion and job flags are just internal state variables, we may
00414 //want to make them query the appropriate motoplus API calls instead.
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 } //controller
00444 } //motoman
00445 
00446 #endif //CONTROLLER_H


dx100
Author(s): Shaun Edwards (Southwest Research Institute)
autogenerated on Mon Oct 6 2014 02:25:33