栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

apollo学习之[python脚本练习]---油门刹车标定表生成代码

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

apollo学习之[python脚本练习]---油门刹车标定表生成代码

#!/usr/bin/env python3
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,%sn" %
                        (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,imun")
    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()
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/323786.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号