浏览代码

加入新电机的偏心校准参数

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui 3 年之前
父节点
当前提交
dca516c892
共有 3 个文件被更改,包括 121 次插入3 次删除
  1. 7 3
      Applications/foc/motor/encoder.c
  2. 1 0
      Applications/foc/motor/encoder.h
  3. 113 0
      Applications/foc/motor/encoder_off5.h

+ 7 - 3
Applications/foc/motor/encoder.c

@@ -12,6 +12,8 @@
 #include "encoder_off3.h"
 #elif defined MOTOR_BLUESHARK_NEW2
 #include "encoder_off4.h"
+#elif defined MOTOR_BLUESHARK_ZD_100
+#include "encoder_off5.h"
 #endif
 static void encoder_do_offset_calibrate(void) ;
 static void _detect_off_finished(void);
@@ -245,18 +247,20 @@ bool encoder_detect_finish(void) {
 	}
 	if (g_encoder.direction == NEGATIVE) {
 		g_encoder.cali_angle = INVALID_ANGLE;
-		_detect_off_finished();//output data to PC tools, and use Matlab do FIR filter
-		_encoder_caliberate_deinit();
 	}
 	return true;
 }
 
+void encoder_detect_upload(void) {
+	_detect_off_finished();//output data to PC tools, and use Matlab do FIR filter
+	_encoder_caliberate_deinit();
+}
 
 static void _detect_off_finished(void) {
 	for (int i = 0; i < 1024; i++) {
 		float angle_off = g_encoder.encoder_off_map[i] / (((g_encoder.encoder_off_count[i] >> 4)&0xF) + (g_encoder.encoder_off_count[i]&0xF));
 		plot_1data16((s16)angle_off);
-		delay_ms(5);
+		delay_ms(30);
 		wdog_reload();
 	}	
 }

+ 1 - 0
Applications/foc/motor/encoder.h

@@ -43,6 +43,7 @@ float encoder_zero_phase_detect(void);
 bool ENC_Check_error(void);
 float encoder_get_abi_angle(void);
 float encoder_get_position(void);
+void encoder_detect_upload(void);
 
 #endif /* _Encoder_H__ */
 

+ 113 - 0
Applications/foc/motor/encoder_off5.h

@@ -0,0 +1,113 @@
+#include "math/fix_math.h" 
+
+/* Auto gen by my tools, and use matlab to desing a FIR filter-(MC100/Simulink/Fir_angle.m) */
+/* Matlib Command: Fir=Fir_angle; angle_off=filter(Fir.Numerator, 1, angle_in); */
+/* angle_in is the data, by plot MC_tools */
+/* Use angle_out=single(angle_off) convert double to float */
+
+#define FIR_PHASE_SHIFT 277
+const static s16q10_t _encoder_off_map[] = {
+11271,11267,11263,11259,11254,11249,11243,11238,11232,11226,11220,11213,11206,11199,11192,11185,
+11177,11170,11162,11154,11146,11137,11129,11120,11112,11103,11094,11085,11076,11067,11058,11049,11040,11031,11022,11013,
+11004,10995,10985,10976,10967,10958,10949,10940,10931,10923,10914,10906,10897,10889,10881,10873,10865,10857,10850,10842,
+10835,10828,10821,10814,10807,10801,10795,10789,10783,10777,10772,10767,10762,10757,10752,10748,10744,10740,10736,10732,
+10729,10725,10722,10719,10717,10714,10712,10710,10708,10706,10704,10702,10701,10700,10698,10697,10696,10696,10695,10694,
+10694,10693,10693,10693,10692,10692,10692,10692,10692,10691,10691,10691,10691,10690,10690,10690,10690,10689,10689,10688,
+10687,10686,10685,10684,10683,10682,10680,10678,10677,10674,10672,10670,10667,10664,10661,10658,10654,10650,10646,10642,
+10638,10633,10628,10622,10617,10611,10604,10598,10591,10584,10577,10569,10561,10553,10544,10535,10526,10517,10507,10497,
+10487,10476,10465,10454,10443,10431,10419,10407,10395,10382,10369,10356,10343,10330,10316,10302,10288,10274,10260,10245,
+10231,10216,10201,10186,10171,10156,10141,10125,10110,10095,10080,10065,10049,10034,10019,10004,9989,9975,9960,9945,
+9931,9917,9903,9889,9876,9863,9850,9837,9824,9812,9800,9789,9778,9767,9756,9746,9737,9727,9719,9710,
+9702,9695,9688,9682,9676,9670,9665,9661,9658,9654,9652,9650,9648,9648,9647,9648,9649,9651,9653,9656,
+9660,9665,9670,9676,9682,9689,9697,9705,9715,9724,9735,9746,9758,9771,9784,9798,9812,9827,9843,9860,
+9877,9895,9913,9933,9952,9973,9994,10015,10037,10060,10084,10107,10132,10157,10182,10208,10235,10262,10290,10318,
+10346,10375,10404,10434,10464,10495,10525,10557,10588,10620,10652,10684,10717,10750,10783,10816,10850,10884,10918,10952,
+10986,11020,11055,11089,11124,11159,11193,11228,11263,11297,11332,11366,11401,11435,11470,11504,11538,11572,11606,11640,
+11673,11707,11740,11773,11806,11838,11870,11903,11934,11966,11997,12028,12059,12089,12119,12149,12179,12208,12236,12265,
+12293,12321,12348,12375,12402,12429,12455,12480,12506,12530,12555,12579,12603,12626,12649,12672,12694,12716,12738,12759,
+12780,12801,12821,12841,12860,12880,12898,12917,12935,12953,12971,12989,13006,13023,13039,13056,13072,13087,13103,13118,
+13134,13148,13163,13178,13192,13206,13220,13233,13247,13260,13273,13286,13299,13312,13325,13337,13350,13362,13374,13386,
+13398,13410,13422,13434,13445,13457,13469,13480,13492,13503,13515,13526,13538,13549,13560,13572,13583,13594,13605,13616,
+13628,13639,13650,13661,13672,13683,13694,13705,13716,13727,13738,13748,13759,13770,13780,13791,13802,13812,13822,13833,
+13843,13853,13863,13873,13883,13893,13902,13912,13921,13930,13939,13948,13957,13965,13974,13982,13990,13997,14005,14012,
+14019,14026,14032,14039,14044,14050,14056,14061,14065,14070,14074,14078,14081,14084,14087,14089,14091,14093,14094,14095,
+14095,14095,14095,14094,14093,14091,14089,14087,14084,14080,14076,14072,14067,14062,14056,14050,14043,14036,14028,14020,
+14011,14002,13993,13983,13973,13962,13950,13939,13926,13914,13900,13887,13873,13858,13843,13828,13812,13796,13779,13762,
+13745,13727,13709,13690,13671,13652,13632,13612,13592,13571,13550,13529,13508,13486,13464,13442,13419,13396,13373,13350,
+13327,13303,13279,13256,13232,13207,13183,13159,13134,13110,13085,13060,13035,13010,12985,12961,12936,12911,12886,12861,
+12836,12811,12786,12761,12736,12711,12687,12663,12638,12614,12590,12566,12542,12518,12494,12471,12447,12424,12401,12379,
+12356,12333,12311,12289,12267,12245,12224,12202,12181,12160,12139,12119,12098,12078,12058,12038,12018,11998,11979,11960,
+11940,11921,11903,11884,11865,11847,11829,11810,11792,11774,11757,11739,11721,11703,11686,11668,11651,11633,11616,11599,
+11581,11564,11546,11529,11512,11494,11477,11459,11441,11423,11406,11388,11369,11351,11333,11314,11295,11276,11257,11238,
+11219,11199,11179,11159,11139,11118,11098,11077,11055,11033,11012,10989,10967,10944,10921,10898,10874,10850,10826,10801,
+10776,10750,10725,10699,10672,10646,10619,10591,10564,10536,10507,10479,10450,10420,10391,10361,10331,10300,10269,10238,
+10206,10175,10143,10110,10078,10045,10012,9979,9946,9912,9878,9844,9810,9776,9741,9707,9672,9637,9602,9567,
+9532,9497,9462,9427,9392,9357,9322,9287,9252,9217,9182,9148,9113,9079,9045,9011,8978,8945,8912,8879,
+8846,8814,8782,8751,8719,8689,8658,8628,8598,8569,8541,8513,8485,8458,8431,8405,8379,8354,8330,8306,
+8283,8260,8239,8217,8197,8177,8158,8139,8121,8104,8088,8072,8057,8043,8030,8017,8005,7994,7984,7974,
+7965,7957,7950,7944,7938,7933,7929,7926,7923,7921,7920,7920,7921,7922,7924,7927,7931,7935,7940,7946,
+7952,7959,7967,7976,7985,7995,8006,8017,8029,8042,8055,8069,8083,8098,8114,8130,8146,8164,8181,8199,
+8218,8237,8256,8276,8296,8317,8338,8360,8381,8403,8426,8449,8472,8495,8518,8542,8566,8590,8614,8639,
+8663,8688,8712,8737,8762,8787,8812,8837,8862,8887,8912,8937,8962,8987,9012,9037,9061,9086,9110,9135,
+9159,9183,9207,9230,9254,9277,9301,9324,9346,9369,9391,9413,9435,9457,9478,9499,9520,9540,9561,9581,
+9601,9620,9639,9658,9677,9695,9713,9731,9749,9766,9783,9800,9816,9832,9848,9864,9879,9895,9910,9924,
+9939,9953,9967,9981,9995,10008,10021,10034,10047,10060,10072,10085,10097,10109,10121,10133,10144,10156,10167,10179,
+10190,10201,10212,10223,10233,10244,10255,10266,10276,10287,10297,10308,10318,10329,10339,10350,10360,10371,10382,10392,
+10403,10414,10424,10435,10446,10457,10468,10479,10490,10501,10512,10523,10534,10545,10557,10568,10580,10591,10603,10615,
+10626,10638,10650,10662,10674,10686,10698,10710,10722,10734,10746,10758,10771,10783,10795,10808,10820,10832,10844,10857,
+10869,10881,10893,10905,10918,10930,10941,10953,10965,10977,10988,11000,11011,11023,11034,11045,11056,11066,11077,11087,
+11098,11108,11117,11127,11136,11146,11155,11163,11172,11180,11188,11196,11204,11211,11218,11225,11231,11237,11243,11249,
+11254,11259,11264,11268,11272,11276,11279,11282,11285,11287,11289,11291,11292,11294,11294,11295,11295,11295,11294,11293,
+11292,11291,11289,11287,11284,11282,11278,11275,11271,11267,11263,11259,11254,11249,11243,11238,11232,11226,11220,11213,
+11206,11199,11192,11185,11177,11170,11162,11154,11146,11137,11129,11120,11112,11103,11094,11085,11076,11067,11058,11049,
+11040,11031,11022,11013,11004,10995,10985,10976,10967,10958,10949,10940,10931,10923,10914,10906,10897,10889,10881,10873,
+10865,10857,10850,10842,10835,10828,10821,10814,10807,10801,10795,10789,10783,10777,10772,10767,10762,10757,10752,10748,
+10744,10740,10736,10732,10729,10725,10722,10719,10717,10714,10712,10710,10708,10706,10704,10702,10701,10700,10698,10697,
+10696,10696,10695,10694,10694,10693,10693,10693,10692,10692,10692,10692,10692,10691,10691,10691,10691,10690,10690,10690,
+10690,10689,10689,10688,10687,10686,10685,10684,10683,10682,10680,10678,10677,10674,10672,10670,10667,10664,10661,10658,
+10654,10650,10646,10642,10638,10633,10628,10622,10617,10611,10604,10598,10591,10584,10577,10569,10561,10553,10544,10535,
+10526,10517,10507,10497,10487,10476,10465,10454,10443,10431,10419,10407,10395,10382,10369,10356,10343,10330,10316,10302,
+10288,10274,10260,10245,10231,10216,10201,10186,10171,10156,10141,10125,10110,10095,10080,10065,10049,10034,10019,10004,
+9989,9975,9960,9945,9931,9917,9903,9889,9876,9863,9850,9837,9824,9812,9800,9789,9778,9767,9756,9746,
+9737,9727,9719,9710,9702,9695,9688,9682,9676,9670,9665,9661,9658,9654,9652,9650,9648,9648,9647,9648,
+9649,9651,9653,9656,9660,9665,9670,9676,9682,9689,9697,9705,9715,9724,9735,9746,9758,9771,9784,9798,
+9812,9827,9843,9860,9877,9895,9913,9933,9952,9973,9994,10015,10037,10060,10084,10107,10132,10157,10182,10208,
+10235,10262,10290,10318,10346,10375,10404,10434,10464,10495,10525,10557,10588,10620,10652,10684,10717,10750,10783,10816,
+10850,10884,10918,10952,10986,11020,11055,11089,11124,11159,11193,11228,11263,11297,11332,11366,11401,11435,11470,11504,
+11538,11572,11606,11640,11673,11707,11740,11773,11806,11838,11870,11903,11934,11966,11997,12028,12059,12089,12119,12149,
+12179,12208,12236,12265,12293,12321,12348,12375,12402,12429,12455,12480,12506,12530,12555,12579,12603,12626,12649,12672,
+12694,12716,12738,12759,12780,12801,12821,12841,12860,12880,12898,12917,12935,12953,12971,12989,13006,13023,13039,13056,
+13072,13087,13103,13118,13134,13148,13163,13178,13192,13206,13220,13233,13247,13260,13273,13286,13299,13312,13325,13337,
+13350,13362,13374,13386,13398,13410,13422,13434,13445,13457,13469,13480,13492,13503,13515,13526,13538,13549,13560,13572,
+13583,13594,13605,13616,13628,13639,13650,13661,13672,13683,13694,13705,13716,13727,13738,13748,13759,13770,13780,13791,
+13802,13812,13822,13833,13843,13853,13863,13873,13883,13893,13902,13912,13921,13930,13939,13948,13957,13965,13974,13982,
+13990,13997,14005,14012,14019,14026,14032,14039,14044,14050,14056,14061,14065,14070,14074,14078,14081,14084,14087,14089,
+14091,14093,14094,14095,14095,14095,14095,14094,14093,14091,14089,14087,14084,14080,14076,14072,14067,14062,14056,14050,
+14043,14036,14028,14020,14011,14002,13993,13983,13973,13962,13950,13939,13926,13914,13900,13887,13873,13858,13843,13828,
+13812,13796,13779,13762,13745,13727,13709,13690,13671,13652,13632,13612,13592,13571,13550,13529,13508,13486,13464,13442,
+13419,13396,13373,13350,13327,13303,13279,13256,13232,13207,13183,13159,13134,13110,13085,13060,13035,13010,12985,12961,
+12936,12911,12886,12861,12836,12811,12786,12761,12736,12711,12687,12663,12638,12614,12590,12566,12542,12518,12494,12471,
+12447,12424,12401,12379,12356,12333,12311,12289,12267,12245,12224,12202,12181,12160,12139,12119,12098,12078,12058,12038,
+12018,11998,11979,11960,11940,11921,11903,11884,11865,11847,11829,11810,11792,11774,11757,11739,11721,11703,11686,11668,
+11651,11633,11616,11599,11581,11564,11546,11529,11512,11494,11477,11459,11441,11423,11406,11388,11369,11351,11333,11314,
+11295,11276,11257,11238,11219,11199,11179,11159,11139,11118,11098,11077,11055,11033,11012,10989,10967,10944,10921,10898,
+10874,10850,10826,10801,10776,10750,10725,10699,10672,10646,10619,10591,10564,10536,10507,10479,10450,10420,10391,10361,
+10331,10300,10269,10238,10206,10175,10143,10110,10078,10045,10012,9979,9946,9912,9878,9844,9810,9776,9741,9707,
+9672,9637,9602,9567,9532,9497,9462,9427,9392,9357,9322,9287,9252,9217,9182,9148,9113,9079,9045,9011,
+8978,8945,8912,8879,8846,8814,8782,8751,8719,8689,8658,8628,8598,8569,8541,8513,8485,8458,8431,8405,
+8379,8354,8330,8306,8283,8260,8239,8217,8197,8177,8158,8139,8121,8104,8088,8072,8057,8043,8030,8017,
+8005,7994,7984,7974,7965,7957,7950,7944,7938,7933,7929,7926,7923,7921,7920,7920,7921,7922,7924,7927,
+7931,7935,7940,7946,7952,7959,7967,7976,7985,7995,8006,8017,8029,8042,8055,8069,8083,8098,8114,8130,
+8146,8164,8181,8199,8218,8237,8256,8276,8296,8317,8338,8360,8381,8403,8426,8449,8472,8495,8518,8542,
+8566,8590,8614,8639,8663,8688,8712,8737,8762,8787,8812,8837,8862,8887,8912,8937,8962,8987,9012,9037,
+9061,9086,9110,9135,9159,9183,9207,9230,9254,9277,9301,9324,9346,9369,9391,9413,9435,9457,9478,9499,
+9520,9540,9561,9581,9601,9620,9639,9658,9677,9695,9713,9731,9749,9766,9783,9800,9816,9832,9848,9864,
+9879,9895,9910,9924,9939,9953,9967,9981,9995,10008,10021,10034,10047,10060,10072,10085,10097,10109,10121,10133,
+10144,10156,10167,10179,10190,10201,10212,10223,10233,10244,10255,10266,10276,10287,10297,10308,10318,10329,10339,10350,
+10360,10371,10382,10392,10403,10414,10424,10435,10446,10457,10468,10479,10490,10501,10512,10523,10534,10545,10557,10568,
+10580,10591,10603,10615,10626,10638,10650,10662,10674,10686,10698,10710,10722,10734,10746,10758,10771,10783,10795,10808,
+10820,10832,10844,10857,10869,10881,10893,10905,10918,10930,10941,10953,10965,10977,10988,11000,11011,11023,11034,11045,
+11056,11066,11077,11087,11098,11108,11117,11127,11136,11146,11155,11163,11172,11180,11188,11196,11204,11211,11218,11225,
+11231,11237,11243,11249,11254,11259,11264,11268,11272,11276,11279,11282,11285,11287,11289,11291,11292,11294,11294,11295,
+11295,11295,11294,11293,11292,11291,11289,11287,11284,11282,11278,11275,
+};