Ejemplo n.º 1
0
def main(start_vel, end_vel):
    """
    Performs a step response test and saves the data to a csv.
    """
    test_len = 10  # Length of test in seconds.
    read_frq = 100  # Frequency of reads
    step_time = 1  # Time (in sec) at which to perform step.

    comms = PIC_USB(0x0005)  
    read_period = 1/float(read_frq)

    STEPPED = False
    motor_speed = start_vel[0]
    motor_dir = start_vel[1]
    print("STARTING STEP RESPONSE TEST")
    data = []
    print("\tStarting at speed {}, dir {}".format(motor_speed, motor_dir))
    comms.command_dcmotor(motor_speed, motor_dir)
    test_start_time = time.clock()
    prev_read_quad_time = test_start_time
    prev_quad_counter = comms.get_quad_info()["counter"]
    while time.clock() - test_start_time < test_len:
        read_start = time.clock()
        this_read = {}
        if read_start > step_time and not STEPPED:
            motor_speed = end_vel[0]
            motor_dir = end_vel[1]
            print("\tStepping to speed {}, dir {}".format(motor_speed, motor_dir))
            comms.command_dcmotor(motor_speed, motor_dir)
            STEPPED = True
        read_quad_time = time.clock()
        quad_info = comms.get_quad_info()
        this_read["time"] = read_quad_time
        this_read["motor_speed_cmd"] = motor_speed
        this_read["motor_dir_cmd"] = motor_dir
        this_read["quad_counter"] = quad_info["counter"]
        this_read["quad_overflow"] = quad_info["overflow"]
        this_read["quad_calc_speed"] = abs(quad_info["counter"] - prev_quad_counter) / (read_quad_time - prev_read_quad_time)
        data.append(this_read)
        prev_read_quad_time = read_quad_time
        prev_quad_counter = quad_info["counter"]
        while time.clock() - read_start < read_period:
            pass
    print("\tTest Concluded. Writing data...")

    filename = "step_response_{0[0]}-{0[1]}_to_{1[0]}-{1[1]}".format(start_vel, end_vel)
    headers = ["time", "motor_speed_cmd", "motor_dir_cmd", "quad_counter", "quad_overflow", "quad_calc_speed"]

    with open("data/{}.csv".format(filename), 'wb') as out_data:
        writer = DictWriter(out_data, fieldnames=headers)
        writer.writeheader()
        writer.writerows(data)

    print("\tData saved to \"data/{}.csv\"".format(filename))
    print("ENDING STEP RESPONSE TEST")
Ejemplo n.º 2
0
def main():
    SERVO_MIN = 120
    SERVO_MAX = 450
    SERVO_CENTER = int(((SERVO_MAX - SERVO_MIN)/2.) + SERVO_MIN)
    c = PIC_USB(0x0005)
    c.debug_servo_set_freq(50)
    c.debug_servo_set_pos(4, 300)
Ejemplo n.º 3
0
def main(start_spd, end_spd, steps, direction):
    """
    Performs a motor deadband test, prints the result, and saves the data to a csv.
    """
    read_frq = 300  # Frequency of reads
    settle_period = 2 # Specify time (s) to let motor settle before assessing deadband
    moving_threshold = 10  # Number of ticks/second to consider the motor to have left the deadband

    comms = PIC_USB(0x0005)  
    read_period = 1/float(read_frq)

    motor_speed = start_spd
    motor_dir = direction
    data = []
    prev_read_quad_time = time.clock()
    prev_quad_counter = comms.get_quad_info()["counter"]
    speeds = range(start_spd, end_spd, steps)
    for spd in speeds:
        set_start = time.clock()
        print("\tSetting motor speed to {}.".format(spd))
        comms.command_dcmotor(spd, motor_dir)
        motor_speed = spd

        while time.clock() - set_start < settle_period:
            this_read = {}
            read_start = time.clock()
            quad_info = comms.get_quad_info()
            this_read["time"] = read_start
            this_read["motor_speed_cmd"] = motor_speed
            this_read["motor_dir_cmd"] = motor_dir
            this_read["quad_counter"] = quad_info["counter"]
            this_read["quad_overflow"] = quad_info["overflow"]
            this_read["quad_calc_speed"] = abs(quad_info["counter"] - prev_quad_counter) / (read_start - prev_read_quad_time)
            data.append(this_read)
            prev_read_quad_time = read_start
            prev_quad_counter = quad_info["counter"]
            while time.clock() - read_start < read_period:
                pass
        # After motor has "settled"
        settle_check_time = time.clock()
        quad_info = comms.get_quad_info()
        settle_vel = abs(quad_info["counter"] - prev_quad_counter) / (settle_check_time - prev_read_quad_time)      
        if settle_vel > moving_threshold:
            print("\tDeadband end identified at speed {}.".format(spd))
            break

    print("\tTest Concluded. Writing data...")

    filename = "deadband_{0}-{1}_steps{2}_{3}".format(start_spd, end_spd, steps, direction)
    headers = ["time", "motor_speed_cmd", "motor_dir_cmd", "quad_counter", "quad_overflow", "quad_calc_speed"]

    with open("data/{}.csv".format(filename), 'wb') as out_data:
        writer = DictWriter(out_data, fieldnames=headers)
        writer.writeheader()
        writer.writerows(data)

    print("\tData saved to \"data/{}.csv\"".format(filename))
    print("ENDING DEADBAND TEST")
Ejemplo n.º 4
0
def main():
    print("START")
    loop_time = .01  # How often to run the main loop, in seconds
    while True:
        start_time = time.clock()
        print(chr(27) + "[2J")
        # quad_info()
        try:
            debug_uart_buffers()
            debug_uart_status()

        except Exception, e:
            print "Error occurred. {}".format(e)
            traceback.print_exc()
            print "Retrying..."
            comms = PIC_USB(0x0005)
        while (time.clock() - start_time) < loop_time:
            pass
Ejemplo n.º 5
0
import time
from usb_vendor import PIC_USB
# Product IDs: Master PIC is 0x0004, Rocket PIC is 0x0005, Barge PIC is 0x0006
comms = PIC_USB(0x0004)


def main():
    print("START")
    loop_time = .25  # How often to run the main loop, in seconds
    while True:
        start_time = time.clock()
        # rocket_info()
        debug_uart_buffers()

        while (time.clock() - start_time) < loop_time:
            pass


def rocket_info():
    info = comms.get_rocket_info()
    print "Rocket Tilt {} | Rocket Speed {} | Rocket State {} | Motor Speed {} | Stepper Speed {}".format(
        info["tilt"], info["speed"], info["state"], info["motor_speed"],
        info["stepper_speed"])


def debug_uart_buffers():
    info = comms.debug_uart_buffers()
    rx = info["rx"]
    tx = info["tx"]
    print "TX_head {} | TX_tail {} | TX_count {} || RX_head {} | RX_tail {} | RX_count {}".format(
        tx["head"],
Ejemplo n.º 6
0
def main(start_spd, end_spd, steps, direction):
    """
    Performs a motor deadband test, prints the result, and saves the data to a csv.
    """
    read_frq = 300  # Frequency of reads
    settle_period = 2  # Specify time (s) to let motor settle before assessing deadband
    moving_threshold = 10  # Number of ticks/second to consider the motor to have left the deadband

    comms = PIC_USB(0x0005)
    read_period = 1 / float(read_frq)

    motor_speed = start_spd
    motor_dir = direction
    data = []
    prev_read_quad_time = time.clock()
    prev_quad_counter = comms.get_quad_info()["counter"]
    speeds = range(start_spd, end_spd, steps)
    for spd in speeds:
        set_start = time.clock()
        print("\tSetting motor speed to {}.".format(spd))
        comms.command_dcmotor(spd, motor_dir)
        motor_speed = spd

        while time.clock() - set_start < settle_period:
            this_read = {}
            read_start = time.clock()
            quad_info = comms.get_quad_info()
            this_read["time"] = read_start
            this_read["motor_speed_cmd"] = motor_speed
            this_read["motor_dir_cmd"] = motor_dir
            this_read["quad_counter"] = quad_info["counter"]
            this_read["quad_overflow"] = quad_info["overflow"]
            this_read["quad_calc_speed"] = abs(
                quad_info["counter"] -
                prev_quad_counter) / (read_start - prev_read_quad_time)
            data.append(this_read)
            prev_read_quad_time = read_start
            prev_quad_counter = quad_info["counter"]
            while time.clock() - read_start < read_period:
                pass
        # After motor has "settled"
        settle_check_time = time.clock()
        quad_info = comms.get_quad_info()
        settle_vel = abs(quad_info["counter"] - prev_quad_counter) / (
            settle_check_time - prev_read_quad_time)
        if settle_vel > moving_threshold:
            print("\tDeadband end identified at speed {}.".format(spd))
            break

    print("\tTest Concluded. Writing data...")

    filename = "deadband_{0}-{1}_steps{2}_{3}".format(start_spd, end_spd,
                                                      steps, direction)
    headers = [
        "time", "motor_speed_cmd", "motor_dir_cmd", "quad_counter",
        "quad_overflow", "quad_calc_speed"
    ]

    with open("data/{}.csv".format(filename), 'wb') as out_data:
        writer = DictWriter(out_data, fieldnames=headers)
        writer.writeheader()
        writer.writerows(data)

    print("\tData saved to \"data/{}.csv\"".format(filename))
    print("ENDING DEADBAND TEST")
Ejemplo n.º 7
0
def main(speed, direction):
    comms = PIC_USB(0x0005)
    comms.command_dcmotor(speed, direction)
Ejemplo n.º 8
0
import time
from usb_vendor import PIC_USB

comms = PIC_USB()


def main():
    print("START")
    loop_time = .25  # How often to run the main loop, in seconds
    while True:
        start_time = time.clock()
        rocket_info()

        while (time.clock() - start_time) < loop_time:
            pass


def rocket_info():
    info = comms.get_rocket_info()
    print "Rocket Tilt {} | Rocket Speed {} | Rocket State {}".format(
        info["tilt"], info["speed"], info["state"])


def debug_uart_buffers():
    info = comms.debug_uart_buffers()
    rx = info["rx"]
    tx = info["tx"]
    print "TX_head {} | TX_tail {} | TX_count {} || RX_head {} | RX_tail {} | RX_count {}".format(
        tx["head"],
        tx["tail"],
        tx["count"],
Ejemplo n.º 9
0
def main(start_vel, end_vel):
    """
    Performs a step response test and saves the data to a csv.
    """
    test_len = 10  # Length of test in seconds.
    read_frq = 100  # Frequency of reads
    step_time = 1  # Time (in sec) at which to perform step.

    comms = PIC_USB(0x0005)
    read_period = 1 / float(read_frq)

    STEPPED = False
    motor_speed = start_vel[0]
    motor_dir = start_vel[1]
    print("STARTING STEP RESPONSE TEST")
    data = []
    print("\tStarting at speed {}, dir {}".format(motor_speed, motor_dir))
    comms.command_dcmotor(motor_speed, motor_dir)
    test_start_time = time.clock()
    prev_read_quad_time = test_start_time
    prev_quad_counter = comms.get_quad_info()["counter"]
    while time.clock() - test_start_time < test_len:
        read_start = time.clock()
        this_read = {}
        if read_start > step_time and not STEPPED:
            motor_speed = end_vel[0]
            motor_dir = end_vel[1]
            print("\tStepping to speed {}, dir {}".format(
                motor_speed, motor_dir))
            comms.command_dcmotor(motor_speed, motor_dir)
            STEPPED = True
        read_quad_time = time.clock()
        quad_info = comms.get_quad_info()
        this_read["time"] = read_quad_time
        this_read["motor_speed_cmd"] = motor_speed
        this_read["motor_dir_cmd"] = motor_dir
        this_read["quad_counter"] = quad_info["counter"]
        this_read["quad_overflow"] = quad_info["overflow"]
        this_read["quad_calc_speed"] = abs(
            quad_info["counter"] - prev_quad_counter) / (read_quad_time -
                                                         prev_read_quad_time)
        data.append(this_read)
        prev_read_quad_time = read_quad_time
        prev_quad_counter = quad_info["counter"]
        while time.clock() - read_start < read_period:
            pass
    print("\tTest Concluded. Writing data...")

    filename = "step_response_{0[0]}-{0[1]}_to_{1[0]}-{1[1]}".format(
        start_vel, end_vel)
    headers = [
        "time", "motor_speed_cmd", "motor_dir_cmd", "quad_counter",
        "quad_overflow", "quad_calc_speed"
    ]

    with open("data/{}.csv".format(filename), 'wb') as out_data:
        writer = DictWriter(out_data, fieldnames=headers)
        writer.writeheader()
        writer.writerows(data)

    print("\tData saved to \"data/{}.csv\"".format(filename))
    print("ENDING STEP RESPONSE TEST")
Ejemplo n.º 10
0
def main(speed, direction):
    comms = PIC_USB(0x0005)
    comms.command_dcmotor(speed, direction)