CANopenMotorDriver.h
Go to the documentation of this file.
00001 /*********************************************************************
00002 *
00003 * Software License Agreement (BSD License)
00004 *
00005 *  Copyright (c) 2012, ISR University of Coimbra.
00006 *  All rights reserved.
00007 *
00008 *  Redistribution and use in source and binary forms, with or without
00009 *  modification, are permitted provided that the following conditions
00010 *  are met:
00011 *
00012 *   * Redistributions of source code must retain the above copyright
00013 *     notice, this list of conditions and the following disclaimer.
00014 *   * Redistributions in binary form must reproduce the above
00015 *     copyright notice, this list of conditions and the following
00016 *     disclaimer in the documentation and/or other materials provided
00017 *     with the distribution.
00018 *   * Neither the name of the ISR University of Coimbra nor the names of its
00019 *     contributors may be used to endorse or promote products derived
00020 *     from this software without specific prior written permission.
00021 *
00022 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00025 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00026 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00027 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00028 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00029 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00030 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00032 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00033 *  POSSIBILITY OF SUCH DAMAGE.
00034 *
00035 * Author: Gonçalo Cabrita on 17/04/2012
00036 *********************************************************************/
00037 
00038 #include <boost/function.hpp>
00039 #include <boost/thread/thread.hpp>
00040 
00041 #include <ros/ros.h>
00042 #include <can_msgs/CANFrame.h>
00043 
00044 #define ID_MASK             0x7F
00045 
00047 #define COB_NMT_SERVICE     0x0
00048 #define COB_SYNC            0x80
00049 #define COB_EMCY            0x80
00050 #define COB_T_PDO1          0x180
00051 #define COB_R_PDO1          0x200
00052 #define COB_T_PDO2          0x280
00053 #define COB_R_PDO2          0x300
00054 #define COB_T_PDO3          0x380
00055 #define COB_R_PDO3          0x400
00056 #define COB_T_SDO           0x580
00057 #define COB_R_SDO           0x600
00058 #define COB_NMT_ERROR       0x700
00059 
00061 #define WRITE_REQUEST_4BYTE 0x23
00062 #define WRITE_REQUEST_3BYTE 0x27
00063 #define WRITE_REQUEST_2BYTE 0x2B
00064 #define WRITE_REQUEST_1BYTE 0x2F
00065 #define WRITE_RESPONSE      0x60
00066 #define READ_REQUEST_4BYTE  0x43
00067 #define READ_REQUEST_3BYTE  0x47
00068 #define READ_REQUEST_2BYTE  0x4B
00069 #define READ_REQUEST_1BYTE  0x4F
00070 #define READ_RESPONSE       0x40
00071 #define ERROR_RESPONSE      0x80
00072 
00073 namespace canopen
00074 {
00076         /*#define DEF_EXCEPTION(name, parent) \
00077         class name : public parent { \
00078                 public: \
00079         name(const char* msg) : parent(msg) {} \
00080         }
00081   
00083         DEF_EXCEPTION(Exception, std::runtime_error);
00084 
00085         #undef DEF_EXCEPTION*/
00086     
00088     typedef enum _HomingMethod
00089     {
00090         method_1 = 1,
00091         method_2 = 2,
00092         method_3 = 3,
00093         method_4 = 4,
00094         method_5 = 5,
00095         method_6 = 6,
00096         method_7 = 7,
00097         method_8 = 8,
00098         method_9 = 9,
00099         method_10 = 10,
00100         method_11 = 11,
00101         method_12 = 12,
00102         method_13 = 13,
00103         method_14 = 14,
00104         method_17 = 17,
00105         method_18 = 18,
00106         method_19 = 19,
00107         method_20 = 20,
00108         method_21 = 21,
00109         method_22 = 22,
00110         method_23 = 23,
00111         method_24 = 24,
00112         method_25 = 25,
00113         method_26 = 26,
00114         method_27 = 27,
00115         method_28 = 28,
00116         method_29 = 29,
00117         method_30 = 30,
00118         method_33 = 33,
00119         method_34 = 34,
00120         method_35 = 35,
00121         
00122     } HomingMethod;
00123 
00129         class CANopenMotorDriver
00130         {
00131         
00132     public:
00134                 CANopenMotorDriver(unsigned char axis_id, ros::NodeHandle * nh);
00136                 ~CANopenMotorDriver();
00137         
00138         
00139         /***************************************** SCALING FACTORS STUFF *****************************************/
00140         
00141         void setupDCmotorWithEncoder(unsigned int num_of_encoder_lines, double Tr, double T);
00142         
00143         void setupStepperMotor(unsigned int num_of_steps, unsigned int num_of_usteps, double Tr, double T);
00144         
00145         
00146         /***************************************** GENERAL STUFF *****************************************/
00147          
00149 
00153         void startNode();
00154         
00156 
00160         void readyToSwitchOn();
00161         
00163 
00167         void switchOn();
00168         
00170 
00174         void enableOperation();
00175         
00177 
00181         void run();
00182         
00183         
00184         
00185         /***************************************** HOMING MODE *****************************************/
00186          
00188 
00200         void setupHomingMode(HomingMethod method, double fast_speed, double slow_speed, double acceleration, double offset=0.0);
00201         
00202         
00203         
00204         /***************************************** POSITION MODE *****************************************/
00205          
00207 
00217         void setupPositionTrapezoidalProfileMode(double target, double speed, double acceleration);
00218         
00220 
00233         void setupPositionScurveProfileMode(double target, double speed, double acceleration, double jerk_time);
00234         
00236 
00242         void setQuickStopDeceleration(double deceleration);
00243         
00244         // TODO: Implement getPositionActualValue();
00245         
00246         // TODO: Implement setFollowingErrorWindow();
00247         // TODO: Implement setFollowingErrorTimeOut();
00248         
00249         // TODO: Implement setPositionWindow();
00250         // TODO: Implement setPositionTimeOut();
00251         
00252         // TODO: Implement getFollowingErrorActualValue();
00253         
00254         // TODO: Implement getPositionDemandValue();
00255         
00256         // TODO: Implement getControlEffort();
00257         
00258         
00259         
00260         /***************************************** VELOCITY MODE *****************************************/
00261          
00263 
00273         void setupVelocityProfileMode(double target_speed, double acceleration);
00274         
00275         // TODO: Implement getVelocitySensorActualValue();
00276         
00277         // TODO: Implement getVelocityDemandValue();
00278         
00279         // TODO: Implement getVelocityActualValue();
00280         
00281         // TODO: Implement setVelocityThreshold();
00282         
00283         // TODO: Implement setMaxSlippage();
00284         // TODO: Implement setSlippageTimeOut();
00285         
00286         
00287         
00288     private:
00289         
00291         unsigned char id_;
00292         
00293         
00294         /***************************************** SCALING FACTORS STUFF *****************************************/
00295         
00297         double T_;
00299         double load_to_motor_position_;
00301         double load_to_motor_speed_;
00303         double load_to_motor_acceleration_;
00305         double load_to_motor_jerk_;
00306         
00307         
00308         
00309         /***************************************** ROS STUFF *****************************************/
00310         //ros::NodeHandle nh_;
00312         ros::Publisher can_pub_;
00314         ros::Subscriber can_sub_;
00315         
00317 
00323         void receivedCANframe(const can_msgs::CANFrame::ConstPtr& msg);
00324         
00325         
00326         
00327         /***************************************** CALLBACKS *****************************************/
00328         
00330                 boost::function<void(char*, int)> limitSwitchesCallback_;
00331         };
00332 
00333 }
00334 
00335 // EOF


canopen
Author(s): Gonçalo Cabrita
autogenerated on Mon Jan 6 2014 11:27:52