Joris Kaal / Mbed 2 deprecated haptic_hid_beter_metuitgangp2

Dependencies:   MODSERIAL USBDevice compensation_tables mbed-dsp mbed

Fork of haptic_hid by First Last

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.h Source File

main.h

00001 #ifndef MAIN_H
00002 #define MAIN_H
00003 
00004 // System
00005 #define ENABLE_COGGING_COMPENSATION     1
00006 #define ENABLE_POSITION_COMPENSATION    1
00007 #define ENABLE_FRICTION_COMPENSATION    1
00008 // Torque Controller
00009 #define TORQUE_CONTROLLER_INTERVAL_US   100
00010 #define TORQUE_CONTROLLER_INTERVAL_INV  10000
00011 #define TORQUE_LIMIT                    2.0f
00012 #define POSITION_RESOLUTION             8192
00013 #define POSITION_ANTIALIAS              4096
00014 #define ELECTRICAL_POSITION_TO_RAD      0.038349f   // 2*pi/(8192/50)
00015 // Friction Model
00016 #define COULOMB_VELOCITY_CONST          9.0f
00017 #define STRIBECK_VELOCITY_CONST         0.5f
00018 #define COULOMB_FRICTION                0.058f
00019 #define STRIBECK_FRICTION               0.060f
00020 #define VISCOUS_FRICTION_COEF_FWD       (float)2.65e-3 //2.16561e-3
00021 #define VISCOUS_FRICTION_COEF_REV       (float)2.55e-3 //2.16561e-3
00022 #define ENABLE_DITHER                   0
00023 #define DITHER_FORCE                    0.02f
00024 #define DITHER_TICKS                    70
00025 // Current Controller
00026 #define CURRENT_CONTROLLER_KP           1.0f
00027 #define CURRENT_CONTROLLER_KI           7500.0f
00028 #define CURRENT_CONTROLLER_I_LIMIT      0.0001f
00029 // Function-likes
00030 #define GET_POSITION()                  ((int)(spi.write(0xFFFF) & 0x1FFF))
00031 #define GET_CURRENT_A()                 (-6.6f*(current_sensor_a.read() - current_sensor_a_offset))
00032 #define GET_CURRENT_B()                 (-6.6f*(current_sensor_b.read() - current_sensor_b_offset))
00033 #define LOWPASSIIR(v,i,w)               v+=w*(i-v)
00034 #define SGN(x)                          (x > 0 ? 1 : (x < 0 ? -1 : 0))
00035 #define ABSPOS()                        (position - position_ref + 8192*position_offset_count)  // dont forget POSITION_RESOLUTION
00036 // Speed estimator
00037 #define SPEED_ESTIMATOR_FAST_GAIN       50
00038 #define SPEED_ESTIMATOR_DEADBAND        1
00039 #define SPEED_ESTIMATOR_FILTER          0.02f
00040 #define SAMPLE_TIME_US                  100
00041 #define SAMPLE_TIME_INVERSE_S           10000.0f
00042 
00043 // Current Controller Variables
00044 float       current_sensor_a_offset = 0;
00045 float       current_sensor_b_offset = 0;
00046 // Torque Controller Variables
00047 float       torque = 0;
00048 float       speed;
00049 float       acceleration;
00050 int32_t     position;
00051 int         position_offset_count = 0;
00052 int         position_ref;
00053 int         dither_tick = 0;
00054 // Impedance controller variables
00055 float       ZControl_K  = 0;
00056 float       ZControl_B  = 0;
00057 float       ZControl_I  = 0;
00058 int         ZControl_RefPos = 0;
00059 
00060 // IO Variables
00061 //USBHID      hid(16,16);
00062 //HID_REPORT  send_report;
00063 //HID_REPORT  recv_report;
00064 DigitalIn   user_btn(p23);
00065 SPI         spi(NC, p6, p7);  
00066 Serial      pc(USBTX, USBRX);
00067 AnalogIn    current_sensor_a(p15);
00068 AnalogIn    current_sensor_b(p16);
00069 PwmOut      driver_1a(p28);
00070 PwmOut      driver_2a(p27);
00071 PwmOut      driver_1b(p26);
00072 PwmOut      driver_2b(p25);
00073 DigitalOut  driver_enable_a(p34);
00074 DigitalOut  driver_enable_b(p33);
00075 PwmOut      driver_vref_ab(p29);
00076 DigitalOut  info_led_1(LED1);
00077 DigitalOut  info_led_2(LED2);
00078 DigitalOut  info_led_3(LED3);
00079 DigitalOut  info_led_4(LED4);
00080 // Ticker Variables
00081 Ticker      torque_controller;
00082 Ticker      hid_controller;
00083 
00084 // Function declarations
00085 void calibrate_current_sensor();
00086 void calibrate_position();
00087 void initialize_io();
00088 void torque_control();
00089 void initialiseer_prbs();
00090 //void hid_control();
00091 
00092 #endif