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
00033
00034
00035
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
00077
00078
00079
00080
00081
00083
00084
00085
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
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
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
00186
00188
00200 void setupHomingMode(HomingMethod method, double fast_speed, double slow_speed, double acceleration, double offset=0.0);
00201
00202
00203
00204
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
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00263
00273 void setupVelocityProfileMode(double target_speed, double acceleration);
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288 private:
00289
00291 unsigned char id_;
00292
00293
00294
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
00310
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
00328
00330 boost::function<void(char*, int)> limitSwitchesCallback_;
00331 };
00332
00333 }
00334
00335