$search
00001 #ifndef _KURT_H_ 00002 #define _KURT_H_ 00003 00004 #include <string> 00005 00006 #include <net/if.h> 00007 #include <sys/ioctl.h> 00008 00009 #include <linux/can.h> 00010 00011 #include "can.h" 00012 #include "comm.h" 00013 00014 //CAN IDs 00015 #define CAN_CONTROL 0x00000001 // control message 00016 #define CAN_ADC00_03 0x00000005 // analog input channels: 0 - 3 00017 #define CAN_ADC04_07 0x00000006 // analog input channels: 4 - 7 00018 #define CAN_ADC08_11 0x00000007 // analog input channels: 8 - 11 00019 #define CAN_ENCODER 0x00000009 // 2 motor encoders 00020 #define CAN_TILT_COMP 0x0000000D // data from tilt sensor 00021 #define CAN_GYRO_MC1 0x0000000E // data from gyro connected to 1st C167 00022 #define CAN_GETROTUNIT 0x00000010 // current rotunit angle 00023 #define CAN_SETROTUNT 0x00000080 // send rotunit speed 00024 00025 //unused CAN IDs 00026 #define CAN_INFO_1 0x00000004 // info message (hardware identification, firmware version, loop count): hw_id[2], fw_version[2], loop[4] 00027 #define CAN_ADC12_15 0x00000008 // analog input channels: 12 - 15, motor current right and left in milli Amper, adc channel 14, board temperature 00028 #define CAN_BUMPERC 0x0000000A // bumpers and remote control 00029 #define CAN_DEADRECK 0x0000000B // position as ascertained by odometry: position_x[3], position_y[3], orientation[2] 00030 #define CAN_GETSPEED 0x0000000C // current transl. and rot. speed (MACS spec say accumulated values of left and right motor's encoders: enc_odo_left[4], enc_odo_right[4] 00031 #define CAN_BDC00_03 0x00000015 // analog input channels: 0 - 3 00032 #define CAN_BDC04_07 0x00000016 // analog input channels: 4 - 7 00033 #define CAN_BDC08_11 0x00000017 // analog input channels: 8 - 11 00034 #define CAN_BDC12_15 0x00000018 // analog input channels: 12 - 15 00035 #define CAN_GYRO_MC2 0x0000001E // data from gyro connected to 2nd C167 00036 00037 #define RAW 0 // raw control mode 00038 #define SPEED_CM 2 // speed (cm/s) control mode 00039 #define MAX_V_LIST 200 00040 00041 // values from Sharp GP2D12 IR ranger data sheet 00042 #define IR_MIN 0.10 // [m] 00043 #define IR_MAX 0.80 // [m] 00044 #define IR_FOV 0.074859848 // [rad] 00045 00046 // values from Baumer UNDK30I6103 ultrasonic data sheet 00047 #define SONAR_MIN 0.10 // [m] 00048 #define SONAR_MAX 1.00 // [m] 00049 #define SONAR_FOV 0.17809294 // [rad] 00050 00051 class Kurt 00052 { 00053 public: 00054 Kurt( 00055 Comm &comm, 00056 double wheel_perimeter, 00057 double axis_length, 00058 double turning_adaptation, 00059 int ticks_per_turn_of_wheel) : 00060 comm_(comm), 00061 wheel_perimeter_(wheel_perimeter), 00062 axis_length_(axis_length), 00063 turning_adaptation_(turning_adaptation), 00064 ticks_per_turn_of_wheel_(ticks_per_turn_of_wheel), 00065 use_microcontroller_(true), 00066 use_rotunit_(false), 00067 nr_v_(1000), 00068 leerlauf_adapt_(0), 00069 v_encoder_left_(0.0), 00070 v_encoder_right_(0.0) { } 00071 ~Kurt(); 00072 00073 bool setPWMData(const std::string &speedPwmLeerlaufTable, double feedforward_turn, double ki, double kp); 00074 00075 int can_motor(int left_pwm, char left_dir, char left_brake, 00076 int right_pwm, char right_dir, char right_brake); 00077 void set_wheel_speed(double _v_l_soll, double _v_r_soll, double _AntiWindup); 00078 int can_read_fifo(); 00079 00080 void can_rotunit_send(double speed); 00081 00082 private: 00083 CAN can_; 00084 Comm &comm_; 00085 00086 //odometry 00087 double wheel_perimeter_; 00088 double axis_length_; 00089 double turning_adaptation_; 00090 int ticks_per_turn_of_wheel_; 00091 00092 bool use_microcontroller_; 00093 bool use_rotunit_; 00094 00095 //PWM data 00096 const int nr_v_; 00097 double vmax_; 00098 int *pwm_v_l_, *pwm_v_r_; 00099 double kp_l, kp_r; // schnell aenderung folgen 00100 double ki_l, ki_r; // integrierer relative langsam 00101 int leerlauf_adapt_; 00102 double feedforward_turn_; // in v = m/s 00103 // speed from encoder in m/s 00104 double v_encoder_left_, v_encoder_right_; 00105 00106 //motor 00107 void k_hard_stop(void); 00108 void set_wheel_speed1(double v_l, double v_r, int integration_l, int integration_r); 00109 void set_wheel_speed2(double _v_l_soll, double _v_r_soll, double _v_l_ist, 00110 double _v_r_ist, double _omega, double _AntiWindup); 00111 void set_wheel_speed2_mc(double _v_l_soll, double _v_r_soll, double _omega, 00112 double _AntiWindup); 00113 void odometry(int wheel_a, int wheel_b); 00114 bool read_speed_to_pwm_leerlauf_tabelle(const std::string &filename, int *nr, 00115 double **v_pwm_l, double **v_pwm_r); 00116 void make_pwm_v_tab(int nr, double *v_pwm_l, double *v_pwm_r, int nr_v, int 00117 **pwm_v_l, int **pwm_v_r, double *v_max); 00118 00119 //sensors 00120 void can_encoder(const can_frame &frame); 00121 int normalize_ir(int ir); 00122 int normalize_sonar(int s); 00123 void can_sonar8_9(const can_frame &frame); 00124 void can_sonar4_7(const can_frame &frame); 00125 void can_sonar0_3(const can_frame &frame); 00126 void can_tilt_comp(const can_frame &frame); 00127 void can_gyro_mc1(const can_frame &frame); 00128 00129 void can_rotunit(const can_frame &frame); 00130 }; 00131 00132 #endif