Exemplo n.º 1
0
def main():
    joystick = init_joystick()

    device = hamr_serial.initialize(port,
                                    baudrate,
                                    timeout_=2,
                                    write_timeout_=2)
    hamr_serial.connect(device)
    time.sleep(1)
    # device.write(b'1')
    # device.write(b'1')

    sig_r_prev = 0
    sig_l_prev = 0
    sig_t_prev = 0

    while (True):
        time.sleep(.1)
        commands = get_readings(joystick, 0)

        # obtain signals
        x = commands[0]  # left/right
        y = -commands[1]  # forward/backward
        theta = commands[2]  # rotation

        # round signals
        sig_r = str(int(y * 10) / 10.0)
        sig_l = str(int(x * 10) / 10.0)
        sig_t = str(int(theta * 10) / 10.0)

        # send data to HAMR
        if (sig_r != sig_r_prev or sig_t != sig_t_prev):
            sending = ""
            if device.is_open:
                sending = "sending:"

                device.write(SIG_R_MOTOR)
                device.write(sig_r)
                time.sleep(.1)

                # uncomment this part to send these signals
                # device.write(SIG_L_MOTOR)
                # device.write(sig_l)
                # time.sleep(.1)

                device.write(SIG_T_MOTOR)
                device.write(sig_t)
                time.sleep(.1)

                sig_r_prev = sig_t
                sig_l_prev = sig_l
                sig_t_prev = sig_r

            print sending + sig_r + ", " + sig_t
Exemplo n.º 2
0
def main():
    joystick = init_joystick()

    device = hamr_serial.initialize(port, baudrate, timeout_=2, write_timeout_=2)
    hamr_serial.connect(device)
    time.sleep(1)
    # device.write(b'1')
    # device.write(b'1')

    sig_r_prev = 0
    sig_l_prev = 0
    sig_t_prev = 0

    while (True):
        time.sleep(.1)
        commands = get_readings(joystick, 0)

        # obtain signals
        x = commands[0]     # left/right
        y = -commands[1]    # forward/backward
        theta = commands[2] # rotation

        # round signals
        sig_r = str(int(y * 10) / 10.0)
        sig_l = str(int(x * 10) / 10.0)
        sig_t = str(int(theta * 10) / 10.0)

        # send data to HAMR
        if(sig_r != sig_r_prev or sig_t != sig_t_prev):
            sending = ""
            if device.is_open:
                sending = "sending:"

                device.write(SIG_R_MOTOR)
                device.write(sig_r)
                time.sleep(.1)

                # uncomment this part to send these signals
                # device.write(SIG_L_MOTOR)
                # device.write(sig_l)
                # time.sleep(.1)

                device.write(SIG_T_MOTOR)
                device.write(sig_t)
                time.sleep(.1)

                sig_r_prev = sig_t
                sig_l_prev = sig_l
                sig_t_prev = sig_r

            print sending + sig_r + ", " + sig_t
Exemplo n.º 3
0
def main():
    global device
    global reading  # while this is true, thread_read is still alive
    global continue_reading  # If this is true, then the thread_read thread will not exit

    # begin setup hamr serial connection
    reading = False     
    device = hamr_serial.initialize(PORT, BAUDRATE, timeout_=.3, write_timeout_=.3)

    # begin joystick thread
    thread_joystick = threading.Thread(target=read_joystick)
    thread_joystick.start()

    # begin animating plot
    anim = animation.FuncAnimation(fig, update_animation, init_func=init_blit, interval=GRAPH_UPDATE_DELAY, blit=BLIT)
    plt.show()

    # program was closed
    continue_reading = False  # tell thread_read to exit
    while reading: pass  # wait until thread_read has finished
    device.close()
    print 'Program Exitted'
Exemplo n.º 4
0
def main():
    global device
    global reading  # while this is true, thread_read is still alive
    global continue_reading  # If this is true, then the thread_read thread will not exit

    # begin setup hamr serial connection
    reading = False
    device = hamr_serial.initialize(PORT, BAUDRATE, timeout_=0.3, write_timeout_=0.3)

    # begin joystick thread
    thread_joystick = threading.Thread(target=read_joystick)
    thread_joystick.start()

    # begin animating plot
    anim = animation.FuncAnimation(fig, update_animation, init_func=init_blit, interval=GRAPH_UPDATE_DELAY, blit=BLIT)
    plt.show()

    # program was closed
    continue_reading = False  # tell thread_read to exit
    while reading:
        pass  # wait until thread_read has finished
    device.close()
    print "Program Exitted"
Exemplo n.º 5
0
def initialize_hamr():
    global device
    device = hamr_serial.initialize(port, baudrate, timeout_=2, write_timeout_=2)
    hamr_serial.connect(device)
    time.sleep(1)