[Python] Cannot understand 'Module' object not callable -cannot understand this error in the...

Discussão em 'Python' iniciado por Stack, Setembro 24, 2024.

  1. Stack

    Stack Membro Participativo

    I am working on a python code involving two cameras(flir and logitech camera) and Iam using usb relay to control light for each of the camera and getting this error inside motion_start. Relay 1 turns on but then the error comes. I have attached the code block where error comes. The Led indicator on camera does turn on

    def motion_start(self):
    check = self.initialize_devices()

    if len(self.devices) < 3:
    print(len(self.devices))
    return None

    self.move(Decimal(self.motion_params.x_cam2), Decimal(self.motion_params.y_cam2), Decimal(self.motion_params.z_cam2))

    relay_controller = RelayApp()
    relay_controller.get_Hid_USBRelay()
    relay_controller.open_device()

    camera_app = SecondaryCameraApp()
    cap = camera_app.initialize_camera()

    try:
    relay_controller.turn_off_all_relays()
    time.sleep(0.5)
    relay_controller.turn_on_relay(1)
    time.sleep(4) # Wait for 4 seconds

    # Capture image using the secondary camera
    frame = camera_app.capture_image(cap)
    transformed_image = camera_app.apply_perspective_transform(frame)

    relay_controller.turn_off_relay(1)
    time.sleep(0.5)
    relay_controller.turn_on_relay(2)
    time.sleep(0.5)
    relay_controller.turn_off_relay(2)

    self.current_data.set_stop_acquisition(False)

    for i in range(self.motion_params.y_steps):
    if self.current_data.get_stop_acquisition():
    print("Acquisition stopped in y loop.")
    break
    y_position = Decimal(self.motion_params.y_start + i * self.motion_params.y_increment)
    print(f"New y_position: {y_position}")

    for j in range(self.motion_params.x_steps):
    if self.current_data.get_stop_acquisition():
    print("Acquisition stopped in x loop.")
    break
    x_position = Decimal(self.motion_params.x_start + j * self.motion_params.x_increment)
    print(f"New x_position: {x_position}")

    if not self.motion_params.optimal_z_movement:
    print(f"Calling z_movement_incremental for x: {x_position}, y: {y_position}")
    self.z_movement_incremental(x_position, y_position, j)
    else:
    print(f"Calling z_movement_optimal for x: {x_position}, y: {y_position}")
    self.z_movement_optimal(x_position, y_position, j)

    if j == 0:
    self.current_data.set_row_start_z(self.current_data.get_best_z())
    print(f"Set row start z to: {self.current_data.get_best_z()}")

    print("Homing")
    self.move(Decimal(0.1), Decimal(0.1), Decimal(0.1))
    print("Homing completed")

    time.sleep(0.1)
    self.update_positions()

    except Exception as e:
    print(f"Error during relay or camera control: {e}")
    return None

    finally:
    cap.release() # Ensure the camera is released
    relay_controller.close_device() # Ensure the relay device is closed



    I had isolated the two classes SecondaryCameraApp and RelayApp in a separate python file with a Controller class then the code runs fine

    Continue reading...

Compartilhe esta Página