Tencent / TAD_Sim

腾讯自动驾驶仿真系统 TAD Sim (Tencent Autonomous Driving Simulation) 单机版是腾讯自动驾驶以建立更加安全和高效的自动驾驶测试工具为目标, 为自动驾驶系统研发和验证而量身定做的跨平台分布式系统.
Other
302 stars 84 forks source link

【SDK】SimModule的on_init方法在第一次连接到仿真后没有被回调 #68

Closed XiaoFei9704 closed 1 month ago

XiaoFei9704 commented 2 months ago
  1. 打开TADSim
  2. 打开场景
  3. 运行 python3 my_module.py --name t1,结果如下图,on_init 方法没有被回调
  4. 另外,重置场景后,on_reset也没有被回调
  5. 仿真运行(车跑起来了)的时候,on_step没有被调用
  6. 仿真结束后,on_stop没有被调用
  7. 在容器中运行结果是一样的

是否需要在前端配置自定义模块对应的参数?我没有找到在哪里配置

Screenshot from 2024-09-14 16-25-31

示例代码中写的 on_init 方法在算法第一次连接仿真系统时候被回调 Screenshot from 2024-09-14 16-41-39

dongfeng2134 commented 2 months ago

需要在前端配置自定义模块 1

2

3

XiaoFei9704 commented 2 months ago

@dongfeng2134 谢谢,还有个问题,我开启了动力学模块,然后发送CONTROL_V2消息,接收LOCATION和VEHICLE_STATE消息,但是消息都是空的,为什么呢?

补充1:控制指令是生效的,可以从仿真观察出来。 补充2:试了同样的方法来获取Traffic消息,可以正常获取到 补充3:关闭动力学模块,用Perfect_Control,订阅LOCATION,也收不到任何消息

我的接收消息的代码如下:

`import argparse from txsim_module import * from vehState_pb2 import VehicleState from location_pb2 import Location

VEHICLE_STATE_TOPIC = 'VEHICLE_STATE' LOCATION_TOPIC = 'LOCATION'

class MyModule(SimModule): def init(self): super().init() self.max_step_time = None

def on_init(self, helper):
    print("========== my module on_init called. ==========")
    v = helper.get_parameter('max_step')
    self.max_step_time = 0
    if len(v) > 0:
        self.max_step_time = int(v) * 1000
        print("max step time = {}s".format(v))
    helper.subscribe(VEHICLE_STATE_TOPIC)
    helper.subscribe(LOCATION_TOPIC)
    print(f"{VEHICLE_STATE_TOPIC} subscribed")
    print(f"{LOCATION_TOPIC} subscribed")

def on_reset(self, helper):
    print("========== my module on_reset called. ==========")

def on_step(self, helper):
    t = helper.timestamp()
    msg = helper.get_subscribed_message(VEHICLE_STATE_TOPIC)
    vehicle_state = VehicleState()
    vehicle_state.ParseFromString(msg)
    print('received {} msg: {}'.format(
        VEHICLE_STATE_TOPIC, vehicle_state))

    location_msg = helper.get_subscribed_message(LOCATION_TOPIC)
    location = Location()
    location.ParseFromString(location_msg)
    print('received {} msg: {}'.format(
        LOCATION_TOPIC, location))

    if 0 < self.max_step_time < t:
        helper.stop_scenario("max step time reached!")

def on_stop(self, helper):
    print("========== my module on_stop called. ==========")

if name == 'main': parser = argparse.ArgumentParser() parser.add_argument('--name', required=True) args = parser.parse_args() m = MyModule() s = SimModuleService() s.serve(args.name, m) print("python sim module service exit.") `

songkeke commented 2 months ago

前端也是依靠topic显示的location,得检查是收到的字节是空的,还是因为pb版本问题导致没有反序列化出来