Category: Hardware
Product Number: TMCM3212
I have connected a optical home sensor(OPB800) and a stepper motor to TMCM3212 module. But when doing the homing procedure, it's not detecting the home position. I am exploiting the reference search function of the module. After starting the reference search, the motor starts rotating continuosly but its not detecting the home sensor. I am quite not sure whether the problem is with the code or the hardware of sensor. Could someone tell me whether it is the right way of doing homing procedure or is anything missing in this code? The code is attached here.
def go_to_home_position(self):
time_out=10
start_time=time.time()
print('Starting homing procedure')
# Set reference speed
self.motor.set_axis_parameter(self.motor.AP.ReferenceSearchSpeed, 10000)
self.motor.set_axis_parameter(self.motor.AP.RefSwitchSpeed, 500)
self.motor.set_axis_parameter(self.motor.AP.ReferenceSearchMode, 7)
initial_status=self.connection.reference_search(command_type=2,motor=0)
print(f'Reference search status initially: {initial_status}')
#Start reference search
self.connection.reference_search(command_type=0,motor=0)
print('Starting reference search')
while True:
status=self.connection.reference_search(command_type=2,motor=0)
print(f'Reference search sts: {status}')
if status == 0:
print('Reference search completed')
self.connection.reference_search(command_type=1,motor=0)
break
time.sleep(0.2)
if time.time() - start_time > time_out:
print("Homing procedure timed out. Stopping the motor.")
self.connection.reference_search(command_type=1,motor=0)
#self.motor.stop()
self.motor.set_axis_parameter(self.motor.AP.ActualPosition, 0)