eclipse-sumo / sumo

Eclipse SUMO is an open source, highly portable, microscopic and continuous traffic simulation package designed to handle large networks. It allows for intermodal simulation including pedestrians and comes with a large set of tools for scenario creation.
https://eclipse.dev/sumo
Eclipse Public License 2.0
2.49k stars 1.41k forks source link

met an error when i use the function traci.trafficlight.Phase() #15313

Closed sjh30 closed 1 month ago

sjh30 commented 1 month ago

I am trying to use traci function by python in matlab. Here is my code:

% 确保项目路径已添加
projectPath = 'C:\Users\admin\PycharmProjects\pythonforsumo';
if count(py.sys.path, projectPath) == 0
    insert(py.sys.path, int32(0), projectPath);
end

% 显示当前 Python 路径以进行调试
disp('Current Python Path:');
disp(py.sys.path);

% 导入 NumPy 模块
numpy = py.importlib.import_module('numpy');
traci = py.importlib.import_module('traci');

% 确保重新加载模块
% 重新加载模块缓存
py.importlib.invalidate_caches();
sumocfgfile = "D:\sumo\sumoandaladin\sumoandaladin.sumocfg"  ;
% 启动 Traci 仿真 (请根据您的实际配置文件路径更改)
traci.start(py.list({'sumo-gui', '-c', sumocfgfile}));

And i met an error when i use the function: phase1=traci.trafficlight.Phase(py.int(30), "GGGGGrrrrrGGGGGrrrrr", py.int(0), py.int(0), py.list({1}));

Here is the error message: 未识别类 'py.traci._trafficlight.TrafficLightDomain' 的方法、属性或字段 'Phase'。 Which means Did not identify the class 'py. Traci. _trafficlight. TrafficLightDomain' methods, properties, or fields' Phase '.

Can anyone tell me how to solve this problem

**SUMO-version:1.1

**operating system:windows11

m-kro commented 1 month ago

Can you confirm the error for the newest release as well? As you now try to use the python client in MATLAB, you don't need to use an older version like you might have to with outdated traci4matlab.

sjh30 commented 1 month ago

I download the newest version sumo1.20.But the erros is still the same :Did not identify the class 'py. Traci. _trafficlight. TrafficLightDomain' methods, properties, or fields' Phase '.

sjh30 commented 1 month ago

I check the py.traci.trafficlight , the function Phase and Logic are not in it. And Phase is class in trafficlight.py .I dont know whether this is the reason why i cant use the function?

m-kro commented 1 month ago

In either case Phase should be available. In newer releases the class is declared in sumolib.net but imported into _trafficlight.py.

sjh30 commented 1 month ago

But i failed to use the function.I think i have to turn to other solutions. Thank you so much for your help.You really help me a lot!