def iq_module(self, hardware_type, usb_handle):
        hardware_types = {
            "step_dir": iq.StepDirModule,
        }

        if hardware_type not in hardware_types.keys():
            print("THIS TYPE IS NOT HANDLED IN TEST SPEED")
            sys.exit()

        com = iq.SerialCommunicator(usb_handle)
        iq_module = hardware_types[hardware_type](com, 0)

        return iq_module
Ejemplo n.º 2
0
    def iq_module(self, hardware_type, usb_handle):
        hardware_types = {
            "speed": iq.SpeedModule,
        }

        if hardware_type not in hardware_types.keys():
            print("THIS TYPE IS NOT HANDLED IN TEST SPEED")
            sys.exit()

        com = iq.SerialCommunicator(usb_handle)
        iq_module = hardware_types[hardware_type](com, 0)

        # timeout for speed modules
        if hardware_type == "speed":
            iq_module.set("propeller_motor_control", "timeout", 10)

        return iq_module
import iqmotion as iq
import time


if __name__ == "__main__":
    com = iq.SerialCommunicator("/dev/ttyUSB0")
    iq_module = iq.SpeedModule(com, 0)

    MAX_SPEED = 50
    SPEED_STEP = 1

    velocity_to_set = 0
    velocity_sign = 1

    while True:

        # Update velocity direction
        if abs(velocity_to_set) >= MAX_SPEED:
            velocity_sign *= -1

        # Increase velocity
        velocity_to_set += SPEED_STEP * velocity_sign
        iq_module.set("propeller_motor_control", "ctrl_velocity", velocity_to_set)

        # Limit acceleration at a constant rate
        time.sleep(0.2)