markniu / Bed_Distance_sensor

Auto bed level with High resolution distance sensor
281 stars 27 forks source link

Pi as secondary MCU: segmentation fault on homing Z (G28) #92

Closed CasperVerswijvelt closed 9 months ago

CasperVerswijvelt commented 9 months ago

After banging my head against a wall in #84, I switched to a 32 bit version of MainSailOS, and now I am getting a lot further.

However, when trying to home Z it again gives a segmentation fault in the klipper-mcu process.

Console logs:

21:19 Klipper state: Shutdown
21:19 G28
21:17 BDsensorVer:V1.2 pandapi3d.com ,switch_mode=0,collision_homing=0
21:17 BDSENSOR_VERSION
21:16 0.03mm
21:16 BDSENSOR_DISTANCE
21:16 0.21mm
21:16 BDSENSOR_DISTANCE
21:16 0.84mm
21:16 BDSENSOR_DISTANCE
21:16 10.15mm BDsensor:Out of measure Range or too close to the bed
21:16 BDSENSOR_DISTANCE
21:16 1015
21:16 1015
21:16 1015
21:16 1015
21:16 1015
21:16 957
21:16 957
21:16 957
21:16 950
21:16 939
21:16 930
21:16 915
21:16 902
21:16 887
21:16 872
21:16 860
21:16 841
21:16 824
21:16 809
21:16 788
21:16 769
21:16 748
21:16 728
21:16 704
21:16 682
21:16 659
21:16 632
21:16 609
21:16 579
21:16 553
21:16 524
21:16 497
21:16 467
21:16 437
21:16 406
21:16 376
21:16 346
21:16 317
21:16 299
21:16 290
21:16 BDSENSOR_READ_CALIBRATION
21:16 You can send command BDSENSOR_READ_CALIBRATION to check the calibration data
21:16 Calibrate Finished!
21:15 Please Wait...
21:15 Calibrating, don't power off the printer
21:15 BDsensorVer:V1.2 pandapi3d.com ,switch_mode=0,collision_homing=0
21:15 BDSENSOR_CALIBRATE
21:15 SET_KINEMATIC_POSITION Z=200
Extract from klippy.log ``` Sent 67 1261.469275 1261.468755 13: seq: 12, queue_step oid=3 interval=36000 count=100 add=0 Sent 68 1261.495074 1261.494594 12: seq: 13, trsync_set_timeout oid=5 clock=223038037 Sent 69 1261.519263 1261.518743 13: seq: 14, queue_step oid=3 interval=36000 count=100 add=0 Sent 70 1261.569147 1261.568667 12: seq: 15, trsync_set_timeout oid=5 clock=228438077 Sent 71 1261.570242 1261.569722 13: seq: 16, queue_step oid=3 interval=36000 count=100 add=0 Sent 72 1261.620199 1261.619679 13: seq: 17, queue_step oid=3 interval=36000 count=100 add=0 Sent 73 1261.640865 1261.640545 8: seq: 18, trsync_trigger oid=5 reason=3 Sent 74 1261.642610 1261.642050 14: seq: 19, endstop_home oid=4 clock=0 sample_ticks=0 sample_count=0 rest_ticks=0 pin_value=0 trsync_oid=0 trigger_reason=0 Sent 75 1261.642930 1261.642342 8: seq: 1a, trsync_trigger oid=5 reason=3 Sent 76 1261.648035 1261.647755 7: seq: 1b, stepper_get_position oid=3 Sent 77 1261.653311 1261.653031 7: seq: 1c, endstop_query_state oid=4 Sent 78 1261.658422 1261.658102 8: seq: 1d, reset_step_clock oid=3 clock=0 Sent 79 1261.670155 1261.667715 61: seq: 1e, set_next_step_dir oid=0 dir=0, set_next_step_dir oid=3 dir=1, queue_step oid=3 interval=247224623 count=1 add=0, queue_step oid=3 interval=175940 count=1 add=0, queue_step oid=3 interval=120009 count=2 add=-20422, queue_step oid=3 interval=83770 count=3 add=-11817, queue_step oid=0 interval=247625882 count=1 add=0, queue_step oid=0 interval=138079 count=1 add=0 Sent 80 1261.672675 1261.667715 63: seq: 1f, queue_step oid=0 interval=91243 count=2 add=-21571, queue_step oid=3 interval=55966 count=7 add=-2285, queue_step oid=0 interval=54949 count=5 add=-4742, queue_step oid=0 interval=35416 count=6 add=-1443, queue_step oid=3 interval=40893 count=12 add=-995, queue_step oid=0 interval=29039 count=13 add=-396, queue_step oid=3 interval=30705 count=23 add=-247 Sent 81 1261.675115 1261.672602 61: seq: 10, queue_step oid=0 interval=25147 count=1473 add=0, queue_step oid=3 interval=25778 count=1415 add=0, queue_step oid=3 interval=25777 count=1397 add=0, queue_step oid=0 interval=25146 count=1431 add=0, queue_step oid=0 interval=25146 count=1432 add=0, queue_step oid=3 interval=25777 count=1396 add=0, queue_step oid=3 interval=25778 count=1397 add=0 Sent 82 1261.680024 1261.677584 61: seq: 11, queue_step oid=0 interval=25146 count=1432 add=0, queue_step oid=3 interval=25777 count=1396 add=0, queue_step oid=0 interval=25146 count=1431 add=0, queue_step oid=3 interval=25777 count=1397 add=0, queue_step oid=0 interval=25146 count=1432 add=0, queue_step oid=0 interval=25146 count=1100 add=0, queue_step oid=3 interval=25778 count=1073 add=0 Sent 83 1261.682464 1261.677584 61: seq: 12, queue_step oid=3 interval=25183 count=19 add=418, queue_step oid=0 interval=25178 count=21 add=0, queue_step oid=0 interval=25697 count=12 add=778, queue_step oid=3 interval=33488 count=7 add=1053, queue_step oid=3 interval=42692 count=7 add=2598, queue_step oid=0 interval=37280 count=4 add=4095, queue_step oid=0 interval=55588 count=2 add=14083 Sent 84 1261.686964 1261.684404 64: seq: 13, queue_step oid=3 interval=62972 count=3 add=7074, queue_step oid=0 interval=94000 count=1 add=0, queue_step oid=0 interval=161068 count=1 add=0, queue_step oid=3 interval=86334 count=2 add=29870, queue_step oid=3 interval=153500 count=1 add=0, queue_step oid=3 interval=222950 count=1 add=0, trsync_start oid=7 report_clock=497990142 report_ticks=540000 expire_reason=2, stepper_stop_on_trigger oid=6 trsync_oid=7 Sent 85 1262.176918 1262.176398 13: seq: 14, get_clock, trsync_set_timeout oid=7 clock=499520142 Sent 86 1263.161220 1263.160980 6: seq: 15, get_clock Sent 87 1264.145509 1264.145269 6: seq: 16, get_clock Sent 88 1265.129642 1265.129402 6: seq: 17, get_clock Sent 89 1265.409688 1265.409008 17: seq: 18, set_next_step_dir oid=6 dir=1, queue_step oid=6 interval=776372221 count=1 add=0 Sent 90 1265.460574 1265.458694 47: seq: 19, queue_step oid=6 interval=263539 count=1 add=0, queue_step oid=6 interval=179947 count=2 add=-30962, queue_step oid=6 interval=125824 count=3 add=-10648, queue_step oid=6 interval=94500 count=6 add=-4400, queue_step oid=6 interval=69895 count=9 add=-1908 Sent 91 1265.509978 1265.509138 21: seq: 1a, queue_step oid=6 interval=53974 count=12 add=-929, queue_step oid=6 interval=45012 count=141 add=0 Sent 92 1265.563924 1265.563444 12: seq: 1b, queue_step oid=6 interval=45000 count=80 add=0 Sent 93 1265.585898 1265.585578 8: seq: 1c, trsync_trigger oid=7 reason=3 Sent 94 1265.587480 1265.587000 12: seq: 1d, queue_step oid=6 interval=45068 count=1 add=0 Sent 95 1266.114054 1266.113814 6: seq: 1e, get_clock Sent 96 1267.098862 1267.098622 6: seq: 1f, get_clock Sent 97 1268.083710 1268.083470 6: seq: 10, get_clock Sent 98 1269.068720 1269.068480 6: seq: 11, get_clock Sent 99 1269.717056 1269.716816 6: seq: 12, emergency_stop Dumping receive queue 100 messages Receive: 0 1260.521155 1260.472482 13: seq: 14, trsync_state oid=5 can_trigger=1 trigger_reason=0 clock=135037729 Receive: 1 1260.596552 1260.572436 13: seq: 17, trsync_state oid=5 can_trigger=1 trigger_reason=0 clock=140437715 Receive: 2 1260.671902 1260.622528 13: seq: 19, trsync_state oid=5 can_trigger=1 trigger_reason=0 clock=145837755 Receive: 3 1260.682083 1260.672951 14: seq: 1b, analog_in_state oid=9 next_clock=167643520 value=31505 Receive: 4 1260.731108 1260.722767 14: seq: 1c, analog_in_state oid=14 next_clock=171243520 value=31480 Receive: 5 1260.746260 1260.722767 13: seq: 1c, trsync_state oid=5 can_trigger=1 trigger_reason=0 clock=151237729 Receive: 6 1260.821600 1260.773140 13: seq: 1e, trsync_state oid=5 can_trigger=1 trigger_reason=0 clock=156637729 Receive: 7 1260.897027 1260.872273 13: seq: 11, trsync_state oid=5 can_trigger=1 trigger_reason=0 clock=162037715 Receive: 8 1260.971145 1260.922209 13: seq: 13, trsync_state oid=5 can_trigger=1 trigger_reason=0 clock=167437755 Receive: 9 1260.981470 1260.972405 14: seq: 14, analog_in_state oid=9 next_clock=189243520 value=31506 Receive: 10 1260.993992 1260.972405 13: seq: 14, trsync_state oid=5 can_trigger=0 trigger_reason=1 clock=169043045 Receive: 11 1260.997992 1260.994876 10: seq: 15, trsync_state oid=5 can_trigger=0 trigger_reason=1 clock=0 Receive: 12 1260.998007 1260.996811 10: seq: 17, trsync_state oid=5 can_trigger=0 trigger_reason=1 clock=0 Receive: 13 1261.003227 1261.000685 10: seq: 18, stepper_position oid=3 pos=-9582 Receive: 14 1261.008246 1261.004759 13: seq: 19, endstop_state oid=4 homing=0 next_clock=169057109 pin_value=1 Receive: 15 1261.031187 1261.016092 14: seq: 1c, analog_in_state oid=14 next_clock=192843520 value=31480 Receive: 16 1261.194115 1261.191406 10: seq: 1e, clock clock=183481709 Receive: 17 1261.281647 1261.269406 15: seq: 1f, analog_in_state oid=9 next_clock=210843520 value=31502 Receive: 18 1261.331947 1261.322226 15: seq: 10, analog_in_state oid=14 next_clock=214443520 value=31481 Receive: 19 1261.418503 1261.369304 13: seq: 11, trsync_state oid=5 can_trigger=1 trigger_reason=0 clock=199637961 Receive: 20 1261.493976 1261.469275 14: seq: 13, trsync_state oid=5 can_trigger=1 trigger_reason=0 clock=205038037 Receive: 21 1261.568067 1261.519263 14: seq: 15, trsync_state oid=5 can_trigger=1 trigger_reason=0 clock=210438077 Receive: 22 1261.582020 1261.570242 15: seq: 17, analog_in_state oid=9 next_clock=232443520 value=31504 Receive: 23 1261.631025 1261.620199 15: seq: 18, analog_in_state oid=14 next_clock=236043520 value=31480 Receive: 24 1261.639947 1261.620199 14: seq: 18, trsync_state oid=5 can_trigger=0 trigger_reason=1 clock=215589367 Receive: 25 1261.642575 1261.620199 14: seq: 18, trsync_state oid=5 can_trigger=0 trigger_reason=1 clock=215837921 Receive: 26 1261.642749 1261.640865 10: seq: 19, trsync_state oid=5 can_trigger=0 trigger_reason=1 clock=0 Receive: 27 1261.646592 1261.642930 10: seq: 1b, trsync_state oid=5 can_trigger=0 trigger_reason=1 clock=0 Receive: 28 1261.651723 1261.648035 10: seq: 1c, stepper_position oid=3 pos=-9577 Receive: 29 1261.656696 1261.653311 14: seq: 1d, endstop_state oid=4 homing=0 next_clock=215621431 pin_value=1 Receive: 30 1261.881557 1261.686964 15: seq: 14, analog_in_state oid=9 next_clock=254043520 value=31504 Receive: 31 1261.931671 1261.686964 15: seq: 14, analog_in_state oid=14 next_clock=257643520 value=31480 Receive: 32 1262.181960 1262.176918 11: seq: 15, clock clock=254444610 Receive: 33 1262.181813 1262.176918 15: seq: 15, analog_in_state oid=9 next_clock=275643520 value=31501 Receive: 34 1262.232234 1262.176918 15: seq: 15, analog_in_state oid=14 next_clock=279243520 value=31486 Receive: 35 1262.482123 1262.176918 15: seq: 15, analog_in_state oid=9 next_clock=297243520 value=31505 Receive: 36 1262.530956 1262.176918 15: seq: 15, analog_in_state oid=14 next_clock=300843520 value=31478 Receive: 37 1262.781050 1262.176918 15: seq: 15, analog_in_state oid=9 next_clock=318843520 value=31506 Receive: 38 1262.831206 1262.176918 15: seq: 15, analog_in_state oid=14 next_clock=322443520 value=31479 Receive: 39 1263.081317 1262.176918 15: seq: 15, analog_in_state oid=9 next_clock=340443520 value=31503 Receive: 40 1263.131447 1262.176918 15: seq: 15, analog_in_state oid=14 next_clock=344043520 value=31484 Receive: 41 1263.164207 1263.161220 11: seq: 16, clock clock=325317695 Receive: 42 1263.381706 1263.161220 15: seq: 16, analog_in_state oid=9 next_clock=362043520 value=31506 Receive: 43 1263.431816 1263.161220 15: seq: 16, analog_in_state oid=14 next_clock=365643520 value=31476 Receive: 44 1263.682003 1263.161220 15: seq: 16, analog_in_state oid=9 next_clock=383643520 value=31502 Receive: 45 1263.730861 1263.161220 15: seq: 16, analog_in_state oid=14 next_clock=387243520 value=31479 Receive: 46 1263.980990 1263.161220 15: seq: 16, analog_in_state oid=9 next_clock=405243520 value=31506 Receive: 47 1264.031533 1263.161220 15: seq: 16, analog_in_state oid=14 next_clock=408843520 value=31479 Receive: 48 1264.148837 1264.145509 11: seq: 17, clock clock=396198794 Receive: 49 1264.281339 1264.145509 15: seq: 17, analog_in_state oid=9 next_clock=426843520 value=31501 Receive: 50 1264.331466 1264.145509 15: seq: 17, analog_in_state oid=14 next_clock=430443520 value=31482 Receive: 51 1264.581590 1264.145509 15: seq: 17, analog_in_state oid=9 next_clock=448443520 value=31503 Receive: 52 1264.584153 1264.145509 15: seq: 17, stats count=195 sum=319834 sumsq=2930862 Receive: 53 1264.631852 1264.145509 15: seq: 17, analog_in_state oid=14 next_clock=452043520 value=31480 Receive: 54 1264.880648 1264.145509 15: seq: 17, analog_in_state oid=9 next_clock=470043520 value=31505 Receive: 55 1264.930809 1264.145509 15: seq: 17, analog_in_state oid=14 next_clock=473643520 value=31481 Receive: 56 1265.132307 1265.129642 11: seq: 18, clock clock=467052305 Receive: 57 1265.181013 1265.129642 15: seq: 18, analog_in_state oid=9 next_clock=491643520 value=31502 Receive: 58 1265.231140 1265.129642 15: seq: 18, analog_in_state oid=14 next_clock=495243520 value=31483 Receive: 59 1265.481483 1265.460574 15: seq: 1a, analog_in_state oid=9 next_clock=513243520 value=31501 Receive: 60 1265.531763 1265.509978 15: seq: 1b, analog_in_state oid=14 next_clock=516843520 value=31480 Receive: 61 1265.562068 1265.509978 14: seq: 1b, trsync_state oid=7 can_trigger=1 trigger_reason=0 clock=497990704 Receive: 62 1265.569692 1265.563924 14: seq: 1c, trsync_state oid=7 can_trigger=1 trigger_reason=0 clock=498530702 Receive: 63 1265.577329 1265.563924 14: seq: 1c, trsync_state oid=7 can_trigger=1 trigger_reason=0 clock=499070748 Receive: 64 1265.584961 1265.563924 14: seq: 1c, trsync_state oid=7 can_trigger=0 trigger_reason=2 clock=499520966 Receive: 65 1265.585010 1265.563924 14: seq: 1c, trsync_state oid=7 can_trigger=0 trigger_reason=2 clock=499610704 Receive: 66 1265.590302 1265.585898 10: seq: 1d, trsync_state oid=7 can_trigger=0 trigger_reason=2 clock=0 Receive: 67 1265.781432 1265.587480 15: seq: 1e, analog_in_state oid=9 next_clock=534843520 value=31506 Receive: 68 1265.831533 1265.587480 15: seq: 1e, analog_in_state oid=14 next_clock=538443520 value=31480 Receive: 69 1266.081654 1265.587480 15: seq: 1e, analog_in_state oid=9 next_clock=556443520 value=31504 Receive: 70 1266.116998 1266.114054 11: seq: 1f, clock clock=537935891 Receive: 71 1266.130654 1266.114054 15: seq: 1f, analog_in_state oid=14 next_clock=560043520 value=31480 Receive: 72 1266.380932 1266.114054 15: seq: 1f, analog_in_state oid=9 next_clock=578043520 value=31505 Receive: 73 1266.431049 1266.114054 15: seq: 1f, analog_in_state oid=14 next_clock=581643520 value=31480 Receive: 74 1266.681160 1266.114054 15: seq: 1f, analog_in_state oid=9 next_clock=599643520 value=31505 Receive: 75 1266.731332 1266.114054 15: seq: 1f, analog_in_state oid=14 next_clock=603243520 value=31481 Receive: 76 1266.981411 1266.114054 15: seq: 1f, analog_in_state oid=9 next_clock=621243520 value=31504 Receive: 77 1267.031537 1266.114054 15: seq: 1f, analog_in_state oid=14 next_clock=624843520 value=31482 Receive: 78 1267.101857 1267.098862 11: seq: 10, clock clock=608847971 Receive: 79 1267.280591 1267.098862 15: seq: 10, analog_in_state oid=9 next_clock=642843520 value=31507 Receive: 80 1267.330719 1267.098862 15: seq: 10, analog_in_state oid=14 next_clock=646443520 value=31480 Receive: 81 1267.580892 1267.098862 15: seq: 10, analog_in_state oid=9 next_clock=664443520 value=31504 Receive: 82 1267.630974 1267.098862 15: seq: 10, analog_in_state oid=14 next_clock=668043520 value=31480 Receive: 83 1267.881089 1267.098862 15: seq: 10, analog_in_state oid=9 next_clock=686043520 value=31504 Receive: 84 1267.931188 1267.098862 15: seq: 10, analog_in_state oid=14 next_clock=689643520 value=31480 Receive: 85 1268.086454 1268.083710 11: seq: 11, clock clock=679762067 Receive: 86 1268.181476 1268.083710 15: seq: 11, analog_in_state oid=9 next_clock=707643520 value=31507 Receive: 87 1268.231582 1268.083710 15: seq: 11, analog_in_state oid=14 next_clock=711243520 value=31480 Receive: 88 1268.481718 1268.083710 15: seq: 11, analog_in_state oid=9 next_clock=729243520 value=31505 Receive: 89 1268.530591 1268.083710 15: seq: 11, analog_in_state oid=14 next_clock=732843520 value=31481 Receive: 90 1268.780682 1268.083710 15: seq: 11, analog_in_state oid=9 next_clock=750843520 value=31505 Receive: 91 1268.830797 1268.083710 15: seq: 11, analog_in_state oid=14 next_clock=754443520 value=31480 Receive: 92 1269.072332 1269.068720 11: seq: 12, clock clock=750687107 Receive: 93 1269.081035 1269.068720 15: seq: 12, analog_in_state oid=9 next_clock=772443520 value=31504 Receive: 94 1269.131173 1269.068720 15: seq: 12, analog_in_state oid=14 next_clock=776043520 value=31480 Receive: 95 1269.381323 1269.068720 15: seq: 12, analog_in_state oid=9 next_clock=794043520 value=31504 Receive: 96 1269.431450 1269.068720 15: seq: 12, analog_in_state oid=14 next_clock=797643520 value=31480 Receive: 97 1269.681604 1269.068720 15: seq: 12, analog_in_state oid=9 next_clock=815643520 value=31505 Receive: 98 1269.681665 1269.068720 14: seq: 12, stats count=100 sum=118141 sumsq=772920 Receive: 99 1269.720643 1269.717056 12: seq: 13, shutdown clock=797373085 static_string_id=Command request b'Got EOF when reading from device' Stats 1270.7: gcodein=0 mcu: mcu_awake=0.002 mcu_task_avg=0.000016 mcu_task_stddev=0.000011 bytes_write=10830 bytes_read=43279 bytes_retransmit=0 bytes_invalid=0 send_seq=772 receive_seq=772 retransmit_seq=0 srtt=0.004 rttvar=0.000 rto=0.025 ready_bytes=0 upcoming_bytes=0 freq=72004942 host: mcu_awake=0.006 mcu_task_avg=0.000095 mcu_task_stddev=0.000317 bytes_write=5467 bytes_read=12532 bytes_retransmit=236 bytes_invalid=0 send_seq=696 receive_seq=690 retransmit_seq=696 srtt=0.000 rttvar=0.000 rto=0.400 ready_bytes=0 upcoming_bytes=6 freq=49999772 adj=49996362 heater_bed: target=0 temp=21.3 pwm=0.000 sysload=0.10 cputime=12.931 memavail=610832 print_time=305.455 buffer_time=0.000 print_stall=0 extruder: target=0 temp=21.8 pwm=0.000 Stats 1271.7: gcodein=0 mcu: mcu_awake=0.002 mcu_task_avg=0.000016 mcu_task_stddev=0.000011 bytes_write=10830 bytes_read=43279 bytes_retransmit=0 bytes_invalid=0 send_seq=772 receive_seq=772 retransmit_seq=0 srtt=0.004 rttvar=0.000 rto=0.025 ready_bytes=0 upcoming_bytes=1 freq=72004942 host: mcu_awake=0.006 mcu_task_avg=0.000095 mcu_task_stddev=0.000317 bytes_write=5467 bytes_read=12532 bytes_retransmit=236 bytes_invalid=0 send_seq=696 receive_seq=690 retransmit_seq=696 srtt=0.000 rttvar=0.000 rto=0.400 ready_bytes=0 upcoming_bytes=7 freq=49999772 adj=49996388 heater_bed: target=0 temp=21.3 pwm=0.000 sysload=0.10 cputime=12.946 memavail=608984 print_time=305.455 buffer_time=0.000 print_stall=0 extruder: target=0 temp=21.8 pwm=0.000 Stats 1272.7: gcodein=0 mcu: mcu_awake=0.002 mcu_task_avg=0.000016 mcu_task_stddev=0.000011 bytes_write=10830 bytes_read=43279 bytes_retransmit=0 bytes_invalid=0 send_seq=772 receive_seq=772 retransmit_seq=0 srtt=0.004 rttvar=0.000 rto=0.025 ready_bytes=0 upcoming_bytes=2 freq=72004942 host: mcu_awake=0.006 mcu_task_avg=0.000095 mcu_task_stddev=0.000317 bytes_write=5467 bytes_read=12532 bytes_retransmit=236 bytes_invalid=0 send_seq=696 receive_seq=690 retransmit_seq=696 srtt=0.000 rttvar=0.000 rto=0.400 ready_bytes=0 upcoming_bytes=8 freq=49999772 adj=49996382 heater_bed: target=0 temp=21.3 pwm=0.000 sysload=0.09 cputime=12.959 memavail=608984 print_time=305.455 buffer_time=0.000 print_stall=0 extruder: target=0 temp=21.8 pwm=0.000 Stats 1273.7: gcodein=0 mcu: mcu_awake=0.002 mcu_task_avg=0.000016 mcu_task_stddev=0.000011 bytes_write=10830 bytes_read=43279 bytes_retransmit=0 bytes_invalid=0 send_seq=772 receive_seq=772 retransmit_seq=0 srtt=0.004 rttvar=0.000 rto=0.025 ready_bytes=0 upcoming_bytes=3 freq=72004942 host: mcu_awake=0.006 mcu_task_avg=0.000095 mcu_task_stddev=0.000317 bytes_write=5467 bytes_read=12532 bytes_retransmit=236 bytes_invalid=0 send_seq=696 receive_seq=690 retransmit_seq=696 srtt=0.000 rttvar=0.000 rto=0.400 ready_bytes=0 upcoming_bytes=9 freq=49999772 adj=49996372 heater_bed: target=0 temp=21.3 pwm=0.000 sysload=0.09 cputime=12.974 memavail=607976 print_time=305.455 buffer_time=0.000 print_stall=0 extruder: target=0 temp=21.8 pwm=0.000 Stats 1274.7: gcodein=0 mcu: mcu_awake=0.002 mcu_task_avg=0.000016 mcu_task_stddev=0.000011 bytes_write=10830 bytes_read=43279 bytes_retransmit=0 bytes_invalid=0 send_seq=772 receive_seq=772 retransmit_seq=0 srtt=0.004 rttvar=0.000 rto=0.025 ready_bytes=0 upcoming_bytes=4 freq=72004942 host: mcu_awake=0.006 mcu_task_avg=0.000095 mcu_task_stddev=0.000317 bytes_write=5467 bytes_read=12532 bytes_retransmit=236 bytes_invalid=0 send_seq=696 receive_seq=690 retransmit_seq=696 srtt=0.000 rttvar=0.000 rto=0.400 ready_bytes=0 upcoming_bytes=10 freq=49999772 adj=49996364 heater_bed: target=0 temp=21.3 pwm=0.000 sysload=0.09 cputime=12.986 memavail=607728 print_time=305.455 buffer_time=0.000 print_stall=0 extruder: target=0 temp=21.8 pwm=0.000 ```
printer.cfg ``` # This file contains pin mappings for the Creality CR6-SE with Rev. 4.5.3 Motherboard (Late 2020/2021) as the heater pins changed. # To use this config, during "make menuconfig" select the STM32F103 # with a "28KiB bootloader" and serial (on USART1 PA10/PA9) # communication. # Flash this firmware by copying "out/klipper.bin" to a SD card and # turning on the printer with the card inserted. The firmware # filename must end in ".bin" and must not match the last filename # that was flashed. # See docs/Config_Reference.md for a description of parameters. # The CR-6 stock extruder is defined by default. # Rotation distance is recalculated from the 95 steps/mm in the community firmware - Please always verify whether you actually get the correct extrusion length and adjust if necessary. # When using a BMG or Orbiter extruder uncomment the relevant section and comment out the stock Extruder # To change the BMG extruder to a Nema 14 with 10 tooth pinion change the gear ration from 51:17 to 51:10 # When input Shaper is enabled (uncomment below) the max_accel and max_accel_to_decel values can be increased. Without additional tuning max_accel can be safely increased to 1500 and max_accel_to_decel to 750 [include macros.cfg] [include mainsail.cfg] #[include KAMP_Settings.cfg] #[include adxl.cfg] [stepper_x] step_pin: PB8 dir_pin: !PB7 enable_pin: !PC3 rotation_distance: 40 microsteps: 16 endstop_pin: PC4 position_min: -5 position_endstop: -5 # position_max: 235 # Allow nozzle wipe positions position_max: 255 homing_speed: 50 [stepper_y] step_pin: PB6 dir_pin: PB5 enable_pin: !PC3 rotation_distance: 40 microsteps: 16 endstop_pin: PC5 position_min: -2 position_endstop: -2 position_max: 235 homing_speed: 50 [stepper_z] step_pin: PB4 dir_pin: !PB3 enable_pin: !PC3 rotation_distance: 8 microsteps: 16 endstop_pin: probe:z_virtual_endstop position_min: -1.5 position_max: 250 homing_speed: 4 second_homing_speed: 1 homing_retract_dist: 2.0 [extruder] max_extrude_only_distance: 1000.0 step_pin: PC2 dir_pin: !PB9 enable_pin: !PC3 microsteps: 16 min_extrude_temp: 0 # micro-swiss dual gear extruder (https://www.reddit.com/r/CR6/comments/10u9mdy/comment/j7bx82d/?utm_source=share&utm_medium=web2x&context=3) rotation_distance: 24.62 # stock extruder, stainless steel gear #rotation_distance: 36.87 # Orbiter extruder # gear_ratio: 7.5:1 # rotation_distance: 34.783 # BMG extruder # gear_ratio: 51:17 # rotation_distance: 23.132 # This iso only used for limiting, so put higher for easy nozzle switching nozzle_diameter: 0.600 filament_diameter: 1.750 heater_pin: PB14 sensor_type: EPCOS 100K B57560G104F sensor_pin: PB1 control: pid # tuned for stock hardware with 200 degree Celsius target pid_Kp: 14.32 pid_Ki: 0.81 pid_Kd: 63.12 min_temp: 0 max_temp: 275 # .6 nozzle -> recheck # pressure_advance: 0.096 # .4 nozzlle pressure_advance: 0.32 # Temporary for volumetric flow test max_extrude_cross_section: 20 [heater_bed] heater_pin: PB13 sensor_type: EPCOS 100K B57560G104F sensor_pin: PB0 control: pid # tuned for stock hardware with 50 degree Celsius target pid_Kp: 79.49 pid_Ki: 1.17 pid_Kd: 1349.52 min_temp: 0 max_temp: 120 [fan] pin: PB15 kick_start_time: 0.5 [mcu] serial: /dev/serial/by-id/usb-1a86_USB_Serial-if00-port0 restart_method: command # The rpi microcontroller is used as secondary. # Typically, both the X and Y axes # are connected to the main micro-controller. The rpi microcontroller is used # on non time-critical functions such as enclosure sensors, additional fan or # light sources [mcu host] serial: /tmp/klipper_host_mcu # Before printing the PROBE_CALIBRATE command needs to be issued # to run the probe calibration procedure, described at # docs/Probe_Calibrate.md, to find the correct z_offset. #[probe] #pin: PA4 #x_offset: 0.0 #y_offset: 0.0 ##z_offset: -0.175 #speed: 1 #lift_speed: 5 #samples_tolerance: 0.05 #samples_tolerance_retries: 2 #samples: 3 #activate_gcode: # TARE_PROBE # #[output_pin probe_tare] #pin: !PA5 #value: 1 #[output_pin probe_enable] #pin: PB2 # BED DISTANCE SENSOR [BDsensor] scl_pin:host:gpio17 sda_pin:host:gpio27 #scl_pin: PB12 #sda_pin: PA15 delay: 20 # 20us per pulse, this value should be >=18 but must be below 30 z_offset:0 # this `z_offset` must be set to 0. z_adjust:0.0 # z axis adjustment, replace the z_offset function. within -0.3 to 0.3mm x_offset: -23.5 y_offset: 0 #no_stop_probe: # enable this for fast probe, the toolhead will not stop at the probe point. position_endstop: 0.8 # this value must >0.5, the Z axis will be triggered after it measured the distance is below this value(mm) while homing z, recommend value is 0.5~1.0 #speed:0.8 # this speed only works for the z tilt and PROBE_ACCURACY command. # Disabled since I removed filament sensor for now # [filament_switch_sensor filament_sensor] # pause_on_runout: true # switch_pin: ^!PA7 [output_pin LED_pin] pin: PA6 # DEFAULT [printer] kinematics: cartesian # Originally 350, but bed made loud noise, so lowered this max_velocity: 235 square_corner_velocity: 5 max_z_velocity: 5 max_z_accel: 100 max_accel: 500 max_accel_to_decel: 500 # TWEAKED [printer] # Minimum from recommanded x and y input shaper results # x: 14100 # y: 4400 max_accel: 4400 max_accel_to_decel: 4400 [gcode_arcs] # Creality CR-6 SE specific configuration # The START_PRINT and END_PRINT macro's are called in the slicer start code # Slicer start code: start_print HOTEND_TEMP={material_print_temperature_layer_0} BED_TEMP={material_bed_temperature_layer_0} # Slicer end code: end_print # The end_print sets the part fan to maximum to speed up cooling of the hotend and waits for the hotend and bed to cool below 50 °C. # The end print macro can switch off the printer, this part is commented out as the RPI_MCU needs to be implemneted first. [bed_mesh] algorithm: bicubic # Max velocity of printer, because why not speed: 235 horizontal_move_z: 1 mesh_min: 20,20 mesh_max: 220,220 probe_count: 10,10 fade_start: 1 fade_end: 10 fade_target: 0 [safe_z_home] home_xy_position: 117.5,117.5 z_hop: 10 [force_move] enable_force_move: True [exclude_object] #*# <---------------------- SAVE_CONFIG ----------------------> #*# DO NOT EDIT THIS BLOCK OR BELOW. The contents are auto-generated. #*# #*# [bed_mesh default] #*# version = 1 #*# points = #*# 0.139167, 0.174167, 0.098333, 0.082500, 0.182500, 0.057500, -0.017500, 0.015000, -0.131667, -0.191667 #*# 0.052500, 0.058333, 0.122500, -0.001667, 0.071667, 0.102500, 0.022500, -0.029167, -0.069167, -0.224167 #*# 0.017500, 0.022500, -0.035000, 0.018333, 0.076667, 0.071667, -0.053333, -0.069167, -0.147500, -0.263333 #*# -0.067500, -0.081667, 0.010833, 0.038333, 0.005833, -0.050000, -0.034167, -0.109167, -0.193333, -0.256667 #*# -0.070833, -0.087500, -0.100833, 0.042500, 0.003333, -0.070833, -0.130000, -0.162500, -0.257500, -0.299167 #*# -0.108333, 0.003333, -0.025000, -0.052500, -0.023333, -0.053333, -0.147500, -0.229167, -0.249167, -0.299167 #*# -0.121667, 0.015000, -0.127500, -0.035833, -0.060000, -0.111667, -0.173333, -0.165833, -0.270000, -0.338333 #*# -0.097500, -0.037500, -0.029167, -0.057500, -0.105000, -0.101667, -0.101667, -0.196667, -0.305000, -0.325000 #*# -0.072500, -0.093333, -0.101667, -0.110833, -0.052500, -0.138333, -0.220833, -0.166667, -0.257500, -0.350833 #*# -0.050000, -0.082500, -0.126667, -0.085000, -0.225000, -0.187500, -0.157500, -0.155833, -0.188333, -0.355833 #*# x_count = 10 #*# y_count = 10 #*# mesh_x_pps = 2 #*# mesh_y_pps = 2 #*# algo = bicubic #*# tension = 0.2 #*# min_x = 20.0 #*# max_x = 219.97 #*# min_y = 20.0 #*# max_y = 219.97 #*# #*# [input_shaper] #*# shaper_type_x = zv #*# shaper_freq_x = 99.6 #*# shaper_type_y = mzv #*# shaper_freq_y = 38.6 ```

I checked out other homing related issues like #65 and #57, but not could find anything helpful there. I tried loading a bed mesh before homing, but that does not fix the issue.

Any idea on what could be going on here?

CasperVerswijvelt commented 9 months ago

Added extra logging in most functions as to better see where it might be going wrong

BD_sensor.c

```c // Code for Bed Distance Sensor // Mark yue // This file may be distributed under the terms of the GNU GPLv3 license. #include #include #include "board/gpio.h" #include "board/irq.h" #include "board/misc.h" #include "command.h" #include "sched.h" #include "autoconf.h" // CONFIG_* #include "basecmd.h" // oid_alloc #include "board/gpio.h" // gpio_out_write #include "board/irq.h" // irq_disable #include "board/misc.h" // timer_is_before #include "command.h" // DECL_COMMAND #include "sched.h" // struct timer #include "trsync.h" // trsync_add_signal #define BYTE_CHECK_OK 0x01 #define BYTE_CHECK_ERR 0x00 #define BD_setLow(x) gpio_out_write(x,0) #define BD_setHigh(x) gpio_out_write(x,1) struct endstop { struct timer time; uint32_t rest_time, sample_time, nextwake,pin_num; struct trsync *ts; uint8_t flags, sample_count, trigger_count, trigger_reason; struct gpio_in pin; }; enum { ESF_PIN_HIGH=1<<0, ESF_HOMING=1<<1 }; uint32_t delay_m = 20, homing_pose = 0; int sda_pin = -1, scl_pin = -1, z_ofset = 0; uint16_t BD_Data; uint16_t BD_read_flag=1018,BD_read_lock=0; int switch_mode = 0; //1:in switch mode struct gpio_out sda_gpio, scl_gpio; struct gpio_in sda_gpio_in; static uint_fast8_t endstop_oversample_event(struct timer *t); static struct endstop e ; void BD_i2c_write(unsigned int addr); uint16_t BD_i2c_read(void); int BD_i2c_init(uint32_t _sda,uint32_t _scl, uint32_t delays,uint32_t h_pose,int z_adjust) { output("CASPER DEBUG BD_i2c_init sda=%u scl=%u delays=%u pose=%u adjust=%u 5=%u 6=%u 7=%u",_sda,_scl,delays,h_pose,z_adjust); sda_pin=_sda; scl_pin =_scl; homing_pose = h_pose; z_ofset = z_adjust; if (z_ofset > 500) z_ofset = 0; if(delays>0) delay_m=delays; sda_gpio=gpio_out_setup(sda_pin, 1); scl_gpio=gpio_out_setup(scl_pin, 1); gpio_out_write(sda_gpio, 1); gpio_out_write(scl_gpio, 1); BD_i2c_write(1022); //reset BDsensor return 1; } uint32_t nsecs_to_ticks_bd(uint32_t ns) { //output("CASPER DEBUG nsecs_to_ticks_bd ns=%u",ns); return ns * (CONFIG_CLOCK_FREQ / 1000000); } void ndelay_bd_c(uint32_t nsecs) { //output("CASPER DEBUG ndelay_bd_c nsecs=%u", nsecs); if (CONFIG_MACH_AVR) return; uint32_t end = timer_read_time() + nsecs_to_ticks_bd(nsecs); while (timer_is_before(timer_read_time(), end)) irq_poll(); } void ndelay_bd(uint32_t nsecs) { //output("CASPER DEBUG ndelay_bd nsecs=%u", nsecs); int i=1; while(i--) ndelay_bd_c(nsecs); } unsigned short BD_Add_OddEven(unsigned short send_data) { //output("CASPER DEBUG BD_Add_OddEven send_data=%u ",send_data); unsigned char i; unsigned char n; unsigned short out_data; n =0; for(i=0;i<10;i++){ if(((send_data >>i)&0x01) == 0x01){ n++; } } if((n&0x01) == 0x01){ out_data = send_data | 0x400; } else{ out_data = send_data | 0x00; } return out_data; } unsigned short BD_Check_OddEven(unsigned short rec_data) { //output("CASPER DEBUG BD_Check_OddEven rec_data=%u ",rec_data); unsigned char i; unsigned char n; unsigned char ret; n =0; for(i=0;i<10;i++){ if(((rec_data >>i)&0x01) == 0x01){ n++; } } if((rec_data>>10) == (n&0x01)){ ret = BYTE_CHECK_OK; } else{ ret = BYTE_CHECK_ERR; } return ret; } void BD_I2C_start(void) { output("CASPER DEBUG BD_I2C_start"); sda_gpio=gpio_out_setup(sda_pin, 1); scl_gpio=gpio_out_setup(scl_pin, 1); BD_setHigh(scl_gpio); BD_setHigh(sda_gpio); ndelay_bd(delay_m); BD_setLow(sda_gpio); ndelay_bd(delay_m); BD_setLow(scl_gpio); ndelay_bd(delay_m); } void BD_i2c_stop(void) { output("CASPER DEBUG BD_i2c_stop"); ndelay_bd(delay_m); sda_gpio=gpio_out_setup(sda_pin, 1); BD_setLow(sda_gpio); ndelay_bd(delay_m); scl_gpio=gpio_out_setup(scl_pin, 1); BD_setHigh(scl_gpio); ndelay_bd(delay_m); BD_setHigh(sda_gpio); ndelay_bd(delay_m); } uint16_t BD_i2c_read(void) { output("CASPER DEBUG BD_i2c_read"); uint16_t b = 1024; BD_read_lock=1; BD_I2C_start(); BD_setHigh(sda_gpio); BD_setHigh(scl_gpio); ndelay_bd(delay_m); BD_setLow(scl_gpio); ndelay_bd(delay_m); b = 0; BD_setHigh(sda_gpio); sda_gpio_in=gpio_in_setup(sda_pin, 1); for (unsigned char i = 0; i <= 10; i++) { b <<= 1; ndelay_bd(delay_m); BD_setHigh(scl_gpio); if (gpio_in_read(sda_gpio_in)) b |= 1; ndelay_bd(delay_m); BD_setLow(scl_gpio); } BD_i2c_stop(); if (BD_Check_OddEven(b) && (b & 0x3FF) < 1020){ b = (b & 0x3FF); if(BD_read_flag==1018&&(b<1000)){ b = b - z_ofset; if(b>1024) b=0; } } else b=1024; BD_read_lock=0; return b; } void BD_i2c_write(unsigned int addr) { output("CASPER DEBUG BD_i2c_read addr=%u", addr); BD_I2C_start(); //// write BD_setLow(sda_gpio); BD_setHigh(scl_gpio); ndelay_bd(delay_m*2); BD_setLow(scl_gpio); addr=BD_Add_OddEven(addr); ///write address ndelay_bd(delay_m); for (int i=10; i >=0; i--) { if ((addr>>i)&0x01){ BD_setHigh(sda_gpio); } else BD_setLow(sda_gpio); ndelay_bd(delay_m); BD_setHigh(scl_gpio); ndelay_bd(delay_m*2); BD_setLow(scl_gpio); ndelay_bd(delay_m); } BD_i2c_stop(); } uint32_t INT_to_String(uint32_t BD_z1,uint8_t*data) { output("CASPER DEBUG INT_to_String BD_z1=%u data[0]=%u", BD_z1, data); uint32_t BD_z=BD_z1; uint32_t len=0,j=0; if(BD_z>=1000) { j=BD_z/1000; data[len++] = '0'+j; BD_z-=1000*j; data[len]='0'; data[len+1]='0'; data[len+2]='0'; } if(BD_z>=100) { j=BD_z/100; data[len++] = '0'+j; BD_z-=100*j; data[len]='0'; data[len+1]='0'; } else if(data[len]) len++; if(BD_z>=10) { j=BD_z/10; data[len++] = '0'+j; BD_z-=10*j; data[len]='0'; } else if(data[len]) len++; j=BD_z; data[len++] = '0'+j; data[len]=0; return len; } //for gcode command void command_I2C_BD_receive(uint32_t *args) { output("CASPER DEBUG command_I2C_BD_receive 0=%u 1=%u 2=%u 3=%u 4=%u 5=%u 6=%u 7=%u",args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7]); uint8_t oid = args[0]; uint8_t data[8]; uint16_t BD_z; BD_z=BD_i2c_read();//BD_Data; BD_Data=BD_z; memset(data,0,8); uint32_t len=0,j=0; //same as function itoa() if(BD_z>=1000) { j=BD_z/1000; data[len++] = '0'+j; BD_z-=1000*j; data[len]='0'; data[len+1]='0'; data[len+2]='0'; } if(BD_z>=100) { j=BD_z/100; data[len++] = '0'+j; BD_z-=100*j; data[len]='0'; data[len+1]='0'; } else if(data[len]) len++; if(BD_z>=10) { j=BD_z/10; data[len++] = '0'+j; BD_z-=10*j; data[len]='0'; } else if(data[len]) len++; j=BD_z; data[len++] = '0'+j; sendf("I2C_BD_receive_response oid=%c response=%*s", oid,len,data); } DECL_COMMAND(command_I2C_BD_receive, "I2C_BD_receive oid=%c data=%*s"); void command_I2C_BD_send(uint32_t *args) { output("CASPER DEBUG command_I2C_BD_send 0=%u 1=%u 2=%u 3=%u 4=%u 5=%u 6=%u 7=%u",args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7]); int addr=atoi((char *)args[2]); BD_read_flag=addr; if(addr==1015) return; BD_i2c_write(addr); if (addr==1023) switch_mode=1; else if(addr>1015) switch_mode=0; else if(switch_mode==1){//write switch value sda_gpio_in=gpio_in_setup(sda_pin, 1); BD_setLow(scl_gpio); } } DECL_COMMAND(command_I2C_BD_send, "I2C_BD_send oid=%c data=%*s"); void command_config_I2C_BD(uint32_t *args) { output("CASPER DEBUG command_config_I2C_BD 0=%u 1=%u 2=%u 3=%u 4=%u 5=%u 6=%u 7=%u",args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7]); BD_i2c_init(args[1],args[2],args[3],args[4],args[5]); } DECL_COMMAND(command_config_I2C_BD, "config_I2C_BD oid=%c sda_pin=%u scl_pin=%u" " delay=%u h_pos=%u z_adjust=%u"); int read_endstop_pin(void) { output("CASPER DEBUG read_endstop_pin"); uint16_t tm; tm=BD_i2c_read(); if(tm<1023) BD_Data=tm; else BD_Data=0; if(BD_Data<=homing_pose) BD_Data=0; return BD_Data?0:1; } // Timer callback for an end stop static uint_fast8_t endstop_event(struct timer *t) { output("CASPER DEBUG endstop_event"); uint8_t val =0; if(e.pin_num!=sda_pin) val = gpio_in_read(e.pin); else if (switch_mode == 1){ val = gpio_in_read(sda_gpio_in); } else val = read_endstop_pin(); uint32_t nextwake = e.time.waketime + e.rest_time; if ((val ? ~e.flags : e.flags) & ESF_PIN_HIGH) { // No match - reschedule for the next attempt e.time.waketime = nextwake; return SF_RESCHEDULE; } e.nextwake = nextwake; e.time.func = endstop_oversample_event; return endstop_oversample_event(t); } // Timer callback for an end stop that is sampling extra times static uint_fast8_t endstop_oversample_event(struct timer *t) { output("CASPER DEBUG endstop_oversample_event"); uint8_t val =0; if(e.pin_num!=sda_pin) val = gpio_in_read(e.pin); else if (switch_mode == 1){ val = gpio_in_read(sda_gpio_in); } else{ val = BD_Data?0:1;//read_endstop_pin(); } if ((val ? ~e.flags : e.flags) & ESF_PIN_HIGH) { // No longer matching - reschedule for the next attempt e.time.func = endstop_event; e.time.waketime = e.nextwake; e.trigger_count = e.sample_count; return SF_RESCHEDULE; } uint8_t count = e.trigger_count - 1; if (!count) { trsync_do_trigger(e.ts, e.trigger_reason); return SF_DONE; } e.trigger_count = count; e.time.waketime += e.sample_time; return SF_RESCHEDULE; } // Home an axis void command_BDendstop_home(uint32_t *args) { output("CASPER DEBUG command_BDendstop_home 0=%u 1=%u 2=%u 3=%u 4=%u 5=%u 6=%u 7=%u",args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7]); sched_del_timer(&e.time); e.time.waketime = args[1]; e.sample_time = args[2]; e.sample_count = args[3]; if (!e.sample_count) { // Disable end stop checking e.ts = NULL; e.flags = 0; return; } e.rest_time = args[4]; e.time.func = endstop_event; e.trigger_count = e.sample_count; e.flags = ESF_HOMING | (args[5] ? ESF_PIN_HIGH : 0); e.ts = trsync_oid_lookup(args[6]); e.trigger_reason = args[7]; e.pin_num = args[8]; e.pin = gpio_in_setup(args[8], 1); sched_add_timer(&e.time); } DECL_COMMAND(command_BDendstop_home, "BDendstop_home oid=%c clock=%u sample_ticks=%u sample_count=%c" " rest_ticks=%u pin_value=%c trsync_oid=%c trigger_reason=%c" " endstop_pin=%c"); ```

klippy.log

markniu commented 9 months ago

just fixed this problem. this works well with latest bdsensor firmware that support switch mode, otherwise need to remove the irq_poll in the code. please modify this or update the BD_sensor.c

while (timer_is_before(timer_read_time(), end))
        irq_poll();

to

while (timer_is_before(timer_read_time(), end));
       // irq_poll();
CasperVerswijvelt commented 9 months ago

That fixed it! Thanks for the support!