import os
import signal
import sys
import time
import random
def publish_control(file):
print('publish_control.')
write_file(file)
file.close()
print('file closed.')
def write_file(file):
print('write_file.')
for i in range(1,5):
for j in range(1,5):
for k in range(1,5):
radm=random.randint(0,9)
file.write(
"%.4f,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s\n" %
(radm, radm, radm, radm, radm,
radm, radm, radm,radm, radm, radm, radm, radm))
print('........................................................................')
time.sleep(0.1)
def callback_canbus():
print('callback_canbus.')
def callback_localization():
print('callback_localization.')
def signal_handler(signal,frame):
print('signal_handler.')
def __init__():
print('initilized.')
def signal_handler(signal,frame):
print('Control-C pressed.')
def run(cmd):
signal.signal(signal.SIGINT, signal_handler)
print('run.')
cmd = list(map(float, cmd))
out = ''
if cmd[0] > 0:
out += 't'
else:
out += 'b'\
out = out + str(int(cmd[0]))
if cmd[2] > 0:
out += 't'
else:
out += 'b'
out += str(int(cmd[2])) + 'r'
i = 0
outfile = out + str(i) + '_recorded.csv'
while os.path.exists(outfile):
i += 1
outfile = out + str(i) + '_recorded.csv'
file = open(outfile, 'w')
file.write(
"time,io,ctlmode,ctlbrake,ctlthrottle,ctlgear_location," +
"vehicle_speed,engine_rpm,driving_mode,throttle_percentage," +
"brake_percentage,gear_location,imu\n")
publish_control(file)
def main():
"""
Main function
"""
print('Enter q to quit.')
print('Enter p to plot result from last run.')
print('Enter x to remove result from last run.')
print('Enter x y z, where x is acceleration command, ' +
'y is speed limit, z is decceleration command.')
print('Positive number for throttle and negative number for brake.')
cmd = input("Enter commands: ").split()
if len(cmd)==3:
cmd = list(map(float, cmd))
run(cmd)
elif len(cmd) == 1:
print('Plotting result.')
if __name__ == '__main__':
__init__()
time.sleep(1)
main()
|