Esempio n. 1
0
# Linux address
#device = '/dev/ttyACM0'
# Windows address
#device = 'COM3'

runnum = episode()
pn = PixhawkNode(device)
pn.isactive(True)
# try loop is used to ensure that communication with pixhawk is
# terminated.

try:
    # startup data stream
    pn.isactive(True)
    # change mode
    pn.change_mode('MANUAL')
    motor_out = []
    readtime = []

    total_time = 3  # total collection time, seconds
    run_start = time()
    loop_start = run_start

    while run_start + total_time > loop_start:
        loop_start = time()
        pn.check_readings()
        pn.send_rc(vel_dive=80)
        pn.log(runnum)
        # sleep to maintain constant rate
        pause(loop_start, update_period)
Esempio n. 2
0
pn = PixhawkNode(device)

total_time = 30  # total task time, seconds
target_heading = 80  # random choice
r_P = 3  # proportionality constant for heading correction
r_max = 70  # max rate of turn
r_tol = 5  # if we are within this number of degrees, we have succeeded

# create dictionary of nodes needed for this task
node_dict = {'pn': pn}

# try loop is used to ensure that communication with pixhawk is
# terminated.
try:
    # startup data stream
    pn.isactive(True)
    pn.change_mode('MANUAL')  # change to manual mode

    r_task = constant_r_task(target_heading, r_P, r_max)
    r_succ = constant_r_success(target_heading, r_tol)

    main_loop(node_dict, runnum, total_time, isdone=r_succ, get_r=r_task)
    print('Reached desired heading')

except SerialException:
    print('Pixhawk is not connected to %s' % device)
    raise
finally:
    print('Shutting down communication')
    pn.isactive(False)