@@ -55,13 +55,14 @@ def home_a(self, speed = None, direction = None, endposrelease = None, endstoppo
5555 endstoppolarity = endstoppolarity ,
5656 isBlocking = isBlocking )
5757
58- def home (self , axis = None , timeout = None , speed = None , direction = None , endposrelease = None , endstoppolarity = None , endstoptimeout = 10000 , isBlocking = False ):
58+ def home (self , axis = None , timeout = None , speed = None , direction = None , endposrelease = None , endstoppolarity = None , endstoptimeout = 10000 , isBlocking = False , preMove = True ):
5959 '''
6060 axis = 0,1,2,3 or 'A, 'X','Y','Z'
6161 timeout => when to stop homing (it's a while loop on the MCU)
6262 speed => speed of homing (0...15000)
6363 direction => 1,-1 (left/right)
6464 endposrelease => how far to move after homing (0...3000)
65+ preMove => the motor will first move by some steps in the opposite direction before homing, this is useful to avoid false triggering of the endstop
6566 '''
6667
6768 # default values
@@ -79,6 +80,25 @@ def home(self, axis=None, timeout=None, speed=None, direction=None, endposreleas
7980 if direction not in [- 1 ,1 ]:
8081 direction = 1
8182
83+ if preMove :
84+ # first move in the opposite direction
85+ if direction == 1 :
86+ preMoveDirection = - 1
87+ else :
88+ preMoveDirection = 1
89+
90+ # move away from endstop
91+ if axis == 1 or axis == "X" :
92+ self ._parent .motor .move_x (steps = preMoveDirection * 1000 , speed = 10000 , is_blocking = False , is_absolute = False , is_enabled = True )
93+ elif axis == 2 or axis == "Y" :
94+ self ._parent .motor .move_y (steps = preMoveDirection * 1000 , speed = 10000 , is_blocking = False , is_absolute = False , is_enabled = True )
95+ elif axis == 3 or axis == "Z" :
96+ self ._parent .motor .move_z (steps = preMoveDirection * 1000 , speed = 10000 , is_blocking = False , is_absolute = False , is_enabled = True )
97+ elif axis == 0 or axis == "A" :
98+ self ._parent .motor .move_a (steps = preMoveDirection * 1000 , speed = 10000 , is_blocking = False , is_absolute = False , is_enabled = True )
99+ else :
100+ raise ValueError ("Invalid axis. Use 'X', 'Y', 'Z', or 'A'." )
101+ time .sleep (0.5 )
82102 # construct json string
83103 path = "/home_act"
84104
0 commit comments