Closed XiaoFei9704 closed 1 month 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.") `
前端也是依靠topic显示的location,得检查是收到的字节是空的,还是因为pb版本问题导致没有反序列化出来
python3 my_module.py --name t1
,结果如下图,on_init 方法没有被回调是否需要在前端配置自定义模块对应的参数?我没有找到在哪里配置
示例代码中写的 on_init 方法在算法第一次连接仿真系统时候被回调